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

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

Issue 272573004: Handle TemplateURLService load failure better, and make some test correctness fixes that will be ne… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase after revert / presubmit fixes. Created 6 years, 7 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 | Annotate | Revision Log
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 "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/extensions/extension_web_ui.h" 9 #include "chrome/browser/extensions/extension_web_ui.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/search/instant_service.h" 11 #include "chrome/browser/search/instant_service.h"
12 #include "chrome/browser/search/instant_service_factory.h" 12 #include "chrome/browser/search/instant_service_factory.h"
13 #include "chrome/browser/search/search.h" 13 #include "chrome/browser/search/search.h"
14 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_window.h" 15 #include "chrome/browser/ui/browser_window.h"
16 #include "chrome/browser/ui/omnibox/location_bar.h" 16 #include "chrome/browser/ui/omnibox/location_bar.h"
17 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" 17 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
18 #include "chrome/browser/ui/omnibox/omnibox_view.h" 18 #include "chrome/browser/ui/omnibox/omnibox_view.h"
19 #include "chrome/browser/ui/search/instant_search_prerenderer.h" 19 #include "chrome/browser/ui/search/instant_search_prerenderer.h"
20 #include "chrome/browser/ui/search/search_model.h" 20 #include "chrome/browser/ui/search/search_model.h"
21 #include "chrome/browser/ui/search/search_tab_helper.h" 21 #include "chrome/browser/ui/search/search_tab_helper.h"
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" 22 #include "chrome/browser/ui/tabs/tab_strip_model.h"
23 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" 23 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h"
24 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
25 #include "content/public/browser/render_process_host.h" 25 #include "content/public/browser/render_process_host.h"
26 #include "content/public/browser/user_metrics.h" 26 #include "content/public/browser/user_metrics.h"
27 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
28 28
29 using base::UserMetricsAction; 29
30 // Helpers --------------------------------------------------------------------
30 31
31 namespace { 32 namespace {
32 33
33 InstantSearchPrerenderer* GetInstantSearchPrerenderer(Profile* profile) { 34 InstantSearchPrerenderer* GetInstantSearchPrerenderer(Profile* profile) {
34 DCHECK(profile); 35 DCHECK(profile);
35 InstantService* instant_service = 36 InstantService* instant_service =
36 InstantServiceFactory::GetForProfile(profile); 37 InstantServiceFactory::GetForProfile(profile);
37 return instant_service ? instant_service->instant_search_prerenderer() : NULL; 38 return instant_service ? instant_service->instant_search_prerenderer() : NULL;
38 } 39 }
39 40
40 } // namespace 41 } // namespace
41 42
42 //////////////////////////////////////////////////////////////////////////////// 43
43 // BrowserInstantController, public: 44 // BrowserInstantController ---------------------------------------------------
44 45
45 BrowserInstantController::BrowserInstantController(Browser* browser) 46 BrowserInstantController::BrowserInstantController(Browser* browser)
46 : browser_(browser), 47 : browser_(browser),
47 instant_(this) { 48 instant_(this) {
48 browser_->search_model()->AddObserver(this); 49 browser_->search_model()->AddObserver(this);
49 50
50 InstantService* instant_service = 51 InstantService* instant_service =
51 InstantServiceFactory::GetForProfile(profile()); 52 InstantServiceFactory::GetForProfile(profile());
52 instant_service->AddObserver(this); 53 instant_service->AddObserver(this);
53 } 54 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 113
113 void BrowserInstantController::TabDeactivated(content::WebContents* contents) { 114 void BrowserInstantController::TabDeactivated(content::WebContents* contents) {
114 instant_.TabDeactivated(contents); 115 instant_.TabDeactivated(contents);
115 116
116 InstantSearchPrerenderer* prerenderer = 117 InstantSearchPrerenderer* prerenderer =
117 GetInstantSearchPrerenderer(profile()); 118 GetInstantSearchPrerenderer(profile());
118 if (prerenderer) 119 if (prerenderer)
119 prerenderer->Cancel(); 120 prerenderer->Cancel();
120 } 121 }
121 122
122 ////////////////////////////////////////////////////////////////////////////////
123 // BrowserInstantController, SearchModelObserver implementation:
124
125 void BrowserInstantController::ModelChanged( 123 void BrowserInstantController::ModelChanged(
126 const SearchModel::State& old_state, 124 const SearchModel::State& old_state,
127 const SearchModel::State& new_state) { 125 const SearchModel::State& new_state) {
128 if (old_state.mode != new_state.mode) { 126 if (old_state.mode != new_state.mode) {
129 const SearchMode& new_mode = new_state.mode; 127 const SearchMode& new_mode = new_state.mode;
130 128
131 // Record some actions corresponding to the mode change. Note that to get 129 // Record some actions corresponding to the mode change. Note that to get
132 // the full story, it's necessary to look at other UMA actions as well, 130 // the full story, it's necessary to look at other UMA actions as well,
133 // such as tab switches. 131 // such as tab switches.
134 if (new_mode.is_search_results()) 132 if (new_mode.is_search_results())
135 content::RecordAction(UserMetricsAction("InstantExtended.ShowSRP")); 133 content::RecordAction(base::UserMetricsAction("InstantExtended.ShowSRP"));
136 else if (new_mode.is_ntp()) 134 else if (new_mode.is_ntp())
137 content::RecordAction(UserMetricsAction("InstantExtended.ShowNTP")); 135 content::RecordAction(base::UserMetricsAction("InstantExtended.ShowNTP"));
138 136
139 instant_.SearchModeChanged(old_state.mode, new_mode); 137 instant_.SearchModeChanged(old_state.mode, new_mode);
140 } 138 }
141 139
142 if (old_state.instant_support != new_state.instant_support) 140 if (old_state.instant_support != new_state.instant_support)
143 instant_.InstantSupportChanged(new_state.instant_support); 141 instant_.InstantSupportChanged(new_state.instant_support);
144 } 142 }
145 143
146 ////////////////////////////////////////////////////////////////////////////////
147 // BrowserInstantController, InstantServiceObserver implementation:
148
149 void BrowserInstantController::DefaultSearchProviderChanged() { 144 void BrowserInstantController::DefaultSearchProviderChanged() {
150 ReloadTabsInInstantProcess();
151 }
152
153 void BrowserInstantController::GoogleURLUpdated() {
154 ReloadTabsInInstantProcess();
155 }
156
157 void BrowserInstantController::ReloadTabsInInstantProcess() {
158 InstantService* instant_service = 145 InstantService* instant_service =
159 InstantServiceFactory::GetForProfile(profile()); 146 InstantServiceFactory::GetForProfile(profile());
160 if (!instant_service) 147 if (!instant_service)
161 return; 148 return;
162 149
163 TabStripModel* tab_model = browser_->tab_strip_model(); 150 TabStripModel* tab_model = browser_->tab_strip_model();
164 int count = tab_model->count(); 151 int count = tab_model->count();
165 for (int index = 0; index < count; ++index) { 152 for (int index = 0; index < count; ++index) {
166 content::WebContents* contents = tab_model->GetWebContentsAt(index); 153 content::WebContents* contents = tab_model->GetWebContentsAt(index);
167 if (!contents) 154 if (!contents)
168 continue; 155 continue;
169 156
170 // Send new search URLs to the renderer. 157 // Send new search URLs to the renderer.
171 content::RenderProcessHost* rph = contents->GetRenderProcessHost(); 158 content::RenderProcessHost* rph = contents->GetRenderProcessHost();
172 instant_service->SendSearchURLsToRenderer(rph); 159 instant_service->SendSearchURLsToRenderer(rph);
173 160
174 // Reload the contents to ensure that it gets assigned to a non-priviledged 161 // Reload the contents to ensure that it gets assigned to a non-priviledged
175 // renderer. 162 // renderer.
176 if (!instant_service->IsInstantProcess(rph->GetID())) 163 if (!instant_service->IsInstantProcess(rph->GetID()))
177 continue; 164 continue;
178 contents->GetController().Reload(false); 165 contents->GetController().Reload(false);
179 } 166 }
180 } 167 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_instant_controller.h ('k') | chrome/browser/ui/browser_instant_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698