OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/omnibox/omnibox_edit_model.h" | 5 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 UMA_HISTOGRAM_ENUMERATION("AutocompleteActionPredictor.Action", | 241 UMA_HISTOGRAM_ENUMERATION("AutocompleteActionPredictor.Action", |
242 recommended_action, | 242 recommended_action, |
243 AutocompleteActionPredictor::LAST_PREDICT_ACTION); | 243 AutocompleteActionPredictor::LAST_PREDICT_ACTION); |
244 string16 suggested_text; | 244 string16 suggested_text; |
245 | 245 |
246 if (DoInstant(current_match, &suggested_text)) { | 246 if (DoInstant(current_match, &suggested_text)) { |
247 SetSuggestedText(suggested_text, instant_complete_behavior_); | 247 SetSuggestedText(suggested_text, instant_complete_behavior_); |
248 } else { | 248 } else { |
249 switch (recommended_action) { | 249 switch (recommended_action) { |
250 case AutocompleteActionPredictor::ACTION_PRERENDER: | 250 case AutocompleteActionPredictor::ACTION_PRERENDER: |
251 DoPrerender(current_match); | 251 DoPrerender(action_predictor, current_match); |
252 break; | 252 break; |
253 case AutocompleteActionPredictor::ACTION_PRECONNECT: | 253 case AutocompleteActionPredictor::ACTION_PRECONNECT: |
254 DoPreconnect(current_match); | 254 DoPreconnect(current_match); |
255 break; | 255 break; |
256 case AutocompleteActionPredictor::ACTION_NONE: | 256 case AutocompleteActionPredictor::ACTION_NONE: |
257 break; | 257 break; |
258 default: | 258 default: |
259 NOTREACHED() << "Unexpected recommended action: " << recommended_action; | 259 NOTREACHED() << "Unexpected recommended action: " << recommended_action; |
260 break; | 260 break; |
261 } | 261 } |
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1087 | 1087 |
1088 // It's possible DoInstant() was called due to an OnChanged() event from the | 1088 // It's possible DoInstant() was called due to an OnChanged() event from the |
1089 // omnibox view if the user clicked the renderer while IME composition was | 1089 // omnibox view if the user clicked the renderer while IME composition was |
1090 // active. In that case we still want to commit on mouse up, so don't call | 1090 // active. In that case we still want to commit on mouse up, so don't call |
1091 // Hide(). | 1091 // Hide(). |
1092 if (!instant->commit_on_mouse_up()) | 1092 if (!instant->commit_on_mouse_up()) |
1093 instant->Hide(); | 1093 instant->Hide(); |
1094 return false; | 1094 return false; |
1095 } | 1095 } |
1096 | 1096 |
1097 void OmniboxEditModel::DoPrerender(const AutocompleteMatch& match) { | 1097 void OmniboxEditModel::DoPrerender( |
| 1098 AutocompleteActionPredictor* action_predictor, |
| 1099 const AutocompleteMatch& match) { |
1098 // Do not prerender if the destination URL is the same as the current URL. | 1100 // Do not prerender if the destination URL is the same as the current URL. |
1099 if (match.destination_url == PermanentURL()) | 1101 if (match.destination_url == PermanentURL()) |
1100 return; | 1102 return; |
1101 // It's possible the tab strip does not have an active tab contents, for | 1103 // It's possible the tab strip does not have an active tab contents, for |
1102 // instance if the tab has been closed or on return from a sleep state | 1104 // instance if the tab has been closed or on return from a sleep state |
1103 // (http://crbug.com/105689) | 1105 // (http://crbug.com/105689) |
1104 TabContents* tab = controller_->GetTabContents(); | |
1105 if (!tab) | |
1106 return; | |
1107 prerender::PrerenderManager* prerender_manager = | |
1108 prerender::PrerenderManagerFactory::GetForProfile(tab->profile()); | |
1109 if (!prerender_manager) | |
1110 return; | |
1111 | 1106 |
1112 content::RenderViewHost* current_host = | 1107 if (TabContents* tab = controller_->GetTabContents()) { |
1113 tab->web_contents()->GetRenderViewHost(); | 1108 gfx::Rect container_bounds; |
1114 gfx::Rect container_bounds; | 1109 tab->web_contents()->GetView()->GetContainerBounds(&container_bounds); |
1115 tab->web_contents()->GetView()->GetContainerBounds(&container_bounds); | 1110 content::RenderViewHost* current_host = |
1116 prerender_manager->AddPrerenderFromOmnibox( | 1111 tab->web_contents()->GetRenderViewHost(); |
1117 match.destination_url, current_host->GetSessionStorageNamespace(), | 1112 action_predictor->StartPrerendering( |
1118 container_bounds.size()); | 1113 match.destination_url, |
| 1114 current_host->GetSessionStorageNamespace(), container_bounds.size()); |
| 1115 } |
1119 } | 1116 } |
1120 | 1117 |
1121 void OmniboxEditModel::DoPreconnect(const AutocompleteMatch& match) { | 1118 void OmniboxEditModel::DoPreconnect(const AutocompleteMatch& match) { |
1122 if (!match.destination_url.SchemeIs(chrome::kExtensionScheme)) { | 1119 if (!match.destination_url.SchemeIs(chrome::kExtensionScheme)) { |
1123 // Warm up DNS Prefetch cache, or preconnect to a search service. | 1120 // Warm up DNS Prefetch cache, or preconnect to a search service. |
1124 UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", match.type, | 1121 UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", match.type, |
1125 AutocompleteMatch::NUM_TYPES); | 1122 AutocompleteMatch::NUM_TYPES); |
1126 if (profile_->GetNetworkPredictor()) { | 1123 if (profile_->GetNetworkPredictor()) { |
1127 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl( | 1124 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl( |
1128 match.destination_url, | 1125 match.destination_url, |
(...skipping 22 matching lines...) Expand all Loading... |
1151 return metrics::OmniboxEventProto_PageClassification_INVALID_SPEC; | 1148 return metrics::OmniboxEventProto_PageClassification_INVALID_SPEC; |
1152 const std::string& url = gurl.spec(); | 1149 const std::string& url = gurl.spec(); |
1153 if (url == chrome::kChromeUINewTabURL) | 1150 if (url == chrome::kChromeUINewTabURL) |
1154 return metrics::OmniboxEventProto_PageClassification_NEW_TAB_PAGE; | 1151 return metrics::OmniboxEventProto_PageClassification_NEW_TAB_PAGE; |
1155 if (url == chrome::kAboutBlankURL) | 1152 if (url == chrome::kAboutBlankURL) |
1156 return metrics::OmniboxEventProto_PageClassification_BLANK; | 1153 return metrics::OmniboxEventProto_PageClassification_BLANK; |
1157 if (url == profile()->GetPrefs()->GetString(prefs::kHomePage)) | 1154 if (url == profile()->GetPrefs()->GetString(prefs::kHomePage)) |
1158 return metrics::OmniboxEventProto_PageClassification_HOMEPAGE; | 1155 return metrics::OmniboxEventProto_PageClassification_HOMEPAGE; |
1159 return metrics::OmniboxEventProto_PageClassification_OTHER; | 1156 return metrics::OmniboxEventProto_PageClassification_OTHER; |
1160 } | 1157 } |
OLD | NEW |