| 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 | 24 |
| 25 #if !defined(OS_ANDROID) | 25 #if !defined(OS_ANDROID) |
| 26 #include "chrome/browser/bookmarks/scoped_group_bookmark_actions.h" | 26 #include "chrome/browser/bookmarks/scoped_group_bookmark_actions.h" |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 using base::Time; | 29 using base::Time; |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 } | 361 } |
| 362 | 362 |
| 363 void AddIfNotBookmarked(BookmarkModel* model, | 363 void AddIfNotBookmarked(BookmarkModel* model, |
| 364 const GURL& url, | 364 const GURL& url, |
| 365 const base::string16& title) { | 365 const base::string16& title) { |
| 366 std::vector<const BookmarkNode*> bookmarks; | 366 std::vector<const BookmarkNode*> bookmarks; |
| 367 model->GetNodesByURL(url, &bookmarks); | 367 model->GetNodesByURL(url, &bookmarks); |
| 368 if (!bookmarks.empty()) | 368 if (!bookmarks.empty()) |
| 369 return; // Nothing to do, a bookmark with that url already exists. | 369 return; // Nothing to do, a bookmark with that url already exists. |
| 370 | 370 |
| 371 content::RecordAction(base::UserMetricsAction("BookmarkAdded")); | 371 model->client()->RecordAction(base::UserMetricsAction("BookmarkAdded")); |
| 372 const BookmarkNode* parent = model->GetParentForNewNodes(); | 372 const BookmarkNode* parent = model->GetParentForNewNodes(); |
| 373 model->AddURL(parent, parent->child_count(), title, url); | 373 model->AddURL(parent, parent->child_count(), title, url); |
| 374 } | 374 } |
| 375 | 375 |
| 376 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url) { | 376 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url) { |
| 377 std::vector<const BookmarkNode*> bookmarks; | 377 std::vector<const BookmarkNode*> bookmarks; |
| 378 model->GetNodesByURL(url, &bookmarks); | 378 model->GetNodesByURL(url, &bookmarks); |
| 379 | 379 |
| 380 // Remove all the bookmarks. | 380 // Remove all the bookmarks. |
| 381 for (size_t i = 0; i < bookmarks.size(); ++i) { | 381 for (size_t i = 0; i < bookmarks.size(); ++i) { |
| 382 const BookmarkNode* node = bookmarks[i]; | 382 const BookmarkNode* node = bookmarks[i]; |
| 383 int index = node->parent()->GetIndexOf(node); | 383 int index = node->parent()->GetIndexOf(node); |
| 384 if (index > -1) | 384 if (index > -1) |
| 385 model->Remove(node->parent(), index); | 385 model->Remove(node->parent(), index); |
| 386 } | 386 } |
| 387 } | 387 } |
| 388 | 388 |
| 389 } // namespace bookmark_utils | 389 } // namespace bookmark_utils |
| 390 | 390 |
| 391 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { | 391 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { |
| 392 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. | 392 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. |
| 393 return GetNodeByID(model->root_node(), id); | 393 return GetNodeByID(model->root_node(), id); |
| 394 } | 394 } |
| OLD | NEW |