| 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" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/time.h" | 12 #include "base/time.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/app/chrome_command_ids.h" | 14 #include "chrome/app/chrome_command_ids.h" |
| 15 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 15 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 16 #include "chrome/browser/autocomplete/autocomplete_match.h" | 16 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 17 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 17 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
| 18 #include "chrome/browser/autocomplete/autocomplete_popup_view.h" | 18 #include "chrome/browser/autocomplete/autocomplete_popup_view.h" |
| 19 #include "chrome/browser/autocomplete/keyword_provider.h" | 19 #include "chrome/browser/autocomplete/keyword_provider.h" |
| 20 #include "chrome/browser/autocomplete/network_action_predictor.h" | |
| 21 #include "chrome/browser/autocomplete/network_action_predictor_factory.h" | |
| 22 #include "chrome/browser/autocomplete/search_provider.h" | 20 #include "chrome/browser/autocomplete/search_provider.h" |
| 23 #include "chrome/browser/bookmarks/bookmark_utils.h" | 21 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 24 #include "chrome/browser/command_updater.h" | 22 #include "chrome/browser/command_updater.h" |
| 25 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" | 23 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" |
| 26 #include "chrome/browser/google/google_url_tracker.h" | 24 #include "chrome/browser/google/google_url_tracker.h" |
| 27 #include "chrome/browser/instant/instant_controller.h" | 25 #include "chrome/browser/instant/instant_controller.h" |
| 28 #include "chrome/browser/net/predictor.h" | 26 #include "chrome/browser/net/predictor.h" |
| 29 #include "chrome/browser/net/url_fixer_upper.h" | 27 #include "chrome/browser/net/url_fixer_upper.h" |
| 28 #include "chrome/browser/predictors/autocomplete_action_predictor.h" |
| 29 #include "chrome/browser/predictors/autocomplete_action_predictor_factory.h" |
| 30 #include "chrome/browser/prefs/pref_service.h" | 30 #include "chrome/browser/prefs/pref_service.h" |
| 31 #include "chrome/browser/prerender/prerender_field_trial.h" | 31 #include "chrome/browser/prerender/prerender_field_trial.h" |
| 32 #include "chrome/browser/prerender/prerender_manager.h" | 32 #include "chrome/browser/prerender/prerender_manager.h" |
| 33 #include "chrome/browser/prerender/prerender_manager_factory.h" | 33 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 34 #include "chrome/browser/profiles/profile.h" | 34 #include "chrome/browser/profiles/profile.h" |
| 35 #include "chrome/browser/search_engines/template_url.h" | 35 #include "chrome/browser/search_engines/template_url.h" |
| 36 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 36 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
| 37 #include "chrome/browser/search_engines/template_url_service.h" | 37 #include "chrome/browser/search_engines/template_url_service.h" |
| 38 #include "chrome/browser/search_engines/template_url_service_factory.h" | 38 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 39 #include "chrome/browser/sessions/restore_tab_helper.h" | 39 #include "chrome/browser/sessions/restore_tab_helper.h" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 return InstantController::CommitIfCurrent(controller_->GetInstant()); | 220 return InstantController::CommitIfCurrent(controller_->GetInstant()); |
| 221 } | 221 } |
| 222 | 222 |
| 223 void AutocompleteEditModel::OnChanged() { | 223 void AutocompleteEditModel::OnChanged() { |
| 224 // Don't call CurrentMatch() when there's no editing, as in this case we'll | 224 // Don't call CurrentMatch() when there's no editing, as in this case we'll |
| 225 // never actually use it. This avoids running the autocomplete providers (and | 225 // never actually use it. This avoids running the autocomplete providers (and |
| 226 // any systems they then spin up) during startup. | 226 // any systems they then spin up) during startup. |
| 227 const AutocompleteMatch& current_match = user_input_in_progress_ ? | 227 const AutocompleteMatch& current_match = user_input_in_progress_ ? |
| 228 CurrentMatch() : AutocompleteMatch(); | 228 CurrentMatch() : AutocompleteMatch(); |
| 229 | 229 |
| 230 NetworkActionPredictor::Action recommended_action = | 230 AutocompleteActionPredictor::Action recommended_action = |
| 231 NetworkActionPredictor::ACTION_NONE; | 231 AutocompleteActionPredictor::ACTION_NONE; |
| 232 NetworkActionPredictor* network_action_predictor = | 232 AutocompleteActionPredictor* action_predictor = |
| 233 user_input_in_progress_ ? | 233 user_input_in_progress_ ? |
| 234 NetworkActionPredictorFactory::GetForProfile(profile_) : NULL; | 234 AutocompleteActionPredictorFactory::GetForProfile(profile_) : NULL; |
| 235 if (network_action_predictor) { | 235 if (action_predictor) { |
| 236 network_action_predictor->RegisterTransitionalMatches(user_text_, | 236 action_predictor->RegisterTransitionalMatches(user_text_, result()); |
| 237 result()); | 237 // Confer with the AutocompleteActionPredictor to determine what action, if |
| 238 // Confer with the NetworkActionPredictor to determine what action, if any, | 238 // any, we should take. Get the recommended action here even if we don't |
| 239 // we should take. Get the recommended action here even if we don't need it | 239 // need it so we can get stats for anyone who is opted in to UMA, but only |
| 240 // so we can get stats for anyone who is opted in to UMA, but only get it if | 240 // get it if the user has actually typed something to avoid constructing it |
| 241 // the user has actually typed something to avoid constructing it before | 241 // before it's needed. Note: This event is triggered as part of startup when |
| 242 // it's needed. Note: This event is triggered as part of startup when the | 242 // the initial tab transitions to the start page. |
| 243 // initial tab transitions to the start page. | |
| 244 recommended_action = | 243 recommended_action = |
| 245 network_action_predictor->RecommendAction(user_text_, current_match); | 244 action_predictor->RecommendAction(user_text_, current_match); |
| 246 } | 245 } |
| 247 | 246 |
| 248 UMA_HISTOGRAM_ENUMERATION("NetworkActionPredictor.Action", recommended_action, | 247 UMA_HISTOGRAM_ENUMERATION("NetworkActionPredictor.Action", recommended_action, |
| 249 NetworkActionPredictor::LAST_PREDICT_ACTION); | 248 AutocompleteActionPredictor::LAST_PREDICT_ACTION); |
| 250 string16 suggested_text; | 249 string16 suggested_text; |
| 251 | 250 |
| 252 if (DoInstant(current_match, &suggested_text)) { | 251 if (DoInstant(current_match, &suggested_text)) { |
| 253 SetSuggestedText(suggested_text, instant_complete_behavior_); | 252 SetSuggestedText(suggested_text, instant_complete_behavior_); |
| 254 } else { | 253 } else { |
| 255 switch (recommended_action) { | 254 switch (recommended_action) { |
| 256 case NetworkActionPredictor::ACTION_PRERENDER: | 255 case AutocompleteActionPredictor::ACTION_PRERENDER: |
| 257 DoPrerender(current_match); | 256 DoPrerender(current_match); |
| 258 break; | 257 break; |
| 259 case NetworkActionPredictor::ACTION_PRECONNECT: | 258 case AutocompleteActionPredictor::ACTION_PRECONNECT: |
| 260 DoPreconnect(current_match); | 259 DoPreconnect(current_match); |
| 261 break; | 260 break; |
| 262 case NetworkActionPredictor::ACTION_NONE: | 261 case AutocompleteActionPredictor::ACTION_NONE: |
| 263 break; | 262 break; |
| 264 default: | 263 default: |
| 265 NOTREACHED() << "Unexpected recommended action: " << recommended_action; | 264 NOTREACHED() << "Unexpected recommended action: " << recommended_action; |
| 266 break; | 265 break; |
| 267 } | 266 } |
| 268 | 267 |
| 269 // Hide any suggestions we might be showing. | 268 // Hide any suggestions we might be showing. |
| 270 view_->SetInstantSuggestion(string16(), false); | 269 view_->SetInstantSuggestion(string16(), false); |
| 271 | 270 |
| 272 // No need to wait any longer for instant. | 271 // No need to wait any longer for instant. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 void AutocompleteEditModel::Revert() { | 408 void AutocompleteEditModel::Revert() { |
| 410 SetInputInProgress(false); | 409 SetInputInProgress(false); |
| 411 paste_state_ = NONE; | 410 paste_state_ = NONE; |
| 412 InternalSetUserText(string16()); | 411 InternalSetUserText(string16()); |
| 413 keyword_.clear(); | 412 keyword_.clear(); |
| 414 is_keyword_hint_ = false; | 413 is_keyword_hint_ = false; |
| 415 has_temporary_text_ = false; | 414 has_temporary_text_ = false; |
| 416 view_->SetWindowTextAndCaretPos(permanent_text_, | 415 view_->SetWindowTextAndCaretPos(permanent_text_, |
| 417 has_focus_ ? permanent_text_.length() : 0, | 416 has_focus_ ? permanent_text_.length() : 0, |
| 418 false, true); | 417 false, true); |
| 419 NetworkActionPredictor* network_action_predictor = | 418 AutocompleteActionPredictor* action_predictor = |
| 420 NetworkActionPredictorFactory::GetForProfile(profile_); | 419 AutocompleteActionPredictorFactory::GetForProfile(profile_); |
| 421 if (network_action_predictor) | 420 if (action_predictor) |
| 422 network_action_predictor->ClearTransitionalMatches(); | 421 action_predictor->ClearTransitionalMatches(); |
| 423 } | 422 } |
| 424 | 423 |
| 425 void AutocompleteEditModel::StartAutocomplete( | 424 void AutocompleteEditModel::StartAutocomplete( |
| 426 bool has_selected_text, | 425 bool has_selected_text, |
| 427 bool prevent_inline_autocomplete) const { | 426 bool prevent_inline_autocomplete) const { |
| 428 ClearPopupKeywordMode(); | 427 ClearPopupKeywordMode(); |
| 429 | 428 |
| 430 bool keyword_is_selected = KeywordIsSelected(); | 429 bool keyword_is_selected = KeywordIsSelected(); |
| 431 popup_->SetHoveredLine(AutocompletePopupModel::kNoMatch); | 430 popup_->SetHoveredLine(AutocompletePopupModel::kNoMatch); |
| 432 // We don't explicitly clear AutocompletePopupModel::manually_selected_match, | 431 // We don't explicitly clear AutocompletePopupModel::manually_selected_match, |
| (...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1118 } | 1117 } |
| 1119 | 1118 |
| 1120 void AutocompleteEditModel::DoPreconnect(const AutocompleteMatch& match) { | 1119 void AutocompleteEditModel::DoPreconnect(const AutocompleteMatch& match) { |
| 1121 if (!match.destination_url.SchemeIs(chrome::kExtensionScheme)) { | 1120 if (!match.destination_url.SchemeIs(chrome::kExtensionScheme)) { |
| 1122 // Warm up DNS Prefetch cache, or preconnect to a search service. | 1121 // Warm up DNS Prefetch cache, or preconnect to a search service. |
| 1123 UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", match.type, | 1122 UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", match.type, |
| 1124 AutocompleteMatch::NUM_TYPES); | 1123 AutocompleteMatch::NUM_TYPES); |
| 1125 if (profile_->GetNetworkPredictor()) { | 1124 if (profile_->GetNetworkPredictor()) { |
| 1126 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl( | 1125 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl( |
| 1127 match.destination_url, | 1126 match.destination_url, |
| 1128 NetworkActionPredictor::IsPreconnectable(match)); | 1127 AutocompleteActionPredictor::IsPreconnectable(match)); |
| 1129 } | 1128 } |
| 1130 // We could prefetch the alternate nav URL, if any, but because there | 1129 // We could prefetch the alternate nav URL, if any, but because there |
| 1131 // can be many of these as a user types an initial series of characters, | 1130 // can be many of these as a user types an initial series of characters, |
| 1132 // the OS DNS cache could suffer eviction problems for minimal gain. | 1131 // the OS DNS cache could suffer eviction problems for minimal gain. |
| 1133 } | 1132 } |
| 1134 } | 1133 } |
| 1135 | 1134 |
| 1136 // static | 1135 // static |
| 1137 bool AutocompleteEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { | 1136 bool AutocompleteEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { |
| 1138 switch (c) { | 1137 switch (c) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1150 return metrics::OmniboxEventProto_PageClassification_INVALID_SPEC; | 1149 return metrics::OmniboxEventProto_PageClassification_INVALID_SPEC; |
| 1151 const std::string& url = gurl.spec(); | 1150 const std::string& url = gurl.spec(); |
| 1152 if (url == chrome::kChromeUINewTabURL) | 1151 if (url == chrome::kChromeUINewTabURL) |
| 1153 return metrics::OmniboxEventProto_PageClassification_NEW_TAB_PAGE; | 1152 return metrics::OmniboxEventProto_PageClassification_NEW_TAB_PAGE; |
| 1154 if (url == chrome::kAboutBlankURL) | 1153 if (url == chrome::kAboutBlankURL) |
| 1155 return metrics::OmniboxEventProto_PageClassification_BLANK; | 1154 return metrics::OmniboxEventProto_PageClassification_BLANK; |
| 1156 if (url == profile()->GetPrefs()->GetString(prefs::kHomePage)) | 1155 if (url == profile()->GetPrefs()->GetString(prefs::kHomePage)) |
| 1157 return metrics::OmniboxEventProto_PageClassification_HOMEPAGE; | 1156 return metrics::OmniboxEventProto_PageClassification_HOMEPAGE; |
| 1158 return metrics::OmniboxEventProto_PageClassification_OTHER; | 1157 return metrics::OmniboxEventProto_PageClassification_OTHER; |
| 1159 } | 1158 } |
| OLD | NEW |