Roll src/third_party/WebKit 9f7fb92:f103b33 (svn 202621:202622)
[chromium-blink-merge.git] / components / drive / search_metadata.h
blob26ae88f4f958e67e7eacb61501104b2662a277aa
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_DRIVE_SEARCH_METADATA_H_
6 #define COMPONENTS_DRIVE_SEARCH_METADATA_H_
8 #include <string>
10 #include "base/memory/scoped_vector.h"
11 #include "components/drive/file_system_interface.h"
13 namespace base {
14 namespace i18n {
15 class FixedPatternStringSearchIgnoringCaseAndAccents;
16 } // namespace i18n
17 } // namespace base
19 namespace drive {
20 namespace internal {
22 class ResourceMetadata;
24 typedef base::Callback<bool(const ResourceEntry&)> SearchMetadataPredicate;
26 // Searches the local resource metadata, and returns the entries
27 // |at_most_num_matches| that contain |query| in their base names. Search is
28 // done in a case-insensitive fashion. |query| is splitted into keywords by
29 // whitespace. All keywords are considered as AND condition. The eligible
30 // entries are selected based on the given |options|, which is a bit-wise OR of
31 // SearchMetadataOptions. |callback| must not be null. Must be called on UI
32 // thread. Empty |query| matches any base name. i.e. returns everything.
33 // |blocking_task_runner| must be the same one as |resource_metadata| uses.
34 void SearchMetadata(
35 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner,
36 ResourceMetadata* resource_metadata,
37 const std::string& query,
38 const SearchMetadataPredicate& predicate,
39 size_t at_most_num_matches,
40 const SearchMetadataCallback& callback);
42 // Returns true if |entry| is eligible for the search |options| and should be
43 // tested for the match with the query. If
44 // SEARCH_METADATA_EXCLUDE_HOSTED_DOCUMENTS is requested, the hosted documents
45 // are skipped. If SEARCH_METADATA_EXCLUDE_DIRECTORIES is requested, the
46 // directories are skipped. If SEARCH_METADATA_SHARED_WITH_ME is requested, only
47 // the entries with shared-with-me label will be tested. If
48 // SEARCH_METADATA_OFFLINE is requested, only hosted documents and cached files
49 // match with the query. This option can not be used with other options.
50 bool MatchesType(int options, const ResourceEntry& entry);
52 // Finds |queries| in |text| while ignoring cases or accents. Cases of non-ASCII
53 // characters are also ignored; they are compared in the 'Primary Level' of
54 // http://userguide.icu-project.org/collation/concepts.
55 // Returns true if |queries| are found. |highlighted_text| will have the
56 // original
57 // text with matched portions highlighted with <b> tag (only the first match
58 // is highlighted). Meta characters are escaped like &lt;. The original
59 // contents of |highlighted_text| will be lost.
60 bool FindAndHighlight(
61 const std::string& text,
62 const ScopedVector<
63 base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents>& queries,
64 std::string* highlighted_text);
66 } // namespace internal
67 } // namespace drive
69 #endif // COMPONENTS_DRIVE_SEARCH_METADATA_H_