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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 ++iter) { | 342 ++iter) { |
343 const BookmarkNode* node = model->GetNodeByID(*iter); | 343 const BookmarkNode* node = model->GetNodeByID(*iter); |
344 if (!node) | 344 if (!node) |
345 continue; | 345 continue; |
346 const BookmarkNode* parent = node->parent(); | 346 const BookmarkNode* parent = node->parent(); |
347 model->Remove(parent, parent->GetIndexOf(node)); | 347 model->Remove(parent, parent->GetIndexOf(node)); |
348 } | 348 } |
349 } | 349 } |
350 | 350 |
351 void AddIfNotBookmarked(BookmarkModel* model, | 351 void AddIfNotBookmarked(BookmarkModel* model, |
| 352 BookmarkClient* client, |
352 const GURL& url, | 353 const GURL& url, |
353 const base::string16& title) { | 354 const base::string16& title) { |
354 std::vector<const BookmarkNode*> bookmarks; | 355 std::vector<const BookmarkNode*> bookmarks; |
355 model->GetNodesByURL(url, &bookmarks); | 356 model->GetNodesByURL(url, &bookmarks); |
356 if (!bookmarks.empty()) | 357 if (!bookmarks.empty()) |
357 return; // Nothing to do, a bookmark with that url already exists. | 358 return; // Nothing to do, a bookmark with that url already exists. |
358 | 359 |
359 content::RecordAction(base::UserMetricsAction("BookmarkAdded")); | 360 client->RecordAction(base::UserMetricsAction("BookmarkAdded")); |
360 const BookmarkNode* parent = model->GetParentForNewNodes(); | 361 const BookmarkNode* parent = model->GetParentForNewNodes(); |
361 model->AddURL(parent, parent->child_count(), title, url); | 362 model->AddURL(parent, parent->child_count(), title, url); |
362 } | 363 } |
363 | 364 |
364 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url) { | 365 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url) { |
365 std::vector<const BookmarkNode*> bookmarks; | 366 std::vector<const BookmarkNode*> bookmarks; |
366 model->GetNodesByURL(url, &bookmarks); | 367 model->GetNodesByURL(url, &bookmarks); |
367 | 368 |
368 // Remove all the bookmarks. | 369 // Remove all the bookmarks. |
369 for (size_t i = 0; i < bookmarks.size(); ++i) { | 370 for (size_t i = 0; i < bookmarks.size(); ++i) { |
370 const BookmarkNode* node = bookmarks[i]; | 371 const BookmarkNode* node = bookmarks[i]; |
371 int index = node->parent()->GetIndexOf(node); | 372 int index = node->parent()->GetIndexOf(node); |
372 if (index > -1) | 373 if (index > -1) |
373 model->Remove(node->parent(), index); | 374 model->Remove(node->parent(), index); |
374 } | 375 } |
375 } | 376 } |
376 | 377 |
377 } // namespace bookmark_utils | 378 } // namespace bookmark_utils |
OLD | NEW |