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

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: Format and lint 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_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), 35 instant_(this),
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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 else if (new_mode.is_ntp()) 204 else if (new_mode.is_ntp())
215 content::RecordAction(UserMetricsAction("InstantExtended.ShowNTP")); 205 content::RecordAction(UserMetricsAction("InstantExtended.ShowNTP"));
216 206
217 instant_.SearchModeChanged(old_state.mode, new_mode); 207 instant_.SearchModeChanged(old_state.mode, new_mode);
218 } 208 }
219 209
220 if (old_state.instant_support != new_state.instant_support) 210 if (old_state.instant_support != new_state.instant_support)
221 instant_.InstantSupportChanged(new_state.instant_support); 211 instant_.InstantSupportChanged(new_state.instant_support);
222 } 212 }
223 213
224 void BrowserInstantController::OnDefaultSearchProviderChanged( 214 ////////////////////////////////////////////////////////////////////////////////
225 const std::string& pref_name) { 215 // BrowserInstantController, InstantServiceObserver implementation:
226 DCHECK_EQ(pref_name, std::string(prefs::kDefaultSearchProviderID));
227 216
228 Profile* browser_profile = profile(); 217 void BrowserInstantController::DefaultSearchProviderChanged() {
229 const TemplateURL* template_url = 218 ReloadTabsInInstantProcess();
230 TemplateURLServiceFactory::GetForProfile(browser_profile)-> 219 }
231 GetDefaultSearchProvider();
232 if (!template_url) {
233 // A NULL |template_url| could mean either this notification is sent during
234 // the browser start up operation or the user now has no default search
235 // provider. There is no way for the user to reach this state using the
236 // Chrome settings. Only explicitly poking at the DB or bugs in the Sync
237 // could cause that, neither of which we support.
238 return;
239 }
240 220
221 void BrowserInstantController::GoogleURLUpdated() {
222 ReloadTabsInInstantProcess();
223 }
224
225 void BrowserInstantController::ReloadTabsInInstantProcess() {
241 InstantService* instant_service = 226 InstantService* instant_service =
242 InstantServiceFactory::GetForProfile(browser_profile); 227 InstantServiceFactory::GetForProfile(profile());
243 if (!instant_service) 228 if (!instant_service)
244 return; 229 return;
245 230
246 TabStripModel* tab_model = browser_->tab_strip_model(); 231 TabStripModel* tab_model = browser_->tab_strip_model();
247 int count = tab_model->count(); 232 int count = tab_model->count();
248 for (int index = 0; index < count; ++index) { 233 for (int index = 0; index < count; ++index) {
249 content::WebContents* contents = tab_model->GetWebContentsAt(index); 234 content::WebContents* contents = tab_model->GetWebContentsAt(index);
250 if (!contents) 235 if (!contents)
251 continue; 236 continue;
252 237
253 if (!instant_service->IsInstantProcess( 238 if (!instant_service->IsInstantProcess(
254 contents->GetRenderProcessHost()->GetID())) 239 contents->GetRenderProcessHost()->GetID()))
255 continue; 240 continue;
256 241
257 // Reload the contents to ensure that it gets assigned to a non-priviledged 242 // Reload the contents to ensure that it gets assigned to a non-priviledged
258 // renderer. 243 // renderer.
259 contents->GetController().Reload(false); 244 contents->GetController().Reload(false);
260 } 245 }
261 } 246 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698