Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: chrome/browser/bookmarks/bookmark_utils.cc

Issue 102713002: Support folders in bookmark search (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/browser/bookmarks/bookmark_utils.h" 5 #include "chrome/browser/bookmarks/bookmark_utils.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 const std::vector<string16>& words, 77 const std::vector<string16>& words,
78 const std::string& languages) { 78 const std::string& languages) {
79 return 79 return
80 DoesBookmarkTextContainWords(node->GetTitle(), words) || 80 DoesBookmarkTextContainWords(node->GetTitle(), words) ||
81 DoesBookmarkTextContainWords(UTF8ToUTF16(node->url().spec()), words) || 81 DoesBookmarkTextContainWords(UTF8ToUTF16(node->url().spec()), words) ||
82 DoesBookmarkTextContainWords(net::FormatUrl( 82 DoesBookmarkTextContainWords(net::FormatUrl(
83 node->url(), languages, net::kFormatUrlOmitNothing, 83 node->url(), languages, net::kFormatUrlOmitNothing,
84 net::UnescapeRule::NORMAL, NULL, NULL, NULL), words); 84 net::UnescapeRule::NORMAL, NULL, NULL, NULL), words);
85 } 85 }
86 86
87 bool IsTopLevel(const BookmarkNode *n1) {
tfarina 2013/12/03 21:19:04 do not use abbreviations. I suggest you change thi
sky 2013/12/03 21:19:07 Use BookmarkModel::is_permanent_node, also, update
88 return n1->type() == n1->BOOKMARK_BAR || n1->type() == n1->OTHER_NODE;
89 }
90
87 } // namespace 91 } // namespace
88 92
89 namespace bookmark_utils { 93 namespace bookmark_utils {
90 94
91 void CloneBookmarkNode(BookmarkModel* model, 95 void CloneBookmarkNode(BookmarkModel* model,
92 const std::vector<BookmarkNodeData::Element>& elements, 96 const std::vector<BookmarkNodeData::Element>& elements,
93 const BookmarkNode* parent, 97 const BookmarkNode* parent,
94 int index_to_add_at, 98 int index_to_add_at,
95 bool reset_node_times) { 99 bool reset_node_times) {
96 if (!parent->is_folder() || !model) { 100 if (!parent->is_folder() || !model) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 std::vector<const BookmarkNode*>* nodes) { 225 std::vector<const BookmarkNode*>* nodes) {
222 std::vector<string16> words; 226 std::vector<string16> words;
223 QueryParser parser; 227 QueryParser parser;
224 parser.ParseQueryWords(base::i18n::ToLower(text), &words); 228 parser.ParseQueryWords(base::i18n::ToLower(text), &words);
225 if (words.empty()) 229 if (words.empty())
226 return; 230 return;
227 231
228 ui::TreeNodeIterator<const BookmarkNode> iterator(model->root_node()); 232 ui::TreeNodeIterator<const BookmarkNode> iterator(model->root_node());
229 while (iterator.has_next()) { 233 while (iterator.has_next()) {
230 const BookmarkNode* node = iterator.Next(); 234 const BookmarkNode* node = iterator.Next();
231 if (DoesBookmarkContainWords(node, words, languages)) { 235 if (DoesBookmarkContainWords(node, words, languages) && !IsTopLevel(node)) {
tfarina 2013/12/03 21:19:04 what if we check is_permanent_node()?
232 nodes->push_back(node); 236 nodes->push_back(node);
233 if (nodes->size() == max_count) 237 if (nodes->size() == max_count)
234 return; 238 return;
235 } 239 }
236 } 240 }
237 } 241 }
238 242
239 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { 243 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
240 registry->RegisterBooleanPref( 244 registry->RegisterBooleanPref(
241 prefs::kShowBookmarkBar, 245 prefs::kShowBookmarkBar,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 // Remove all the bookmarks. 315 // Remove all the bookmarks.
312 for (size_t i = 0; i < bookmarks.size(); ++i) { 316 for (size_t i = 0; i < bookmarks.size(); ++i) {
313 const BookmarkNode* node = bookmarks[i]; 317 const BookmarkNode* node = bookmarks[i];
314 int index = node->parent()->GetIndexOf(node); 318 int index = node->parent()->GetIndexOf(node);
315 if (index > -1) 319 if (index > -1)
316 model->Remove(node->parent(), index); 320 model->Remove(node->parent(), index);
317 } 321 }
318 } 322 }
319 323
320 } // namespace bookmark_utils 324 } // namespace bookmark_utils
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698