Chromium Code Reviews| Index: chrome/browser/ui/search/instant_controller.cc |
| diff --git a/chrome/browser/ui/search/instant_controller.cc b/chrome/browser/ui/search/instant_controller.cc |
| index d01af5d992390385c60bd3bfa0da63f82dd122ff..11421fc0e378df3875776f85aa44d87b45f14412 100644 |
| --- a/chrome/browser/ui/search/instant_controller.cc |
| +++ b/chrome/browser/ui/search/instant_controller.cc |
| @@ -269,11 +269,17 @@ InstantController::InstantController(BrowserInstantController* browser, |
| // InstantService sets up profile-level facilities such as the ThemeSource for |
| // the NTP. |
| // However, in some tests, browser_ may be null. |
| - if (browser_) |
| - InstantServiceFactory::GetForProfile(browser_->profile()); |
| + if (browser_) { |
| + InstantService* instant_service = GetInstantService(); |
| + instant_service->AddObserver(this); |
| + } |
| } |
| InstantController::~InstantController() { |
| + if (browser_) { |
| + InstantService* instant_service = GetInstantService(); |
| + instant_service->RemoveObserver(this); |
| + } |
| } |
| void InstantController::OnAutocompleteStart() { |
| @@ -1079,16 +1085,28 @@ void InstantController::SetInstantEnabled(bool instant_enabled, |
| instant_tab_->SetDisplayInstantResults(instant_enabled_); |
| } |
| -void InstantController::ThemeChanged(const ThemeBackgroundInfo& theme_info) { |
| +void InstantController::ThemeInfoChanged( |
| + const ThemeBackgroundInfo& theme_info) { |
| if (!extended_enabled()) |
| return; |
| - if (overlay_) |
| + if (overlay_ && GetOverlayContents() && |
| + SearchTabHelper::FromWebContents(overlay_->contents())-> |
| + UpdateLastKnownThemeBackgroundInfo(theme_info)) { |
| overlay_->SendThemeBackgroundInfo(theme_info); |
| - if (ntp_) |
| + } |
| + |
| + if (ntp_ && ntp_->contents() && |
| + SearchTabHelper::FromWebContents(ntp_->contents())-> |
| + UpdateLastKnownThemeBackgroundInfo(theme_info)) { |
| ntp_->SendThemeBackgroundInfo(theme_info); |
| - if (instant_tab_) |
| + } |
| + |
| + if (instant_tab_ && instant_tab_->contents() && |
| + SearchTabHelper::FromWebContents(instant_tab_->contents())-> |
| + UpdateLastKnownThemeBackgroundInfo(theme_info)) { |
| instant_tab_->SendThemeBackgroundInfo(theme_info); |
| + } |
| } |
| void InstantController::SwappedOverlayContents() { |
| @@ -1119,8 +1137,7 @@ void InstantController::ReloadOverlayIfStale() { |
| void InstantController::OverlayLoadCompletedMainFrame() { |
| if (overlay_->supports_instant()) |
| return; |
| - InstantService* instant_service = |
| - InstantServiceFactory::GetForProfile(browser_->profile()); |
| + InstantService* instant_service = GetInstantService(); |
| content::WebContents* contents = overlay_->contents(); |
| DCHECK(contents); |
| if (instant_service->IsInstantProcess( |
| @@ -1145,8 +1162,7 @@ void InstantController::ClearDebugEvents() { |
| } |
| void InstantController::UpdateMostVisitedItems() { |
| - InstantService* instant_service = |
| - InstantServiceFactory::GetForProfile(profile()); |
| + InstantService* instant_service = GetInstantService(); |
| if (!instant_service) |
| return; |
| @@ -1177,10 +1193,10 @@ void InstantController::UpdateMostVisitedItems() { |
| content::NotificationService::NoDetails()); |
| } |
| + |
|
samarth
2013/06/19 05:34:54
Stray newline
kmadhusu
2013/06/19 17:43:30
Removed.
|
| void InstantController::DeleteMostVisitedItem(const GURL& url) { |
| DCHECK(!url.is_empty()); |
| - InstantService* instant_service = |
| - InstantServiceFactory::GetForProfile(profile()); |
| + InstantService* instant_service = GetInstantService(); |
| if (!instant_service) |
| return; |
| @@ -1189,8 +1205,7 @@ void InstantController::DeleteMostVisitedItem(const GURL& url) { |
| void InstantController::UndoMostVisitedDeletion(const GURL& url) { |
| DCHECK(!url.is_empty()); |
| - InstantService* instant_service = |
| - InstantServiceFactory::GetForProfile(profile()); |
| + InstantService* instant_service = GetInstantService(); |
| if (!instant_service) |
| return; |
| @@ -1198,8 +1213,7 @@ void InstantController::UndoMostVisitedDeletion(const GURL& url) { |
| } |
| void InstantController::UndoAllMostVisitedDeletions() { |
| - InstantService* instant_service = |
| - InstantServiceFactory::GetForProfile(profile()); |
| + InstantService* instant_service = GetInstantService(); |
| if (!instant_service) |
| return; |
| @@ -1230,7 +1244,9 @@ void InstantController::InstantPageRenderViewCreated( |
| return; |
| // Update theme info so that the page picks it up. |
| - browser_->UpdateThemeInfo(); |
| + InstantService* instant_service = GetInstantService(); |
| + if (instant_service) |
| + instant_service->UpdateThemeInfo(); |
| // Ensure the searchbox API has the correct initial state. |
| if (IsContentsFrom(overlay(), contents)) { |
| @@ -1663,7 +1679,11 @@ void InstantController::ResetInstantTab() { |
| void InstantController::UpdateInfoForInstantTab() { |
| if (instant_tab_) { |
| - browser_->UpdateThemeInfo(); |
| + // Update theme details. |
| + InstantService* instant_service = GetInstantService(); |
| + if (instant_service) |
| + instant_service->UpdateThemeInfo(); |
| + |
| instant_tab_->SetDisplayInstantResults(instant_enabled_); |
| instant_tab_->SetOmniboxBounds(omnibox_bounds_); |
| instant_tab_->InitializeFonts(); |
| @@ -1874,3 +1894,7 @@ void InstantController::PopulateInstantAutocompleteResultFromMatch( |
| << result->description << "' '" << result->search_query << "' " |
| << result->transition << " " << result->autocomplete_match_index; |
| } |
| + |
| +InstantService* InstantController::GetInstantService() const { |
|
samarth
2013/06/19 05:34:54
Eh, seeing this, it's arguable whether this functi
kmadhusu
2013/06/19 17:43:30
Let's keep it.
|
| + return InstantServiceFactory::GetForProfile(profile()); |
| +} |