OLD | NEW |
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 | 29 using base::UserMetricsAction; |
30 // Helpers -------------------------------------------------------------------- | |
31 | 30 |
32 namespace { | 31 namespace { |
33 | 32 |
34 InstantSearchPrerenderer* GetInstantSearchPrerenderer(Profile* profile) { | 33 InstantSearchPrerenderer* GetInstantSearchPrerenderer(Profile* profile) { |
35 DCHECK(profile); | 34 DCHECK(profile); |
36 InstantService* instant_service = | 35 InstantService* instant_service = |
37 InstantServiceFactory::GetForProfile(profile); | 36 InstantServiceFactory::GetForProfile(profile); |
38 return instant_service ? instant_service->instant_search_prerenderer() : NULL; | 37 return instant_service ? instant_service->instant_search_prerenderer() : NULL; |
39 } | 38 } |
40 | 39 |
41 } // namespace | 40 } // namespace |
42 | 41 |
43 | 42 //////////////////////////////////////////////////////////////////////////////// |
44 // BrowserInstantController --------------------------------------------------- | 43 // BrowserInstantController, public: |
45 | 44 |
46 BrowserInstantController::BrowserInstantController(Browser* browser) | 45 BrowserInstantController::BrowserInstantController(Browser* browser) |
47 : browser_(browser), | 46 : browser_(browser), |
48 instant_(this) { | 47 instant_(this) { |
49 browser_->search_model()->AddObserver(this); | 48 browser_->search_model()->AddObserver(this); |
50 | 49 |
51 InstantService* instant_service = | 50 InstantService* instant_service = |
52 InstantServiceFactory::GetForProfile(profile()); | 51 InstantServiceFactory::GetForProfile(profile()); |
53 instant_service->AddObserver(this); | 52 instant_service->AddObserver(this); |
54 } | 53 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 112 |
114 void BrowserInstantController::TabDeactivated(content::WebContents* contents) { | 113 void BrowserInstantController::TabDeactivated(content::WebContents* contents) { |
115 instant_.TabDeactivated(contents); | 114 instant_.TabDeactivated(contents); |
116 | 115 |
117 InstantSearchPrerenderer* prerenderer = | 116 InstantSearchPrerenderer* prerenderer = |
118 GetInstantSearchPrerenderer(profile()); | 117 GetInstantSearchPrerenderer(profile()); |
119 if (prerenderer) | 118 if (prerenderer) |
120 prerenderer->Cancel(); | 119 prerenderer->Cancel(); |
121 } | 120 } |
122 | 121 |
| 122 //////////////////////////////////////////////////////////////////////////////// |
| 123 // BrowserInstantController, SearchModelObserver implementation: |
| 124 |
123 void BrowserInstantController::ModelChanged( | 125 void BrowserInstantController::ModelChanged( |
124 const SearchModel::State& old_state, | 126 const SearchModel::State& old_state, |
125 const SearchModel::State& new_state) { | 127 const SearchModel::State& new_state) { |
126 if (old_state.mode != new_state.mode) { | 128 if (old_state.mode != new_state.mode) { |
127 const SearchMode& new_mode = new_state.mode; | 129 const SearchMode& new_mode = new_state.mode; |
128 | 130 |
129 // Record some actions corresponding to the mode change. Note that to get | 131 // Record some actions corresponding to the mode change. Note that to get |
130 // the full story, it's necessary to look at other UMA actions as well, | 132 // the full story, it's necessary to look at other UMA actions as well, |
131 // such as tab switches. | 133 // such as tab switches. |
132 if (new_mode.is_search_results()) | 134 if (new_mode.is_search_results()) |
133 content::RecordAction(base::UserMetricsAction("InstantExtended.ShowSRP")); | 135 content::RecordAction(UserMetricsAction("InstantExtended.ShowSRP")); |
134 else if (new_mode.is_ntp()) | 136 else if (new_mode.is_ntp()) |
135 content::RecordAction(base::UserMetricsAction("InstantExtended.ShowNTP")); | 137 content::RecordAction(UserMetricsAction("InstantExtended.ShowNTP")); |
136 | 138 |
137 instant_.SearchModeChanged(old_state.mode, new_mode); | 139 instant_.SearchModeChanged(old_state.mode, new_mode); |
138 } | 140 } |
139 | 141 |
140 if (old_state.instant_support != new_state.instant_support) | 142 if (old_state.instant_support != new_state.instant_support) |
141 instant_.InstantSupportChanged(new_state.instant_support); | 143 instant_.InstantSupportChanged(new_state.instant_support); |
142 } | 144 } |
143 | 145 |
| 146 //////////////////////////////////////////////////////////////////////////////// |
| 147 // BrowserInstantController, InstantServiceObserver implementation: |
| 148 |
144 void BrowserInstantController::DefaultSearchProviderChanged() { | 149 void BrowserInstantController::DefaultSearchProviderChanged() { |
| 150 ReloadTabsInInstantProcess(); |
| 151 } |
| 152 |
| 153 void BrowserInstantController::GoogleURLUpdated() { |
| 154 ReloadTabsInInstantProcess(); |
| 155 } |
| 156 |
| 157 void BrowserInstantController::ReloadTabsInInstantProcess() { |
145 InstantService* instant_service = | 158 InstantService* instant_service = |
146 InstantServiceFactory::GetForProfile(profile()); | 159 InstantServiceFactory::GetForProfile(profile()); |
147 if (!instant_service) | 160 if (!instant_service) |
148 return; | 161 return; |
149 | 162 |
150 TabStripModel* tab_model = browser_->tab_strip_model(); | 163 TabStripModel* tab_model = browser_->tab_strip_model(); |
151 int count = tab_model->count(); | 164 int count = tab_model->count(); |
152 for (int index = 0; index < count; ++index) { | 165 for (int index = 0; index < count; ++index) { |
153 content::WebContents* contents = tab_model->GetWebContentsAt(index); | 166 content::WebContents* contents = tab_model->GetWebContentsAt(index); |
154 if (!contents) | 167 if (!contents) |
155 continue; | 168 continue; |
156 | 169 |
157 // Send new search URLs to the renderer. | 170 // Send new search URLs to the renderer. |
158 content::RenderProcessHost* rph = contents->GetRenderProcessHost(); | 171 content::RenderProcessHost* rph = contents->GetRenderProcessHost(); |
159 instant_service->SendSearchURLsToRenderer(rph); | 172 instant_service->SendSearchURLsToRenderer(rph); |
160 | 173 |
161 // Reload the contents to ensure that it gets assigned to a non-priviledged | 174 // Reload the contents to ensure that it gets assigned to a non-priviledged |
162 // renderer. | 175 // renderer. |
163 if (!instant_service->IsInstantProcess(rph->GetID())) | 176 if (!instant_service->IsInstantProcess(rph->GetID())) |
164 continue; | 177 continue; |
165 contents->GetController().Reload(false); | 178 contents->GetController().Reload(false); |
166 } | 179 } |
167 } | 180 } |
OLD | NEW |