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

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: Addressed comments, added a test to address the bug 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);
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());
52 instant_service->RemoveObserver(this);
62 instant_service->OnBrowserInstantControllerDestroyed(); 53 instant_service->OnBrowserInstantControllerDestroyed();
63 } 54 }
64 55
65 bool BrowserInstantController::MaybeSwapInInstantNTPContents( 56 bool BrowserInstantController::MaybeSwapInInstantNTPContents(
66 const GURL& url, 57 const GURL& url,
67 content::WebContents* source_contents, 58 content::WebContents* source_contents,
68 content::WebContents** target_contents) { 59 content::WebContents** target_contents) {
69 if (url != GURL(chrome::kChromeUINewTabURL)) 60 if (url != GURL(chrome::kChromeUINewTabURL))
70 return false; 61 return false;
71 62
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 else if (new_mode.is_ntp()) 252 else if (new_mode.is_ntp())
262 content::RecordAction(UserMetricsAction("InstantExtended.ShowNTP")); 253 content::RecordAction(UserMetricsAction("InstantExtended.ShowNTP"));
263 254
264 instant_.SearchModeChanged(old_state.mode, new_mode); 255 instant_.SearchModeChanged(old_state.mode, new_mode);
265 } 256 }
266 257
267 if (old_state.instant_support != new_state.instant_support) 258 if (old_state.instant_support != new_state.instant_support)
268 instant_.InstantSupportChanged(new_state.instant_support); 259 instant_.InstantSupportChanged(new_state.instant_support);
269 } 260 }
270 261
271 void BrowserInstantController::OnDefaultSearchProviderChanged( 262 ////////////////////////////////////////////////////////////////////////////////
272 const std::string& pref_name) { 263 // BrowserInstantController, InstantServiceObserver implementation:
273 DCHECK_EQ(pref_name, std::string(prefs::kDefaultSearchProviderID));
274 264
275 Profile* browser_profile = profile(); 265 void BrowserInstantController::DefaultSearchProviderChanged() {
276 const TemplateURL* template_url = 266 ReloadTabsInInstantProcess();
277 TemplateURLServiceFactory::GetForProfile(browser_profile)-> 267 }
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 268
269 void BrowserInstantController::GoogleURLUpdated() {
270 ReloadTabsInInstantProcess();
271 }
272
273 void BrowserInstantController::ReloadTabsInInstantProcess() {
288 InstantService* instant_service = 274 InstantService* instant_service =
289 InstantServiceFactory::GetForProfile(browser_profile); 275 InstantServiceFactory::GetForProfile(profile());
290 if (!instant_service) 276 if (!instant_service)
291 return; 277 return;
292 278
293 TabStripModel* tab_model = browser_->tab_strip_model(); 279 TabStripModel* tab_model = browser_->tab_strip_model();
294 int count = tab_model->count(); 280 int count = tab_model->count();
295 for (int index = 0; index < count; ++index) { 281 for (int index = 0; index < count; ++index) {
296 content::WebContents* contents = tab_model->GetWebContentsAt(index); 282 content::WebContents* contents = tab_model->GetWebContentsAt(index);
297 if (!contents) 283 if (!contents)
298 continue; 284 continue;
299 285
300 if (!instant_service->IsInstantProcess( 286 if (!instant_service->IsInstantProcess(
301 contents->GetRenderProcessHost()->GetID())) 287 contents->GetRenderProcessHost()->GetID()))
302 continue; 288 continue;
303 289
304 // Reload the contents to ensure that it gets assigned to a non-priviledged 290 // Reload the contents to ensure that it gets assigned to a non-priviledged
305 // renderer. 291 // renderer.
306 contents->GetController().Reload(false); 292 contents->GetController().Reload(false);
307 } 293 }
308 } 294 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698