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]); |
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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 void DeleteBookmarkFolders(BookmarkModel* model, | 432 void DeleteBookmarkFolders(BookmarkModel* model, |
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 model->Remove(node); |
443 model->Remove(parent, parent->GetIndexOf(node)); | |
444 } | 443 } |
445 } | 444 } |
446 | 445 |
447 void AddIfNotBookmarked(BookmarkModel* model, | 446 void AddIfNotBookmarked(BookmarkModel* model, |
448 const GURL& url, | 447 const GURL& url, |
449 const base::string16& title) { | 448 const base::string16& title) { |
450 if (IsBookmarkedByUser(model, url)) | 449 if (IsBookmarkedByUser(model, url)) |
451 return; // Nothing to do, a user bookmark with that url already exists. | 450 return; // Nothing to do, a user bookmark with that url already exists. |
452 model->client()->RecordAction(base::UserMetricsAction("BookmarkAdded")); | 451 model->client()->RecordAction(base::UserMetricsAction("BookmarkAdded")); |
453 const BookmarkNode* parent = model->GetParentForNewNodes(); | 452 const BookmarkNode* parent = model->GetParentForNewNodes(); |
454 model->AddURL(parent, parent->child_count(), title, url); | 453 model->AddURL(parent, parent->child_count(), title, url); |
455 } | 454 } |
456 | 455 |
457 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url) { | 456 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url) { |
458 std::vector<const BookmarkNode*> bookmarks; | 457 std::vector<const BookmarkNode*> bookmarks; |
459 model->GetNodesByURL(url, &bookmarks); | 458 model->GetNodesByURL(url, &bookmarks); |
460 | 459 |
461 // Remove all the user bookmarks. | 460 // Remove all the user bookmarks. |
462 for (size_t i = 0; i < bookmarks.size(); ++i) { | 461 for (size_t i = 0; i < bookmarks.size(); ++i) { |
463 const BookmarkNode* node = bookmarks[i]; | 462 const BookmarkNode* node = bookmarks[i]; |
464 int index = node->parent()->GetIndexOf(node); | 463 int index = node->parent()->GetIndexOf(node); |
465 if (index > -1 && model->client()->CanBeEditedByUser(node)) | 464 if (index > -1 && model->client()->CanBeEditedByUser(node)) |
466 model->Remove(node->parent(), index); | 465 model->Remove(node); |
467 } | 466 } |
468 } | 467 } |
469 | 468 |
470 base::string16 CleanUpUrlForMatching( | 469 base::string16 CleanUpUrlForMatching( |
471 const GURL& gurl, | 470 const GURL& gurl, |
472 const std::string& languages, | 471 const std::string& languages, |
473 base::OffsetAdjuster::Adjustments* adjustments) { | 472 base::OffsetAdjuster::Adjustments* adjustments) { |
474 base::OffsetAdjuster::Adjustments tmp_adjustments; | 473 base::OffsetAdjuster::Adjustments tmp_adjustments; |
475 return base::i18n::ToLower(net::FormatUrlWithAdjustments( | 474 return base::i18n::ToLower(net::FormatUrlWithAdjustments( |
476 GURL(TruncateUrl(gurl.spec())), languages, | 475 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, | 513 bool HasDescendantsOf(const std::vector<const BookmarkNode*>& list, |
515 const BookmarkNode* root) { | 514 const BookmarkNode* root) { |
516 for (const BookmarkNode* node : list) { | 515 for (const BookmarkNode* node : list) { |
517 if (IsDescendantOf(node, root)) | 516 if (IsDescendantOf(node, root)) |
518 return true; | 517 return true; |
519 } | 518 } |
520 return false; | 519 return false; |
521 } | 520 } |
522 | 521 |
523 } // namespace bookmarks | 522 } // namespace bookmarks |
OLD | NEW |