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

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

Issue 2660883002: Introduce a Doodle Fetcher for NTP (Closed)
Patch Set: Created 3 years, 10 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/BUILD.gn ('k') | components/BUILD.gn » ('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 <stddef.h> 7 #include <stddef.h>
8 #include <string>
9 #include <utility>
8 10
9 #include "base/bind.h" 11 #include "base/bind.h"
10 #include "base/feature_list.h" 12 #include "base/feature_list.h"
13 #include "base/json/json_reader.h"
11 #include "build/build_config.h" 14 #include "build/build_config.h"
12 #include "chrome/browser/chrome_notification_types.h" 15 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/favicon/fallback_icon_service_factory.h" 16 #include "chrome/browser/favicon/fallback_icon_service_factory.h"
14 #include "chrome/browser/favicon/favicon_service_factory.h" 17 #include "chrome/browser/favicon/favicon_service_factory.h"
15 #include "chrome/browser/favicon/large_icon_service_factory.h" 18 #include "chrome/browser/favicon/large_icon_service_factory.h"
16 #include "chrome/browser/history/top_sites_factory.h" 19 #include "chrome/browser/history/top_sites_factory.h"
17 #include "chrome/browser/ntp_tiles/chrome_most_visited_sites_factory.h" 20 #include "chrome/browser/ntp_tiles/chrome_most_visited_sites_factory.h"
18 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/search/instant_io_context.h" 22 #include "chrome/browser/search/instant_io_context.h"
20 #include "chrome/browser/search/instant_service_observer.h" 23 #include "chrome/browser/search/instant_service_observer.h"
21 #include "chrome/browser/search/most_visited_iframe_source.h" 24 #include "chrome/browser/search/most_visited_iframe_source.h"
22 #include "chrome/browser/search/search.h" 25 #include "chrome/browser/search/search.h"
23 #include "chrome/browser/search/suggestions/image_decoder_impl.h" 26 #include "chrome/browser/search/suggestions/image_decoder_impl.h"
24 #include "chrome/browser/search/suggestions/suggestions_service_factory.h" 27 #include "chrome/browser/search/suggestions/suggestions_service_factory.h"
25 #include "chrome/browser/search/thumbnail_source.h" 28 #include "chrome/browser/search/thumbnail_source.h"
26 #include "chrome/browser/search_engines/template_url_service_factory.h" 29 #include "chrome/browser/search_engines/template_url_service_factory.h"
27 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" 30 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
28 #include "chrome/browser/thumbnails/thumbnail_list_source.h" 31 #include "chrome/browser/thumbnails/thumbnail_list_source.h"
29 #include "chrome/browser/ui/search/instant_search_prerenderer.h" 32 #include "chrome/browser/ui/search/instant_search_prerenderer.h"
30 #include "chrome/browser/ui/webui/fallback_icon_source.h" 33 #include "chrome/browser/ui/webui/fallback_icon_source.h"
31 #include "chrome/browser/ui/webui/favicon_source.h" 34 #include "chrome/browser/ui/webui/favicon_source.h"
32 #include "chrome/browser/ui/webui/large_icon_source.h" 35 #include "chrome/browser/ui/webui/large_icon_source.h"
33 #include "chrome/browser/ui/webui/theme_source.h" 36 #include "chrome/browser/ui/webui/theme_source.h"
34 #include "chrome/common/render_messages.h" 37 #include "chrome/common/render_messages.h"
35 #include "chrome/grit/theme_resources.h" 38 #include "chrome/grit/theme_resources.h"
39 #include "components/doodle/doodle_fetcher.h"
36 #include "components/favicon/core/fallback_icon_service.h" 40 #include "components/favicon/core/fallback_icon_service.h"
37 #include "components/favicon/core/large_icon_service.h" 41 #include "components/favicon/core/large_icon_service.h"
38 #include "components/history/core/browser/top_sites.h" 42 #include "components/history/core/browser/top_sites.h"
39 #include "components/image_fetcher/image_fetcher_impl.h" 43 #include "components/image_fetcher/image_fetcher_impl.h"
40 #include "components/keyed_service/core/service_access_type.h" 44 #include "components/keyed_service/core/service_access_type.h"
41 #include "components/ntp_tiles/icon_cacher.h" 45 #include "components/ntp_tiles/icon_cacher.h"
42 #include "components/search/search.h" 46 #include "components/search/search.h"
43 #include "components/search_engines/template_url_service.h" 47 #include "components/search_engines/template_url_service.h"
44 #include "content/public/browser/browser_thread.h" 48 #include "content/public/browser/browser_thread.h"
45 #include "content/public/browser/notification_service.h" 49 #include "content/public/browser/notification_service.h"
46 #include "content/public/browser/notification_types.h" 50 #include "content/public/browser/notification_types.h"
47 #include "content/public/browser/render_process_host.h" 51 #include "content/public/browser/render_process_host.h"
48 #include "content/public/browser/url_data_source.h" 52 #include "content/public/browser/url_data_source.h"
49 #include "third_party/skia/include/core/SkColor.h" 53 #include "third_party/skia/include/core/SkColor.h"
50 #include "ui/gfx/color_utils.h" 54 #include "ui/gfx/color_utils.h"
51 #include "ui/gfx/image/image_skia.h" 55 #include "ui/gfx/image/image_skia.h"
52 56
53 #if !defined(OS_ANDROID) 57 #if !defined(OS_ANDROID)
54 #include "chrome/browser/search/local_ntp_source.h" 58 #include "chrome/browser/search/local_ntp_source.h"
55 #include "chrome/browser/themes/theme_properties.h" 59 #include "chrome/browser/themes/theme_properties.h"
56 #include "chrome/browser/themes/theme_service.h" 60 #include "chrome/browser/themes/theme_service.h"
57 #include "chrome/browser/themes/theme_service_factory.h" 61 #include "chrome/browser/themes/theme_service_factory.h"
58 #endif 62 #endif
59 63
60 namespace { 64 namespace {
61 65
62 const base::Feature kNtpTilesFeature{"NTPTilesInInstantService", 66 const base::Feature kNtpTilesFeature{"NTPTilesInInstantService",
63 base::FEATURE_DISABLED_BY_DEFAULT}; 67 base::FEATURE_DISABLED_BY_DEFAULT};
64 68
69 void ParseJson(
70 const std::string& json,
71 const base::Callback<void(std::unique_ptr<base::Value>)>& success_callback,
72 const base::Callback<void(const std::string&)>& error_callback) {
73 base::JSONReader json_reader;
74 std::unique_ptr<base::Value> value = json_reader.ReadToValue(json);
75 if (value) {
76 success_callback.Run(std::move(value));
77 } else {
78 error_callback.Run(json_reader.GetErrorMessage());
79 }
80 }
81
65 } // namespace 82 } // namespace
66 83
67 InstantService::InstantService(Profile* profile) 84 InstantService::InstantService(Profile* profile)
68 : profile_(profile), 85 : profile_(profile),
69 template_url_service_(TemplateURLServiceFactory::GetForProfile(profile_)), 86 template_url_service_(TemplateURLServiceFactory::GetForProfile(profile_)),
70 weak_ptr_factory_(this) { 87 weak_ptr_factory_(this) {
71 // The initialization below depends on a typical set of browser threads. Skip 88 // The initialization below depends on a typical set of browser threads. Skip
72 // it if we are running in a unit test without the full suite. 89 // it if we are running in a unit test without the full suite.
73 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) 90 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI))
74 return; 91 return;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 FallbackIconServiceFactory::GetForBrowserContext(profile_); 158 FallbackIconServiceFactory::GetForBrowserContext(profile_);
142 favicon::LargeIconService* large_icon_service = 159 favicon::LargeIconService* large_icon_service =
143 LargeIconServiceFactory::GetForBrowserContext(profile_); 160 LargeIconServiceFactory::GetForBrowserContext(profile_);
144 content::URLDataSource::Add( 161 content::URLDataSource::Add(
145 profile_, new FallbackIconSource(fallback_icon_service)); 162 profile_, new FallbackIconSource(fallback_icon_service));
146 content::URLDataSource::Add( 163 content::URLDataSource::Add(
147 profile_, new FaviconSource(profile_, FaviconSource::FAVICON)); 164 profile_, new FaviconSource(profile_, FaviconSource::FAVICON));
148 content::URLDataSource::Add( 165 content::URLDataSource::Add(
149 profile_, new LargeIconSource(fallback_icon_service, large_icon_service)); 166 profile_, new LargeIconSource(fallback_icon_service, large_icon_service));
150 content::URLDataSource::Add(profile_, new MostVisitedIframeSource()); 167 content::URLDataSource::Add(profile_, new MostVisitedIframeSource());
168
169 DoodleFetcher doodle_fetcher(profile_->GetRequestContext(),
170 base::Bind(ParseJson));
171 LOG(ERROR) << "DEBUG DoodleFetcher: Fetcher created.";
172 doodle_fetcher.FetchDoodle(base::Bind([](DoodleConfig config) {
173 if (config.error_during_fetch) {
174 LOG(ERROR) << "DEBUG DoodleFetcher: Error during fetch.";
175 }
176 LOG(ERROR) << "DEBUG DoodleFetcher: config.search_url="
177 << config.search_url;
178 LOG(ERROR) << "DEBUG DoodleFetcher: config.large_image.url="
179 << config.large_image.url;
180 }));
181 LOG(ERROR) << "DEBUG DoodleFetcher: Fetch started.";
151 } 182 }
152 183
153 InstantService::~InstantService() { 184 InstantService::~InstantService() {
154 if (template_url_service_) 185 if (template_url_service_)
155 template_url_service_->RemoveObserver(this); 186 template_url_service_->RemoveObserver(this);
156 } 187 }
157 188
158 void InstantService::AddInstantProcess(int process_id) { 189 void InstantService::AddInstantProcess(int process_id) {
159 process_ids_.insert(process_id); 190 process_ids_.insert(process_id);
160 191
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 void InstantService::ResetInstantSearchPrerendererIfNecessary() { 535 void InstantService::ResetInstantSearchPrerendererIfNecessary() {
505 if (!search::IsInstantExtendedAPIEnabled()) 536 if (!search::IsInstantExtendedAPIEnabled())
506 return; 537 return;
507 538
508 GURL url(search::GetSearchResultPrefetchBaseURL(profile_)); 539 GURL url(search::GetSearchResultPrefetchBaseURL(profile_));
509 if (!instant_prerenderer_ || instant_prerenderer_->prerender_url() != url) { 540 if (!instant_prerenderer_ || instant_prerenderer_->prerender_url() != url) {
510 instant_prerenderer_.reset( 541 instant_prerenderer_.reset(
511 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : nullptr); 542 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : nullptr);
512 } 543 }
513 } 544 }
OLDNEW
« no previous file with comments | « chrome/browser/BUILD.gn ('k') | components/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698