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

Side by Side Diff: chrome/browser/search/instant_service.cc

Issue 815983002: Topsites become keyedService based. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix review comments 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/search/instant_service.h" 5 #include "chrome/browser/search/instant_service.h"
6 6
7 #include "chrome/browser/chrome_notification_types.h" 7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/history/top_sites.h" 8 #include "chrome/browser/history/top_sites.h"
9 #include "chrome/browser/history/top_sites_factory.h"
9 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/search/instant_io_context.h" 11 #include "chrome/browser/search/instant_io_context.h"
11 #include "chrome/browser/search/instant_service_observer.h" 12 #include "chrome/browser/search/instant_service_observer.h"
12 #include "chrome/browser/search/most_visited_iframe_source.h" 13 #include "chrome/browser/search/most_visited_iframe_source.h"
13 #include "chrome/browser/search/search.h" 14 #include "chrome/browser/search/search.h"
14 #include "chrome/browser/search/suggestions/suggestions_source.h" 15 #include "chrome/browser/search/suggestions/suggestions_source.h"
15 #include "chrome/browser/search_engines/template_url_service_factory.h" 16 #include "chrome/browser/search_engines/template_url_service_factory.h"
16 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" 17 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
17 #include "chrome/browser/themes/theme_properties.h" 18 #include "chrome/browser/themes/theme_properties.h"
18 #include "chrome/browser/themes/theme_service.h" 19 #include "chrome/browser/themes/theme_service.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 86
86 ResetInstantSearchPrerenderer(); 87 ResetInstantSearchPrerenderer();
87 88
88 registrar_.Add(this, 89 registrar_.Add(this,
89 content::NOTIFICATION_RENDERER_PROCESS_CREATED, 90 content::NOTIFICATION_RENDERER_PROCESS_CREATED,
90 content::NotificationService::AllSources()); 91 content::NotificationService::AllSources());
91 registrar_.Add(this, 92 registrar_.Add(this,
92 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 93 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
93 content::NotificationService::AllSources()); 94 content::NotificationService::AllSources());
94 95
95 history::TopSites* top_sites = profile_->GetTopSites(); 96 scoped_refptr<history::TopSites> top_sites =
97 TopSitesFactory::GetForProfile(profile_);
96 if (top_sites) { 98 if (top_sites) {
97 registrar_.Add(this, 99 registrar_.Add(this, chrome::NOTIFICATION_TOP_SITES_CHANGED,
98 chrome::NOTIFICATION_TOP_SITES_CHANGED, 100 content::Source<history::TopSites>(top_sites.get()));
99 content::Source<history::TopSites>(top_sites));
100 } 101 }
101 102
102 if (profile_ && profile_->GetResourceContext()) { 103 if (profile_ && profile_->GetResourceContext()) {
103 content::BrowserThread::PostTask( 104 content::BrowserThread::PostTask(
104 content::BrowserThread::IO, FROM_HERE, 105 content::BrowserThread::IO, FROM_HERE,
105 base::Bind(&InstantIOContext::SetUserDataOnIO, 106 base::Bind(&InstantIOContext::SetUserDataOnIO,
106 profile->GetResourceContext(), instant_io_context_)); 107 profile->GetResourceContext(), instant_io_context_));
107 } 108 }
108 109
109 // Set up the data sources that Instant uses on the NTP. 110 // Set up the data sources that Instant uses on the NTP.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 155
155 void InstantService::AddObserver(InstantServiceObserver* observer) { 156 void InstantService::AddObserver(InstantServiceObserver* observer) {
156 observers_.AddObserver(observer); 157 observers_.AddObserver(observer);
157 } 158 }
158 159
159 void InstantService::RemoveObserver(InstantServiceObserver* observer) { 160 void InstantService::RemoveObserver(InstantServiceObserver* observer) {
160 observers_.RemoveObserver(observer); 161 observers_.RemoveObserver(observer);
161 } 162 }
162 163
163 void InstantService::DeleteMostVisitedItem(const GURL& url) { 164 void InstantService::DeleteMostVisitedItem(const GURL& url) {
164 history::TopSites* top_sites = profile_->GetTopSites(); 165 scoped_refptr<history::TopSites> top_sites =
166 TopSitesFactory::GetForProfile(profile_);
165 if (!top_sites) 167 if (!top_sites)
166 return; 168 return;
167 169
168 top_sites->AddBlacklistedURL(url); 170 top_sites->AddBlacklistedURL(url);
169 } 171 }
170 172
171 void InstantService::UndoMostVisitedDeletion(const GURL& url) { 173 void InstantService::UndoMostVisitedDeletion(const GURL& url) {
172 history::TopSites* top_sites = profile_->GetTopSites(); 174 scoped_refptr<history::TopSites> top_sites =
175 TopSitesFactory::GetForProfile(profile_);
173 if (!top_sites) 176 if (!top_sites)
174 return; 177 return;
175 178
176 top_sites->RemoveBlacklistedURL(url); 179 top_sites->RemoveBlacklistedURL(url);
177 } 180 }
178 181
179 void InstantService::UndoAllMostVisitedDeletions() { 182 void InstantService::UndoAllMostVisitedDeletions() {
180 history::TopSites* top_sites = profile_->GetTopSites(); 183 scoped_refptr<history::TopSites> top_sites =
184 TopSitesFactory::GetForProfile(profile_);
181 if (!top_sites) 185 if (!top_sites)
182 return; 186 return;
183 187
184 top_sites->ClearBlacklistedURLs(); 188 top_sites->ClearBlacklistedURLs();
185 } 189 }
186 190
187 void InstantService::UpdateThemeInfo() { 191 void InstantService::UpdateThemeInfo() {
188 // Update theme background info. 192 // Update theme background info.
189 // Initialize |theme_info| if necessary. 193 // Initialize |theme_info| if necessary.
190 if (!theme_info_) 194 if (!theme_info_)
(...skipping 24 matching lines...) Expand all
215 switch (type) { 219 switch (type) {
216 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: 220 case content::NOTIFICATION_RENDERER_PROCESS_CREATED:
217 SendSearchURLsToRenderer( 221 SendSearchURLsToRenderer(
218 content::Source<content::RenderProcessHost>(source).ptr()); 222 content::Source<content::RenderProcessHost>(source).ptr());
219 break; 223 break;
220 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: 224 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED:
221 OnRendererProcessTerminated( 225 OnRendererProcessTerminated(
222 content::Source<content::RenderProcessHost>(source)->GetID()); 226 content::Source<content::RenderProcessHost>(source)->GetID());
223 break; 227 break;
224 case chrome::NOTIFICATION_TOP_SITES_CHANGED: { 228 case chrome::NOTIFICATION_TOP_SITES_CHANGED: {
225 history::TopSites* top_sites = profile_->GetTopSites(); 229 scoped_refptr<history::TopSites> top_sites =
230 TopSitesFactory::GetForProfile(profile_);
226 if (top_sites) { 231 if (top_sites) {
227 top_sites->GetMostVisitedURLs( 232 top_sites->GetMostVisitedURLs(
228 base::Bind(&InstantService::OnMostVisitedItemsReceived, 233 base::Bind(&InstantService::OnMostVisitedItemsReceived,
229 weak_ptr_factory_.GetWeakPtr()), false); 234 weak_ptr_factory_.GetWeakPtr()),
235 false);
230 } 236 }
231 break; 237 break;
232 } 238 }
233 #if defined(ENABLE_THEMES) 239 #if defined(ENABLE_THEMES)
234 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { 240 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: {
235 OnThemeChanged(content::Source<ThemeService>(source).ptr()); 241 OnThemeChanged(content::Source<ThemeService>(source).ptr());
236 break; 242 break;
237 } 243 }
238 #endif // defined(ENABLE_THEMES) 244 #endif // defined(ENABLE_THEMES)
239 default: 245 default:
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 } 430 }
425 431
426 void InstantService::ResetInstantSearchPrerenderer() { 432 void InstantService::ResetInstantSearchPrerenderer() {
427 if (!chrome::ShouldPrefetchSearchResults()) 433 if (!chrome::ShouldPrefetchSearchResults())
428 return; 434 return;
429 435
430 GURL url(chrome::GetSearchResultPrefetchBaseURL(profile_)); 436 GURL url(chrome::GetSearchResultPrefetchBaseURL(profile_));
431 instant_prerenderer_.reset( 437 instant_prerenderer_.reset(
432 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL); 438 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL);
433 } 439 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698