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

Side by Side Diff: chrome/browser/ui/webui/ntp/suggestions_page_handler.cc

Issue 815983002: Topsites become keyedService based. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: For trybot Created 5 years, 11 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
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/ui/webui/ntp/suggestions_page_handler.h" 5 #include "chrome/browser/ui/webui/ntp/suggestions_page_handler.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/md5.h" 12 #include "base/md5.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "chrome/browser/chrome_notification_types.h" 18 #include "chrome/browser/chrome_notification_types.h"
19 #include "chrome/browser/history/top_sites.h" 19 #include "chrome/browser/history/top_sites.h"
20 #include "chrome/browser/history/top_sites_factory.h"
20 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/ui/webui/favicon_source.h" 22 #include "chrome/browser/ui/webui/favicon_source.h"
22 #include "chrome/browser/ui/webui/ntp/ntp_stats.h" 23 #include "chrome/browser/ui/webui/ntp/ntp_stats.h"
23 #include "chrome/browser/ui/webui/ntp/suggestions_combiner.h" 24 #include "chrome/browser/ui/webui/ntp/suggestions_combiner.h"
24 #include "chrome/browser/ui/webui/ntp/suggestions_source_top_sites.h" 25 #include "chrome/browser/ui/webui/ntp/suggestions_source_top_sites.h"
25 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" 26 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h"
26 #include "chrome/common/url_constants.h" 27 #include "chrome/common/url_constants.h"
27 #include "components/history/core/browser/page_usage_data.h" 28 #include "components/history/core/browser/page_usage_data.h"
28 #include "components/pref_registry/pref_registry_syncable.h" 29 #include "components/pref_registry/pref_registry_syncable.h"
29 #include "content/public/browser/navigation_controller.h" 30 #include "content/public/browser/navigation_controller.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 63
63 void SuggestionsHandler::RegisterMessages() { 64 void SuggestionsHandler::RegisterMessages() {
64 Profile* profile = Profile::FromWebUI(web_ui()); 65 Profile* profile = Profile::FromWebUI(web_ui());
65 // Set up our sources for thumbnail and favicon data. 66 // Set up our sources for thumbnail and favicon data.
66 content::URLDataSource::Add(profile, new ThumbnailSource(profile, false)); 67 content::URLDataSource::Add(profile, new ThumbnailSource(profile, false));
67 content::URLDataSource::Add( 68 content::URLDataSource::Add(
68 profile, new FaviconSource(profile, FaviconSource::FAVICON)); 69 profile, new FaviconSource(profile, FaviconSource::FAVICON));
69 70
70 // TODO(georgey) change the source of the web-sites to provide our data. 71 // TODO(georgey) change the source of the web-sites to provide our data.
71 // Initial commit uses top sites as a data source. 72 // Initial commit uses top sites as a data source.
72 history::TopSites* top_sites = profile->GetTopSites(); 73 scoped_refptr<history::TopSites> top_sites =
74 TopSitesFactory::GetForProfile(profile);
73 if (top_sites) { 75 if (top_sites) {
74 // TopSites updates itself after a delay. This is especially noticable when 76 // TopSites updates itself after a delay. This is especially noticable when
75 // your profile is empty. Ask TopSites to update itself when we're about to 77 // your profile is empty. Ask TopSites to update itself when we're about to
76 // show the new tab page. 78 // show the new tab page.
77 top_sites->SyncWithHistory(); 79 top_sites->SyncWithHistory();
78 80
79 // Register for notification when TopSites changes so that we can update 81 // Register for notification when TopSites changes so that we can update
80 // ourself. 82 // ourself.
81 registrar_.Add(this, chrome::NOTIFICATION_TOP_SITES_CHANGED, 83 registrar_.Add(this, chrome::NOTIFICATION_TOP_SITES_CHANGED,
sdefresne 2015/01/21 17:57:24 Same here, you have a conflict with upstream that
82 content::Source<history::TopSites>(top_sites)); 84 content::Source<history::TopSites>(top_sites.get()));
83 } 85 }
84 86
85 // Setup the suggestions sources. 87 // Setup the suggestions sources.
86 SuggestionsCombiner* combiner = new SuggestionsCombiner(this, profile); 88 SuggestionsCombiner* combiner = new SuggestionsCombiner(this, profile);
87 combiner->AddSource(new SuggestionsSourceTopSites()); 89 combiner->AddSource(new SuggestionsSourceTopSites());
88 suggestions_combiner_.reset(combiner); 90 suggestions_combiner_.reset(combiner);
89 91
90 // We pre-emptively make a fetch for suggestions so we have the results 92 // We pre-emptively make a fetch for suggestions so we have the results
91 // sooner. 93 // sooner.
92 suggestions_combiner_->FetchItems(profile); 94 suggestions_combiner_->FetchItems(profile);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 192
191 std::string SuggestionsHandler::GetDictionaryKeyForURL(const std::string& url) { 193 std::string SuggestionsHandler::GetDictionaryKeyForURL(const std::string& url) {
192 return base::MD5String(url); 194 return base::MD5String(url);
193 } 195 }
194 196
195 // static 197 // static
196 void SuggestionsHandler::RegisterProfilePrefs( 198 void SuggestionsHandler::RegisterProfilePrefs(
197 user_prefs::PrefRegistrySyncable* registry) { 199 user_prefs::PrefRegistrySyncable* registry) {
198 // TODO(georgey) add user preferences (such as own blacklist) as needed. 200 // TODO(georgey) add user preferences (such as own blacklist) as needed.
199 } 201 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698