| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/ui/browser_instant_controller.h" | 5 #include "chrome/browser/ui/browser_instant_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/prefs/pref_service.h" | |
| 9 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/extension_web_ui.h" | 9 #include "chrome/browser/extensions/extension_web_ui.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/search/instant_service.h" | 11 #include "chrome/browser/search/instant_service.h" |
| 13 #include "chrome/browser/search/instant_service_factory.h" | 12 #include "chrome/browser/search/instant_service_factory.h" |
| 14 #include "chrome/browser/search/search.h" | 13 #include "chrome/browser/search/search.h" |
| 15 #include "chrome/browser/search_engines/template_url.h" | |
| 16 #include "chrome/browser/search_engines/template_url_service.h" | |
| 17 #include "chrome/browser/search_engines/template_url_service_factory.h" | |
| 18 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
| 20 #include "chrome/browser/ui/omnibox/location_bar.h" | 16 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 21 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 17 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
| 22 #include "chrome/browser/ui/search/instant_ntp.h" | 18 #include "chrome/browser/ui/search/instant_ntp.h" |
| 23 #include "chrome/browser/ui/search/search_model.h" | 19 #include "chrome/browser/ui/search/search_model.h" |
| 24 #include "chrome/browser/ui/search/search_tab_helper.h" | 20 #include "chrome/browser/ui/search/search_tab_helper.h" |
| 25 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 26 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" | 22 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
| 27 #include "chrome/common/pref_names.h" | |
| 28 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 29 #include "components/user_prefs/pref_registry_syncable.h" | |
| 30 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
| 31 #include "content/public/browser/user_metrics.h" | 25 #include "content/public/browser/user_metrics.h" |
| 32 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 33 | 27 |
| 34 using content::UserMetricsAction; | 28 using content::UserMetricsAction; |
| 35 | 29 |
| 36 //////////////////////////////////////////////////////////////////////////////// | 30 //////////////////////////////////////////////////////////////////////////////// |
| 37 // BrowserInstantController, public: | 31 // BrowserInstantController, public: |
| 38 | 32 |
| 39 BrowserInstantController::BrowserInstantController(Browser* browser) | 33 BrowserInstantController::BrowserInstantController(Browser* browser) |
| 40 : browser_(browser), | 34 : browser_(browser), |
| 41 instant_(this, chrome::IsInstantExtendedAPIEnabled()), | 35 instant_(this, chrome::IsInstantExtendedAPIEnabled()), |
| 42 instant_unload_handler_(browser) { | 36 instant_unload_handler_(browser) { |
| 43 profile_pref_registrar_.Init(profile()->GetPrefs()); | |
| 44 profile_pref_registrar_.Add( | |
| 45 prefs::kDefaultSearchProviderID, | |
| 46 base::Bind(&BrowserInstantController::OnDefaultSearchProviderChanged, | |
| 47 base::Unretained(this))); | |
| 48 browser_->search_model()->AddObserver(this); | 37 browser_->search_model()->AddObserver(this); |
| 49 | 38 |
| 50 InstantService* instant_service = | 39 InstantService* instant_service = |
| 51 InstantServiceFactory::GetForProfile(profile()); | 40 InstantServiceFactory::GetForProfile(profile()); |
| 52 instant_service->OnBrowserInstantControllerCreated(); | 41 instant_service->OnBrowserInstantControllerCreated(); |
| 42 instant_service->AddObserver(this); |
| 53 } | 43 } |
| 54 | 44 |
| 55 BrowserInstantController::~BrowserInstantController() { | 45 BrowserInstantController::~BrowserInstantController() { |
| 56 browser_->search_model()->RemoveObserver(this); | 46 browser_->search_model()->RemoveObserver(this); |
| 57 | 47 |
| 58 InstantService* instant_service = | 48 InstantService* instant_service = |
| 59 InstantServiceFactory::GetForProfile(profile()); | 49 InstantServiceFactory::GetForProfile(profile()); |
| 60 instant_service->OnBrowserInstantControllerDestroyed(); | 50 instant_service->OnBrowserInstantControllerDestroyed(); |
| 61 } | 51 } |
| 62 | 52 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 content::RecordAction(UserMetricsAction("InstantExtended.ShowNTP")); | 206 content::RecordAction(UserMetricsAction("InstantExtended.ShowNTP")); |
| 217 } | 207 } |
| 218 | 208 |
| 219 instant_.SearchModeChanged(old_state.mode, new_mode); | 209 instant_.SearchModeChanged(old_state.mode, new_mode); |
| 220 } | 210 } |
| 221 | 211 |
| 222 if (old_state.instant_support != new_state.instant_support) | 212 if (old_state.instant_support != new_state.instant_support) |
| 223 instant_.InstantSupportChanged(new_state.instant_support); | 213 instant_.InstantSupportChanged(new_state.instant_support); |
| 224 } | 214 } |
| 225 | 215 |
| 226 void BrowserInstantController::OnDefaultSearchProviderChanged( | 216 //////////////////////////////////////////////////////////////////////////////// |
| 227 const std::string& pref_name) { | 217 // BrowserInstantController, InstantServiceObserver implementation: |
| 228 DCHECK_EQ(pref_name, std::string(prefs::kDefaultSearchProviderID)); | |
| 229 | 218 |
| 230 Profile* browser_profile = profile(); | 219 void BrowserInstantController::DefaultSearchProviderChanged() { |
| 231 const TemplateURL* template_url = | 220 ReloadTabsInInstantProcess(); |
| 232 TemplateURLServiceFactory::GetForProfile(browser_profile)-> | 221 } |
| 233 GetDefaultSearchProvider(); | |
| 234 if (!template_url) { | |
| 235 // A NULL |template_url| could mean either this notification is sent during | |
| 236 // the browser start up operation or the user now has no default search | |
| 237 // provider. There is no way for the user to reach this state using the | |
| 238 // Chrome settings. Only explicitly poking at the DB or bugs in the Sync | |
| 239 // could cause that, neither of which we support. | |
| 240 return; | |
| 241 } | |
| 242 | 222 |
| 223 void BrowserInstantController::GoogleURLUpdated() { |
| 224 ReloadTabsInInstantProcess(); |
| 225 } |
| 226 |
| 227 void BrowserInstantController::ReloadTabsInInstantProcess() { |
| 243 InstantService* instant_service = | 228 InstantService* instant_service = |
| 244 InstantServiceFactory::GetForProfile(browser_profile); | 229 InstantServiceFactory::GetForProfile(profile()); |
| 245 if (!instant_service) | 230 if (!instant_service) |
| 246 return; | 231 return; |
| 247 | 232 |
| 248 TabStripModel* tab_model = browser_->tab_strip_model(); | 233 TabStripModel* tab_model = browser_->tab_strip_model(); |
| 249 int count = tab_model->count(); | 234 int count = tab_model->count(); |
| 250 for (int index = 0; index < count; ++index) { | 235 for (int index = 0; index < count; ++index) { |
| 251 content::WebContents* contents = tab_model->GetWebContentsAt(index); | 236 content::WebContents* contents = tab_model->GetWebContentsAt(index); |
| 252 if (!contents) | 237 if (!contents) |
| 253 continue; | 238 continue; |
| 254 | 239 |
| 255 if (!instant_service->IsInstantProcess( | 240 if (!instant_service->IsInstantProcess( |
| 256 contents->GetRenderProcessHost()->GetID())) | 241 contents->GetRenderProcessHost()->GetID())) |
| 257 continue; | 242 continue; |
| 258 | 243 |
| 259 // Reload the contents to ensure that it gets assigned to a non-priviledged | 244 // Reload the contents to ensure that it gets assigned to a non-priviledged |
| 260 // renderer. | 245 // renderer. |
| 261 contents->GetController().Reload(false); | 246 contents->GetController().Reload(false); |
| 262 } | 247 } |
| 263 } | 248 } |
| OLD | NEW |