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

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 Created 5 years, 12 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_service_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_provider =
sdefresne 2014/12/29 09:48:14 nit: rename top_sites_provider to top_sites
Jitu( very slow this week) 2014/12/30 10:09:03 Done.
96 if (top_sites) { 97 TopSitesServiceFactory::GetForProfile(profile_);
97 registrar_.Add(this, 98 if (top_sites_provider.get()) {
98 chrome::NOTIFICATION_TOP_SITES_CHANGED, 99 registrar_.Add(
99 content::Source<history::TopSites>(top_sites)); 100 this, chrome::NOTIFICATION_TOP_SITES_CHANGED,
101 content::Source<history::TopSites>(top_sites_provider.get()));
100 } 102 }
101 103
102 if (profile_ && profile_->GetResourceContext()) { 104 if (profile_ && profile_->GetResourceContext()) {
103 content::BrowserThread::PostTask( 105 content::BrowserThread::PostTask(
104 content::BrowserThread::IO, FROM_HERE, 106 content::BrowserThread::IO, FROM_HERE,
105 base::Bind(&InstantIOContext::SetUserDataOnIO, 107 base::Bind(&InstantIOContext::SetUserDataOnIO,
106 profile->GetResourceContext(), instant_io_context_)); 108 profile->GetResourceContext(), instant_io_context_));
107 } 109 }
108 110
109 // Set up the data sources that Instant uses on the NTP. 111 // Set up the data sources that Instant uses on the NTP.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 156
155 void InstantService::AddObserver(InstantServiceObserver* observer) { 157 void InstantService::AddObserver(InstantServiceObserver* observer) {
156 observers_.AddObserver(observer); 158 observers_.AddObserver(observer);
157 } 159 }
158 160
159 void InstantService::RemoveObserver(InstantServiceObserver* observer) { 161 void InstantService::RemoveObserver(InstantServiceObserver* observer) {
160 observers_.RemoveObserver(observer); 162 observers_.RemoveObserver(observer);
161 } 163 }
162 164
163 void InstantService::DeleteMostVisitedItem(const GURL& url) { 165 void InstantService::DeleteMostVisitedItem(const GURL& url) {
164 history::TopSites* top_sites = profile_->GetTopSites(); 166 scoped_refptr<history::TopSites> top_sites =
165 if (!top_sites) 167 TopSitesServiceFactory::GetForProfile(profile_);
168 if (top_sites.get() == NULL)
166 return; 169 return;
167 170
168 top_sites->AddBlacklistedURL(url); 171 top_sites->AddBlacklistedURL(url);
169 } 172 }
170 173
171 void InstantService::UndoMostVisitedDeletion(const GURL& url) { 174 void InstantService::UndoMostVisitedDeletion(const GURL& url) {
172 history::TopSites* top_sites = profile_->GetTopSites(); 175 scoped_refptr<history::TopSites> top_sites =
173 if (!top_sites) 176 TopSitesServiceFactory::GetForProfile(profile_);
177 if (top_sites.get() == NULL)
174 return; 178 return;
175 179
176 top_sites->RemoveBlacklistedURL(url); 180 top_sites->RemoveBlacklistedURL(url);
177 } 181 }
178 182
179 void InstantService::UndoAllMostVisitedDeletions() { 183 void InstantService::UndoAllMostVisitedDeletions() {
180 history::TopSites* top_sites = profile_->GetTopSites(); 184 scoped_refptr<history::TopSites> top_sites =
181 if (!top_sites) 185 TopSitesServiceFactory::GetForProfile(profile_);
186 if (top_sites.get() == NULL)
182 return; 187 return;
183 188
184 top_sites->ClearBlacklistedURLs(); 189 top_sites->ClearBlacklistedURLs();
185 } 190 }
186 191
187 void InstantService::UpdateThemeInfo() { 192 void InstantService::UpdateThemeInfo() {
188 // Update theme background info. 193 // Update theme background info.
189 // Initialize |theme_info| if necessary. 194 // Initialize |theme_info| if necessary.
190 if (!theme_info_) 195 if (!theme_info_)
191 OnThemeChanged(ThemeServiceFactory::GetForProfile(profile_)); 196 OnThemeChanged(ThemeServiceFactory::GetForProfile(profile_));
(...skipping 23 matching lines...) Expand all
215 switch (type) { 220 switch (type) {
216 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: 221 case content::NOTIFICATION_RENDERER_PROCESS_CREATED:
217 SendSearchURLsToRenderer( 222 SendSearchURLsToRenderer(
218 content::Source<content::RenderProcessHost>(source).ptr()); 223 content::Source<content::RenderProcessHost>(source).ptr());
219 break; 224 break;
220 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: 225 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED:
221 OnRendererProcessTerminated( 226 OnRendererProcessTerminated(
222 content::Source<content::RenderProcessHost>(source)->GetID()); 227 content::Source<content::RenderProcessHost>(source)->GetID());
223 break; 228 break;
224 case chrome::NOTIFICATION_TOP_SITES_CHANGED: { 229 case chrome::NOTIFICATION_TOP_SITES_CHANGED: {
225 history::TopSites* top_sites = profile_->GetTopSites(); 230 scoped_refptr<history::TopSites> top_sites =
226 if (top_sites) { 231 TopSitesServiceFactory::GetForProfile(profile_);
232 if (top_sites.get()) {
227 top_sites->GetMostVisitedURLs( 233 top_sites->GetMostVisitedURLs(
228 base::Bind(&InstantService::OnMostVisitedItemsReceived, 234 base::Bind(&InstantService::OnMostVisitedItemsReceived,
229 weak_ptr_factory_.GetWeakPtr()), false); 235 weak_ptr_factory_.GetWeakPtr()),
236 false);
230 } 237 }
231 break; 238 break;
232 } 239 }
233 #if defined(ENABLE_THEMES) 240 #if defined(ENABLE_THEMES)
234 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { 241 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: {
235 OnThemeChanged(content::Source<ThemeService>(source).ptr()); 242 OnThemeChanged(content::Source<ThemeService>(source).ptr());
236 break; 243 break;
237 } 244 }
238 #endif // defined(ENABLE_THEMES) 245 #endif // defined(ENABLE_THEMES)
239 default: 246 default:
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 } 431 }
425 432
426 void InstantService::ResetInstantSearchPrerenderer() { 433 void InstantService::ResetInstantSearchPrerenderer() {
427 if (!chrome::ShouldPrefetchSearchResults()) 434 if (!chrome::ShouldPrefetchSearchResults())
428 return; 435 return;
429 436
430 GURL url(chrome::GetSearchResultPrefetchBaseURL(profile_)); 437 GURL url(chrome::GetSearchResultPrefetchBaseURL(profile_));
431 instant_prerenderer_.reset( 438 instant_prerenderer_.reset(
432 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL); 439 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL);
433 } 440 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698