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/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/public/browser/notification_service.h" | 45 #include "content/public/browser/notification_service.h" |
46 #include "content/public/browser/render_view_host.h" | 46 #include "content/public/browser/render_view_host.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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // Don't call CurrentMatch() when there's no editing, as in this case we'll | 223 // 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 | 224 // never actually use it. This avoids running the autocomplete providers (and |
223 // any systems they then spin up) during startup. | 225 // any systems they then spin up) during startup. |
224 const AutocompleteMatch& current_match = user_input_in_progress_ ? | 226 const AutocompleteMatch& current_match = user_input_in_progress_ ? |
225 CurrentMatch() : AutocompleteMatch(); | 227 CurrentMatch() : AutocompleteMatch(); |
226 | 228 |
227 NetworkActionPredictor::Action recommended_action = | 229 AutocompleteActionPredictor::Action recommended_action = |
228 NetworkActionPredictor::ACTION_NONE; | 230 AutocompleteActionPredictor::ACTION_NONE; |
229 NetworkActionPredictor* network_action_predictor = | 231 AutocompleteActionPredictor* action_predictor = |
230 user_input_in_progress_ ? | 232 user_input_in_progress_ ? |
231 NetworkActionPredictorFactory::GetForProfile(profile_) : NULL; | 233 AutocompleteActionPredictorFactory::GetForProfile(profile_) : NULL; |
232 if (network_action_predictor) { | 234 if (action_predictor) { |
233 network_action_predictor->RegisterTransitionalMatches(user_text_, | 235 action_predictor->RegisterTransitionalMatches(user_text_, result()); |
234 result()); | 236 // Confer with the AutocompleteActionPredictor to determine what action, if |
235 // Confer with the NetworkActionPredictor to determine what action, if any, | 237 // 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 | 238 // 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 | 239 // 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 | 240 // 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 | 241 // the initial tab transitions to the start page. |
240 // initial tab transitions to the start page. | |
241 recommended_action = | 242 recommended_action = |
242 network_action_predictor->RecommendAction(user_text_, current_match); | 243 action_predictor->RecommendAction(user_text_, current_match); |
243 } | 244 } |
244 | 245 |
245 UMA_HISTOGRAM_ENUMERATION("NetworkActionPredictor.Action", recommended_action, | 246 UMA_HISTOGRAM_ENUMERATION("AutocompleteActionPredictor.Action", |
246 NetworkActionPredictor::LAST_PREDICT_ACTION); | 247 recommended_action, |
| 248 AutocompleteActionPredictor::LAST_PREDICT_ACTION); |
247 string16 suggested_text; | 249 string16 suggested_text; |
248 | 250 |
249 if (DoInstant(current_match, &suggested_text)) { | 251 if (DoInstant(current_match, &suggested_text)) { |
250 SetSuggestedText(suggested_text, instant_complete_behavior_); | 252 SetSuggestedText(suggested_text, instant_complete_behavior_); |
251 } else { | 253 } else { |
252 switch (recommended_action) { | 254 switch (recommended_action) { |
253 case NetworkActionPredictor::ACTION_PRERENDER: | 255 case AutocompleteActionPredictor::ACTION_PRERENDER: |
254 DoPrerender(current_match); | 256 DoPrerender(current_match); |
255 break; | 257 break; |
256 case NetworkActionPredictor::ACTION_PRECONNECT: | 258 case AutocompleteActionPredictor::ACTION_PRECONNECT: |
257 DoPreconnect(current_match); | 259 DoPreconnect(current_match); |
258 break; | 260 break; |
259 case NetworkActionPredictor::ACTION_NONE: | 261 case AutocompleteActionPredictor::ACTION_NONE: |
260 break; | 262 break; |
261 default: | 263 default: |
262 NOTREACHED() << "Unexpected recommended action: " << recommended_action; | 264 NOTREACHED() << "Unexpected recommended action: " << recommended_action; |
263 break; | 265 break; |
264 } | 266 } |
265 | 267 |
266 // Hide any suggestions we might be showing. | 268 // Hide any suggestions we might be showing. |
267 view_->SetInstantSuggestion(string16(), false); | 269 view_->SetInstantSuggestion(string16(), false); |
268 | 270 |
269 // 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... |
406 void AutocompleteEditModel::Revert() { | 408 void AutocompleteEditModel::Revert() { |
407 SetInputInProgress(false); | 409 SetInputInProgress(false); |
408 paste_state_ = NONE; | 410 paste_state_ = NONE; |
409 InternalSetUserText(string16()); | 411 InternalSetUserText(string16()); |
410 keyword_.clear(); | 412 keyword_.clear(); |
411 is_keyword_hint_ = false; | 413 is_keyword_hint_ = false; |
412 has_temporary_text_ = false; | 414 has_temporary_text_ = false; |
413 view_->SetWindowTextAndCaretPos(permanent_text_, | 415 view_->SetWindowTextAndCaretPos(permanent_text_, |
414 has_focus_ ? permanent_text_.length() : 0, | 416 has_focus_ ? permanent_text_.length() : 0, |
415 false, true); | 417 false, true); |
416 NetworkActionPredictor* network_action_predictor = | 418 AutocompleteActionPredictor* action_predictor = |
417 NetworkActionPredictorFactory::GetForProfile(profile_); | 419 AutocompleteActionPredictorFactory::GetForProfile(profile_); |
418 if (network_action_predictor) | 420 if (action_predictor) |
419 network_action_predictor->ClearTransitionalMatches(); | 421 action_predictor->ClearTransitionalMatches(); |
420 } | 422 } |
421 | 423 |
422 void AutocompleteEditModel::StartAutocomplete( | 424 void AutocompleteEditModel::StartAutocomplete( |
423 bool has_selected_text, | 425 bool has_selected_text, |
424 bool prevent_inline_autocomplete) const { | 426 bool prevent_inline_autocomplete) const { |
425 ClearPopupKeywordMode(); | 427 ClearPopupKeywordMode(); |
426 | 428 |
427 bool keyword_is_selected = KeywordIsSelected(); | 429 bool keyword_is_selected = KeywordIsSelected(); |
428 popup_->SetHoveredLine(AutocompletePopupModel::kNoMatch); | 430 popup_->SetHoveredLine(AutocompletePopupModel::kNoMatch); |
429 // We don't explicitly clear AutocompletePopupModel::manually_selected_match, | 431 // We don't explicitly clear AutocompletePopupModel::manually_selected_match, |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 } | 1120 } |
1119 | 1121 |
1120 void AutocompleteEditModel::DoPreconnect(const AutocompleteMatch& match) { | 1122 void AutocompleteEditModel::DoPreconnect(const AutocompleteMatch& match) { |
1121 if (!match.destination_url.SchemeIs(chrome::kExtensionScheme)) { | 1123 if (!match.destination_url.SchemeIs(chrome::kExtensionScheme)) { |
1122 // Warm up DNS Prefetch cache, or preconnect to a search service. | 1124 // Warm up DNS Prefetch cache, or preconnect to a search service. |
1123 UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", match.type, | 1125 UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", match.type, |
1124 AutocompleteMatch::NUM_TYPES); | 1126 AutocompleteMatch::NUM_TYPES); |
1125 if (profile_->GetNetworkPredictor()) { | 1127 if (profile_->GetNetworkPredictor()) { |
1126 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl( | 1128 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl( |
1127 match.destination_url, | 1129 match.destination_url, |
1128 NetworkActionPredictor::IsPreconnectable(match)); | 1130 AutocompleteActionPredictor::IsPreconnectable(match)); |
1129 } | 1131 } |
1130 // We could prefetch the alternate nav URL, if any, but because there | 1132 // 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, | 1133 // 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. | 1134 // the OS DNS cache could suffer eviction problems for minimal gain. |
1133 } | 1135 } |
1134 } | 1136 } |
1135 | 1137 |
1136 // static | 1138 // static |
1137 bool AutocompleteEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { | 1139 bool AutocompleteEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { |
1138 switch (c) { | 1140 switch (c) { |
1139 case 0x0020: // Space | 1141 case 0x0020: // Space |
1140 case 0x3000: // Ideographic Space | 1142 case 0x3000: // Ideographic Space |
1141 return true; | 1143 return true; |
1142 default: | 1144 default: |
1143 return false; | 1145 return false; |
1144 } | 1146 } |
1145 } | 1147 } |
OLD | NEW |