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

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: Created 8 years, 9 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"
40 #include "chrome/browser/ui/omnibox/omnibox_view.h" 40 #include "chrome/browser/ui/omnibox/omnibox_view.h"
41 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 41 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
42 #include "chrome/common/chrome_notification_types.h" 42 #include "chrome/common/chrome_notification_types.h"
43 #include "chrome/common/chrome_switches.h" 43 #include "chrome/common/chrome_switches.h"
44 #include "chrome/common/url_constants.h" 44 #include "chrome/common/url_constants.h"
45 #include "content/browser/renderer_host/render_view_host.h" 45 #include "content/browser/renderer_host/render_view_host.h"
46 #include "content/public/browser/notification_service.h" 46 #include "content/public/browser/notification_service.h"
47 #include "content/public/browser/user_metrics.h" 47 #include "content/public/browser/user_metrics.h"
48 #include "content/public/browser/web_contents.h" 48 #include "content/public/browser/web_contents.h"
49 #include "googleurl/src/gurl.h" 49 #include "googleurl/src/gurl.h"
50 #include "googleurl/src/url_util.h" 50 #include "googleurl/src/url_util.h"
51 #include "third_party/skia/include/core/SkBitmap.h" 51 #include "third_party/skia/include/core/SkBitmap.h"
52 52
53 using content::UserMetricsAction; 53 using content::UserMetricsAction;
54 using predictors::AutocompleteActionPredictor;
55 using predictors::AutocompleteActionPredictorFactory;
54 56
55 /////////////////////////////////////////////////////////////////////////////// 57 ///////////////////////////////////////////////////////////////////////////////
56 // AutocompleteEditController 58 // AutocompleteEditController
57 59
58 AutocompleteEditController::~AutocompleteEditController() { 60 AutocompleteEditController::~AutocompleteEditController() {
59 } 61 }
60 62
61 /////////////////////////////////////////////////////////////////////////////// 63 ///////////////////////////////////////////////////////////////////////////////
62 // AutocompleteEditModel::State 64 // AutocompleteEditModel::State
63 65
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 return true; 215 return true;
214 } 216 }
215 217
216 bool AutocompleteEditModel::AcceptCurrentInstantPreview() { 218 bool AutocompleteEditModel::AcceptCurrentInstantPreview() {
217 return InstantController::CommitIfCurrent(controller_->GetInstant()); 219 return InstantController::CommitIfCurrent(controller_->GetInstant());
218 } 220 }
219 221
220 void AutocompleteEditModel::OnChanged() { 222 void AutocompleteEditModel::OnChanged() {
221 const AutocompleteMatch current_match = CurrentMatch(); 223 const AutocompleteMatch current_match = CurrentMatch();
222 224
223 NetworkActionPredictor::Action recommended_action = 225 AutocompleteActionPredictor::Action recommended_action =
224 NetworkActionPredictor::ACTION_NONE; 226 AutocompleteActionPredictor::ACTION_NONE;
225 NetworkActionPredictor* network_action_predictor = 227 AutocompleteActionPredictor* action_predictor =
226 user_input_in_progress() ? 228 user_input_in_progress() ?
227 NetworkActionPredictorFactory::GetForProfile(profile_) : NULL; 229 AutocompleteActionPredictorFactory::GetForProfile(profile_) : NULL;
228 if (network_action_predictor) { 230 if (action_predictor) {
229 network_action_predictor->RegisterTransitionalMatches(user_text_, 231 action_predictor->RegisterTransitionalMatches(user_text_, result());
230 result()); 232 // Confer with the AutocompleteActionPredictor to determine what action, if
231 // Confer with the NetworkActionPredictor to determine what action, if any, 233 // any, we should take. Get the recommended action here even if we don't
232 // we should take. Get the recommended action here even if we don't need it 234 // need it so we can get stats for anyone who is opted in to UMA, but only
233 // so we can get stats for anyone who is opted in to UMA, but only get it if 235 // get it if the user has actually typed something to avoid constructing it
234 // the user has actually typed something to avoid constructing it before 236 // before it's needed. Note: This event is triggered as part of startup when
235 // it's needed. Note: This event is triggered as part of startup when the 237 // the initial tab transitions to the start page.
236 // initial tab transitions to the start page. 238 recommended_action = action_predictor->RecommendAction(user_text_,
237 recommended_action = 239 current_match);
238 network_action_predictor->RecommendAction(user_text_, current_match);
239 } 240 }
240 241
241 UMA_HISTOGRAM_ENUMERATION("NetworkActionPredictor.Action", recommended_action, 242 UMA_HISTOGRAM_ENUMERATION("AutocompleteActionPredictor.Action",
dominich 2012/03/06 16:42:13 add these to histograms.xml. maybe mark the old o
Shishir 2012/03/14 21:14:37 Done. Will send out a separate CL and check that i
242 NetworkActionPredictor::LAST_PREDICT_ACTION); 243 recommended_action,
244 AutocompleteActionPredictor::LAST_PREDICT_ACTION);
243 string16 suggested_text; 245 string16 suggested_text;
244 246
245 if (DoInstant(current_match, &suggested_text)) { 247 if (DoInstant(current_match, &suggested_text)) {
246 SetSuggestedText(suggested_text, instant_complete_behavior_); 248 SetSuggestedText(suggested_text, instant_complete_behavior_);
247 } else { 249 } else {
248 switch (recommended_action) { 250 switch (recommended_action) {
249 case NetworkActionPredictor::ACTION_PRERENDER: 251 case AutocompleteActionPredictor::ACTION_PRERENDER:
250 DoPrerender(current_match); 252 DoPrerender(current_match);
251 break; 253 break;
252 case NetworkActionPredictor::ACTION_PRECONNECT: 254 case AutocompleteActionPredictor::ACTION_PRECONNECT:
253 DoPreconnect(current_match); 255 DoPreconnect(current_match);
254 break; 256 break;
255 case NetworkActionPredictor::ACTION_NONE: 257 case AutocompleteActionPredictor::ACTION_NONE:
256 break; 258 break;
257 default: 259 default:
258 NOTREACHED() << "Unexpected recommended action: " << recommended_action; 260 NOTREACHED() << "Unexpected recommended action: " << recommended_action;
259 break; 261 break;
260 } 262 }
261 263
262 // Hide any suggestions we might be showing. 264 // Hide any suggestions we might be showing.
263 view_->SetInstantSuggestion(string16(), false); 265 view_->SetInstantSuggestion(string16(), false);
264 266
265 // No need to wait any longer for instant. 267 // No need to wait any longer for instant.
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 void AutocompleteEditModel::Revert() { 404 void AutocompleteEditModel::Revert() {
403 SetInputInProgress(false); 405 SetInputInProgress(false);
404 paste_state_ = NONE; 406 paste_state_ = NONE;
405 InternalSetUserText(string16()); 407 InternalSetUserText(string16());
406 keyword_.clear(); 408 keyword_.clear();
407 is_keyword_hint_ = false; 409 is_keyword_hint_ = false;
408 has_temporary_text_ = false; 410 has_temporary_text_ = false;
409 view_->SetWindowTextAndCaretPos(permanent_text_, 411 view_->SetWindowTextAndCaretPos(permanent_text_,
410 has_focus_ ? permanent_text_.length() : 0, 412 has_focus_ ? permanent_text_.length() : 0,
411 false, true); 413 false, true);
412 NetworkActionPredictor* network_action_predictor = 414 AutocompleteActionPredictor* action_predictor =
413 NetworkActionPredictorFactory::GetForProfile(profile_); 415 AutocompleteActionPredictorFactory::GetForProfile(profile_);
414 if (network_action_predictor) 416 if (action_predictor)
415 network_action_predictor->ClearTransitionalMatches(); 417 action_predictor->ClearTransitionalMatches();
416 } 418 }
417 419
418 void AutocompleteEditModel::StartAutocomplete( 420 void AutocompleteEditModel::StartAutocomplete(
419 bool has_selected_text, 421 bool has_selected_text,
420 bool prevent_inline_autocomplete) const { 422 bool prevent_inline_autocomplete) const {
421 ClearPopupKeywordMode(); 423 ClearPopupKeywordMode();
422 424
423 bool keyword_is_selected = KeywordIsSelected(); 425 bool keyword_is_selected = KeywordIsSelected();
424 popup_->SetHoveredLine(AutocompletePopupModel::kNoMatch); 426 popup_->SetHoveredLine(AutocompletePopupModel::kNoMatch);
425 // We don't explicitly clear AutocompletePopupModel::manually_selected_match, 427 // We don't explicitly clear AutocompletePopupModel::manually_selected_match,
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 } 1122 }
1121 1123
1122 void AutocompleteEditModel::DoPreconnect(const AutocompleteMatch& match) { 1124 void AutocompleteEditModel::DoPreconnect(const AutocompleteMatch& match) {
1123 if (!match.destination_url.SchemeIs(chrome::kExtensionScheme)) { 1125 if (!match.destination_url.SchemeIs(chrome::kExtensionScheme)) {
1124 // Warm up DNS Prefetch cache, or preconnect to a search service. 1126 // Warm up DNS Prefetch cache, or preconnect to a search service.
1125 UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", match.type, 1127 UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", match.type,
1126 AutocompleteMatch::NUM_TYPES); 1128 AutocompleteMatch::NUM_TYPES);
1127 if (profile_->GetNetworkPredictor()) { 1129 if (profile_->GetNetworkPredictor()) {
1128 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl( 1130 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl(
1129 match.destination_url, 1131 match.destination_url,
1130 NetworkActionPredictor::IsPreconnectable(match)); 1132 AutocompleteActionPredictor::IsPreconnectable(match));
1131 } 1133 }
1132 // We could prefetch the alternate nav URL, if any, but because there 1134 // We could prefetch the alternate nav URL, if any, but because there
1133 // can be many of these as a user types an initial series of characters, 1135 // can be many of these as a user types an initial series of characters,
1134 // the OS DNS cache could suffer eviction problems for minimal gain. 1136 // the OS DNS cache could suffer eviction problems for minimal gain.
1135 } 1137 }
1136 } 1138 }
1137 1139
1138 // static 1140 // static
1139 bool AutocompleteEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { 1141 bool AutocompleteEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) {
1140 switch (c) { 1142 switch (c) {
1141 case 0x0020: // Space 1143 case 0x0020: // Space
1142 case 0x3000: // Ideographic Space 1144 case 0x3000: // Ideographic Space
1143 return true; 1145 return true;
1144 default: 1146 default:
1145 return false; 1147 return false;
1146 } 1148 }
1147 } 1149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698