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

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

Issue 2367533003: Always add bookmarks to the mobile node on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Put new method into ifdef Created 4 years, 2 months 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 | « components/bookmarks/browser/bookmark_utils.h ('k') | 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 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 #include "components/bookmarks/browser/bookmark_utils.h" 5 #include "components/bookmarks/browser/bookmark_utils.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 } 199 }
200 if (query.title && node->GetTitle() != *query.title) 200 if (query.title && node->GetTitle() != *query.title)
201 continue; 201 continue;
202 202
203 nodes->push_back(node); 203 nodes->push_back(node);
204 if (nodes->size() == max_count) 204 if (nodes->size() == max_count)
205 return; 205 return;
206 } 206 }
207 } 207 }
208 208
209 #if defined(OS_ANDROID)
210 // Returns whether or not a bookmark model contains any bookmarks aside of the
211 // permanent nodes.
212 bool HasUserCreatedBookmarks(BookmarkModel* model) {
213 const BookmarkNode* root_node = model->root_node();
214
215 for (int i = 0; i < root_node->child_count(); ++i) {
216 const BookmarkNode* node = root_node->GetChild(i);
217 if (node->child_count() > 0)
218 return true;
219 }
220 return false;
221 }
222 #endif
223
209 } // namespace 224 } // namespace
210 225
211 QueryFields::QueryFields() {} 226 QueryFields::QueryFields() {}
212 QueryFields::~QueryFields() {} 227 QueryFields::~QueryFields() {}
213 228
214 void CloneBookmarkNode(BookmarkModel* model, 229 void CloneBookmarkNode(BookmarkModel* model,
215 const std::vector<BookmarkNodeData::Element>& elements, 230 const std::vector<BookmarkNodeData::Element>& elements,
216 const BookmarkNode* parent, 231 const BookmarkNode* parent,
217 int index_to_add_at, 232 int index_to_add_at,
218 bool reset_node_times) { 233 bool reset_node_times) {
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 model->Remove(node); 506 model->Remove(node);
492 } 507 }
493 } 508 }
494 509
495 void AddIfNotBookmarked(BookmarkModel* model, 510 void AddIfNotBookmarked(BookmarkModel* model,
496 const GURL& url, 511 const GURL& url,
497 const base::string16& title) { 512 const base::string16& title) {
498 if (IsBookmarkedByUser(model, url)) 513 if (IsBookmarkedByUser(model, url))
499 return; // Nothing to do, a user bookmark with that url already exists. 514 return; // Nothing to do, a user bookmark with that url already exists.
500 model->client()->RecordAction(base::UserMetricsAction("BookmarkAdded")); 515 model->client()->RecordAction(base::UserMetricsAction("BookmarkAdded"));
501 const BookmarkNode* parent = model->GetParentForNewNodes(); 516 const BookmarkNode* parent = GetParentForNewNodes(model);
502 model->AddURL(parent, parent->child_count(), title, url); 517 model->AddURL(parent, parent->child_count(), title, url);
503 } 518 }
504 519
505 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url) { 520 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url) {
506 std::vector<const BookmarkNode*> bookmarks; 521 std::vector<const BookmarkNode*> bookmarks;
507 model->GetNodesByURL(url, &bookmarks); 522 model->GetNodesByURL(url, &bookmarks);
508 523
509 // Remove all the user bookmarks. 524 // Remove all the user bookmarks.
510 for (size_t i = 0; i < bookmarks.size(); ++i) { 525 for (size_t i = 0; i < bookmarks.size(); ++i) {
511 const BookmarkNode* node = bookmarks[i]; 526 const BookmarkNode* node = bookmarks[i];
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 577
563 bool HasDescendantsOf(const std::vector<const BookmarkNode*>& list, 578 bool HasDescendantsOf(const std::vector<const BookmarkNode*>& list,
564 const BookmarkNode* root) { 579 const BookmarkNode* root) {
565 for (const BookmarkNode* node : list) { 580 for (const BookmarkNode* node : list) {
566 if (IsDescendantOf(node, root)) 581 if (IsDescendantOf(node, root))
567 return true; 582 return true;
568 } 583 }
569 return false; 584 return false;
570 } 585 }
571 586
587 const BookmarkNode* GetParentForNewNodes(BookmarkModel* model) {
588 #if defined(OS_ANDROID)
589 if (!HasUserCreatedBookmarks(model))
Ian Wen 2016/10/12 17:40:06 This is a bit confusing because even if it is labe
590 return model->mobile_node();
591 #endif
592 std::vector<const BookmarkNode*> nodes =
593 GetMostRecentlyModifiedUserFolders(model, 1);
594 DCHECK(!nodes.empty()); // This list is always padded with default folders.
595 return nodes[0];
596 }
597
572 } // namespace bookmarks 598 } // namespace bookmarks
OLDNEW
« no previous file with comments | « components/bookmarks/browser/bookmark_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698