| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/bookmarks/bookmark_utils.h" | 5 #include "chrome/browser/bookmarks/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/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/i18n/case_conversion.h" | 11 #include "base/i18n/case_conversion.h" |
| 12 #include "base/i18n/string_search.h" | 12 #include "base/i18n/string_search.h" |
| 13 #include "base/metrics/user_metrics_action.h" |
| 13 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 14 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 17 #include "chrome/browser/bookmarks/bookmark_model.h" | 18 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 18 #include "components/bookmarks/core/common/bookmark_pref_names.h" | 19 #include "components/bookmarks/core/common/bookmark_pref_names.h" |
| 19 #include "components/query_parser/query_parser.h" | 20 #include "components/query_parser/query_parser.h" |
| 20 #include "components/user_prefs/pref_registry_syncable.h" | 21 #include "components/user_prefs/pref_registry_syncable.h" |
| 21 #include "content/public/browser/user_metrics.h" | |
| 22 #include "net/base/net_util.h" | 22 #include "net/base/net_util.h" |
| 23 #include "ui/base/models/tree_node_iterator.h" | 23 #include "ui/base/models/tree_node_iterator.h" |
| 24 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 25 | 25 |
| 26 #if !defined(OS_ANDROID) | 26 #if !defined(OS_ANDROID) |
| 27 #include "chrome/browser/bookmarks/scoped_group_bookmark_actions.h" | 27 #include "chrome/browser/bookmarks/scoped_group_bookmark_actions.h" |
| 28 #endif | 28 #endif |
| 29 | 29 |
| 30 using base::Time; | 30 using base::Time; |
| 31 | 31 |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 } | 382 } |
| 383 | 383 |
| 384 void AddIfNotBookmarked(BookmarkModel* model, | 384 void AddIfNotBookmarked(BookmarkModel* model, |
| 385 const GURL& url, | 385 const GURL& url, |
| 386 const base::string16& title) { | 386 const base::string16& title) { |
| 387 std::vector<const BookmarkNode*> bookmarks; | 387 std::vector<const BookmarkNode*> bookmarks; |
| 388 model->GetNodesByURL(url, &bookmarks); | 388 model->GetNodesByURL(url, &bookmarks); |
| 389 if (!bookmarks.empty()) | 389 if (!bookmarks.empty()) |
| 390 return; // Nothing to do, a bookmark with that url already exists. | 390 return; // Nothing to do, a bookmark with that url already exists. |
| 391 | 391 |
| 392 content::RecordAction(base::UserMetricsAction("BookmarkAdded")); | 392 model->client()->RecordAction(base::UserMetricsAction("BookmarkAdded")); |
| 393 const BookmarkNode* parent = model->GetParentForNewNodes(); | 393 const BookmarkNode* parent = model->GetParentForNewNodes(); |
| 394 model->AddURL(parent, parent->child_count(), title, url); | 394 model->AddURL(parent, parent->child_count(), title, url); |
| 395 } | 395 } |
| 396 | 396 |
| 397 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url) { | 397 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url) { |
| 398 std::vector<const BookmarkNode*> bookmarks; | 398 std::vector<const BookmarkNode*> bookmarks; |
| 399 model->GetNodesByURL(url, &bookmarks); | 399 model->GetNodesByURL(url, &bookmarks); |
| 400 | 400 |
| 401 // Remove all the bookmarks. | 401 // Remove all the bookmarks. |
| 402 for (size_t i = 0; i < bookmarks.size(); ++i) { | 402 for (size_t i = 0; i < bookmarks.size(); ++i) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 419 base::string16 CleanUpTitleForMatching(const base::string16& title) { | 419 base::string16 CleanUpTitleForMatching(const base::string16& title) { |
| 420 return base::i18n::ToLower(title.substr(0u, kCleanedUpTitleMaxLength)); | 420 return base::i18n::ToLower(title.substr(0u, kCleanedUpTitleMaxLength)); |
| 421 } | 421 } |
| 422 | 422 |
| 423 } // namespace bookmark_utils | 423 } // namespace bookmark_utils |
| 424 | 424 |
| 425 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { | 425 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { |
| 426 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. | 426 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. |
| 427 return GetNodeByID(model->root_node(), id); | 427 return GetNodeByID(model->root_node(), id); |
| 428 } | 428 } |
| OLD | NEW |