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

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: Fixed 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 =
sdefresne 2015/01/23 13:25:46 Add a dependency on TopSitesFactory to InstantServ
Jitu( very slow this week) 2015/01/23 13:52:52 Done.
97 TopSitesFactory::GetForProfile(profile_);
96 if (top_sites) 98 if (top_sites)
97 top_sites->AddObserver(this); 99 top_sites->AddObserver(this);
98 100
99 if (profile_ && profile_->GetResourceContext()) { 101 if (profile_ && profile_->GetResourceContext()) {
100 content::BrowserThread::PostTask( 102 content::BrowserThread::PostTask(
101 content::BrowserThread::IO, FROM_HERE, 103 content::BrowserThread::IO, FROM_HERE,
102 base::Bind(&InstantIOContext::SetUserDataOnIO, 104 base::Bind(&InstantIOContext::SetUserDataOnIO,
103 profile->GetResourceContext(), instant_io_context_)); 105 profile->GetResourceContext(), instant_io_context_));
104 } 106 }
105 107
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 153
152 void InstantService::AddObserver(InstantServiceObserver* observer) { 154 void InstantService::AddObserver(InstantServiceObserver* observer) {
153 observers_.AddObserver(observer); 155 observers_.AddObserver(observer);
154 } 156 }
155 157
156 void InstantService::RemoveObserver(InstantServiceObserver* observer) { 158 void InstantService::RemoveObserver(InstantServiceObserver* observer) {
157 observers_.RemoveObserver(observer); 159 observers_.RemoveObserver(observer);
158 } 160 }
159 161
160 void InstantService::DeleteMostVisitedItem(const GURL& url) { 162 void InstantService::DeleteMostVisitedItem(const GURL& url) {
161 history::TopSites* top_sites = profile_->GetTopSites(); 163 scoped_refptr<history::TopSites> top_sites =
164 TopSitesFactory::GetForProfile(profile_);
162 if (!top_sites) 165 if (!top_sites)
163 return; 166 return;
164 167
165 top_sites->AddBlacklistedURL(url); 168 top_sites->AddBlacklistedURL(url);
166 } 169 }
167 170
168 void InstantService::UndoMostVisitedDeletion(const GURL& url) { 171 void InstantService::UndoMostVisitedDeletion(const GURL& url) {
169 history::TopSites* top_sites = profile_->GetTopSites(); 172 scoped_refptr<history::TopSites> top_sites =
173 TopSitesFactory::GetForProfile(profile_);
170 if (!top_sites) 174 if (!top_sites)
171 return; 175 return;
172 176
173 top_sites->RemoveBlacklistedURL(url); 177 top_sites->RemoveBlacklistedURL(url);
174 } 178 }
175 179
176 void InstantService::UndoAllMostVisitedDeletions() { 180 void InstantService::UndoAllMostVisitedDeletions() {
177 history::TopSites* top_sites = profile_->GetTopSites(); 181 scoped_refptr<history::TopSites> top_sites =
182 TopSitesFactory::GetForProfile(profile_);
178 if (!top_sites) 183 if (!top_sites)
179 return; 184 return;
180 185
181 top_sites->ClearBlacklistedURLs(); 186 top_sites->ClearBlacklistedURLs();
182 } 187 }
183 188
184 void InstantService::UpdateThemeInfo() { 189 void InstantService::UpdateThemeInfo() {
185 // Update theme background info. 190 // Update theme background info.
186 // Initialize |theme_info| if necessary. 191 // Initialize |theme_info| if necessary.
187 if (!theme_info_) 192 if (!theme_info_)
188 OnThemeChanged(ThemeServiceFactory::GetForProfile(profile_)); 193 OnThemeChanged(ThemeServiceFactory::GetForProfile(profile_));
189 else 194 else
190 OnThemeChanged(NULL); 195 OnThemeChanged(NULL);
191 } 196 }
192 197
193 void InstantService::UpdateMostVisitedItemsInfo() { 198 void InstantService::UpdateMostVisitedItemsInfo() {
194 NotifyAboutMostVisitedItems(); 199 NotifyAboutMostVisitedItems();
195 } 200 }
196 201
197 void InstantService::Shutdown() { 202 void InstantService::Shutdown() {
198 process_ids_.clear(); 203 process_ids_.clear();
199 204
200 if (instant_io_context_.get()) { 205 if (instant_io_context_.get()) {
201 content::BrowserThread::PostTask( 206 content::BrowserThread::PostTask(
202 content::BrowserThread::IO, FROM_HERE, 207 content::BrowserThread::IO, FROM_HERE,
203 base::Bind(&InstantIOContext::ClearInstantProcessesOnIO, 208 base::Bind(&InstantIOContext::ClearInstantProcessesOnIO,
204 instant_io_context_)); 209 instant_io_context_));
205 } 210 }
206 211
207 history::TopSites* top_sites = profile_->GetTopSites(); 212 scoped_refptr<history::TopSites> top_sites =
213 TopSitesFactory::GetForProfile(profile_);
208 if (top_sites) 214 if (top_sites)
209 top_sites->RemoveObserver(this); 215 top_sites->RemoveObserver(this);
210 216
211 instant_io_context_ = NULL; 217 instant_io_context_ = NULL;
212 } 218 }
213 219
214 void InstantService::Observe(int type, 220 void InstantService::Observe(int type,
215 const content::NotificationSource& source, 221 const content::NotificationSource& source,
216 const content::NotificationDetails& details) { 222 const content::NotificationDetails& details) {
217 switch (type) { 223 switch (type) {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 } 433 }
428 434
429 void InstantService::ResetInstantSearchPrerenderer() { 435 void InstantService::ResetInstantSearchPrerenderer() {
430 if (!chrome::ShouldPrefetchSearchResults()) 436 if (!chrome::ShouldPrefetchSearchResults())
431 return; 437 return;
432 438
433 GURL url(chrome::GetSearchResultPrefetchBaseURL(profile_)); 439 GURL url(chrome::GetSearchResultPrefetchBaseURL(profile_));
434 instant_prerenderer_.reset( 440 instant_prerenderer_.reset(
435 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL); 441 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL);
436 } 442 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698