| 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/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 top_sites->ClearBlacklistedURLs(); | 192 top_sites->ClearBlacklistedURLs(); |
| 193 } | 193 } |
| 194 | 194 |
| 195 void InstantService::UpdateThemeInfo() { | 195 void InstantService::UpdateThemeInfo() { |
| 196 #if defined(ENABLE_THEMES) | 196 #if defined(ENABLE_THEMES) |
| 197 // Update theme background info. | 197 // Update theme background info. |
| 198 // Initialize |theme_info| if necessary. | 198 // Initialize |theme_info| if necessary. |
| 199 if (!theme_info_) { | 199 if (!theme_info_) { |
| 200 OnThemeChanged(); | 200 OnThemeChanged(); |
| 201 } else { | 201 } else { |
| 202 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, | 202 for (InstantServiceObserver& observer : observers_) |
| 203 ThemeInfoChanged(*theme_info_)); | 203 observer.ThemeInfoChanged(*theme_info_); |
| 204 } | 204 } |
| 205 #endif // defined(ENABLE_THEMES) | 205 #endif // defined(ENABLE_THEMES) |
| 206 } | 206 } |
| 207 | 207 |
| 208 void InstantService::UpdateMostVisitedItemsInfo() { | 208 void InstantService::UpdateMostVisitedItemsInfo() { |
| 209 NotifyAboutMostVisitedItems(); | 209 NotifyAboutMostVisitedItems(); |
| 210 } | 210 } |
| 211 | 211 |
| 212 void InstantService::Shutdown() { | 212 void InstantService::Shutdown() { |
| 213 process_ids_.clear(); | 213 process_ids_.clear(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 item.url = mv_url.url; | 273 item.url = mv_url.url; |
| 274 item.title = mv_url.title; | 274 item.title = mv_url.title; |
| 275 item.is_server_side_suggestion = false; | 275 item.is_server_side_suggestion = false; |
| 276 most_visited_items_.push_back(item); | 276 most_visited_items_.push_back(item); |
| 277 } | 277 } |
| 278 | 278 |
| 279 NotifyAboutMostVisitedItems(); | 279 NotifyAboutMostVisitedItems(); |
| 280 } | 280 } |
| 281 | 281 |
| 282 void InstantService::NotifyAboutMostVisitedItems() { | 282 void InstantService::NotifyAboutMostVisitedItems() { |
| 283 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, | 283 for (InstantServiceObserver& observer : observers_) |
| 284 MostVisitedItemsChanged(most_visited_items_)); | 284 observer.MostVisitedItemsChanged(most_visited_items_); |
| 285 } | 285 } |
| 286 | 286 |
| 287 #if defined(ENABLE_THEMES) | 287 #if defined(ENABLE_THEMES) |
| 288 | 288 |
| 289 namespace { | 289 namespace { |
| 290 | 290 |
| 291 const int kSectionBorderAlphaTransparency = 80; | 291 const int kSectionBorderAlphaTransparency = 80; |
| 292 | 292 |
| 293 // Converts SkColor to RGBAColor | 293 // Converts SkColor to RGBAColor |
| 294 RGBAColor SkColorToRGBAColor(const SkColor& sKColor) { | 294 RGBAColor SkColorToRGBAColor(const SkColor& sKColor) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 // Set theme background image height. | 393 // Set theme background image height. |
| 394 gfx::ImageSkia* image = | 394 gfx::ImageSkia* image = |
| 395 theme_provider.GetImageSkiaNamed(IDR_THEME_NTP_BACKGROUND); | 395 theme_provider.GetImageSkiaNamed(IDR_THEME_NTP_BACKGROUND); |
| 396 DCHECK(image); | 396 DCHECK(image); |
| 397 theme_info_->image_height = image->height(); | 397 theme_info_->image_height = image->height(); |
| 398 | 398 |
| 399 theme_info_->has_attribution = | 399 theme_info_->has_attribution = |
| 400 theme_provider.HasCustomImage(IDR_THEME_NTP_ATTRIBUTION); | 400 theme_provider.HasCustomImage(IDR_THEME_NTP_ATTRIBUTION); |
| 401 } | 401 } |
| 402 | 402 |
| 403 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, | 403 for (InstantServiceObserver& observer : observers_) |
| 404 ThemeInfoChanged(*theme_info_)); | 404 observer.ThemeInfoChanged(*theme_info_); |
| 405 } | 405 } |
| 406 #endif // defined(ENABLE_THEMES) | 406 #endif // defined(ENABLE_THEMES) |
| 407 | 407 |
| 408 void InstantService::OnTemplateURLServiceChanged() { | 408 void InstantService::OnTemplateURLServiceChanged() { |
| 409 // Check whether the default search provider was changed. | 409 // Check whether the default search provider was changed. |
| 410 const TemplateURL* template_url = | 410 const TemplateURL* template_url = |
| 411 template_url_service_->GetDefaultSearchProvider(); | 411 template_url_service_->GetDefaultSearchProvider(); |
| 412 bool default_search_provider_changed = !TemplateURL::MatchesData( | 412 bool default_search_provider_changed = !TemplateURL::MatchesData( |
| 413 template_url, previous_default_search_provider_.get(), | 413 template_url, previous_default_search_provider_.get(), |
| 414 UIThreadSearchTermsData(profile_)); | 414 UIThreadSearchTermsData(profile_)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 425 GURL google_base_url(UIThreadSearchTermsData(profile_).GoogleBaseURLValue()); | 425 GURL google_base_url(UIThreadSearchTermsData(profile_).GoogleBaseURLValue()); |
| 426 if (google_base_url != previous_google_base_url_) { | 426 if (google_base_url != previous_google_base_url_) { |
| 427 previous_google_base_url_ = google_base_url; | 427 previous_google_base_url_ = google_base_url; |
| 428 if (template_url && template_url->HasGoogleBaseURLs( | 428 if (template_url && template_url->HasGoogleBaseURLs( |
| 429 UIThreadSearchTermsData(profile_))) | 429 UIThreadSearchTermsData(profile_))) |
| 430 google_base_url_domain_changed = true; | 430 google_base_url_domain_changed = true; |
| 431 } | 431 } |
| 432 | 432 |
| 433 if (default_search_provider_changed || google_base_url_domain_changed) { | 433 if (default_search_provider_changed || google_base_url_domain_changed) { |
| 434 ResetInstantSearchPrerenderer(); | 434 ResetInstantSearchPrerenderer(); |
| 435 FOR_EACH_OBSERVER( | 435 for (InstantServiceObserver& observer : observers_) |
| 436 InstantServiceObserver, observers_, | 436 observer.DefaultSearchProviderChanged(google_base_url_domain_changed); |
| 437 DefaultSearchProviderChanged(google_base_url_domain_changed)); | |
| 438 } | 437 } |
| 439 } | 438 } |
| 440 | 439 |
| 441 void InstantService::TopSitesLoaded(history::TopSites* top_sites) { | 440 void InstantService::TopSitesLoaded(history::TopSites* top_sites) { |
| 442 } | 441 } |
| 443 | 442 |
| 444 void InstantService::TopSitesChanged(history::TopSites* top_sites, | 443 void InstantService::TopSitesChanged(history::TopSites* top_sites, |
| 445 ChangeReason change_reason) { | 444 ChangeReason change_reason) { |
| 446 // As forced urls already come from tiles, we can safely ignore those updates. | 445 // As forced urls already come from tiles, we can safely ignore those updates. |
| 447 if (change_reason == history::TopSitesObserver::ChangeReason::FORCED_URL) | 446 if (change_reason == history::TopSitesObserver::ChangeReason::FORCED_URL) |
| 448 return; | 447 return; |
| 449 top_sites->GetMostVisitedURLs( | 448 top_sites->GetMostVisitedURLs( |
| 450 base::Bind(&InstantService::OnMostVisitedItemsReceived, | 449 base::Bind(&InstantService::OnMostVisitedItemsReceived, |
| 451 weak_ptr_factory_.GetWeakPtr()), | 450 weak_ptr_factory_.GetWeakPtr()), |
| 452 false); | 451 false); |
| 453 } | 452 } |
| 454 | 453 |
| 455 void InstantService::ResetInstantSearchPrerenderer() { | 454 void InstantService::ResetInstantSearchPrerenderer() { |
| 456 if (!search::ShouldPrefetchSearchResults()) | 455 if (!search::ShouldPrefetchSearchResults()) |
| 457 return; | 456 return; |
| 458 | 457 |
| 459 GURL url(search::GetSearchResultPrefetchBaseURL(profile_)); | 458 GURL url(search::GetSearchResultPrefetchBaseURL(profile_)); |
| 460 instant_prerenderer_.reset( | 459 instant_prerenderer_.reset( |
| 461 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL); | 460 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL); |
| 462 } | 461 } |
| OLD | NEW |