| 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 c861a1c963ed4ba3eedc309720e62e8b417164da..3470bce18540b224b0e2b136e3a775e6e6c11e77 100644
|
| --- a/chrome/browser/ui/search/instant_controller.cc
|
| +++ b/chrome/browser/ui/search/instant_controller.cc
|
| @@ -274,11 +274,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() {
|
| @@ -796,6 +802,30 @@ void InstantController::InstantPageLoadFailed(content::WebContents* contents) {
|
| }
|
| }
|
|
|
| +void InstantController::ThemeInfoChanged(
|
| + const ThemeBackgroundInfo& theme_info) {
|
| + if (!extended_enabled())
|
| + return;
|
| +
|
| + if (overlay_ && GetOverlayContents() &&
|
| + SearchTabHelper::FromWebContents(overlay_->contents())->
|
| + UpdateLastKnownThemeBackgroundInfo(theme_info)) {
|
| + overlay_->SendThemeBackgroundInfo(theme_info);
|
| + }
|
| +
|
| + if (ntp_ && ntp_->contents() &&
|
| + SearchTabHelper::FromWebContents(ntp_->contents())->
|
| + UpdateLastKnownThemeBackgroundInfo(theme_info)) {
|
| + ntp_->SendThemeBackgroundInfo(theme_info);
|
| + }
|
| +
|
| + if (instant_tab_ && instant_tab_->contents() &&
|
| + SearchTabHelper::FromWebContents(instant_tab_->contents())->
|
| + UpdateLastKnownThemeBackgroundInfo(theme_info)) {
|
| + instant_tab_->SendThemeBackgroundInfo(theme_info);
|
| + }
|
| +}
|
| +
|
| content::WebContents* InstantController::GetOverlayContents() const {
|
| return overlay_ ? overlay_->contents() : NULL;
|
| }
|
| @@ -1084,18 +1114,6 @@ void InstantController::SetInstantEnabled(bool instant_enabled,
|
| instant_tab_->SetDisplayInstantResults(instant_enabled_);
|
| }
|
|
|
| -void InstantController::ThemeChanged(const ThemeBackgroundInfo& theme_info) {
|
| - if (!extended_enabled())
|
| - return;
|
| -
|
| - if (overlay_)
|
| - overlay_->SendThemeBackgroundInfo(theme_info);
|
| - if (ntp_)
|
| - ntp_->SendThemeBackgroundInfo(theme_info);
|
| - if (instant_tab_)
|
| - instant_tab_->SendThemeBackgroundInfo(theme_info);
|
| -}
|
| -
|
| void InstantController::SwappedOverlayContents() {
|
| model_.SetOverlayContents(GetOverlayContents());
|
| }
|
| @@ -1124,8 +1142,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(
|
| @@ -1150,8 +1167,7 @@ void InstantController::ClearDebugEvents() {
|
| }
|
|
|
| void InstantController::UpdateMostVisitedItems() {
|
| - InstantService* instant_service =
|
| - InstantServiceFactory::GetForProfile(profile());
|
| + InstantService* instant_service = GetInstantService();
|
| if (!instant_service)
|
| return;
|
|
|
| @@ -1184,8 +1200,7 @@ void InstantController::UpdateMostVisitedItems() {
|
|
|
| void InstantController::DeleteMostVisitedItem(const GURL& url) {
|
| DCHECK(!url.is_empty());
|
| - InstantService* instant_service =
|
| - InstantServiceFactory::GetForProfile(profile());
|
| + InstantService* instant_service = GetInstantService();
|
| if (!instant_service)
|
| return;
|
|
|
| @@ -1194,8 +1209,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;
|
|
|
| @@ -1203,8 +1217,7 @@ void InstantController::UndoMostVisitedDeletion(const GURL& url) {
|
| }
|
|
|
| void InstantController::UndoAllMostVisitedDeletions() {
|
| - InstantService* instant_service =
|
| - InstantServiceFactory::GetForProfile(profile());
|
| + InstantService* instant_service = GetInstantService();
|
| if (!instant_service)
|
| return;
|
|
|
| @@ -1235,7 +1248,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)) {
|
| @@ -1672,7 +1687,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();
|
| @@ -1907,3 +1926,7 @@ bool InstantController::InStartup() const {
|
| // startup time.
|
| return !browser_->GetActiveWebContents();
|
| }
|
| +
|
| +InstantService* InstantController::GetInstantService() const {
|
| + return InstantServiceFactory::GetForProfile(profile());
|
| +}
|
|
|