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/favicon/fallback_icon_service_factory.h" | 8 #include "chrome/browser/favicon/fallback_icon_service_factory.h" |
| 9 #include "chrome/browser/favicon/favicon_service_factory.h" | 9 #include "chrome/browser/favicon/large_icon_service_factory.h" |
| 10 #include "chrome/browser/history/top_sites_factory.h" | 10 #include "chrome/browser/history/top_sites_factory.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/search/instant_io_context.h" | 12 #include "chrome/browser/search/instant_io_context.h" |
| 13 #include "chrome/browser/search/instant_service_observer.h" | 13 #include "chrome/browser/search/instant_service_observer.h" |
| 14 #include "chrome/browser/search/most_visited_iframe_source.h" | 14 #include "chrome/browser/search/most_visited_iframe_source.h" |
| 15 #include "chrome/browser/search/search.h" | 15 #include "chrome/browser/search/search.h" |
| 16 #include "chrome/browser/search/suggestions/suggestions_source.h" | 16 #include "chrome/browser/search/suggestions/suggestions_source.h" |
| 17 #include "chrome/browser/search_engines/template_url_service_factory.h" | 17 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 18 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 18 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
| 19 #include "chrome/browser/themes/theme_properties.h" | |
|
huangs
2015/04/21 05:00:27
Artifact from syncing?
beaudoin
2015/04/21 15:11:11
Artifact from a revert before syncing. Good catch.
| |
| 20 #include "chrome/browser/themes/theme_service.h" | |
| 21 #include "chrome/browser/themes/theme_service_factory.h" | |
| 19 #include "chrome/browser/thumbnails/thumbnail_list_source.h" | 22 #include "chrome/browser/thumbnails/thumbnail_list_source.h" |
| 20 #include "chrome/browser/ui/search/instant_search_prerenderer.h" | 23 #include "chrome/browser/ui/search/instant_search_prerenderer.h" |
| 21 #include "chrome/browser/ui/webui/fallback_icon_source.h" | 24 #include "chrome/browser/ui/webui/fallback_icon_source.h" |
| 22 #include "chrome/browser/ui/webui/favicon_source.h" | 25 #include "chrome/browser/ui/webui/favicon_source.h" |
| 23 #include "chrome/browser/ui/webui/large_icon_source.h" | 26 #include "chrome/browser/ui/webui/large_icon_source.h" |
| 24 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" | 27 #include "chrome/browser/ui/webui/ntp/thumbnail_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/favicon_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" |
| 32 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
| 33 #include "content/public/browser/notification_service.h" | 36 #include "content/public/browser/notification_service.h" |
| 34 #include "content/public/browser/notification_types.h" | 37 #include "content/public/browser/notification_types.h" |
| 35 #include "content/public/browser/render_process_host.h" | 38 #include "content/public/browser/render_process_host.h" |
| 36 #include "content/public/browser/url_data_source.h" | 39 #include "content/public/browser/url_data_source.h" |
| 37 #include "grit/theme_resources.h" | 40 #include "grit/theme_resources.h" |
| 38 #include "third_party/skia/include/core/SkColor.h" | 41 #include "third_party/skia/include/core/SkColor.h" |
| 39 #include "ui/gfx/color_utils.h" | 42 #include "ui/gfx/color_utils.h" |
| 40 #include "ui/gfx/image/image_skia.h" | 43 #include "ui/gfx/image/image_skia.h" |
| 41 #include "ui/gfx/sys_color_change_listener.h" | 44 #include "ui/gfx/sys_color_change_listener.h" |
| 42 | 45 |
| 43 #if !defined(OS_ANDROID) | 46 #if !defined(OS_ANDROID) |
| 44 #include "chrome/browser/search/local_ntp_source.h" | 47 #include "chrome/browser/search/local_ntp_source.h" |
| 45 #endif | 48 #endif |
| 46 | 49 |
| 47 #if defined(ENABLE_THEMES) | 50 namespace { |
|
huangs
2015/04/21 05:00:27
Artifact from syncing? Etc.
beaudoin
2015/04/21 15:11:11
Done.
| |
| 48 #include "chrome/browser/themes/theme_properties.h" | 51 |
| 49 #include "chrome/browser/themes/theme_service.h" | 52 const int kSectionBorderAlphaTransparency = 80; |
| 50 #include "chrome/browser/themes/theme_service_factory.h" | 53 |
| 51 #endif // defined(ENABLE_THEMES) | 54 // Converts SkColor to RGBAColor |
| 55 RGBAColor SkColorToRGBAColor(const SkColor& sKColor) { | |
| 56 RGBAColor color; | |
| 57 color.r = SkColorGetR(sKColor); | |
| 58 color.g = SkColorGetG(sKColor); | |
| 59 color.b = SkColorGetB(sKColor); | |
| 60 color.a = SkColorGetA(sKColor); | |
| 61 return color; | |
| 62 } | |
| 63 | |
| 64 } // namespace | |
| 52 | 65 |
| 53 InstantService::InstantService(Profile* profile) | 66 InstantService::InstantService(Profile* profile) |
| 54 : profile_(profile), | 67 : profile_(profile), |
| 55 template_url_service_(TemplateURLServiceFactory::GetForProfile(profile_)), | 68 template_url_service_(TemplateURLServiceFactory::GetForProfile(profile_)), |
| 56 omnibox_start_margin_(chrome::kDisableStartMargin), | 69 omnibox_start_margin_(chrome::kDisableStartMargin), |
| 57 weak_ptr_factory_(this) { | 70 weak_ptr_factory_(this) { |
| 58 // The initialization below depends on a typical set of browser threads. Skip | 71 // The initialization below depends on a typical set of browser threads. Skip |
| 59 // it if we are running in a unit test without the full suite. | 72 // it if we are running in a unit test without the full suite. |
| 60 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) | 73 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) |
| 61 return; | 74 return; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 | 124 |
| 112 // TODO(aurimas) remove this #if once instant_service.cc is no longer compiled | 125 // TODO(aurimas) remove this #if once instant_service.cc is no longer compiled |
| 113 // on Android. | 126 // on Android. |
| 114 #if !defined(OS_ANDROID) | 127 #if !defined(OS_ANDROID) |
| 115 content::URLDataSource::Add(profile_, new LocalNtpSource(profile_)); | 128 content::URLDataSource::Add(profile_, new LocalNtpSource(profile_)); |
| 116 content::URLDataSource::Add(profile_, new ThumbnailSource(profile_, false)); | 129 content::URLDataSource::Add(profile_, new ThumbnailSource(profile_, false)); |
| 117 content::URLDataSource::Add(profile_, new ThumbnailSource(profile_, true)); | 130 content::URLDataSource::Add(profile_, new ThumbnailSource(profile_, true)); |
| 118 content::URLDataSource::Add(profile_, new ThumbnailListSource(profile_)); | 131 content::URLDataSource::Add(profile_, new ThumbnailListSource(profile_)); |
| 119 #endif // !defined(OS_ANDROID) | 132 #endif // !defined(OS_ANDROID) |
| 120 | 133 |
| 121 favicon::FaviconService* favicon_service = | |
| 122 FaviconServiceFactory::GetForProfile(profile_, | |
| 123 ServiceAccessType::EXPLICIT_ACCESS); | |
| 124 favicon::FallbackIconService* fallback_icon_service = | 134 favicon::FallbackIconService* fallback_icon_service = |
| 125 FallbackIconServiceFactory::GetForBrowserContext(profile_); | 135 FallbackIconServiceFactory::GetForBrowserContext(profile_); |
| 136 favicon::LargeIconService* large_icon_service = | |
| 137 LargeIconServiceFactory::GetForBrowserContext(profile_); | |
| 126 | 138 |
| 127 content::URLDataSource::Add(profile_, | |
| 128 new LargeIconSource(favicon_service, fallback_icon_service)); | |
| 129 content::URLDataSource::Add( | 139 content::URLDataSource::Add( |
| 130 profile_, new FallbackIconSource(fallback_icon_service)); | 140 profile_, new FallbackIconSource(fallback_icon_service)); |
| 131 content::URLDataSource::Add( | 141 content::URLDataSource::Add( |
| 132 profile_, new FaviconSource(profile_, FaviconSource::FAVICON)); | 142 profile_, new FaviconSource(profile_, FaviconSource::FAVICON)); |
| 143 content::URLDataSource::Add(profile_, new LargeIconSource( | |
| 144 fallback_icon_service, large_icon_service)); | |
| 133 content::URLDataSource::Add(profile_, new MostVisitedIframeSource()); | 145 content::URLDataSource::Add(profile_, new MostVisitedIframeSource()); |
| 134 content::URLDataSource::Add( | 146 content::URLDataSource::Add( |
| 135 profile_, new suggestions::SuggestionsSource(profile_)); | 147 profile_, new suggestions::SuggestionsSource(profile_)); |
| 136 } | 148 } |
| 137 | 149 |
| 138 InstantService::~InstantService() { | 150 InstantService::~InstantService() { |
| 139 if (template_url_service_) | 151 if (template_url_service_) |
| 140 template_url_service_->RemoveObserver(this); | 152 template_url_service_->RemoveObserver(this); |
| 141 } | 153 } |
| 142 | 154 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 void InstantService::UndoAllMostVisitedDeletions() { | 196 void InstantService::UndoAllMostVisitedDeletions() { |
| 185 scoped_refptr<history::TopSites> top_sites = | 197 scoped_refptr<history::TopSites> top_sites = |
| 186 TopSitesFactory::GetForProfile(profile_); | 198 TopSitesFactory::GetForProfile(profile_); |
| 187 if (!top_sites) | 199 if (!top_sites) |
| 188 return; | 200 return; |
| 189 | 201 |
| 190 top_sites->ClearBlacklistedURLs(); | 202 top_sites->ClearBlacklistedURLs(); |
| 191 } | 203 } |
| 192 | 204 |
| 193 void InstantService::UpdateThemeInfo() { | 205 void InstantService::UpdateThemeInfo() { |
| 194 #if defined(ENABLE_THEMES) | |
| 195 // Update theme background info. | 206 // Update theme background info. |
| 196 // Initialize |theme_info| if necessary. | 207 // Initialize |theme_info| if necessary. |
| 197 if (!theme_info_) | 208 if (!theme_info_) |
| 198 OnThemeChanged(ThemeServiceFactory::GetForProfile(profile_)); | 209 OnThemeChanged(ThemeServiceFactory::GetForProfile(profile_)); |
| 199 else | 210 else |
| 200 OnThemeChanged(NULL); | 211 OnThemeChanged(NULL); |
| 201 #endif // defined(ENABLE_THEMES) | |
| 202 } | 212 } |
| 203 | 213 |
| 204 void InstantService::UpdateMostVisitedItemsInfo() { | 214 void InstantService::UpdateMostVisitedItemsInfo() { |
| 205 NotifyAboutMostVisitedItems(); | 215 NotifyAboutMostVisitedItems(); |
| 206 } | 216 } |
| 207 | 217 |
| 208 void InstantService::Shutdown() { | 218 void InstantService::Shutdown() { |
| 209 process_ids_.clear(); | 219 process_ids_.clear(); |
| 210 | 220 |
| 211 if (instant_io_context_.get()) { | 221 if (instant_io_context_.get()) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 | 292 |
| 283 most_visited_items_ = new_most_visited_items; | 293 most_visited_items_ = new_most_visited_items; |
| 284 NotifyAboutMostVisitedItems(); | 294 NotifyAboutMostVisitedItems(); |
| 285 } | 295 } |
| 286 | 296 |
| 287 void InstantService::NotifyAboutMostVisitedItems() { | 297 void InstantService::NotifyAboutMostVisitedItems() { |
| 288 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, | 298 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, |
| 289 MostVisitedItemsChanged(most_visited_items_)); | 299 MostVisitedItemsChanged(most_visited_items_)); |
| 290 } | 300 } |
| 291 | 301 |
| 292 #if defined(ENABLE_THEMES) | |
| 293 | |
| 294 namespace { | |
| 295 | |
| 296 const int kSectionBorderAlphaTransparency = 80; | |
| 297 | |
| 298 // Converts SkColor to RGBAColor | |
| 299 RGBAColor SkColorToRGBAColor(const SkColor& sKColor) { | |
| 300 RGBAColor color; | |
| 301 color.r = SkColorGetR(sKColor); | |
| 302 color.g = SkColorGetG(sKColor); | |
| 303 color.b = SkColorGetB(sKColor); | |
| 304 color.a = SkColorGetA(sKColor); | |
| 305 return color; | |
| 306 } | |
| 307 | |
| 308 } // namespace | |
| 309 | |
| 310 void InstantService::OnThemeChanged(ThemeService* theme_service) { | 302 void InstantService::OnThemeChanged(ThemeService* theme_service) { |
| 311 if (!theme_service) { | 303 if (!theme_service) { |
| 312 DCHECK(theme_info_.get()); | 304 DCHECK(theme_info_.get()); |
| 313 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, | 305 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, |
| 314 ThemeInfoChanged(*theme_info_)); | 306 ThemeInfoChanged(*theme_info_)); |
| 315 return; | 307 return; |
| 316 } | 308 } |
| 317 | 309 |
| 318 // Get theme information from theme service. | 310 // Get theme information from theme service. |
| 319 theme_info_.reset(new ThemeBackgroundInfo()); | 311 theme_info_.reset(new ThemeBackgroundInfo()); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 DCHECK(image); | 399 DCHECK(image); |
| 408 theme_info_->image_height = image->height(); | 400 theme_info_->image_height = image->height(); |
| 409 | 401 |
| 410 theme_info_->has_attribution = | 402 theme_info_->has_attribution = |
| 411 theme_service->HasCustomImage(IDR_THEME_NTP_ATTRIBUTION); | 403 theme_service->HasCustomImage(IDR_THEME_NTP_ATTRIBUTION); |
| 412 } | 404 } |
| 413 | 405 |
| 414 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, | 406 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, |
| 415 ThemeInfoChanged(*theme_info_)); | 407 ThemeInfoChanged(*theme_info_)); |
| 416 } | 408 } |
| 417 #endif // defined(ENABLE_THEMES) | |
| 418 | 409 |
| 419 void InstantService::OnTemplateURLServiceChanged() { | 410 void InstantService::OnTemplateURLServiceChanged() { |
| 420 // Check whether the default search provider was changed. | 411 // Check whether the default search provider was changed. |
| 421 const TemplateURL* template_url = | 412 const TemplateURL* template_url = |
| 422 template_url_service_->GetDefaultSearchProvider(); | 413 template_url_service_->GetDefaultSearchProvider(); |
| 423 bool default_search_provider_changed = !TemplateURL::MatchesData( | 414 bool default_search_provider_changed = !TemplateURL::MatchesData( |
| 424 template_url, previous_default_search_provider_.get(), | 415 template_url, previous_default_search_provider_.get(), |
| 425 UIThreadSearchTermsData(profile_)); | 416 UIThreadSearchTermsData(profile_)); |
| 426 if (default_search_provider_changed) { | 417 if (default_search_provider_changed) { |
| 427 previous_default_search_provider_.reset( | 418 previous_default_search_provider_.reset( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 460 } | 451 } |
| 461 | 452 |
| 462 void InstantService::ResetInstantSearchPrerenderer() { | 453 void InstantService::ResetInstantSearchPrerenderer() { |
| 463 if (!chrome::ShouldPrefetchSearchResults()) | 454 if (!chrome::ShouldPrefetchSearchResults()) |
| 464 return; | 455 return; |
| 465 | 456 |
| 466 GURL url(chrome::GetSearchResultPrefetchBaseURL(profile_)); | 457 GURL url(chrome::GetSearchResultPrefetchBaseURL(profile_)); |
| 467 instant_prerenderer_.reset( | 458 instant_prerenderer_.reset( |
| 468 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL); | 459 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL); |
| 469 } | 460 } |
| OLD | NEW |