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

Side by Side 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: Rebase 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/bookmarks/chrome_bookmark_client.h"
6
7 #include "chrome/browser/bookmarks/bookmark_model.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/favicon/favicon_changed_details.h"
10 #include "chrome/browser/favicon/favicon_service.h"
11 #include "chrome/browser/favicon/favicon_service_factory.h"
12 #include "chrome/browser/history/history_service.h"
13 #include "chrome/browser/history/history_service_factory.h"
14 #include "chrome/browser/history/url_database.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "content/public/browser/notification_details.h"
17 #include "content/public/browser/notification_source.h"
18 #include "content/public/browser/user_metrics.h"
19
20 ChromeBookmarkClient::ChromeBookmarkClient(Profile* profile)
21 : profile_(profile), model_(new BookmarkModel(this)) {
22 }
23
24 ChromeBookmarkClient::~ChromeBookmarkClient() {
25 }
26
27 base::CancelableTaskTracker::TaskId ChromeBookmarkClient::GetFaviconImageForURL(
28 const GURL& page_url,
29 int icon_types,
30 int desired_size_in_dip,
31 const FaviconImageCallback& callback,
32 base::CancelableTaskTracker* tracker) {
33 FaviconService* favicon_service =
34 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
35 if (!favicon_service)
36 return base::CancelableTaskTracker::kBadTaskId;
37 return favicon_service->GetFaviconImageForURL(
38 FaviconService::FaviconForURLParams(
39 page_url, icon_types, desired_size_in_dip),
40 callback,
41 tracker);
42 }
43
44 bool ChromeBookmarkClient::SupportsTypedCountForNodes() {
45 return true;
46 }
47
48 void ChromeBookmarkClient::GetTypedCountForNodes(
49 const NodeSet& nodes,
50 NodeTypedCountPairs* node_typed_count_pairs) {
51 HistoryService* history_service =
52 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
53 history::URLDatabase* url_db =
54 history_service ? history_service->InMemoryDatabase() : NULL;
55 for (NodeSet::const_iterator i = nodes.begin(); i != nodes.end(); ++i) {
56 int typed_count = 0;
57
58 // If |url_db| is the InMemoryDatabase, it might not cache all URLRows, but
59 // it guarantees to contain those with |typed_count| > 0. Thus, if we cannot
60 // fetch the URLRow, it is safe to assume that its |typed_count| is 0.
61 history::URLRow url;
62 if (url_db && url_db->GetRowForURL((*i)->url(), &url))
63 typed_count = url.typed_count();
64
65 NodeTypedCountPair pair(*i, typed_count);
66 node_typed_count_pairs->push_back(pair);
67 }
68 }
69
70 void ChromeBookmarkClient::RecordAction(const base::UserMetricsAction& action) {
71 content::RecordAction(action);
72 }
73
74 void ChromeBookmarkClient::OnLoad() {
75 // Listen for changes to favicons so that we can update the favicon of the
76 // node appropriately.
77 registrar_.Add(this,
78 chrome::NOTIFICATION_FAVICON_CHANGED,
79 content::Source<Profile>(profile_));
80 }
81
82 void ChromeBookmarkClient::OnClearStore() {
83 registrar_.RemoveAll();
84 }
85
86 void ChromeBookmarkClient::NotifyHistoryAboutRemovedBookmarks(
87 const std::set<GURL>& removed_bookmark_urls) {
88 if (removed_bookmark_urls.empty()) {
89 // No point in sending out notification if the starred state didn't change.
90 return;
91 }
92
93 HistoryService* history_service =
94 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
95 if (history_service)
96 history_service->URLsNoLongerBookmarked(removed_bookmark_urls);
97 }
98
99 void ChromeBookmarkClient::Observe(
100 int type,
101 const content::NotificationSource& source,
102 const content::NotificationDetails& details) {
103 switch (type) {
104 case chrome::NOTIFICATION_FAVICON_CHANGED: {
105 content::Details<FaviconChangedDetails> favicon_details(details);
106 model_->OnFaviconChanged(favicon_details->urls);
107 break;
108 }
109
110 default:
111 NOTREACHED();
112 break;
113 }
114 }
115
116 void ChromeBookmarkClient::Shutdown() {
117 model_->Shutdown();
118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698