| 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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 } | 381 } |
| 382 | 382 |
| 383 void AddIfNotBookmarked(BookmarkModel* model, | 383 void AddIfNotBookmarked(BookmarkModel* model, |
| 384 const GURL& url, | 384 const GURL& url, |
| 385 const base::string16& title) { | 385 const base::string16& title) { |
| 386 std::vector<const BookmarkNode*> bookmarks; | 386 std::vector<const BookmarkNode*> bookmarks; |
| 387 model->GetNodesByURL(url, &bookmarks); | 387 model->GetNodesByURL(url, &bookmarks); |
| 388 if (!bookmarks.empty()) | 388 if (!bookmarks.empty()) |
| 389 return; // Nothing to do, a bookmark with that url already exists. | 389 return; // Nothing to do, a bookmark with that url already exists. |
| 390 | 390 |
| 391 content::RecordAction(base::UserMetricsAction("BookmarkAdded")); | 391 model->client()->RecordAction(base::UserMetricsAction("BookmarkAdded")); |
| 392 const BookmarkNode* parent = model->GetParentForNewNodes(); | 392 const BookmarkNode* parent = model->GetParentForNewNodes(); |
| 393 model->AddURL(parent, parent->child_count(), title, url); | 393 model->AddURL(parent, parent->child_count(), title, url); |
| 394 } | 394 } |
| 395 | 395 |
| 396 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url) { | 396 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url) { |
| 397 std::vector<const BookmarkNode*> bookmarks; | 397 std::vector<const BookmarkNode*> bookmarks; |
| 398 model->GetNodesByURL(url, &bookmarks); | 398 model->GetNodesByURL(url, &bookmarks); |
| 399 | 399 |
| 400 // Remove all the bookmarks. | 400 // Remove all the bookmarks. |
| 401 for (size_t i = 0; i < bookmarks.size(); ++i) { | 401 for (size_t i = 0; i < bookmarks.size(); ++i) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 418 base::string16 CleanUpTitleForMatching(const base::string16& title) { | 418 base::string16 CleanUpTitleForMatching(const base::string16& title) { |
| 419 return base::i18n::ToLower(title.substr(0u, kCleanedUpTitleMaxLength)); | 419 return base::i18n::ToLower(title.substr(0u, kCleanedUpTitleMaxLength)); |
| 420 } | 420 } |
| 421 | 421 |
| 422 } // namespace bookmark_utils | 422 } // namespace bookmark_utils |
| 423 | 423 |
| 424 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { | 424 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { |
| 425 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. | 425 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. |
| 426 return GetNodeByID(model->root_node(), id); | 426 return GetNodeByID(model->root_node(), id); |
| 427 } | 427 } |
| OLD | NEW |