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/autocomplete/autocomplete_edit.h" | 5 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 UMA_HISTOGRAM_ENUMERATION("AutocompleteActionPredictor.Action", | 252 UMA_HISTOGRAM_ENUMERATION("AutocompleteActionPredictor.Action", |
253 recommended_action, | 253 recommended_action, |
254 AutocompleteActionPredictor::LAST_PREDICT_ACTION); | 254 AutocompleteActionPredictor::LAST_PREDICT_ACTION); |
255 string16 suggested_text; | 255 string16 suggested_text; |
256 | 256 |
257 if (DoInstant(current_match, &suggested_text)) { | 257 if (DoInstant(current_match, &suggested_text)) { |
258 SetSuggestedText(suggested_text, instant_complete_behavior_); | 258 SetSuggestedText(suggested_text, instant_complete_behavior_); |
259 } else { | 259 } else { |
260 switch (recommended_action) { | 260 switch (recommended_action) { |
261 case AutocompleteActionPredictor::ACTION_PRERENDER: | 261 case AutocompleteActionPredictor::ACTION_PRERENDER: |
262 DoPrerender(current_match); | 262 DoPrerender(action_predictor, current_match); |
263 break; | 263 break; |
264 case AutocompleteActionPredictor::ACTION_PRECONNECT: | 264 case AutocompleteActionPredictor::ACTION_PRECONNECT: |
265 DoPreconnect(current_match); | 265 DoPreconnect(current_match); |
266 break; | 266 break; |
267 case AutocompleteActionPredictor::ACTION_NONE: | 267 case AutocompleteActionPredictor::ACTION_NONE: |
268 break; | 268 break; |
269 default: | 269 default: |
270 NOTREACHED() << "Unexpected recommended action: " << recommended_action; | 270 NOTREACHED() << "Unexpected recommended action: " << recommended_action; |
271 break; | 271 break; |
272 } | 272 } |
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 | 1092 |
1093 // It's possible DoInstant() was called due to an OnChanged() event from the | 1093 // It's possible DoInstant() was called due to an OnChanged() event from the |
1094 // omnibox view if the user clicked the renderer while IME composition was | 1094 // omnibox view if the user clicked the renderer while IME composition was |
1095 // active. In that case we still want to commit on mouse up, so don't call | 1095 // active. In that case we still want to commit on mouse up, so don't call |
1096 // Hide(). | 1096 // Hide(). |
1097 if (!instant->commit_on_mouse_up()) | 1097 if (!instant->commit_on_mouse_up()) |
1098 instant->Hide(); | 1098 instant->Hide(); |
1099 return false; | 1099 return false; |
1100 } | 1100 } |
1101 | 1101 |
1102 void AutocompleteEditModel::DoPrerender(const AutocompleteMatch& match) { | 1102 void AutocompleteEditModel::DoPrerender( |
| 1103 AutocompleteActionPredictor* action_predictor, |
| 1104 const AutocompleteMatch& match) { |
| 1105 DCHECK(action_predictor); |
| 1106 |
1103 // Do not prerender if the destination URL is the same as the current URL. | 1107 // Do not prerender if the destination URL is the same as the current URL. |
1104 if (match.destination_url == PermanentURL()) | 1108 if (match.destination_url == PermanentURL()) |
1105 return; | 1109 return; |
1106 // It's possible the tab strip does not have an active tab contents, for | 1110 // It's possible the tab strip does not have an active tab contents, for |
1107 // instance if the tab has been closed or on return from a sleep state | 1111 // instance if the tab has been closed or on return from a sleep state |
1108 // (http://crbug.com/105689) | 1112 // (http://crbug.com/105689) |
1109 TabContents* tab = controller_->GetTabContents(); | 1113 if (TabContents* tab = controller_->GetTabContents()) { |
1110 if (!tab) | |
1111 return; | |
1112 prerender::PrerenderManager* prerender_manager = | |
1113 prerender::PrerenderManagerFactory::GetForProfile(tab->profile()); | |
1114 if (prerender_manager) { | |
1115 content::RenderViewHost* current_host = | 1114 content::RenderViewHost* current_host = |
1116 tab->web_contents()->GetRenderViewHost(); | 1115 tab->web_contents()->GetRenderViewHost(); |
1117 prerender_manager->AddPrerenderFromOmnibox( | 1116 prerender::PrerenderHandle prerender = action_predictor->StartPrerendering( |
1118 match.destination_url, current_host->GetSessionStorageNamespace()); | 1117 match.destination_url, current_host->GetSessionStorageNamespace()); |
| 1118 match.prerender = prerender->AsWeakPtr(); |
1119 } | 1119 } |
1120 } | 1120 } |
1121 | 1121 |
1122 void AutocompleteEditModel::DoPreconnect(const AutocompleteMatch& match) { | 1122 void AutocompleteEditModel::DoPreconnect(const AutocompleteMatch& match) { |
1123 if (!match.destination_url.SchemeIs(chrome::kExtensionScheme)) { | 1123 if (!match.destination_url.SchemeIs(chrome::kExtensionScheme)) { |
1124 // Warm up DNS Prefetch cache, or preconnect to a search service. | 1124 // Warm up DNS Prefetch cache, or preconnect to a search service. |
1125 UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", match.type, | 1125 UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", match.type, |
1126 AutocompleteMatch::NUM_TYPES); | 1126 AutocompleteMatch::NUM_TYPES); |
1127 if (profile_->GetNetworkPredictor()) { | 1127 if (profile_->GetNetworkPredictor()) { |
1128 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl( | 1128 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl( |
(...skipping 23 matching lines...) Expand all Loading... |
1152 return metrics::OmniboxEventProto_PageClassification_INVALID_SPEC; | 1152 return metrics::OmniboxEventProto_PageClassification_INVALID_SPEC; |
1153 const std::string& url = gurl.spec(); | 1153 const std::string& url = gurl.spec(); |
1154 if (url == chrome::kChromeUINewTabURL) | 1154 if (url == chrome::kChromeUINewTabURL) |
1155 return metrics::OmniboxEventProto_PageClassification_NEW_TAB_PAGE; | 1155 return metrics::OmniboxEventProto_PageClassification_NEW_TAB_PAGE; |
1156 if (url == chrome::kAboutBlankURL) | 1156 if (url == chrome::kAboutBlankURL) |
1157 return metrics::OmniboxEventProto_PageClassification_BLANK; | 1157 return metrics::OmniboxEventProto_PageClassification_BLANK; |
1158 if (url == profile()->GetPrefs()->GetString(prefs::kHomePage)) | 1158 if (url == profile()->GetPrefs()->GetString(prefs::kHomePage)) |
1159 return metrics::OmniboxEventProto_PageClassification_HOMEPAGE; | 1159 return metrics::OmniboxEventProto_PageClassification_HOMEPAGE; |
1160 return metrics::OmniboxEventProto_PageClassification_OTHER; | 1160 return metrics::OmniboxEventProto_PageClassification_OTHER; |
1161 } | 1161 } |
OLD | NEW |