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/predictors/autocomplete_action_predictor.h" | 5 #include "chrome/browser/predictors/autocomplete_action_predictor.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/guid.h" | 12 #include "base/guid.h" |
13 #include "base/i18n/case_conversion.h" | 13 #include "base/i18n/case_conversion.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "chrome/browser/autocomplete/autocomplete.h" | 18 #include "chrome/browser/autocomplete/autocomplete.h" |
19 #include "chrome/browser/autocomplete/autocomplete_log.h" | 19 #include "chrome/browser/autocomplete/autocomplete_log.h" |
20 #include "chrome/browser/autocomplete/autocomplete_match.h" | 20 #include "chrome/browser/autocomplete/autocomplete_match.h" |
21 #include "chrome/browser/history/history.h" | 21 #include "chrome/browser/history/history.h" |
22 #include "chrome/browser/history/history_notifications.h" | 22 #include "chrome/browser/history/history_notifications.h" |
23 #include "chrome/browser/history/history_service_factory.h" | 23 #include "chrome/browser/history/history_service_factory.h" |
24 #include "chrome/browser/history/in_memory_database.h" | 24 #include "chrome/browser/history/in_memory_database.h" |
25 #include "chrome/browser/predictors/autocomplete_action_predictor_factory.h" | 25 #include "chrome/browser/predictors/autocomplete_action_predictor_factory.h" |
26 #include "chrome/browser/predictors/predictor_database.h" | 26 #include "chrome/browser/predictors/predictor_database.h" |
27 #include "chrome/browser/predictors/predictor_database_factory.h" | 27 #include "chrome/browser/predictors/predictor_database_factory.h" |
28 #include "chrome/browser/prerender/prerender_field_trial.h" | 28 #include "chrome/browser/prerender/prerender_field_trial.h" |
29 #include "chrome/browser/prerender/prerender_handle.h" | |
29 #include "chrome/browser/prerender/prerender_manager.h" | 30 #include "chrome/browser/prerender/prerender_manager.h" |
30 #include "chrome/browser/prerender/prerender_manager_factory.h" | 31 #include "chrome/browser/prerender/prerender_manager_factory.h" |
31 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
32 #include "chrome/common/chrome_notification_types.h" | 33 #include "chrome/common/chrome_notification_types.h" |
33 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
34 #include "content/public/browser/notification_details.h" | 35 #include "content/public/browser/notification_details.h" |
35 #include "content/public/browser/notification_service.h" | 36 #include "content/public/browser/notification_service.h" |
36 #include "content/public/browser/notification_source.h" | 37 #include "content/public/browser/notification_source.h" |
37 | 38 |
38 namespace { | 39 namespace { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 it->destination_url) == match_it->urls.end()) { | 147 it->destination_url) == match_it->urls.end()) { |
147 match_it->urls.push_back(it->destination_url); | 148 match_it->urls.push_back(it->destination_url); |
148 } | 149 } |
149 } | 150 } |
150 } | 151 } |
151 | 152 |
152 void AutocompleteActionPredictor::ClearTransitionalMatches() { | 153 void AutocompleteActionPredictor::ClearTransitionalMatches() { |
153 transitional_matches_.clear(); | 154 transitional_matches_.clear(); |
154 } | 155 } |
155 | 156 |
157 void AutocompleteActionPredictor::StartPrerendering( | |
158 const GURL& url, | |
159 content::SessionStorageNamespace* session_storage_namespace, | |
160 gfx::Size size) { | |
161 if (prerender_handle_) | |
162 prerender_handle_->Release(); | |
163 if (prerender::PrerenderManager* prerender_manager = | |
164 prerender::PrerenderManagerFactory::GetForProfile(profile_)) { | |
165 prerender_handle_ = prerender_manager->AddPrerenderFromOmnibox( | |
166 url, session_storage_namespace, size); | |
167 } | |
168 } | |
169 | |
156 // Given a match, return a recommended action. | 170 // Given a match, return a recommended action. |
157 AutocompleteActionPredictor::Action | 171 AutocompleteActionPredictor::Action |
158 AutocompleteActionPredictor::RecommendAction( | 172 AutocompleteActionPredictor::RecommendAction( |
159 const string16& user_text, | 173 const string16& user_text, |
160 const AutocompleteMatch& match) const { | 174 const AutocompleteMatch& match) const { |
161 bool is_in_db = false; | 175 bool is_in_db = false; |
162 const double confidence = CalculateConfidence(user_text, match, &is_in_db); | 176 const double confidence = CalculateConfidence(user_text, match, &is_in_db); |
163 DCHECK(confidence >= 0.0 && confidence <= 1.0); | 177 DCHECK(confidence >= 0.0 && confidence <= 1.0); |
164 | 178 |
165 UMA_HISTOGRAM_BOOLEAN("AutocompleteActionPredictor.MatchIsInDb", is_in_db); | 179 UMA_HISTOGRAM_BOOLEAN("AutocompleteActionPredictor.MatchIsInDb", is_in_db); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 return; | 315 return; |
302 | 316 |
303 const AutocompleteMatch& match = log.result.match_at(log.selected_index); | 317 const AutocompleteMatch& match = log.result.match_at(log.selected_index); |
304 | 318 |
305 UMA_HISTOGRAM_BOOLEAN( | 319 UMA_HISTOGRAM_BOOLEAN( |
306 StringPrintf("Prerender.OmniboxNavigationsCouldPrerender%s", | 320 StringPrintf("Prerender.OmniboxNavigationsCouldPrerender%s", |
307 prerender::PrerenderManager::GetModeString()).c_str(), | 321 prerender::PrerenderManager::GetModeString()).c_str(), |
308 prerender::IsOmniboxEnabled(profile_)); | 322 prerender::IsOmniboxEnabled(profile_)); |
309 | 323 |
310 const GURL& opened_url = match.destination_url; | 324 const GURL& opened_url = match.destination_url; |
325 | |
326 // TODO(gavinp,dominich): When we add proper abandonment semantics to | |
327 // prerenders, we should mark the prerender_ as abandoned here, so that it | |
328 // won't live the full expiry period. | |
dominich
2012/06/28 00:34:32
the opened_url might match something in the redire
| |
329 // See: http://code.google.com/p/chromium/issues/detail?id=134268 | |
330 | |
311 const string16 lower_user_text(base::i18n::ToLower(log.text)); | 331 const string16 lower_user_text(base::i18n::ToLower(log.text)); |
312 | 332 |
313 // Traverse transitional matches for those that have a user_text that is a | 333 // Traverse transitional matches for those that have a user_text that is a |
314 // prefix of |lower_user_text|. | 334 // prefix of |lower_user_text|. |
315 std::vector<AutocompleteActionPredictorTable::Row> rows_to_add; | 335 std::vector<AutocompleteActionPredictorTable::Row> rows_to_add; |
316 std::vector<AutocompleteActionPredictorTable::Row> rows_to_update; | 336 std::vector<AutocompleteActionPredictorTable::Row> rows_to_update; |
317 | 337 |
318 for (std::vector<TransitionalMatch>::const_iterator it = | 338 for (std::vector<TransitionalMatch>::const_iterator it = |
319 transitional_matches_.begin(); it != transitional_matches_.end(); | 339 transitional_matches_.begin(); it != transitional_matches_.end(); |
320 ++it) { | 340 ++it) { |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
550 return number_of_hits / (number_of_hits + value.number_of_misses); | 570 return number_of_hits / (number_of_hits + value.number_of_misses); |
551 } | 571 } |
552 | 572 |
553 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() { | 573 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() { |
554 } | 574 } |
555 | 575 |
556 AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() { | 576 AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() { |
557 } | 577 } |
558 | 578 |
559 } // namespace predictors | 579 } // namespace predictors |
OLD | NEW |