Chromium Code Reviews| 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 #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 Loading... | |
| 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 Loading... | |
| 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 const BookmarkNode* GetParentForNewNodes(BookmarkModel* model) { | |
| 573 std::vector<const BookmarkNode*> nodes = | |
| 574 GetMostRecentlyModifiedUserFolders(model, 1); | |
| 575 DCHECK(!nodes.empty()); // This list is always padded with default folders. | |
| 576 #if defined(OS_ANDROID) | |
| 577 // Default cross-platform node. We should instead return the mobile node as | |
| 578 // default on Android. | |
| 579 if (nodes[0] == model->bookmark_bar_node() && nodes[0]->child_count() == 0) { | |
|
sky
2016/10/10 21:02:24
Your check should be more of are all the permance
kraush
2016/10/10 22:18:05
Will do!
I'll iterate over all the children of the
| |
| 580 return model->mobile_node(); | |
| 581 } | |
| 582 #endif | |
| 583 return nodes[0]; | |
| 584 } | |
| 585 | |
| 572 } // namespace bookmarks | 586 } // namespace bookmarks |
| OLD | NEW |