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::PrerenderManager* prerender_manager = | |
162 prerender::PrerenderManagerFactory::GetForProfile(profile_)) { | |
163 prerender_handle_.reset( | |
164 prerender_manager->AddPrerenderFromOmnibox( | |
165 url, session_storage_namespace, size)); | |
166 } else { | |
167 prerender_handle_.reset(); | |
168 } | |
169 } | |
170 | |
156 // Given a match, return a recommended action. | 171 // Given a match, return a recommended action. |
157 AutocompleteActionPredictor::Action | 172 AutocompleteActionPredictor::Action |
158 AutocompleteActionPredictor::RecommendAction( | 173 AutocompleteActionPredictor::RecommendAction( |
159 const string16& user_text, | 174 const string16& user_text, |
160 const AutocompleteMatch& match) const { | 175 const AutocompleteMatch& match) const { |
161 bool is_in_db = false; | 176 bool is_in_db = false; |
162 const double confidence = CalculateConfidence(user_text, match, &is_in_db); | 177 const double confidence = CalculateConfidence(user_text, match, &is_in_db); |
163 DCHECK(confidence >= 0.0 && confidence <= 1.0); | 178 DCHECK(confidence >= 0.0 && confidence <= 1.0); |
164 | 179 |
165 UMA_HISTOGRAM_BOOLEAN("AutocompleteActionPredictor.MatchIsInDb", is_in_db); | 180 UMA_HISTOGRAM_BOOLEAN("AutocompleteActionPredictor.MatchIsInDb", is_in_db); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 return; | 316 return; |
302 | 317 |
303 const AutocompleteMatch& match = log.result.match_at(log.selected_index); | 318 const AutocompleteMatch& match = log.result.match_at(log.selected_index); |
304 | 319 |
305 UMA_HISTOGRAM_BOOLEAN( | 320 UMA_HISTOGRAM_BOOLEAN( |
306 StringPrintf("Prerender.OmniboxNavigationsCouldPrerender%s", | 321 StringPrintf("Prerender.OmniboxNavigationsCouldPrerender%s", |
307 prerender::PrerenderManager::GetModeString()).c_str(), | 322 prerender::PrerenderManager::GetModeString()).c_str(), |
308 prerender::IsOmniboxEnabled(profile_)); | 323 prerender::IsOmniboxEnabled(profile_)); |
309 | 324 |
310 const GURL& opened_url = match.destination_url; | 325 const GURL& opened_url = match.destination_url; |
326 | |
327 prerender_handle_->OnNavigateAway(); | |
dominich
2012/07/02 20:43:03
I know that OnNavigateAway doesn't immediately del
gavinp
2012/07/03 16:41:02
Done. I'll add it back when prerenders become long
| |
328 prerender_handle_.reset(); | |
329 | |
311 const string16 lower_user_text(base::i18n::ToLower(log.text)); | 330 const string16 lower_user_text(base::i18n::ToLower(log.text)); |
312 | 331 |
313 // Traverse transitional matches for those that have a user_text that is a | 332 // Traverse transitional matches for those that have a user_text that is a |
314 // prefix of |lower_user_text|. | 333 // prefix of |lower_user_text|. |
315 std::vector<AutocompleteActionPredictorTable::Row> rows_to_add; | 334 std::vector<AutocompleteActionPredictorTable::Row> rows_to_add; |
316 std::vector<AutocompleteActionPredictorTable::Row> rows_to_update; | 335 std::vector<AutocompleteActionPredictorTable::Row> rows_to_update; |
317 | 336 |
318 for (std::vector<TransitionalMatch>::const_iterator it = | 337 for (std::vector<TransitionalMatch>::const_iterator it = |
319 transitional_matches_.begin(); it != transitional_matches_.end(); | 338 transitional_matches_.begin(); it != transitional_matches_.end(); |
320 ++it) { | 339 ++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); | 569 return number_of_hits / (number_of_hits + value.number_of_misses); |
551 } | 570 } |
552 | 571 |
553 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() { | 572 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() { |
554 } | 573 } |
555 | 574 |
556 AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() { | 575 AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() { |
557 } | 576 } |
558 | 577 |
559 } // namespace predictors | 578 } // namespace predictors |
OLD | NEW |