Chromium Code Reviews| 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 "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/history/top_sites_factory.h" | 8 #include "chrome/browser/history/top_sites_factory.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/search/instant_io_context.h" | 10 #include "chrome/browser/search/instant_io_context.h" |
| 11 #include "chrome/browser/search/instant_service_observer.h" | 11 #include "chrome/browser/search/instant_service_observer.h" |
| 12 #include "chrome/browser/search/most_visited_iframe_source.h" | 12 #include "chrome/browser/search/most_visited_iframe_source.h" |
| 13 #include "chrome/browser/search/search.h" | 13 #include "chrome/browser/search/search.h" |
| 14 #include "chrome/browser/search/suggestions/suggestions_source.h" | 14 #include "chrome/browser/search/suggestions/suggestions_source.h" |
| 15 #include "chrome/browser/search_engines/template_url_service_factory.h" | 15 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 16 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 16 #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_service.h" | |
| 19 #include "chrome/browser/themes/theme_service_factory.h" | |
| 20 #include "chrome/browser/thumbnails/thumbnail_list_source.h" | 17 #include "chrome/browser/thumbnails/thumbnail_list_source.h" |
| 21 #include "chrome/browser/ui/search/instant_search_prerenderer.h" | 18 #include "chrome/browser/ui/search/instant_search_prerenderer.h" |
| 22 #include "chrome/browser/ui/webui/fallback_icon_source.h" | 19 #include "chrome/browser/ui/webui/fallback_icon_source.h" |
| 23 #include "chrome/browser/ui/webui/favicon_source.h" | 20 #include "chrome/browser/ui/webui/favicon_source.h" |
| 24 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" | 21 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" |
| 25 #include "chrome/browser/ui/webui/theme_source.h" | |
| 26 #include "chrome/common/render_messages.h" | 22 #include "chrome/common/render_messages.h" |
| 27 #include "components/history/core/browser/top_sites.h" | 23 #include "components/history/core/browser/top_sites.h" |
| 28 #include "components/search_engines/template_url_service.h" | 24 #include "components/search_engines/template_url_service.h" |
| 29 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 30 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 31 #include "content/public/browser/notification_types.h" | 27 #include "content/public/browser/notification_types.h" |
| 32 #include "content/public/browser/render_process_host.h" | 28 #include "content/public/browser/render_process_host.h" |
| 33 #include "content/public/browser/url_data_source.h" | 29 #include "content/public/browser/url_data_source.h" |
| 34 #include "grit/theme_resources.h" | |
| 35 #include "third_party/skia/include/core/SkColor.h" | 30 #include "third_party/skia/include/core/SkColor.h" |
| 36 #include "ui/gfx/color_utils.h" | 31 #include "ui/gfx/color_utils.h" |
| 37 #include "ui/gfx/image/image_skia.h" | 32 #include "ui/gfx/image/image_skia.h" |
| 38 #include "ui/gfx/sys_color_change_listener.h" | 33 #include "ui/gfx/sys_color_change_listener.h" |
| 39 | 34 |
| 40 #if !defined(OS_ANDROID) | 35 #if !defined(OS_ANDROID) |
| 41 #include "chrome/browser/search/local_ntp_source.h" | 36 #include "chrome/browser/search/local_ntp_source.h" |
| 42 #endif | 37 #endif |
| 43 | 38 |
| 39 #if defined(ENABLE_THEMES) | |
| 40 #include "chrome/browser/themes/theme_properties.h" | |
| 41 #include "chrome/browser/themes/theme_service.h" | |
| 42 #include "chrome/browser/themes/theme_service_factory.h" | |
| 43 #include "chrome/browser/ui/webui/theme_source.h" | |
| 44 #include "grit/theme_resources.h" | |
|
pkotwicz
2015/03/11 01:02:58
Nit: theme_resources.h should not be in the ifdef.
| |
| 45 #endif | |
| 46 | |
| 44 namespace { | 47 namespace { |
| 45 | 48 |
| 49 #if defined(ENABLE_THEMES) | |
| 46 const int kSectionBorderAlphaTransparency = 80; | 50 const int kSectionBorderAlphaTransparency = 80; |
| 47 | 51 |
| 48 // Converts SkColor to RGBAColor | 52 // Converts SkColor to RGBAColor |
| 49 RGBAColor SkColorToRGBAColor(const SkColor& sKColor) { | 53 RGBAColor SkColorToRGBAColor(const SkColor& sKColor) { |
| 50 RGBAColor color; | 54 RGBAColor color; |
| 51 color.r = SkColorGetR(sKColor); | 55 color.r = SkColorGetR(sKColor); |
| 52 color.g = SkColorGetG(sKColor); | 56 color.g = SkColorGetG(sKColor); |
| 53 color.b = SkColorGetB(sKColor); | 57 color.b = SkColorGetB(sKColor); |
| 54 color.a = SkColorGetA(sKColor); | 58 color.a = SkColorGetA(sKColor); |
| 55 return color; | 59 return color; |
| 56 } | 60 } |
| 61 #endif | |
| 57 | 62 |
| 58 } // namespace | 63 } // namespace |
| 59 | 64 |
| 60 InstantService::InstantService(Profile* profile) | 65 InstantService::InstantService(Profile* profile) |
| 61 : profile_(profile), | 66 : profile_(profile), |
| 62 template_url_service_(TemplateURLServiceFactory::GetForProfile(profile_)), | 67 template_url_service_(TemplateURLServiceFactory::GetForProfile(profile_)), |
| 63 omnibox_start_margin_(chrome::kDisableStartMargin), | 68 omnibox_start_margin_(chrome::kDisableStartMargin), |
| 64 weak_ptr_factory_(this) { | 69 weak_ptr_factory_(this) { |
| 65 // The initialization below depends on a typical set of browser threads. Skip | 70 // The initialization below depends on a typical set of browser threads. Skip |
| 66 // it if we are running in a unit test without the full suite. | 71 // it if we are running in a unit test without the full suite. |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 void InstantService::UndoAllMostVisitedDeletions() { | 187 void InstantService::UndoAllMostVisitedDeletions() { |
| 183 scoped_refptr<history::TopSites> top_sites = | 188 scoped_refptr<history::TopSites> top_sites = |
| 184 TopSitesFactory::GetForProfile(profile_); | 189 TopSitesFactory::GetForProfile(profile_); |
| 185 if (!top_sites) | 190 if (!top_sites) |
| 186 return; | 191 return; |
| 187 | 192 |
| 188 top_sites->ClearBlacklistedURLs(); | 193 top_sites->ClearBlacklistedURLs(); |
| 189 } | 194 } |
| 190 | 195 |
| 191 void InstantService::UpdateThemeInfo() { | 196 void InstantService::UpdateThemeInfo() { |
| 197 #if defined(ENABLE_THEMES) | |
| 192 // Update theme background info. | 198 // Update theme background info. |
| 193 // Initialize |theme_info| if necessary. | 199 // Initialize |theme_info| if necessary. |
| 194 if (!theme_info_) | 200 if (!theme_info_) |
| 195 OnThemeChanged(ThemeServiceFactory::GetForProfile(profile_)); | 201 OnThemeChanged(ThemeServiceFactory::GetForProfile(profile_)); |
| 196 else | 202 else |
| 197 OnThemeChanged(NULL); | 203 OnThemeChanged(NULL); |
| 204 #endif | |
| 198 } | 205 } |
| 199 | 206 |
| 200 void InstantService::UpdateMostVisitedItemsInfo() { | 207 void InstantService::UpdateMostVisitedItemsInfo() { |
| 201 NotifyAboutMostVisitedItems(); | 208 NotifyAboutMostVisitedItems(); |
| 202 } | 209 } |
| 203 | 210 |
| 204 void InstantService::Shutdown() { | 211 void InstantService::Shutdown() { |
| 205 process_ids_.clear(); | 212 process_ids_.clear(); |
| 206 | 213 |
| 207 if (instant_io_context_.get()) { | 214 if (instant_io_context_.get()) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 | 285 |
| 279 most_visited_items_ = new_most_visited_items; | 286 most_visited_items_ = new_most_visited_items; |
| 280 NotifyAboutMostVisitedItems(); | 287 NotifyAboutMostVisitedItems(); |
| 281 } | 288 } |
| 282 | 289 |
| 283 void InstantService::NotifyAboutMostVisitedItems() { | 290 void InstantService::NotifyAboutMostVisitedItems() { |
| 284 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, | 291 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, |
| 285 MostVisitedItemsChanged(most_visited_items_)); | 292 MostVisitedItemsChanged(most_visited_items_)); |
| 286 } | 293 } |
| 287 | 294 |
| 295 #if defined(ENABLE_THEMES) | |
| 288 void InstantService::OnThemeChanged(ThemeService* theme_service) { | 296 void InstantService::OnThemeChanged(ThemeService* theme_service) { |
| 289 if (!theme_service) { | 297 if (!theme_service) { |
| 290 DCHECK(theme_info_.get()); | 298 DCHECK(theme_info_.get()); |
| 291 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, | 299 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, |
| 292 ThemeInfoChanged(*theme_info_)); | 300 ThemeInfoChanged(*theme_info_)); |
| 293 return; | 301 return; |
| 294 } | 302 } |
| 295 | 303 |
| 296 // Get theme information from theme service. | 304 // Get theme information from theme service. |
| 297 theme_info_.reset(new ThemeBackgroundInfo()); | 305 theme_info_.reset(new ThemeBackgroundInfo()); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 DCHECK(image); | 393 DCHECK(image); |
| 386 theme_info_->image_height = image->height(); | 394 theme_info_->image_height = image->height(); |
| 387 | 395 |
| 388 theme_info_->has_attribution = | 396 theme_info_->has_attribution = |
| 389 theme_service->HasCustomImage(IDR_THEME_NTP_ATTRIBUTION); | 397 theme_service->HasCustomImage(IDR_THEME_NTP_ATTRIBUTION); |
| 390 } | 398 } |
| 391 | 399 |
| 392 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, | 400 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, |
| 393 ThemeInfoChanged(*theme_info_)); | 401 ThemeInfoChanged(*theme_info_)); |
| 394 } | 402 } |
| 403 #endif // defined(ENABLE_THEMES) | |
| 395 | 404 |
| 396 void InstantService::OnTemplateURLServiceChanged() { | 405 void InstantService::OnTemplateURLServiceChanged() { |
| 397 // Check whether the default search provider was changed. | 406 // Check whether the default search provider was changed. |
| 398 const TemplateURL* template_url = | 407 const TemplateURL* template_url = |
| 399 template_url_service_->GetDefaultSearchProvider(); | 408 template_url_service_->GetDefaultSearchProvider(); |
| 400 bool default_search_provider_changed = !TemplateURL::MatchesData( | 409 bool default_search_provider_changed = !TemplateURL::MatchesData( |
| 401 template_url, previous_default_search_provider_.get(), | 410 template_url, previous_default_search_provider_.get(), |
| 402 UIThreadSearchTermsData(profile_)); | 411 UIThreadSearchTermsData(profile_)); |
| 403 if (default_search_provider_changed) { | 412 if (default_search_provider_changed) { |
| 404 previous_default_search_provider_.reset( | 413 previous_default_search_provider_.reset( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 } | 446 } |
| 438 | 447 |
| 439 void InstantService::ResetInstantSearchPrerenderer() { | 448 void InstantService::ResetInstantSearchPrerenderer() { |
| 440 if (!chrome::ShouldPrefetchSearchResults()) | 449 if (!chrome::ShouldPrefetchSearchResults()) |
| 441 return; | 450 return; |
| 442 | 451 |
| 443 GURL url(chrome::GetSearchResultPrefetchBaseURL(profile_)); | 452 GURL url(chrome::GetSearchResultPrefetchBaseURL(profile_)); |
| 444 instant_prerenderer_.reset( | 453 instant_prerenderer_.reset( |
| 445 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL); | 454 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL); |
| 446 } | 455 } |
| OLD | NEW |