Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(822)

Side by Side Diff: chrome/browser/ui/browser_instant_controller.cc

Issue 20388003: Reload Instant NTP and Instant-process tabs on search url change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased and addressed comments Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_popup_model.h" 17 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
22 #include "chrome/browser/ui/omnibox/omnibox_view.h" 18 #include "chrome/browser/ui/omnibox/omnibox_view.h"
23 #include "chrome/browser/ui/search/instant_ntp.h" 19 #include "chrome/browser/ui/search/instant_ntp.h"
24 #include "chrome/browser/ui/search/search_model.h" 20 #include "chrome/browser/ui/search/search_model.h"
25 #include "chrome/browser/ui/search/search_tab_helper.h" 21 #include "chrome/browser/ui/search/search_tab_helper.h"
26 #include "chrome/browser/ui/tabs/tab_strip_model.h" 22 #include "chrome/browser/ui/tabs/tab_strip_model.h"
27 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" 23 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h"
28 #include "chrome/common/pref_names.h"
29 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
30 #include "components/user_prefs/pref_registry_syncable.h"
31 #include "content/public/browser/render_process_host.h" 25 #include "content/public/browser/render_process_host.h"
32 #include "content/public/browser/user_metrics.h" 26 #include "content/public/browser/user_metrics.h"
33 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
34 #include "content/public/browser/web_contents_view.h" 28 #include "content/public/browser/web_contents_view.h"
35 29
36 using content::UserMetricsAction; 30 using content::UserMetricsAction;
37 31
38 //////////////////////////////////////////////////////////////////////////////// 32 ////////////////////////////////////////////////////////////////////////////////
39 // BrowserInstantController, public: 33 // BrowserInstantController, public:
40 34
41 BrowserInstantController::BrowserInstantController(Browser* browser) 35 BrowserInstantController::BrowserInstantController(Browser* browser)
42 : browser_(browser), 36 : browser_(browser),
43 instant_(this), 37 instant_(this),
44 instant_unload_handler_(browser) { 38 instant_unload_handler_(browser) {
45 profile_pref_registrar_.Init(profile()->GetPrefs());
46 profile_pref_registrar_.Add(
47 prefs::kDefaultSearchProviderID,
48 base::Bind(&BrowserInstantController::OnDefaultSearchProviderChanged,
49 base::Unretained(this)));
50 browser_->search_model()->AddObserver(this); 39 browser_->search_model()->AddObserver(this);
51 40
52 InstantService* instant_service = 41 InstantService* instant_service =
53 InstantServiceFactory::GetForProfile(profile()); 42 InstantServiceFactory::GetForProfile(profile());
54 instant_service->OnBrowserInstantControllerCreated(); 43 instant_service->OnBrowserInstantControllerCreated();
44 instant_service->AddObserver(this);
samarth 2013/08/14 00:24:14 Call RemoveObserver in the destructor. I'm surpris
Anuj 2013/08/14 06:38:57 Done. Added BrowserWindowLifeCycle unit test in In
55 } 45 }
56 46
57 BrowserInstantController::~BrowserInstantController() { 47 BrowserInstantController::~BrowserInstantController() {
58 browser_->search_model()->RemoveObserver(this); 48 browser_->search_model()->RemoveObserver(this);
59 49
60 InstantService* instant_service = 50 InstantService* instant_service =
61 InstantServiceFactory::GetForProfile(profile()); 51 InstantServiceFactory::GetForProfile(profile());
62 instant_service->OnBrowserInstantControllerDestroyed(); 52 instant_service->OnBrowserInstantControllerDestroyed();
63 } 53 }
64 54
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 else if (new_mode.is_ntp()) 251 else if (new_mode.is_ntp())
262 content::RecordAction(UserMetricsAction("InstantExtended.ShowNTP")); 252 content::RecordAction(UserMetricsAction("InstantExtended.ShowNTP"));
263 253
264 instant_.SearchModeChanged(old_state.mode, new_mode); 254 instant_.SearchModeChanged(old_state.mode, new_mode);
265 } 255 }
266 256
267 if (old_state.instant_support != new_state.instant_support) 257 if (old_state.instant_support != new_state.instant_support)
268 instant_.InstantSupportChanged(new_state.instant_support); 258 instant_.InstantSupportChanged(new_state.instant_support);
269 } 259 }
270 260
271 void BrowserInstantController::OnDefaultSearchProviderChanged( 261 ////////////////////////////////////////////////////////////////////////////////
272 const std::string& pref_name) { 262 // BrowserInstantController, InstantServiceObserver implementation:
273 DCHECK_EQ(pref_name, std::string(prefs::kDefaultSearchProviderID));
274 263
275 Profile* browser_profile = profile(); 264 void BrowserInstantController::DefaultSearchProviderChanged() {
276 const TemplateURL* template_url = 265 ReloadTabsInInstantProcess();
277 TemplateURLServiceFactory::GetForProfile(browser_profile)-> 266 }
278 GetDefaultSearchProvider();
279 if (!template_url) {
280 // A NULL |template_url| could mean either this notification is sent during
281 // the browser start up operation or the user now has no default search
282 // provider. There is no way for the user to reach this state using the
283 // Chrome settings. Only explicitly poking at the DB or bugs in the Sync
284 // could cause that, neither of which we support.
285 return;
286 }
287 267
268 void BrowserInstantController::GoogleURLUpdated() {
269 ReloadTabsInInstantProcess();
270 }
271
272 void BrowserInstantController::ReloadTabsInInstantProcess() {
288 InstantService* instant_service = 273 InstantService* instant_service =
289 InstantServiceFactory::GetForProfile(browser_profile); 274 InstantServiceFactory::GetForProfile(profile());
290 if (!instant_service) 275 if (!instant_service)
291 return; 276 return;
292 277
293 TabStripModel* tab_model = browser_->tab_strip_model(); 278 TabStripModel* tab_model = browser_->tab_strip_model();
294 int count = tab_model->count(); 279 int count = tab_model->count();
295 for (int index = 0; index < count; ++index) { 280 for (int index = 0; index < count; ++index) {
296 content::WebContents* contents = tab_model->GetWebContentsAt(index); 281 content::WebContents* contents = tab_model->GetWebContentsAt(index);
297 if (!contents) 282 if (!contents)
298 continue; 283 continue;
299 284
300 if (!instant_service->IsInstantProcess( 285 if (!instant_service->IsInstantProcess(
301 contents->GetRenderProcessHost()->GetID())) 286 contents->GetRenderProcessHost()->GetID()))
302 continue; 287 continue;
303 288
304 // Reload the contents to ensure that it gets assigned to a non-priviledged 289 // Reload the contents to ensure that it gets assigned to a non-priviledged
305 // renderer. 290 // renderer.
306 contents->GetController().Reload(false); 291 contents->GetController().Reload(false);
307 } 292 }
308 } 293 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698