OLD | NEW |
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/bind.h" | 9 #include "base/bind.h" |
10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 #include "content/public/browser/notification_service.h" | 44 #include "content/public/browser/notification_service.h" |
45 #include "content/public/browser/notification_types.h" | 45 #include "content/public/browser/notification_types.h" |
46 #include "content/public/browser/render_process_host.h" | 46 #include "content/public/browser/render_process_host.h" |
47 #include "content/public/browser/url_data_source.h" | 47 #include "content/public/browser/url_data_source.h" |
48 #include "third_party/skia/include/core/SkColor.h" | 48 #include "third_party/skia/include/core/SkColor.h" |
49 #include "ui/gfx/color_utils.h" | 49 #include "ui/gfx/color_utils.h" |
50 #include "ui/gfx/image/image_skia.h" | 50 #include "ui/gfx/image/image_skia.h" |
51 | 51 |
52 #if !defined(OS_ANDROID) | 52 #if !defined(OS_ANDROID) |
53 #include "chrome/browser/search/local_ntp_source.h" | 53 #include "chrome/browser/search/local_ntp_source.h" |
54 #endif | |
55 | |
56 #if defined(ENABLE_THEMES) | |
57 #include "chrome/browser/themes/theme_properties.h" | 54 #include "chrome/browser/themes/theme_properties.h" |
58 #include "chrome/browser/themes/theme_service.h" | 55 #include "chrome/browser/themes/theme_service.h" |
59 #include "chrome/browser/themes/theme_service_factory.h" | 56 #include "chrome/browser/themes/theme_service_factory.h" |
60 #endif // defined(ENABLE_THEMES) | 57 #endif |
61 | 58 |
62 namespace { | 59 namespace { |
63 | 60 |
64 const base::Feature kNtpTilesFeature{"NTPTilesInInstantService", | 61 const base::Feature kNtpTilesFeature{"NTPTilesInInstantService", |
65 base::FEATURE_DISABLED_BY_DEFAULT}; | 62 base::FEATURE_DISABLED_BY_DEFAULT}; |
66 | 63 |
67 } // namespace | 64 } // namespace |
68 | 65 |
69 InstantService::InstantService(Profile* profile) | 66 InstantService::InstantService(Profile* profile) |
70 : profile_(profile), | 67 : profile_(profile), |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 } | 126 } |
130 | 127 |
131 if (profile_ && profile_->GetResourceContext()) { | 128 if (profile_ && profile_->GetResourceContext()) { |
132 content::BrowserThread::PostTask( | 129 content::BrowserThread::PostTask( |
133 content::BrowserThread::IO, FROM_HERE, | 130 content::BrowserThread::IO, FROM_HERE, |
134 base::Bind(&InstantIOContext::SetUserDataOnIO, | 131 base::Bind(&InstantIOContext::SetUserDataOnIO, |
135 profile->GetResourceContext(), instant_io_context_)); | 132 profile->GetResourceContext(), instant_io_context_)); |
136 } | 133 } |
137 | 134 |
138 // Set up the data sources that Instant uses on the NTP. | 135 // Set up the data sources that Instant uses on the NTP. |
139 #if defined(ENABLE_THEMES) | 136 // TODO(aurimas) remove this #if once instant_service.cc is no longer compiled |
| 137 // on Android. |
| 138 #if !defined(OS_ANDROID) |
140 // Listen for theme installation. | 139 // Listen for theme installation. |
141 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 140 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
142 content::Source<ThemeService>( | 141 content::Source<ThemeService>( |
143 ThemeServiceFactory::GetForProfile(profile_))); | 142 ThemeServiceFactory::GetForProfile(profile_))); |
144 | 143 |
145 content::URLDataSource::Add(profile_, new ThemeSource(profile_)); | 144 content::URLDataSource::Add(profile_, new ThemeSource(profile_)); |
146 #endif // defined(ENABLE_THEMES) | |
147 | |
148 // TODO(aurimas) remove this #if once instant_service.cc is no longer compiled | |
149 // on Android. | |
150 #if !defined(OS_ANDROID) | |
151 content::URLDataSource::Add(profile_, new LocalNtpSource(profile_)); | 145 content::URLDataSource::Add(profile_, new LocalNtpSource(profile_)); |
152 content::URLDataSource::Add(profile_, new ThumbnailSource(profile_, false)); | 146 content::URLDataSource::Add(profile_, new ThumbnailSource(profile_, false)); |
153 content::URLDataSource::Add(profile_, new ThumbnailSource(profile_, true)); | 147 content::URLDataSource::Add(profile_, new ThumbnailSource(profile_, true)); |
154 content::URLDataSource::Add(profile_, new ThumbnailListSource(profile_)); | 148 content::URLDataSource::Add(profile_, new ThumbnailListSource(profile_)); |
155 #endif // !defined(OS_ANDROID) | 149 #endif // !defined(OS_ANDROID) |
156 | 150 |
157 favicon::FallbackIconService* fallback_icon_service = | 151 favicon::FallbackIconService* fallback_icon_service = |
158 FallbackIconServiceFactory::GetForBrowserContext(profile_); | 152 FallbackIconServiceFactory::GetForBrowserContext(profile_); |
159 favicon::LargeIconService* large_icon_service = | 153 favicon::LargeIconService* large_icon_service = |
160 LargeIconServiceFactory::GetForBrowserContext(profile_); | 154 LargeIconServiceFactory::GetForBrowserContext(profile_); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 | 215 |
222 void InstantService::UndoAllMostVisitedDeletions() { | 216 void InstantService::UndoAllMostVisitedDeletions() { |
223 if (most_visited_sites_) { | 217 if (most_visited_sites_) { |
224 most_visited_sites_->ClearBlacklistedUrls(); | 218 most_visited_sites_->ClearBlacklistedUrls(); |
225 } else if (top_sites_) { | 219 } else if (top_sites_) { |
226 top_sites_->ClearBlacklistedURLs(); | 220 top_sites_->ClearBlacklistedURLs(); |
227 } | 221 } |
228 } | 222 } |
229 | 223 |
230 void InstantService::UpdateThemeInfo() { | 224 void InstantService::UpdateThemeInfo() { |
231 #if defined(ENABLE_THEMES) | 225 #if !defined(OS_ANDROID) |
232 // Update theme background info. | 226 // Update theme background info. |
233 // Initialize |theme_info| if necessary. | 227 // Initialize |theme_info| if necessary. |
234 if (!theme_info_) { | 228 if (!theme_info_) { |
235 OnThemeChanged(); | 229 OnThemeChanged(); |
236 } else { | 230 } else { |
237 for (InstantServiceObserver& observer : observers_) | 231 for (InstantServiceObserver& observer : observers_) |
238 observer.ThemeInfoChanged(*theme_info_); | 232 observer.ThemeInfoChanged(*theme_info_); |
239 } | 233 } |
240 #endif // defined(ENABLE_THEMES) | 234 #endif // !defined(OS_ANDROID) |
241 } | 235 } |
242 | 236 |
243 void InstantService::UpdateMostVisitedItemsInfo() { | 237 void InstantService::UpdateMostVisitedItemsInfo() { |
244 NotifyAboutMostVisitedItems(); | 238 NotifyAboutMostVisitedItems(); |
245 } | 239 } |
246 | 240 |
247 void InstantService::SendSearchURLsToRenderer(content::RenderProcessHost* rph) { | 241 void InstantService::SendSearchURLsToRenderer(content::RenderProcessHost* rph) { |
248 rph->Send(new ChromeViewMsg_SetSearchURLs( | 242 rph->Send(new ChromeViewMsg_SetSearchURLs( |
249 search::GetSearchURLs(profile_), search::GetNewTabPageURL(profile_))); | 243 search::GetSearchURLs(profile_), search::GetNewTabPageURL(profile_))); |
250 } | 244 } |
(...skipping 30 matching lines...) Expand all Loading... |
281 const content::NotificationDetails& details) { | 275 const content::NotificationDetails& details) { |
282 switch (type) { | 276 switch (type) { |
283 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: | 277 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: |
284 SendSearchURLsToRenderer( | 278 SendSearchURLsToRenderer( |
285 content::Source<content::RenderProcessHost>(source).ptr()); | 279 content::Source<content::RenderProcessHost>(source).ptr()); |
286 break; | 280 break; |
287 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: | 281 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: |
288 OnRendererProcessTerminated( | 282 OnRendererProcessTerminated( |
289 content::Source<content::RenderProcessHost>(source)->GetID()); | 283 content::Source<content::RenderProcessHost>(source)->GetID()); |
290 break; | 284 break; |
291 #if defined(ENABLE_THEMES) | 285 #if !defined(OS_ANDROID) |
292 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: | 286 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: |
293 OnThemeChanged(); | 287 OnThemeChanged(); |
294 break; | 288 break; |
295 #endif // defined(ENABLE_THEMES) | 289 #endif // !defined(OS_ANDROID) |
296 default: | 290 default: |
297 NOTREACHED() << "Unexpected notification type in InstantService."; | 291 NOTREACHED() << "Unexpected notification type in InstantService."; |
298 } | 292 } |
299 } | 293 } |
300 | 294 |
301 void InstantService::OnRendererProcessTerminated(int process_id) { | 295 void InstantService::OnRendererProcessTerminated(int process_id) { |
302 process_ids_.erase(process_id); | 296 process_ids_.erase(process_id); |
303 | 297 |
304 if (instant_io_context_.get()) { | 298 if (instant_io_context_.get()) { |
305 content::BrowserThread::PostTask( | 299 content::BrowserThread::PostTask( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 NotifyAboutMostVisitedItems(); | 334 NotifyAboutMostVisitedItems(); |
341 } | 335 } |
342 | 336 |
343 void InstantService::OnIconMadeAvailable(const GURL& site_url) {} | 337 void InstantService::OnIconMadeAvailable(const GURL& site_url) {} |
344 | 338 |
345 void InstantService::NotifyAboutMostVisitedItems() { | 339 void InstantService::NotifyAboutMostVisitedItems() { |
346 for (InstantServiceObserver& observer : observers_) | 340 for (InstantServiceObserver& observer : observers_) |
347 observer.MostVisitedItemsChanged(most_visited_items_); | 341 observer.MostVisitedItemsChanged(most_visited_items_); |
348 } | 342 } |
349 | 343 |
350 #if defined(ENABLE_THEMES) | 344 #if !defined(OS_ANDROID) |
351 | 345 |
352 namespace { | 346 namespace { |
353 | 347 |
354 const int kSectionBorderAlphaTransparency = 80; | 348 const int kSectionBorderAlphaTransparency = 80; |
355 | 349 |
356 // Converts SkColor to RGBAColor | 350 // Converts SkColor to RGBAColor |
357 RGBAColor SkColorToRGBAColor(const SkColor& sKColor) { | 351 RGBAColor SkColorToRGBAColor(const SkColor& sKColor) { |
358 RGBAColor color; | 352 RGBAColor color; |
359 color.r = SkColorGetR(sKColor); | 353 color.r = SkColorGetR(sKColor); |
360 color.g = SkColorGetG(sKColor); | 354 color.g = SkColorGetG(sKColor); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 DCHECK(image); | 453 DCHECK(image); |
460 theme_info_->image_height = image->height(); | 454 theme_info_->image_height = image->height(); |
461 | 455 |
462 theme_info_->has_attribution = | 456 theme_info_->has_attribution = |
463 theme_provider.HasCustomImage(IDR_THEME_NTP_ATTRIBUTION); | 457 theme_provider.HasCustomImage(IDR_THEME_NTP_ATTRIBUTION); |
464 } | 458 } |
465 | 459 |
466 for (InstantServiceObserver& observer : observers_) | 460 for (InstantServiceObserver& observer : observers_) |
467 observer.ThemeInfoChanged(*theme_info_); | 461 observer.ThemeInfoChanged(*theme_info_); |
468 } | 462 } |
469 #endif // defined(ENABLE_THEMES) | 463 #endif // !defined(OS_ANDROID) |
470 | 464 |
471 void InstantService::OnTemplateURLServiceChanged() { | 465 void InstantService::OnTemplateURLServiceChanged() { |
472 // Check whether the default search provider was changed. | 466 // Check whether the default search provider was changed. |
473 const TemplateURL* template_url = | 467 const TemplateURL* template_url = |
474 template_url_service_->GetDefaultSearchProvider(); | 468 template_url_service_->GetDefaultSearchProvider(); |
475 bool default_search_provider_changed = !TemplateURL::MatchesData( | 469 bool default_search_provider_changed = !TemplateURL::MatchesData( |
476 template_url, previous_default_search_provider_.get(), | 470 template_url, previous_default_search_provider_.get(), |
477 UIThreadSearchTermsData(profile_)); | 471 UIThreadSearchTermsData(profile_)); |
478 if (default_search_provider_changed) { | 472 if (default_search_provider_changed) { |
479 previous_default_search_provider_.reset( | 473 previous_default_search_provider_.reset( |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 void InstantService::ResetInstantSearchPrerendererIfNecessary() { | 515 void InstantService::ResetInstantSearchPrerendererIfNecessary() { |
522 if (!search::ShouldPrefetchSearchResults()) | 516 if (!search::ShouldPrefetchSearchResults()) |
523 return; | 517 return; |
524 | 518 |
525 GURL url(search::GetSearchResultPrefetchBaseURL(profile_)); | 519 GURL url(search::GetSearchResultPrefetchBaseURL(profile_)); |
526 if (!instant_prerenderer_ || instant_prerenderer_->prerender_url() != url) { | 520 if (!instant_prerenderer_ || instant_prerenderer_->prerender_url() != url) { |
527 instant_prerenderer_.reset( | 521 instant_prerenderer_.reset( |
528 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : nullptr); | 522 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : nullptr); |
529 } | 523 } |
530 } | 524 } |
OLD | NEW |