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

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: Fixed comment and new empty check 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 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 model->Remove(node); 491 model->Remove(node);
492 } 492 }
493 } 493 }
494 494
495 void AddIfNotBookmarked(BookmarkModel* model, 495 void AddIfNotBookmarked(BookmarkModel* model,
496 const GURL& url, 496 const GURL& url,
497 const base::string16& title) { 497 const base::string16& title) {
498 if (IsBookmarkedByUser(model, url)) 498 if (IsBookmarkedByUser(model, url))
499 return; // Nothing to do, a user bookmark with that url already exists. 499 return; // Nothing to do, a user bookmark with that url already exists.
500 model->client()->RecordAction(base::UserMetricsAction("BookmarkAdded")); 500 model->client()->RecordAction(base::UserMetricsAction("BookmarkAdded"));
501 const BookmarkNode* parent = model->GetParentForNewNodes(); 501 const BookmarkNode* parent = GetParentForNewNodes(model);
502 model->AddURL(parent, parent->child_count(), title, url); 502 model->AddURL(parent, parent->child_count(), title, url);
503 } 503 }
504 504
505 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url) { 505 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url) {
506 std::vector<const BookmarkNode*> bookmarks; 506 std::vector<const BookmarkNode*> bookmarks;
507 model->GetNodesByURL(url, &bookmarks); 507 model->GetNodesByURL(url, &bookmarks);
508 508
509 // Remove all the user bookmarks. 509 // Remove all the user bookmarks.
510 for (size_t i = 0; i < bookmarks.size(); ++i) { 510 for (size_t i = 0; i < bookmarks.size(); ++i) {
511 const BookmarkNode* node = bookmarks[i]; 511 const BookmarkNode* node = bookmarks[i];
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 562
563 bool HasDescendantsOf(const std::vector<const BookmarkNode*>& list, 563 bool HasDescendantsOf(const std::vector<const BookmarkNode*>& list,
564 const BookmarkNode* root) { 564 const BookmarkNode* root) {
565 for (const BookmarkNode* node : list) { 565 for (const BookmarkNode* node : list) {
566 if (IsDescendantOf(node, root)) 566 if (IsDescendantOf(node, root))
567 return true; 567 return true;
568 } 568 }
569 return false; 569 return false;
570 } 570 }
571 571
572 bool HasUserCreatedBookmarks(BookmarkModel* model) {
sky 2016/10/11 19:13:39 Move this to anonymous namespace.
kraush 2016/10/11 21:22:39 Will do.
573 const BookmarkNode* root_node = model->root_node();
574
575 for (int i = 0; i < root_node->child_count(); ++i) {
576 const BookmarkNode* node = root_node->GetChild(i);
577 if (node->IsVisible() && model->client()->CanBeEditedByUser(node) &&
sky 2016/10/11 19:13:39 Can't you just check child_count() here?
kraush 2016/10/11 21:22:39 I wanted to be super-safe, but it's probably unnec
578 node->child_count() > 0) {
579 return true;
580 }
581 }
582 return false;
583 }
584
585 const BookmarkNode* GetParentForNewNodes(BookmarkModel* model) {
586 #if defined(OS_ANDROID)
587 if (!HasUserCreatedBookmarks(model)) {
sky 2016/10/11 19:13:39 no {} (see style guide)
kraush 2016/10/11 21:22:39 Removed.
588 return model->mobile_node();
589 }
590 #endif
591 std::vector<const BookmarkNode*> nodes =
592 GetMostRecentlyModifiedUserFolders(model, 1);
593 DCHECK(!nodes.empty()); // This list is always padded with default folders.
594 return nodes[0];
595 }
596
572 } // namespace bookmarks 597 } // 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