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

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: 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, 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();
53 } 42 }
54 43
55 BrowserInstantController::~BrowserInstantController() { 44 BrowserInstantController::~BrowserInstantController() {
56 browser_->search_model()->RemoveObserver(this); 45 browser_->search_model()->RemoveObserver(this);
57 46
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 content::RecordAction(UserMetricsAction("InstantExtended.ShowNTP")); 205 content::RecordAction(UserMetricsAction("InstantExtended.ShowNTP"));
217 } 206 }
218 207
219 instant_.SearchModeChanged(old_state.mode, new_mode); 208 instant_.SearchModeChanged(old_state.mode, new_mode);
220 } 209 }
221 210
222 if (old_state.instant_support != new_state.instant_support) 211 if (old_state.instant_support != new_state.instant_support)
223 instant_.InstantSupportChanged(new_state.instant_support); 212 instant_.InstantSupportChanged(new_state.instant_support);
224 } 213 }
225 214
226 void BrowserInstantController::OnDefaultSearchProviderChanged( 215 ////////////////////////////////////////////////////////////////////////////////
227 const std::string& pref_name) { 216 // BrowserInstantController, InstantServiceObserver implementation:
228 DCHECK_EQ(pref_name, std::string(prefs::kDefaultSearchProviderID));
229 217
218 void BrowserInstantController::DefaultSearchProviderChanged() {
219 MaybeReloadInstantWebContents();
220 }
221
222 void BrowserInstantController::GoogleURLUpdated() {
223 MaybeReloadInstantWebContents();
224 }
225
226 void BrowserInstantController::MaybeReloadInstantWebContents() {
230 Profile* browser_profile = profile(); 227 Profile* browser_profile = profile();
samarth 2013/07/26 23:33:15 Just inline this call below.
Anuj 2013/07/31 07:16:18 Done.
231 const TemplateURL* template_url =
232 TemplateURLServiceFactory::GetForProfile(browser_profile)->
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
243 InstantService* instant_service = 228 InstantService* instant_service =
244 InstantServiceFactory::GetForProfile(browser_profile); 229 InstantServiceFactory::GetForProfile(browser_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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698