| 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/file_path.h" | 10 #include "base/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/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/string16.h" | 14 #include "base/string16.h" |
| 15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
| 16 #include "base/time.h" | 16 #include "base/time.h" |
| 17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "chrome/browser/bookmarks/bookmark_model.h" | 18 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 19 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 19 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 20 #include "chrome/browser/bookmarks/bookmark_node_data.h" | 20 #include "chrome/browser/bookmarks/bookmark_node_data.h" |
| 21 #include "chrome/browser/history/query_parser.h" | 21 #include "chrome/browser/history/query_parser.h" |
| 22 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
| 25 #include "chrome/browser/ui/browser_tabstrip.h" | 25 #include "chrome/browser/ui/browser_tabstrip.h" |
| 26 #include "chrome/browser/ui/simple_message_box.h" | 26 #include "chrome/browser/ui/simple_message_box.h" |
| 27 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 28 #include "content/public/browser/user_metrics.h" |
| 28 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| 29 #include "grit/chromium_strings.h" | 30 #include "grit/chromium_strings.h" |
| 30 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
| 31 #include "grit/ui_strings.h" | 32 #include "grit/ui_strings.h" |
| 32 #include "net/base/net_util.h" | 33 #include "net/base/net_util.h" |
| 33 #include "ui/base/dragdrop/drag_drop_types.h" | 34 #include "ui/base/dragdrop/drag_drop_types.h" |
| 34 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
| 35 #include "ui/base/models/tree_node_iterator.h" | 36 #include "ui/base/models/tree_node_iterator.h" |
| 36 | 37 |
| 37 #if defined(OS_MACOSX) | 38 #if defined(OS_MACOSX) |
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 } | 691 } |
| 691 | 692 |
| 692 void AddIfNotBookmarked(BookmarkModel* model, | 693 void AddIfNotBookmarked(BookmarkModel* model, |
| 693 const GURL& url, | 694 const GURL& url, |
| 694 const string16& title) { | 695 const string16& title) { |
| 695 std::vector<const BookmarkNode*> bookmarks; | 696 std::vector<const BookmarkNode*> bookmarks; |
| 696 model->GetNodesByURL(url, &bookmarks); | 697 model->GetNodesByURL(url, &bookmarks); |
| 697 if (!bookmarks.empty()) | 698 if (!bookmarks.empty()) |
| 698 return; // Nothing to do, a bookmark with that url already exists. | 699 return; // Nothing to do, a bookmark with that url already exists. |
| 699 | 700 |
| 701 content::RecordAction(content::UserMetricsAction("BookmarkAdded")); |
| 700 const BookmarkNode* parent = model->GetParentForNewNodes(); | 702 const BookmarkNode* parent = model->GetParentForNewNodes(); |
| 701 model->AddURL(parent, parent->child_count(), title, url); | 703 model->AddURL(parent, parent->child_count(), title, url); |
| 702 } | 704 } |
| 703 | 705 |
| 704 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url) { | 706 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url) { |
| 705 std::vector<const BookmarkNode*> bookmarks; | 707 std::vector<const BookmarkNode*> bookmarks; |
| 706 model->GetNodesByURL(url, &bookmarks); | 708 model->GetNodesByURL(url, &bookmarks); |
| 707 | 709 |
| 708 // Remove all the bookmarks. | 710 // Remove all the bookmarks. |
| 709 for (size_t i = 0; i < bookmarks.size(); ++i) { | 711 for (size_t i = 0; i < bookmarks.size(); ++i) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 727 void DisableBookmarkBarViewAnimationsForTesting(bool disabled) { | 729 void DisableBookmarkBarViewAnimationsForTesting(bool disabled) { |
| 728 g_bookmark_bar_view_animations_disabled = disabled; | 730 g_bookmark_bar_view_animations_disabled = disabled; |
| 729 } | 731 } |
| 730 | 732 |
| 731 bool IsBookmarkBarViewAnimationsDisabled() { | 733 bool IsBookmarkBarViewAnimationsDisabled() { |
| 732 return g_bookmark_bar_view_animations_disabled; | 734 return g_bookmark_bar_view_animations_disabled; |
| 733 } | 735 } |
| 734 #endif | 736 #endif |
| 735 | 737 |
| 736 } // namespace bookmark_utils | 738 } // namespace bookmark_utils |
| OLD | NEW |