Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Unified Diff: chrome/browser/bookmarks/chrome_bookmark_client.cc

Issue 242693003: Introduce BookmarkClient interface to abstract embedder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Work around STL android bug Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/bookmarks/chrome_bookmark_client.h ('k') | chrome/browser/bookmarks/test_bookmark_client.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..e37b9438f28f7e0fa40260ae6313aafd62f8472c
--- /dev/null
+++ b/chrome/browser/bookmarks/chrome_bookmark_client.cc
@@ -0,0 +1,113 @@
+// 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();
+}
« no previous file with comments | « chrome/browser/bookmarks/chrome_bookmark_client.h ('k') | chrome/browser/bookmarks/test_bookmark_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698