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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit.cc

Issue 9610006: Refactoring, moving and renaming the NetworkActionPredictor. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Breaking the CL to be only the moved files. Created 8 years, 8 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
OLDNEW
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/extension_omnibox_api.h" 23 #include "chrome/browser/extensions/extension_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/prerender/prerender_field_trial.h" 30 #include "chrome/browser/prerender/prerender_field_trial.h"
31 #include "chrome/browser/prerender/prerender_manager.h" 31 #include "chrome/browser/prerender/prerender_manager.h"
32 #include "chrome/browser/prerender/prerender_manager_factory.h" 32 #include "chrome/browser/prerender/prerender_manager_factory.h"
33 #include "chrome/browser/profiles/profile.h" 33 #include "chrome/browser/profiles/profile.h"
34 #include "chrome/browser/search_engines/template_url.h" 34 #include "chrome/browser/search_engines/template_url.h"
35 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" 35 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
36 #include "chrome/browser/search_engines/template_url_service.h" 36 #include "chrome/browser/search_engines/template_url_service.h"
37 #include "chrome/browser/search_engines/template_url_service_factory.h" 37 #include "chrome/browser/search_engines/template_url_service_factory.h"
38 #include "chrome/browser/sessions/restore_tab_helper.h" 38 #include "chrome/browser/sessions/restore_tab_helper.h"
39 #include "chrome/browser/ui/browser_list.h" 39 #include "chrome/browser/ui/browser_list.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 return InstantController::CommitIfCurrent(controller_->GetInstant()); 217 return InstantController::CommitIfCurrent(controller_->GetInstant());
218 } 218 }
219 219
220 void AutocompleteEditModel::OnChanged() { 220 void AutocompleteEditModel::OnChanged() {
221 // Don't call CurrentMatch() when there's no editing, as in this case we'll 221 // Don't call CurrentMatch() when there's no editing, as in this case we'll
222 // never actually use it. This avoids running the autocomplete providers (and 222 // never actually use it. This avoids running the autocomplete providers (and
223 // any systems they then spin up) during startup. 223 // any systems they then spin up) during startup.
224 const AutocompleteMatch& current_match = user_input_in_progress_ ? 224 const AutocompleteMatch& current_match = user_input_in_progress_ ?
225 CurrentMatch() : AutocompleteMatch(); 225 CurrentMatch() : AutocompleteMatch();
226 226
227 NetworkActionPredictor::Action recommended_action = 227 AutocompleteActionPredictor::Action recommended_action =
228 NetworkActionPredictor::ACTION_NONE; 228 AutocompleteActionPredictor::ACTION_NONE;
229 NetworkActionPredictor* network_action_predictor = 229 AutocompleteActionPredictor* action_predictor =
230 user_input_in_progress_ ? 230 user_input_in_progress_ ?
231 NetworkActionPredictorFactory::GetForProfile(profile_) : NULL; 231 AutocompleteActionPredictorFactory::GetForProfile(profile_) : NULL;
232 if (network_action_predictor) { 232 if (action_predictor) {
233 network_action_predictor->RegisterTransitionalMatches(user_text_, 233 action_predictor->RegisterTransitionalMatches(user_text_, result());
234 result()); 234 // Confer with the AutocompleteActionPredictor to determine what action, if
235 // Confer with the NetworkActionPredictor to determine what action, if any, 235 // any, we should take. Get the recommended action here even if we don't
236 // we should take. Get the recommended action here even if we don't need it 236 // need it so we can get stats for anyone who is opted in to UMA, but only
237 // so we can get stats for anyone who is opted in to UMA, but only get it if 237 // get it if the user has actually typed something to avoid constructing it
238 // the user has actually typed something to avoid constructing it before 238 // before it's needed. Note: This event is triggered as part of startup when
239 // it's needed. Note: This event is triggered as part of startup when the 239 // the initial tab transitions to the start page.
240 // initial tab transitions to the start page.
241 recommended_action = 240 recommended_action =
242 network_action_predictor->RecommendAction(user_text_, current_match); 241 action_predictor->RecommendAction(user_text_, current_match);
243 } 242 }
244 243
245 UMA_HISTOGRAM_ENUMERATION("NetworkActionPredictor.Action", recommended_action, 244 UMA_HISTOGRAM_ENUMERATION("NetworkActionPredictor.Action", recommended_action,
246 NetworkActionPredictor::LAST_PREDICT_ACTION); 245 AutocompleteActionPredictor::LAST_PREDICT_ACTION);
247 string16 suggested_text; 246 string16 suggested_text;
248 247
249 if (DoInstant(current_match, &suggested_text)) { 248 if (DoInstant(current_match, &suggested_text)) {
250 SetSuggestedText(suggested_text, instant_complete_behavior_); 249 SetSuggestedText(suggested_text, instant_complete_behavior_);
251 } else { 250 } else {
252 switch (recommended_action) { 251 switch (recommended_action) {
253 case NetworkActionPredictor::ACTION_PRERENDER: 252 case AutocompleteActionPredictor::ACTION_PRERENDER:
254 DoPrerender(current_match); 253 DoPrerender(current_match);
255 break; 254 break;
256 case NetworkActionPredictor::ACTION_PRECONNECT: 255 case AutocompleteActionPredictor::ACTION_PRECONNECT:
257 DoPreconnect(current_match); 256 DoPreconnect(current_match);
258 break; 257 break;
259 case NetworkActionPredictor::ACTION_NONE: 258 case AutocompleteActionPredictor::ACTION_NONE:
260 break; 259 break;
261 default: 260 default:
262 NOTREACHED() << "Unexpected recommended action: " << recommended_action; 261 NOTREACHED() << "Unexpected recommended action: " << recommended_action;
263 break; 262 break;
264 } 263 }
265 264
266 // Hide any suggestions we might be showing. 265 // Hide any suggestions we might be showing.
267 view_->SetInstantSuggestion(string16(), false); 266 view_->SetInstantSuggestion(string16(), false);
268 267
269 // No need to wait any longer for instant. 268 // No need to wait any longer for instant.
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 void AutocompleteEditModel::Revert() { 405 void AutocompleteEditModel::Revert() {
407 SetInputInProgress(false); 406 SetInputInProgress(false);
408 paste_state_ = NONE; 407 paste_state_ = NONE;
409 InternalSetUserText(string16()); 408 InternalSetUserText(string16());
410 keyword_.clear(); 409 keyword_.clear();
411 is_keyword_hint_ = false; 410 is_keyword_hint_ = false;
412 has_temporary_text_ = false; 411 has_temporary_text_ = false;
413 view_->SetWindowTextAndCaretPos(permanent_text_, 412 view_->SetWindowTextAndCaretPos(permanent_text_,
414 has_focus_ ? permanent_text_.length() : 0, 413 has_focus_ ? permanent_text_.length() : 0,
415 false, true); 414 false, true);
416 NetworkActionPredictor* network_action_predictor = 415 AutocompleteActionPredictor* action_predictor =
417 NetworkActionPredictorFactory::GetForProfile(profile_); 416 AutocompleteActionPredictorFactory::GetForProfile(profile_);
418 if (network_action_predictor) 417 if (action_predictor)
419 network_action_predictor->ClearTransitionalMatches(); 418 action_predictor->ClearTransitionalMatches();
420 } 419 }
421 420
422 void AutocompleteEditModel::StartAutocomplete( 421 void AutocompleteEditModel::StartAutocomplete(
423 bool has_selected_text, 422 bool has_selected_text,
424 bool prevent_inline_autocomplete) const { 423 bool prevent_inline_autocomplete) const {
425 ClearPopupKeywordMode(); 424 ClearPopupKeywordMode();
426 425
427 bool keyword_is_selected = KeywordIsSelected(); 426 bool keyword_is_selected = KeywordIsSelected();
428 popup_->SetHoveredLine(AutocompletePopupModel::kNoMatch); 427 popup_->SetHoveredLine(AutocompletePopupModel::kNoMatch);
429 // We don't explicitly clear AutocompletePopupModel::manually_selected_match, 428 // We don't explicitly clear AutocompletePopupModel::manually_selected_match,
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 } 1115 }
1117 1116
1118 void AutocompleteEditModel::DoPreconnect(const AutocompleteMatch& match) { 1117 void AutocompleteEditModel::DoPreconnect(const AutocompleteMatch& match) {
1119 if (!match.destination_url.SchemeIs(chrome::kExtensionScheme)) { 1118 if (!match.destination_url.SchemeIs(chrome::kExtensionScheme)) {
1120 // Warm up DNS Prefetch cache, or preconnect to a search service. 1119 // Warm up DNS Prefetch cache, or preconnect to a search service.
1121 UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", match.type, 1120 UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", match.type,
1122 AutocompleteMatch::NUM_TYPES); 1121 AutocompleteMatch::NUM_TYPES);
1123 if (profile_->GetNetworkPredictor()) { 1122 if (profile_->GetNetworkPredictor()) {
1124 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl( 1123 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl(
1125 match.destination_url, 1124 match.destination_url,
1126 NetworkActionPredictor::IsPreconnectable(match)); 1125 AutocompleteActionPredictor::IsPreconnectable(match));
1127 } 1126 }
1128 // We could prefetch the alternate nav URL, if any, but because there 1127 // We could prefetch the alternate nav URL, if any, but because there
1129 // can be many of these as a user types an initial series of characters, 1128 // can be many of these as a user types an initial series of characters,
1130 // the OS DNS cache could suffer eviction problems for minimal gain. 1129 // the OS DNS cache could suffer eviction problems for minimal gain.
1131 } 1130 }
1132 } 1131 }
1133 1132
1134 // static 1133 // static
1135 bool AutocompleteEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { 1134 bool AutocompleteEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) {
1136 switch (c) { 1135 switch (c) {
1137 case 0x0020: // Space 1136 case 0x0020: // Space
1138 case 0x3000: // Ideographic Space 1137 case 0x3000: // Ideographic Space
1139 return true; 1138 return true;
1140 default: 1139 default:
1141 return false; 1140 return false;
1142 } 1141 }
1143 } 1142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698