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

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

Issue 1770843002: SuggestionsService: implement SyncServiceObserver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix2 Created 4 years, 9 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/favicon/fallback_icon_service_factory.h" 15 #include "chrome/browser/favicon/fallback_icon_service_factory.h"
16 #include "chrome/browser/favicon/large_icon_service_factory.h" 16 #include "chrome/browser/favicon/large_icon_service_factory.h"
17 #include "chrome/browser/history/top_sites_factory.h" 17 #include "chrome/browser/history/top_sites_factory.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/search/instant_io_context.h" 19 #include "chrome/browser/search/instant_io_context.h"
20 #include "chrome/browser/search/instant_service_observer.h" 20 #include "chrome/browser/search/instant_service_observer.h"
21 #include "chrome/browser/search/most_visited_iframe_source.h" 21 #include "chrome/browser/search/most_visited_iframe_source.h"
22 #include "chrome/browser/search/search.h" 22 #include "chrome/browser/search/search.h"
23 #include "chrome/browser/search/suggestions/suggestions_service_factory.h" 23 #include "chrome/browser/search/suggestions/suggestions_service_factory.h"
24 #include "chrome/browser/search/suggestions/suggestions_source.h" 24 #include "chrome/browser/search/suggestions/suggestions_source.h"
25 #include "chrome/browser/search/suggestions/suggestions_utils.h"
26 #include "chrome/browser/search/thumbnail_source.h" 25 #include "chrome/browser/search/thumbnail_source.h"
27 #include "chrome/browser/search_engines/template_url_service_factory.h" 26 #include "chrome/browser/search_engines/template_url_service_factory.h"
28 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" 27 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
29 #include "chrome/browser/thumbnails/thumbnail_list_source.h" 28 #include "chrome/browser/thumbnails/thumbnail_list_source.h"
30 #include "chrome/browser/ui/search/instant_search_prerenderer.h" 29 #include "chrome/browser/ui/search/instant_search_prerenderer.h"
31 #include "chrome/browser/ui/webui/fallback_icon_source.h" 30 #include "chrome/browser/ui/webui/fallback_icon_source.h"
32 #include "chrome/browser/ui/webui/favicon_source.h" 31 #include "chrome/browser/ui/webui/favicon_source.h"
33 #include "chrome/browser/ui/webui/large_icon_source.h" 32 #include "chrome/browser/ui/webui/large_icon_source.h"
34 #include "chrome/browser/ui/webui/theme_source.h" 33 #include "chrome/browser/ui/webui/theme_source.h"
35 #include "chrome/common/render_messages.h" 34 #include "chrome/common/render_messages.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 content::URLDataSource::Add(profile_, new MostVisitedIframeSource()); 176 content::URLDataSource::Add(profile_, new MostVisitedIframeSource());
178 content::URLDataSource::Add( 177 content::URLDataSource::Add(
179 profile_, new suggestions::SuggestionsSource(profile_)); 178 profile_, new suggestions::SuggestionsSource(profile_));
180 179
181 if (IsLocalNTPSuggestionServiceEnabled()) { 180 if (IsLocalNTPSuggestionServiceEnabled()) {
182 suggestions_service_ = 181 suggestions_service_ =
183 suggestions::SuggestionsServiceFactory::GetForProfile(profile_); 182 suggestions::SuggestionsServiceFactory::GetForProfile(profile_);
184 } 183 }
185 184
186 if (suggestions_service_) { 185 if (suggestions_service_) {
187 suggestions_service_->FetchSuggestionsData( 186 suggestions_subscription_ = suggestions_service_->AddCallback(
188 suggestions::GetSyncState(profile_),
189 base::Bind(&InstantService::OnSuggestionsAvailable, 187 base::Bind(&InstantService::OnSuggestionsAvailable,
190 weak_ptr_factory_.GetWeakPtr())); 188 base::Unretained(this)));
189 suggestions_service_->FetchSuggestionsData();
190 // TODO(treib): Also re-fetch suggestions on local NTP loads.
191 } 191 }
192 } 192 }
193 193
194 InstantService::~InstantService() { 194 InstantService::~InstantService() {
195 if (template_url_service_) 195 if (template_url_service_)
196 template_url_service_->RemoveObserver(this); 196 template_url_service_->RemoveObserver(this);
197 } 197 }
198 198
199 void InstantService::AddInstantProcess(int process_id) { 199 void InstantService::AddInstantProcess(int process_id) {
200 process_ids_.insert(process_id); 200 process_ids_.insert(process_id);
(...skipping 17 matching lines...) Expand all
218 void InstantService::RemoveObserver(InstantServiceObserver* observer) { 218 void InstantService::RemoveObserver(InstantServiceObserver* observer) {
219 observers_.RemoveObserver(observer); 219 observers_.RemoveObserver(observer);
220 } 220 }
221 221
222 void InstantService::DeleteMostVisitedItem(const GURL& url) { 222 void InstantService::DeleteMostVisitedItem(const GURL& url) {
223 scoped_refptr<history::TopSites> top_sites = 223 scoped_refptr<history::TopSites> top_sites =
224 TopSitesFactory::GetForProfile(profile_); 224 TopSitesFactory::GetForProfile(profile_);
225 if (top_sites) 225 if (top_sites)
226 top_sites->AddBlacklistedURL(url); 226 top_sites->AddBlacklistedURL(url);
227 227
228 if (suggestions_service_) { 228 if (suggestions_service_)
229 suggestions_service_->BlacklistURL( 229 suggestions_service_->BlacklistURL(url);
230 url, base::Bind(&InstantService::OnSuggestionsAvailable,
231 weak_ptr_factory_.GetWeakPtr()),
232 base::Closure());
233 }
234 } 230 }
235 231
236 void InstantService::UndoMostVisitedDeletion(const GURL& url) { 232 void InstantService::UndoMostVisitedDeletion(const GURL& url) {
237 scoped_refptr<history::TopSites> top_sites = 233 scoped_refptr<history::TopSites> top_sites =
238 TopSitesFactory::GetForProfile(profile_); 234 TopSitesFactory::GetForProfile(profile_);
239 if (top_sites) 235 if (top_sites)
240 top_sites->RemoveBlacklistedURL(url); 236 top_sites->RemoveBlacklistedURL(url);
241 237
242 if (suggestions_service_) { 238 if (suggestions_service_)
243 suggestions_service_->UndoBlacklistURL( 239 suggestions_service_->UndoBlacklistURL(url);
244 url, base::Bind(&InstantService::OnSuggestionsAvailable,
245 weak_ptr_factory_.GetWeakPtr()),
246 base::Closure());
247 }
248 } 240 }
249 241
250 void InstantService::UndoAllMostVisitedDeletions() { 242 void InstantService::UndoAllMostVisitedDeletions() {
251 scoped_refptr<history::TopSites> top_sites = 243 scoped_refptr<history::TopSites> top_sites =
252 TopSitesFactory::GetForProfile(profile_); 244 TopSitesFactory::GetForProfile(profile_);
253 if (top_sites) 245 if (top_sites)
254 top_sites->ClearBlacklistedURLs(); 246 top_sites->ClearBlacklistedURLs();
255 247
256 if (suggestions_service_) { 248 if (suggestions_service_)
257 suggestions_service_->ClearBlacklist( 249 suggestions_service_->ClearBlacklist();
258 base::Bind(&InstantService::OnSuggestionsAvailable,
259 weak_ptr_factory_.GetWeakPtr()));
260 }
261 } 250 }
262 251
263 void InstantService::UpdateThemeInfo() { 252 void InstantService::UpdateThemeInfo() {
264 #if defined(ENABLE_THEMES) 253 #if defined(ENABLE_THEMES)
265 // Update theme background info. 254 // Update theme background info.
266 // Initialize |theme_info| if necessary. 255 // Initialize |theme_info| if necessary.
267 if (!theme_info_) { 256 if (!theme_info_) {
268 OnThemeChanged(); 257 OnThemeChanged();
269 } else { 258 } else {
270 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, 259 FOR_EACH_OBSERVER(InstantServiceObserver, observers_,
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 } 593 }
605 594
606 void InstantService::ResetInstantSearchPrerenderer() { 595 void InstantService::ResetInstantSearchPrerenderer() {
607 if (!search::ShouldPrefetchSearchResults()) 596 if (!search::ShouldPrefetchSearchResults())
608 return; 597 return;
609 598
610 GURL url(search::GetSearchResultPrefetchBaseURL(profile_)); 599 GURL url(search::GetSearchResultPrefetchBaseURL(profile_));
611 instant_prerenderer_.reset( 600 instant_prerenderer_.reset(
612 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL); 601 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL);
613 } 602 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698