OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_UTILS_H_ | 5 #ifndef COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_UTILS_H_ |
6 #define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_UTILS_H_ | 6 #define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_UTILS_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 void GetMostRecentlyAddedEntries(BookmarkModel* model, | 78 void GetMostRecentlyAddedEntries(BookmarkModel* model, |
79 size_t count, | 79 size_t count, |
80 std::vector<const BookmarkNode*>* nodes); | 80 std::vector<const BookmarkNode*>* nodes); |
81 | 81 |
82 // Returns true if |n1| was added more recently than |n2|. | 82 // Returns true if |n1| was added more recently than |n2|. |
83 bool MoreRecentlyAdded(const BookmarkNode* n1, const BookmarkNode* n2); | 83 bool MoreRecentlyAdded(const BookmarkNode* n1, const BookmarkNode* n2); |
84 | 84 |
85 // Returns up to |max_count| bookmarks from |model| whose url or title contain | 85 // Returns up to |max_count| bookmarks from |model| whose url or title contain |
86 // the text |query.word_phrase_query| and exactly match |query.url| and | 86 // the text |query.word_phrase_query| and exactly match |query.url| and |
87 // |query.title|, for all of the preceding fields that are not NULL. | 87 // |query.title|, for all of the preceding fields that are not NULL. |
88 // |languages| is user's accept-language setting to decode IDN. | |
89 void GetBookmarksMatchingProperties(BookmarkModel* model, | 88 void GetBookmarksMatchingProperties(BookmarkModel* model, |
90 const QueryFields& query, | 89 const QueryFields& query, |
91 size_t max_count, | 90 size_t max_count, |
92 const std::string& languages, | |
93 std::vector<const BookmarkNode*>* nodes); | 91 std::vector<const BookmarkNode*>* nodes); |
94 | 92 |
95 // Register user preferences for Bookmarks Bar. | 93 // Register user preferences for Bookmarks Bar. |
96 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 94 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
97 | 95 |
98 // Register managed bookmarks preferences. | 96 // Register managed bookmarks preferences. |
99 void RegisterManagedBookmarksPrefs(PrefRegistrySimple* registry); | 97 void RegisterManagedBookmarksPrefs(PrefRegistrySimple* registry); |
100 | 98 |
101 // Returns the parent for newly created folders/bookmarks. If |selection| has | 99 // Returns the parent for newly created folders/bookmarks. If |selection| has |
102 // one element and it is a folder, |selection[0]| is returned, otherwise | 100 // one element and it is a folder, |selection[0]| is returned, otherwise |
103 // |parent| is returned. If |index| is non-null it is set to the index newly | 101 // |parent| is returned. If |index| is non-null it is set to the index newly |
104 // added nodes should be added at. | 102 // added nodes should be added at. |
105 const BookmarkNode* GetParentForNewNodes( | 103 const BookmarkNode* GetParentForNewNodes( |
106 const BookmarkNode* parent, | 104 const BookmarkNode* parent, |
107 const std::vector<const BookmarkNode*>& selection, | 105 const std::vector<const BookmarkNode*>& selection, |
108 int* index); | 106 int* index); |
109 | 107 |
110 // Deletes the bookmark folders for the given list of |ids|. | 108 // Deletes the bookmark folders for the given list of |ids|. |
111 void DeleteBookmarkFolders(BookmarkModel* model, | 109 void DeleteBookmarkFolders(BookmarkModel* model, |
112 const std::vector<int64_t>& ids); | 110 const std::vector<int64_t>& ids); |
113 | 111 |
114 // If there are no user bookmarks for url, a bookmark is created. | 112 // If there are no user bookmarks for url, a bookmark is created. |
115 void AddIfNotBookmarked(BookmarkModel* model, | 113 void AddIfNotBookmarked(BookmarkModel* model, |
116 const GURL& url, | 114 const GURL& url, |
117 const base::string16& title); | 115 const base::string16& title); |
118 | 116 |
119 // Removes all bookmarks for the given |url|. | 117 // Removes all bookmarks for the given |url|. |
120 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url); | 118 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url); |
121 | 119 |
122 // Truncates an overly-long URL, unescapes it and interprets the characters | 120 // Truncates an overly-long URL, unescapes it and interprets the |
123 // as UTF-8 (both via url_formatter::FormatUrl()), and lower-cases it, returning | 121 // characters as UTF-8 (both via url_formatter::FormatUrl()), and |
124 // the result. |languages| is passed to url_formatter::FormatUrl(). | 122 // lower-cases it, returning the result. |adjustments|, if non-NULL, is |
125 // |adjustments|, if non-NULL, is set to reflect the transformations the URL | 123 // set to reflect the transformations the URL spec underwent to become the |
126 // spec underwent to become the return value. If a caller computes offsets | 124 // return value. If a caller computes offsets (e.g., for the position |
127 // (e.g., for the position of matched text) in this cleaned-up string, it can | 125 // of matched text) in this cleaned-up string, it can use |adjustments| |
128 // use |adjustments| to calculate the location of these offsets in the original | 126 // to calculate the location of these offsets in the original string |
129 // string (via base::OffsetAdjuster::UnadjustOffsets()). This is useful if | 127 // (via base::OffsetAdjuster::UnadjustOffsets()). This is useful if later |
130 // later the original string gets formatted in a different way for displaying. | 128 // the original string gets formatted in a different way for displaying. |
131 // In this case, knowing the offsets in the original string will allow them to | 129 // In this case, knowing the offsets in the original string will allow them |
132 // be properly translated to offsets in the newly-formatted string. | 130 // to be properly translated to offsets in the newly-formatted string. |
133 // | 131 // |
134 // The unescaping done by this function makes it possible to match substrings | 132 // The unescaping done by this function makes it possible to match substrings |
135 // that were originally escaped for navigation; for example, if the user | 133 // that were originally escaped for navigation; for example, if the user |
136 // searched for "a&p", the query would be escaped as "a%26p", so without | 134 // searched for "a&p", the query would be escaped as "a%26p", so without |
137 // unescaping, an input string of "a&p" would no longer match this URL. Note | 135 // unescaping, an input string of "a&p" would no longer match this URL. Note |
138 // that the resulting unescaped URL may not be directly navigable (which is | 136 // that the resulting unescaped URL may not be directly navigable (which is |
139 // why it was escaped to begin with). | 137 // why it was escaped to begin with). |
140 base::string16 CleanUpUrlForMatching( | 138 base::string16 CleanUpUrlForMatching( |
141 const GURL& gurl, | 139 const GURL& gurl, |
142 const std::string& languages, | |
143 base::OffsetAdjuster::Adjustments* adjustments); | 140 base::OffsetAdjuster::Adjustments* adjustments); |
144 | 141 |
145 // Returns the lower-cased title, possibly truncated if the original title | 142 // Returns the lower-cased title, possibly truncated if the original title |
146 // is overly-long. | 143 // is overly-long. |
147 base::string16 CleanUpTitleForMatching(const base::string16& title); | 144 base::string16 CleanUpTitleForMatching(const base::string16& title); |
148 | 145 |
149 // Returns true if all the |nodes| can be edited by the user, | 146 // Returns true if all the |nodes| can be edited by the user, |
150 // as determined by BookmarkClient::CanBeEditedByUser(). | 147 // as determined by BookmarkClient::CanBeEditedByUser(). |
151 bool CanAllBeEditedByUser(BookmarkClient* client, | 148 bool CanAllBeEditedByUser(BookmarkClient* client, |
152 const std::vector<const BookmarkNode*>& nodes); | 149 const std::vector<const BookmarkNode*>& nodes); |
153 | 150 |
154 // Returns true if |url| has a bookmark in the |model| that can be edited | 151 // Returns true if |url| has a bookmark in the |model| that can be edited |
155 // by the user. | 152 // by the user. |
156 bool IsBookmarkedByUser(BookmarkModel* model, const GURL& url); | 153 bool IsBookmarkedByUser(BookmarkModel* model, const GURL& url); |
157 | 154 |
158 // Returns the node with |id|, or NULL if there is no node with |id|. | 155 // Returns the node with |id|, or NULL if there is no node with |id|. |
159 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64_t id); | 156 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64_t id); |
160 | 157 |
161 // Returns true if |node| is a descendant of |root|. | 158 // Returns true if |node| is a descendant of |root|. |
162 bool IsDescendantOf(const BookmarkNode* node, const BookmarkNode* root); | 159 bool IsDescendantOf(const BookmarkNode* node, const BookmarkNode* root); |
163 | 160 |
164 // Returns true if any node in |list| is a descendant of |root|. | 161 // Returns true if any node in |list| is a descendant of |root|. |
165 bool HasDescendantsOf(const std::vector<const BookmarkNode*>& list, | 162 bool HasDescendantsOf(const std::vector<const BookmarkNode*>& list, |
166 const BookmarkNode* root); | 163 const BookmarkNode* root); |
167 | 164 |
168 } // namespace bookmarks | 165 } // namespace bookmarks |
169 | 166 |
170 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_UTILS_H_ | 167 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_UTILS_H_ |
OLD | NEW |