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

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, bool index_urls)
21 : profile_(profile), model_(new BookmarkModel(this, index_urls)) {
22 // Listen for changes to favicons so that we can update the favicon of the
23 // node appropriately.
24 registrar_.Add(this,
25 chrome::NOTIFICATION_FAVICON_CHANGED,
26 content::Source<Profile>(profile_));
27 }
28
29 ChromeBookmarkClient::~ChromeBookmarkClient() {
30 registrar_.RemoveAll();
31 }
32
33 base::CancelableTaskTracker::TaskId ChromeBookmarkClient::GetFaviconImageForURL(
34 const GURL& page_url,
35 int icon_types,
36 int desired_size_in_dip,
37 const FaviconImageCallback& callback,
38 base::CancelableTaskTracker* tracker) {
39 FaviconService* favicon_service =
40 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
41 if (!favicon_service)
42 return base::CancelableTaskTracker::kBadTaskId;
43 return favicon_service->GetFaviconImageForURL(
44 FaviconService::FaviconForURLParams(
45 page_url, icon_types, desired_size_in_dip),
46 callback,
47 tracker);
48 }
49
50 bool ChromeBookmarkClient::SupportsTypedCountForNodes() {
51 return true;
52 }
53
54 void ChromeBookmarkClient::GetTypedCountForNodes(
55 const NodeSet& nodes,
56 NodeTypedCountPairs* node_typed_count_pairs) {
57 HistoryService* history_service =
58 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
59 history::URLDatabase* url_db =
60 history_service ? history_service->InMemoryDatabase() : NULL;
61 for (NodeSet::const_iterator i = nodes.begin(); i != nodes.end(); ++i) {
62 int typed_count = 0;
63
64 // If |url_db| is the InMemoryDatabase, it might not cache all URLRows, but
65 // it guarantees to contain those with |typed_count| > 0. Thus, if we cannot
66 // fetch the URLRow, it is safe to assume that its |typed_count| is 0.
67 history::URLRow url;
68 if (url_db && url_db->GetRowForURL((*i)->url(), &url))
69 typed_count = url.typed_count();
70
71 NodeTypedCountPair pair(*i, typed_count);
72 node_typed_count_pairs->push_back(pair);
73 }
74 }
75
76 void ChromeBookmarkClient::RecordAction(const base::UserMetricsAction& action) {
77 content::RecordAction(action);
78 }
79
80 void ChromeBookmarkClient::NotifyHistoryAboutRemovedBookmarks(
81 const std::set<GURL>& removed_bookmark_urls) {
82 if (removed_bookmark_urls.empty()) {
83 // No point in sending out notification if the starred state didn't change.
84 return;
85 }
86
87 HistoryService* history_service =
88 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
89 if (history_service)
90 history_service->URLsNoLongerBookmarked(removed_bookmark_urls);
91 }
92
93 void ChromeBookmarkClient::Observe(
94 int type,
95 const content::NotificationSource& source,
96 const content::NotificationDetails& details) {
97 switch (type) {
98 case chrome::NOTIFICATION_FAVICON_CHANGED: {
99 content::Details<FaviconChangedDetails> favicon_details(details);
100 model_->OnFaviconChanged(favicon_details->urls);
101 break;
102 }
103
104 default:
105 NOTREACHED();
106 break;
107 }
108 }
109
110 void ChromeBookmarkClient::Shutdown() {
111 model_->Shutdown();
112 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698