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

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

Issue 1260113002: Adds an experiment that enabled SuggestionsService suggestions (MostLikely) on LocalNTP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « chrome/browser/search/instant_service.h ('k') | chrome/common/instant_types.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/metrics/field_trial.h"
8 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/favicon/fallback_icon_service_factory.h" 10 #include "chrome/browser/favicon/fallback_icon_service_factory.h"
9 #include "chrome/browser/favicon/large_icon_service_factory.h" 11 #include "chrome/browser/favicon/large_icon_service_factory.h"
10 #include "chrome/browser/history/top_sites_factory.h" 12 #include "chrome/browser/history/top_sites_factory.h"
11 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/search/instant_io_context.h" 14 #include "chrome/browser/search/instant_io_context.h"
13 #include "chrome/browser/search/instant_service_observer.h" 15 #include "chrome/browser/search/instant_service_observer.h"
14 #include "chrome/browser/search/most_visited_iframe_source.h" 16 #include "chrome/browser/search/most_visited_iframe_source.h"
15 #include "chrome/browser/search/search.h" 17 #include "chrome/browser/search/search.h"
18 #include "chrome/browser/search/suggestions/suggestions_service_factory.h"
16 #include "chrome/browser/search/suggestions/suggestions_source.h" 19 #include "chrome/browser/search/suggestions/suggestions_source.h"
17 #include "chrome/browser/search/thumbnail_source.h" 20 #include "chrome/browser/search/thumbnail_source.h"
18 #include "chrome/browser/search_engines/template_url_service_factory.h" 21 #include "chrome/browser/search_engines/template_url_service_factory.h"
19 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" 22 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
20 #include "chrome/browser/thumbnails/thumbnail_list_source.h" 23 #include "chrome/browser/thumbnails/thumbnail_list_source.h"
21 #include "chrome/browser/ui/search/instant_search_prerenderer.h" 24 #include "chrome/browser/ui/search/instant_search_prerenderer.h"
22 #include "chrome/browser/ui/webui/fallback_icon_source.h" 25 #include "chrome/browser/ui/webui/fallback_icon_source.h"
23 #include "chrome/browser/ui/webui/favicon_source.h" 26 #include "chrome/browser/ui/webui/favicon_source.h"
24 #include "chrome/browser/ui/webui/large_icon_source.h" 27 #include "chrome/browser/ui/webui/large_icon_source.h"
25 #include "chrome/browser/ui/webui/theme_source.h" 28 #include "chrome/browser/ui/webui/theme_source.h"
26 #include "chrome/common/render_messages.h" 29 #include "chrome/common/render_messages.h"
27 #include "components/favicon/core/fallback_icon_service.h" 30 #include "components/favicon/core/fallback_icon_service.h"
28 #include "components/favicon/core/large_icon_service.h" 31 #include "components/favicon/core/large_icon_service.h"
29 #include "components/history/core/browser/top_sites.h" 32 #include "components/history/core/browser/top_sites.h"
30 #include "components/keyed_service/core/service_access_type.h" 33 #include "components/keyed_service/core/service_access_type.h"
31 #include "components/search_engines/template_url_service.h" 34 #include "components/search_engines/template_url_service.h"
35 #include "components/suggestions/proto/suggestions.pb.h"
36 #include "components/suggestions/suggestions_service.h"
32 #include "content/public/browser/browser_thread.h" 37 #include "content/public/browser/browser_thread.h"
33 #include "content/public/browser/notification_service.h" 38 #include "content/public/browser/notification_service.h"
34 #include "content/public/browser/notification_types.h" 39 #include "content/public/browser/notification_types.h"
35 #include "content/public/browser/render_process_host.h" 40 #include "content/public/browser/render_process_host.h"
36 #include "content/public/browser/url_data_source.h" 41 #include "content/public/browser/url_data_source.h"
37 #include "grit/theme_resources.h" 42 #include "grit/theme_resources.h"
38 #include "third_party/skia/include/core/SkColor.h" 43 #include "third_party/skia/include/core/SkColor.h"
39 #include "ui/gfx/color_utils.h" 44 #include "ui/gfx/color_utils.h"
40 #include "ui/gfx/image/image_skia.h" 45 #include "ui/gfx/image/image_skia.h"
41 46
42 #if !defined(OS_ANDROID) 47 #if !defined(OS_ANDROID)
43 #include "chrome/browser/search/local_ntp_source.h" 48 #include "chrome/browser/search/local_ntp_source.h"
44 #endif 49 #endif
45 50
46 #if defined(ENABLE_THEMES) 51 #if defined(ENABLE_THEMES)
47 #include "chrome/browser/themes/theme_properties.h" 52 #include "chrome/browser/themes/theme_properties.h"
48 #include "chrome/browser/themes/theme_service.h" 53 #include "chrome/browser/themes/theme_service.h"
49 #include "chrome/browser/themes/theme_service_factory.h" 54 #include "chrome/browser/themes/theme_service_factory.h"
50 #endif // defined(ENABLE_THEMES) 55 #endif // defined(ENABLE_THEMES)
51 56
52 InstantService::InstantService(Profile* profile) 57 InstantService::InstantService(Profile* profile)
53 : profile_(profile), 58 : profile_(profile),
54 template_url_service_(TemplateURLServiceFactory::GetForProfile(profile_)), 59 template_url_service_(TemplateURLServiceFactory::GetForProfile(profile_)),
55 omnibox_start_margin_(chrome::kDisableStartMargin), 60 omnibox_start_margin_(chrome::kDisableStartMargin),
56 weak_ptr_factory_(this) { 61 weak_ptr_factory_(this),
62 suggestions_service(NULL) {
57 // The initialization below depends on a typical set of browser threads. Skip 63 // The initialization below depends on a typical set of browser threads. Skip
58 // it if we are running in a unit test without the full suite. 64 // it if we are running in a unit test without the full suite.
59 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) 65 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI))
60 return; 66 return;
61 67
62 // This depends on the existence of the typical browser threads. Therefore it 68 // This depends on the existence of the typical browser threads. Therefore it
63 // is only instantiated here (after the check for a UI thread above). 69 // is only instantiated here (after the check for a UI thread above).
64 instant_io_context_ = new InstantIOContext(); 70 instant_io_context_ = new InstantIOContext();
65 71
66 previous_google_base_url_ = 72 previous_google_base_url_ =
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 LargeIconServiceFactory::GetForBrowserContext(profile_); 129 LargeIconServiceFactory::GetForBrowserContext(profile_);
124 content::URLDataSource::Add( 130 content::URLDataSource::Add(
125 profile_, new FallbackIconSource(fallback_icon_service)); 131 profile_, new FallbackIconSource(fallback_icon_service));
126 content::URLDataSource::Add( 132 content::URLDataSource::Add(
127 profile_, new FaviconSource(profile_, FaviconSource::FAVICON)); 133 profile_, new FaviconSource(profile_, FaviconSource::FAVICON));
128 content::URLDataSource::Add( 134 content::URLDataSource::Add(
129 profile_, new LargeIconSource(fallback_icon_service, large_icon_service)); 135 profile_, new LargeIconSource(fallback_icon_service, large_icon_service));
130 content::URLDataSource::Add(profile_, new MostVisitedIframeSource()); 136 content::URLDataSource::Add(profile_, new MostVisitedIframeSource());
131 content::URLDataSource::Add( 137 content::URLDataSource::Add(
132 profile_, new suggestions::SuggestionsSource(profile_)); 138 profile_, new suggestions::SuggestionsSource(profile_));
139
140 if (base::StartsWith(
141 base::FieldTrialList::FindFullName("LocalNTPSuggestionsService"),
142 "Enabled", base::CompareCase::INSENSITIVE_ASCII)) {
143 suggestions_service =
144 suggestions::SuggestionsServiceFactory::GetForProfile(profile_);
145 }
146
147 if (suggestions_service) {
148 suggestions::SuggestionsService* if (suggestions_service) {
kmadhusu 2015/07/29 17:42:31 Can you please explain this code? Why do you need
fserb 2015/07/29 19:02:59 I messed up the last comment fix. :) thanks. done.
149 suggestions_service->FetchSuggestionsData(
150 suggestions::INITIALIZED_ENABLED_HISTORY,
151 base::Bind(&InstantService::OnSuggestionsAvailable,
152 weak_ptr_factory_.GetWeakPtr()));
153 }
154 }
133 } 155 }
134 156
135 InstantService::~InstantService() { 157 InstantService::~InstantService() {
136 if (template_url_service_) 158 if (template_url_service_)
137 template_url_service_->RemoveObserver(this); 159 template_url_service_->RemoveObserver(this);
138 } 160 }
139 161
140 void InstantService::AddInstantProcess(int process_id) { 162 void InstantService::AddInstantProcess(int process_id) {
141 process_ids_.insert(process_id); 163 process_ids_.insert(process_id);
142 164
(...skipping 17 matching lines...) Expand all
160 observers_.RemoveObserver(observer); 182 observers_.RemoveObserver(observer);
161 } 183 }
162 184
163 void InstantService::DeleteMostVisitedItem(const GURL& url) { 185 void InstantService::DeleteMostVisitedItem(const GURL& url) {
164 scoped_refptr<history::TopSites> top_sites = 186 scoped_refptr<history::TopSites> top_sites =
165 TopSitesFactory::GetForProfile(profile_); 187 TopSitesFactory::GetForProfile(profile_);
166 if (!top_sites) 188 if (!top_sites)
167 return; 189 return;
168 190
169 top_sites->AddBlacklistedURL(url); 191 top_sites->AddBlacklistedURL(url);
192 if (suggestions_service) {
193 suggestions_service->BlacklistURL(
194 url, base::Bind(&InstantService::OnSuggestionsAvailable,
kmadhusu 2015/07/29 17:42:31 Instead of passing a callback as an argument, have
fserb 2015/07/29 19:03:00 SuggestionsService has a callback model, it doesn'
kmadhusu 2015/07/30 21:57:02 (My 2 cents) Hmm. I am not entirely convinced by t
195 weak_ptr_factory_.GetWeakPtr()),
196 base::Closure());
197 }
170 } 198 }
171 199
172 void InstantService::UndoMostVisitedDeletion(const GURL& url) { 200 void InstantService::UndoMostVisitedDeletion(const GURL& url) {
173 scoped_refptr<history::TopSites> top_sites = 201 scoped_refptr<history::TopSites> top_sites =
174 TopSitesFactory::GetForProfile(profile_); 202 TopSitesFactory::GetForProfile(profile_);
175 if (!top_sites) 203 if (!top_sites)
kmadhusu 2015/07/30 21:57:02 Do you want to do an early return when top_sites i
fserb 2015/07/31 17:08:17 Nice catch. Fixed them all.
fserb 2015/07/31 17:08:17 ops. Fixed all of them. Thanks for catching this.
176 return; 204 return;
177 205
178 top_sites->RemoveBlacklistedURL(url); 206 top_sites->RemoveBlacklistedURL(url);
207 if (suggestions_service) {
208 suggestions_service->UndoBlacklistURL(
209 url, base::Bind(&InstantService::OnSuggestionsAvailable,
210 weak_ptr_factory_.GetWeakPtr()),
211 base::Closure());
212 }
179 } 213 }
180 214
181 void InstantService::UndoAllMostVisitedDeletions() { 215 void InstantService::UndoAllMostVisitedDeletions() {
182 scoped_refptr<history::TopSites> top_sites = 216 scoped_refptr<history::TopSites> top_sites =
183 TopSitesFactory::GetForProfile(profile_); 217 TopSitesFactory::GetForProfile(profile_);
184 if (!top_sites) 218 if (!top_sites)
185 return; 219 return;
186 220
187 top_sites->ClearBlacklistedURLs(); 221 top_sites->ClearBlacklistedURLs();
222 if (suggestions_service) {
223 suggestions_service->ClearBlacklist(
224 base::Bind(&InstantService::OnSuggestionsAvailable,
225 weak_ptr_factory_.GetWeakPtr()));
226 }
188 } 227 }
189 228
190 void InstantService::UpdateThemeInfo() { 229 void InstantService::UpdateThemeInfo() {
191 #if defined(ENABLE_THEMES) 230 #if defined(ENABLE_THEMES)
192 // Update theme background info. 231 // Update theme background info.
193 // Initialize |theme_info| if necessary. 232 // Initialize |theme_info| if necessary.
194 if (!theme_info_) 233 if (!theme_info_)
195 OnThemeChanged(ThemeServiceFactory::GetForProfile(profile_)); 234 OnThemeChanged(ThemeServiceFactory::GetForProfile(profile_));
196 else 235 else
197 OnThemeChanged(NULL); 236 OnThemeChanged(NULL);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 process_ids_.erase(process_id); 297 process_ids_.erase(process_id);
259 298
260 if (instant_io_context_.get()) { 299 if (instant_io_context_.get()) {
261 content::BrowserThread::PostTask( 300 content::BrowserThread::PostTask(
262 content::BrowserThread::IO, FROM_HERE, 301 content::BrowserThread::IO, FROM_HERE,
263 base::Bind(&InstantIOContext::RemoveInstantProcessOnIO, 302 base::Bind(&InstantIOContext::RemoveInstantProcessOnIO,
264 instant_io_context_, process_id)); 303 instant_io_context_, process_id));
265 } 304 }
266 } 305 }
267 306
307 void InstantService::OnSuggestionsAvailable(
308 const suggestions::SuggestionsProfile& profile) {
309 std::vector<InstantMostVisitedItem> new_suggestions_items;
310 for (int i = 0; i < profile.suggestions_size(); ++i) {
311 const suggestions::ChromeSuggestion& suggestion = profile.suggestions(i);
312
313 InstantMostVisitedItem item;
314 item.url = GURL(suggestion.url());
315 item.title = base::UTF8ToUTF16(suggestion.title());
316 item.thumbnail = GURL(suggestion.thumbnail());
317 item.favicon = GURL(suggestion.favicon_url());
318 new_suggestions_items.push_back(item);
319 }
320 suggestions_items_ = new_suggestions_items;
321 NotifyAboutMostVisitedItems();
322 }
323
268 void InstantService::OnMostVisitedItemsReceived( 324 void InstantService::OnMostVisitedItemsReceived(
269 const history::MostVisitedURLList& data) { 325 const history::MostVisitedURLList& data) {
270 history::MostVisitedURLList reordered_data(data); 326 history::MostVisitedURLList reordered_data(data);
271 std::vector<InstantMostVisitedItem> new_most_visited_items; 327 std::vector<InstantMostVisitedItem> new_most_visited_items;
272 for (size_t i = 0; i < reordered_data.size(); i++) { 328 for (size_t i = 0; i < reordered_data.size(); i++) {
273 const history::MostVisitedURL& url = reordered_data[i]; 329 const history::MostVisitedURL& url = reordered_data[i];
274 InstantMostVisitedItem item; 330 InstantMostVisitedItem item;
275 item.url = url.url; 331 item.url = url.url;
276 item.title = url.title; 332 item.title = url.title;
277 new_most_visited_items.push_back(item); 333 new_most_visited_items.push_back(item);
278 } 334 }
279 335
280 most_visited_items_ = new_most_visited_items; 336 most_visited_items_ = new_most_visited_items;
281 NotifyAboutMostVisitedItems(); 337 NotifyAboutMostVisitedItems();
282 } 338 }
283 339
284 void InstantService::NotifyAboutMostVisitedItems() { 340 void InstantService::NotifyAboutMostVisitedItems() {
285 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, 341 if (suggestions_service && !suggestions_items_.empty()) {
286 MostVisitedItemsChanged(most_visited_items_)); 342 FOR_EACH_OBSERVER(InstantServiceObserver, observers_,
343 MostVisitedItemsChanged(suggestions_items_));
344 } else {
345 FOR_EACH_OBSERVER(InstantServiceObserver, observers_,
346 MostVisitedItemsChanged(most_visited_items_));
347 }
287 } 348 }
288 349
289 #if defined(ENABLE_THEMES) 350 #if defined(ENABLE_THEMES)
290 351
291 namespace { 352 namespace {
292 353
293 const int kSectionBorderAlphaTransparency = 80; 354 const int kSectionBorderAlphaTransparency = 80;
294 355
295 // Converts SkColor to RGBAColor 356 // Converts SkColor to RGBAColor
296 RGBAColor SkColorToRGBAColor(const SkColor& sKColor) { 357 RGBAColor SkColorToRGBAColor(const SkColor& sKColor) {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 } 522 }
462 523
463 void InstantService::ResetInstantSearchPrerenderer() { 524 void InstantService::ResetInstantSearchPrerenderer() {
464 if (!chrome::ShouldPrefetchSearchResults()) 525 if (!chrome::ShouldPrefetchSearchResults())
465 return; 526 return;
466 527
467 GURL url(chrome::GetSearchResultPrefetchBaseURL(profile_)); 528 GURL url(chrome::GetSearchResultPrefetchBaseURL(profile_));
468 instant_prerenderer_.reset( 529 instant_prerenderer_.reset(
469 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL); 530 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL);
470 } 531 }
OLDNEW
« no previous file with comments | « chrome/browser/search/instant_service.h ('k') | chrome/common/instant_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698