| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 filtered_nodes.push_back(nodes[i]); | 197 filtered_nodes.push_back(nodes[i]); |
| 198 | 198 |
| 199 BookmarkNodeData(filtered_nodes). | 199 BookmarkNodeData(filtered_nodes). |
| 200 WriteToClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE); | 200 WriteToClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE); |
| 201 | 201 |
| 202 if (remove_nodes) { | 202 if (remove_nodes) { |
| 203 ScopedGroupBookmarkActions group_cut(model); | 203 ScopedGroupBookmarkActions group_cut(model); |
| 204 for (size_t i = 0; i < filtered_nodes.size(); ++i) { | 204 for (size_t i = 0; i < filtered_nodes.size(); ++i) { |
| 205 int index = filtered_nodes[i]->parent()->GetIndexOf(filtered_nodes[i]); | 205 int index = filtered_nodes[i]->parent()->GetIndexOf(filtered_nodes[i]); |
| 206 if (index > -1) | 206 if (index > -1) |
| 207 model->Remove(filtered_nodes[i]->parent(), index); | 207 model->Remove(filtered_nodes[i]->parent(), filtered_nodes[i]); |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 } | 210 } |
| 211 | 211 |
| 212 // Updates |title| such that |url| and |title| pair are unique among the | 212 // Updates |title| such that |url| and |title| pair are unique among the |
| 213 // children of |parent|. | 213 // children of |parent|. |
| 214 void MakeTitleUnique(const BookmarkModel* model, | 214 void MakeTitleUnique(const BookmarkModel* model, |
| 215 const BookmarkNode* parent, | 215 const BookmarkNode* parent, |
| 216 const GURL& url, | 216 const GURL& url, |
| 217 base::string16* title) { | 217 base::string16* title) { |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 const std::vector<int64>& ids) { | 433 const std::vector<int64>& ids) { |
| 434 // Remove the folders that were removed. This has to be done after all the | 434 // Remove the folders that were removed. This has to be done after all the |
| 435 // other changes have been committed. | 435 // other changes have been committed. |
| 436 for (std::vector<int64>::const_iterator iter = ids.begin(); | 436 for (std::vector<int64>::const_iterator iter = ids.begin(); |
| 437 iter != ids.end(); | 437 iter != ids.end(); |
| 438 ++iter) { | 438 ++iter) { |
| 439 const BookmarkNode* node = GetBookmarkNodeByID(model, *iter); | 439 const BookmarkNode* node = GetBookmarkNodeByID(model, *iter); |
| 440 if (!node) | 440 if (!node) |
| 441 continue; | 441 continue; |
| 442 const BookmarkNode* parent = node->parent(); | 442 const BookmarkNode* parent = node->parent(); |
| 443 model->Remove(parent, parent->GetIndexOf(node)); | 443 model->Remove(parent, node); |
| 444 } | 444 } |
| 445 } | 445 } |
| 446 | 446 |
| 447 void AddIfNotBookmarked(BookmarkModel* model, | 447 void AddIfNotBookmarked(BookmarkModel* model, |
| 448 const GURL& url, | 448 const GURL& url, |
| 449 const base::string16& title) { | 449 const base::string16& title) { |
| 450 if (IsBookmarkedByUser(model, url)) | 450 if (IsBookmarkedByUser(model, url)) |
| 451 return; // Nothing to do, a user bookmark with that url already exists. | 451 return; // Nothing to do, a user bookmark with that url already exists. |
| 452 model->client()->RecordAction(base::UserMetricsAction("BookmarkAdded")); | 452 model->client()->RecordAction(base::UserMetricsAction("BookmarkAdded")); |
| 453 const BookmarkNode* parent = model->GetParentForNewNodes(); | 453 const BookmarkNode* parent = model->GetParentForNewNodes(); |
| 454 model->AddURL(parent, parent->child_count(), title, url); | 454 model->AddURL(parent, parent->child_count(), title, url); |
| 455 } | 455 } |
| 456 | 456 |
| 457 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url) { | 457 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url) { |
| 458 std::vector<const BookmarkNode*> bookmarks; | 458 std::vector<const BookmarkNode*> bookmarks; |
| 459 model->GetNodesByURL(url, &bookmarks); | 459 model->GetNodesByURL(url, &bookmarks); |
| 460 | 460 |
| 461 // Remove all the user bookmarks. | 461 // Remove all the user bookmarks. |
| 462 for (size_t i = 0; i < bookmarks.size(); ++i) { | 462 for (size_t i = 0; i < bookmarks.size(); ++i) { |
| 463 const BookmarkNode* node = bookmarks[i]; | 463 const BookmarkNode* node = bookmarks[i]; |
| 464 int index = node->parent()->GetIndexOf(node); | 464 int index = node->parent()->GetIndexOf(node); |
| 465 if (index > -1 && model->client()->CanBeEditedByUser(node)) | 465 if (index > -1 && model->client()->CanBeEditedByUser(node)) |
| 466 model->Remove(node->parent(), index); | 466 model->Remove(node->parent(), node); |
| 467 } | 467 } |
| 468 } | 468 } |
| 469 | 469 |
| 470 base::string16 CleanUpUrlForMatching( | 470 base::string16 CleanUpUrlForMatching( |
| 471 const GURL& gurl, | 471 const GURL& gurl, |
| 472 const std::string& languages, | 472 const std::string& languages, |
| 473 base::OffsetAdjuster::Adjustments* adjustments) { | 473 base::OffsetAdjuster::Adjustments* adjustments) { |
| 474 base::OffsetAdjuster::Adjustments tmp_adjustments; | 474 base::OffsetAdjuster::Adjustments tmp_adjustments; |
| 475 return base::i18n::ToLower(net::FormatUrlWithAdjustments( | 475 return base::i18n::ToLower(net::FormatUrlWithAdjustments( |
| 476 GURL(TruncateUrl(gurl.spec())), languages, | 476 GURL(TruncateUrl(gurl.spec())), languages, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 bool HasDescendantsOf(const std::vector<const BookmarkNode*>& list, | 514 bool HasDescendantsOf(const std::vector<const BookmarkNode*>& list, |
| 515 const BookmarkNode* root) { | 515 const BookmarkNode* root) { |
| 516 for (const BookmarkNode* node : list) { | 516 for (const BookmarkNode* node : list) { |
| 517 if (IsDescendantOf(node, root)) | 517 if (IsDescendantOf(node, root)) |
| 518 return true; | 518 return true; |
| 519 } | 519 } |
| 520 return false; | 520 return false; |
| 521 } | 521 } |
| 522 | 522 |
| 523 } // namespace bookmarks | 523 } // namespace bookmarks |
| OLD | NEW |