Index: chrome/browser/bookmarks/chrome_bookmark_client.cc |
diff --git a/chrome/browser/bookmarks/chrome_bookmark_client.cc b/chrome/browser/bookmarks/chrome_bookmark_client.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..34c9462e1dea4be9815ea71c7f61fe2674fa4150 |
--- /dev/null |
+++ b/chrome/browser/bookmarks/chrome_bookmark_client.cc |
@@ -0,0 +1,112 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/bookmarks/chrome_bookmark_client.h" |
+ |
+#include "chrome/browser/bookmarks/bookmark_model.h" |
+#include "chrome/browser/chrome_notification_types.h" |
+#include "chrome/browser/favicon/favicon_changed_details.h" |
+#include "chrome/browser/favicon/favicon_service.h" |
+#include "chrome/browser/favicon/favicon_service_factory.h" |
+#include "chrome/browser/history/history_service.h" |
+#include "chrome/browser/history/history_service_factory.h" |
+#include "chrome/browser/history/url_database.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "content/public/browser/notification_details.h" |
+#include "content/public/browser/notification_source.h" |
+#include "content/public/browser/user_metrics.h" |
+ |
+ChromeBookmarkClient::ChromeBookmarkClient(Profile* profile, bool index_urls) |
+ : profile_(profile), model_(new BookmarkModel(this, index_urls)) { |
+ // Listen for changes to favicons so that we can update the favicon of the |
+ // node appropriately. |
+ registrar_.Add(this, |
+ chrome::NOTIFICATION_FAVICON_CHANGED, |
+ content::Source<Profile>(profile_)); |
+} |
+ |
+ChromeBookmarkClient::~ChromeBookmarkClient() { |
+ registrar_.RemoveAll(); |
+} |
+ |
+base::CancelableTaskTracker::TaskId ChromeBookmarkClient::GetFaviconImageForURL( |
+ const GURL& page_url, |
+ int icon_types, |
+ int desired_size_in_dip, |
+ const FaviconImageCallback& callback, |
+ base::CancelableTaskTracker* tracker) { |
+ FaviconService* favicon_service = |
+ FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
+ if (!favicon_service) |
+ return base::CancelableTaskTracker::kBadTaskId; |
+ return favicon_service->GetFaviconImageForURL( |
+ FaviconService::FaviconForURLParams( |
+ page_url, icon_types, desired_size_in_dip), |
+ callback, |
+ tracker); |
+} |
+ |
+bool ChromeBookmarkClient::SupportsTypedCountForNodes() { |
+ return true; |
+} |
+ |
+void ChromeBookmarkClient::GetTypedCountForNodes( |
+ const NodeSet& nodes, |
+ NodeTypedCountPairs* node_typed_count_pairs) { |
+ HistoryService* history_service = |
+ HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
+ history::URLDatabase* url_db = |
+ history_service ? history_service->InMemoryDatabase() : NULL; |
+ for (NodeSet::const_iterator i = nodes.begin(); i != nodes.end(); ++i) { |
+ int typed_count = 0; |
+ |
+ // If |url_db| is the InMemoryDatabase, it might not cache all URLRows, but |
+ // it guarantees to contain those with |typed_count| > 0. Thus, if we cannot |
+ // fetch the URLRow, it is safe to assume that its |typed_count| is 0. |
+ history::URLRow url; |
+ if (url_db && url_db->GetRowForURL((*i)->url(), &url)) |
+ typed_count = url.typed_count(); |
+ |
+ NodeTypedCountPair pair(*i, typed_count); |
+ node_typed_count_pairs->push_back(pair); |
+ } |
+} |
+ |
+void ChromeBookmarkClient::RecordAction(const base::UserMetricsAction& action) { |
+ content::RecordAction(action); |
+} |
+ |
+void ChromeBookmarkClient::NotifyHistoryAboutRemovedBookmarks( |
+ const std::set<GURL>& removed_bookmark_urls) { |
+ if (removed_bookmark_urls.empty()) { |
+ // No point in sending out notification if the starred state didn't change. |
+ return; |
+ } |
+ |
+ HistoryService* history_service = |
+ HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
+ if (history_service) |
+ history_service->URLsNoLongerBookmarked(removed_bookmark_urls); |
+} |
+ |
+void ChromeBookmarkClient::Observe( |
+ int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) { |
+ switch (type) { |
+ case chrome::NOTIFICATION_FAVICON_CHANGED: { |
+ content::Details<FaviconChangedDetails> favicon_details(details); |
+ model_->OnFaviconChanged(favicon_details->urls); |
+ break; |
+ } |
+ |
+ default: |
+ NOTREACHED(); |
+ break; |
+ } |
+} |
+ |
+void ChromeBookmarkClient::Shutdown() { |
+ model_->Shutdown(); |
+} |