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/favicon_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" | |
20 #include "chrome/browser/themes/theme_service.h" | |
21 #include "chrome/browser/themes/theme_service_factory.h" | |
22 #include "chrome/browser/thumbnails/thumbnail_list_source.h" | 19 #include "chrome/browser/thumbnails/thumbnail_list_source.h" |
23 #include "chrome/browser/ui/search/instant_search_prerenderer.h" | 20 #include "chrome/browser/ui/search/instant_search_prerenderer.h" |
24 #include "chrome/browser/ui/webui/fallback_icon_source.h" | 21 #include "chrome/browser/ui/webui/fallback_icon_source.h" |
25 #include "chrome/browser/ui/webui/favicon_source.h" | 22 #include "chrome/browser/ui/webui/favicon_source.h" |
26 #include "chrome/browser/ui/webui/large_icon_source.h" | 23 #include "chrome/browser/ui/webui/large_icon_source.h" |
27 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" | 24 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" |
28 #include "chrome/browser/ui/webui/theme_source.h" | 25 #include "chrome/browser/ui/webui/theme_source.h" |
29 #include "chrome/common/render_messages.h" | 26 #include "chrome/common/render_messages.h" |
30 #include "components/favicon/core/fallback_icon_service.h" | 27 #include "components/favicon/core/fallback_icon_service.h" |
31 #include "components/favicon/core/favicon_service.h" | 28 #include "components/favicon/core/favicon_service.h" |
32 #include "components/history/core/browser/top_sites.h" | 29 #include "components/history/core/browser/top_sites.h" |
33 #include "components/keyed_service/core/service_access_type.h" | 30 #include "components/keyed_service/core/service_access_type.h" |
34 #include "components/search_engines/template_url_service.h" | 31 #include "components/search_engines/template_url_service.h" |
35 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
36 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
37 #include "content/public/browser/notification_types.h" | 34 #include "content/public/browser/notification_types.h" |
38 #include "content/public/browser/render_process_host.h" | 35 #include "content/public/browser/render_process_host.h" |
39 #include "content/public/browser/url_data_source.h" | 36 #include "content/public/browser/url_data_source.h" |
40 #include "grit/theme_resources.h" | 37 #include "grit/theme_resources.h" |
41 #include "third_party/skia/include/core/SkColor.h" | 38 #include "third_party/skia/include/core/SkColor.h" |
42 #include "ui/gfx/color_utils.h" | 39 #include "ui/gfx/color_utils.h" |
43 #include "ui/gfx/image/image_skia.h" | 40 #include "ui/gfx/image/image_skia.h" |
44 #include "ui/gfx/sys_color_change_listener.h" | 41 #include "ui/gfx/sys_color_change_listener.h" |
45 | 42 |
46 #if !defined(OS_ANDROID) | 43 #if !defined(OS_ANDROID) |
47 #include "chrome/browser/search/local_ntp_source.h" | 44 #include "chrome/browser/search/local_ntp_source.h" |
48 #endif | 45 #endif |
49 | 46 |
50 namespace { | 47 #if defined(ENABLE_THEMES) |
51 | 48 #include "chrome/browser/themes/theme_properties.h" |
52 const int kSectionBorderAlphaTransparency = 80; | 49 #include "chrome/browser/themes/theme_service.h" |
53 | 50 #include "chrome/browser/themes/theme_service_factory.h" |
54 // Converts SkColor to RGBAColor | 51 #endif // defined(ENABLE_THEMES) |
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 | |
65 | 52 |
66 InstantService::InstantService(Profile* profile) | 53 InstantService::InstantService(Profile* profile) |
67 : profile_(profile), | 54 : profile_(profile), |
68 template_url_service_(TemplateURLServiceFactory::GetForProfile(profile_)), | 55 template_url_service_(TemplateURLServiceFactory::GetForProfile(profile_)), |
69 omnibox_start_margin_(chrome::kDisableStartMargin), | 56 omnibox_start_margin_(chrome::kDisableStartMargin), |
70 weak_ptr_factory_(this) { | 57 weak_ptr_factory_(this) { |
71 // The initialization below depends on a typical set of browser threads. Skip | 58 // 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. | 59 // it if we are running in a unit test without the full suite. |
73 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) | 60 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) |
74 return; | 61 return; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 void InstantService::UndoAllMostVisitedDeletions() { | 184 void InstantService::UndoAllMostVisitedDeletions() { |
198 scoped_refptr<history::TopSites> top_sites = | 185 scoped_refptr<history::TopSites> top_sites = |
199 TopSitesFactory::GetForProfile(profile_); | 186 TopSitesFactory::GetForProfile(profile_); |
200 if (!top_sites) | 187 if (!top_sites) |
201 return; | 188 return; |
202 | 189 |
203 top_sites->ClearBlacklistedURLs(); | 190 top_sites->ClearBlacklistedURLs(); |
204 } | 191 } |
205 | 192 |
206 void InstantService::UpdateThemeInfo() { | 193 void InstantService::UpdateThemeInfo() { |
| 194 #if defined(ENABLE_THEMES) |
207 // Update theme background info. | 195 // Update theme background info. |
208 // Initialize |theme_info| if necessary. | 196 // Initialize |theme_info| if necessary. |
209 if (!theme_info_) | 197 if (!theme_info_) |
210 OnThemeChanged(ThemeServiceFactory::GetForProfile(profile_)); | 198 OnThemeChanged(ThemeServiceFactory::GetForProfile(profile_)); |
211 else | 199 else |
212 OnThemeChanged(NULL); | 200 OnThemeChanged(NULL); |
| 201 #endif // defined(ENABLE_THEMES) |
213 } | 202 } |
214 | 203 |
215 void InstantService::UpdateMostVisitedItemsInfo() { | 204 void InstantService::UpdateMostVisitedItemsInfo() { |
216 NotifyAboutMostVisitedItems(); | 205 NotifyAboutMostVisitedItems(); |
217 } | 206 } |
218 | 207 |
219 void InstantService::Shutdown() { | 208 void InstantService::Shutdown() { |
220 process_ids_.clear(); | 209 process_ids_.clear(); |
221 | 210 |
222 if (instant_io_context_.get()) { | 211 if (instant_io_context_.get()) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 | 282 |
294 most_visited_items_ = new_most_visited_items; | 283 most_visited_items_ = new_most_visited_items; |
295 NotifyAboutMostVisitedItems(); | 284 NotifyAboutMostVisitedItems(); |
296 } | 285 } |
297 | 286 |
298 void InstantService::NotifyAboutMostVisitedItems() { | 287 void InstantService::NotifyAboutMostVisitedItems() { |
299 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, | 288 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, |
300 MostVisitedItemsChanged(most_visited_items_)); | 289 MostVisitedItemsChanged(most_visited_items_)); |
301 } | 290 } |
302 | 291 |
| 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 |
303 void InstantService::OnThemeChanged(ThemeService* theme_service) { | 310 void InstantService::OnThemeChanged(ThemeService* theme_service) { |
304 if (!theme_service) { | 311 if (!theme_service) { |
305 DCHECK(theme_info_.get()); | 312 DCHECK(theme_info_.get()); |
306 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, | 313 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, |
307 ThemeInfoChanged(*theme_info_)); | 314 ThemeInfoChanged(*theme_info_)); |
308 return; | 315 return; |
309 } | 316 } |
310 | 317 |
311 // Get theme information from theme service. | 318 // Get theme information from theme service. |
312 theme_info_.reset(new ThemeBackgroundInfo()); | 319 theme_info_.reset(new ThemeBackgroundInfo()); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 DCHECK(image); | 407 DCHECK(image); |
401 theme_info_->image_height = image->height(); | 408 theme_info_->image_height = image->height(); |
402 | 409 |
403 theme_info_->has_attribution = | 410 theme_info_->has_attribution = |
404 theme_service->HasCustomImage(IDR_THEME_NTP_ATTRIBUTION); | 411 theme_service->HasCustomImage(IDR_THEME_NTP_ATTRIBUTION); |
405 } | 412 } |
406 | 413 |
407 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, | 414 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, |
408 ThemeInfoChanged(*theme_info_)); | 415 ThemeInfoChanged(*theme_info_)); |
409 } | 416 } |
| 417 #endif // defined(ENABLE_THEMES) |
410 | 418 |
411 void InstantService::OnTemplateURLServiceChanged() { | 419 void InstantService::OnTemplateURLServiceChanged() { |
412 // Check whether the default search provider was changed. | 420 // Check whether the default search provider was changed. |
413 const TemplateURL* template_url = | 421 const TemplateURL* template_url = |
414 template_url_service_->GetDefaultSearchProvider(); | 422 template_url_service_->GetDefaultSearchProvider(); |
415 bool default_search_provider_changed = !TemplateURL::MatchesData( | 423 bool default_search_provider_changed = !TemplateURL::MatchesData( |
416 template_url, previous_default_search_provider_.get(), | 424 template_url, previous_default_search_provider_.get(), |
417 UIThreadSearchTermsData(profile_)); | 425 UIThreadSearchTermsData(profile_)); |
418 if (default_search_provider_changed) { | 426 if (default_search_provider_changed) { |
419 previous_default_search_provider_.reset( | 427 previous_default_search_provider_.reset( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 } | 460 } |
453 | 461 |
454 void InstantService::ResetInstantSearchPrerenderer() { | 462 void InstantService::ResetInstantSearchPrerenderer() { |
455 if (!chrome::ShouldPrefetchSearchResults()) | 463 if (!chrome::ShouldPrefetchSearchResults()) |
456 return; | 464 return; |
457 | 465 |
458 GURL url(chrome::GetSearchResultPrefetchBaseURL(profile_)); | 466 GURL url(chrome::GetSearchResultPrefetchBaseURL(profile_)); |
459 instant_prerenderer_.reset( | 467 instant_prerenderer_.reset( |
460 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL); | 468 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL); |
461 } | 469 } |
OLD | NEW |