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 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 it->destination_url) == match_it->urls.end()) { | 144 it->destination_url) == match_it->urls.end()) { |
145 match_it->urls.push_back(it->destination_url); | 145 match_it->urls.push_back(it->destination_url); |
146 } | 146 } |
147 } | 147 } |
148 } | 148 } |
149 | 149 |
150 void AutocompleteActionPredictor::ClearTransitionalMatches() { | 150 void AutocompleteActionPredictor::ClearTransitionalMatches() { |
151 transitional_matches_.clear(); | 151 transitional_matches_.clear(); |
152 } | 152 } |
153 | 153 |
154 prerender::PrerenderHandle AutocompleteActionPredictor::StartPrerendering( | |
155 const GURL& url, | |
156 content::SessionStorageNamespace* session_storage_namespace) { | |
157 if (prerender::PrerenderManager* prerender_manager = | |
158 prerender::PrerenderManagerFactory::GetForProfile(profile_)) { | |
159 prerender_ = prerender_manager->AddPrerenderFromOmnibox( | |
160 url, session_storage_namespace); | |
161 return prerender_; | |
162 } | |
163 prerender_ = prerender::PrerenderHandle(); | |
164 return prerender_; | |
165 } | |
166 | |
154 // Given a match, return a recommended action. | 167 // Given a match, return a recommended action. |
155 AutocompleteActionPredictor::Action | 168 AutocompleteActionPredictor::Action |
156 AutocompleteActionPredictor::RecommendAction( | 169 AutocompleteActionPredictor::RecommendAction( |
157 const string16& user_text, | 170 const string16& user_text, |
158 const AutocompleteMatch& match) const { | 171 const AutocompleteMatch& match) const { |
159 bool is_in_db = false; | 172 bool is_in_db = false; |
160 const double confidence = CalculateConfidence(user_text, match, &is_in_db); | 173 const double confidence = CalculateConfidence(user_text, match, &is_in_db); |
161 DCHECK(confidence >= 0.0 && confidence <= 1.0); | 174 DCHECK(confidence >= 0.0 && confidence <= 1.0); |
162 | 175 |
163 UMA_HISTOGRAM_BOOLEAN("AutocompleteActionPredictor.MatchIsInDb", is_in_db); | 176 UMA_HISTOGRAM_BOOLEAN("AutocompleteActionPredictor.MatchIsInDb", is_in_db); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 | 313 |
301 const AutocompleteMatch& match = log.result.match_at(log.selected_index); | 314 const AutocompleteMatch& match = log.result.match_at(log.selected_index); |
302 | 315 |
303 UMA_HISTOGRAM_BOOLEAN( | 316 UMA_HISTOGRAM_BOOLEAN( |
304 StringPrintf("Prerender.OmniboxNavigationsCouldPrerender%s", | 317 StringPrintf("Prerender.OmniboxNavigationsCouldPrerender%s", |
305 prerender::PrerenderManager::GetModeString()).c_str(), | 318 prerender::PrerenderManager::GetModeString()).c_str(), |
306 prerender::IsOmniboxEnabled(profile_)); | 319 prerender::IsOmniboxEnabled(profile_)); |
307 | 320 |
308 const GURL& opened_url = match.destination_url; | 321 const GURL& opened_url = match.destination_url; |
309 | 322 |
310 // If the Omnibox triggered a prerender but the URL doesn't match the one the | 323 // If the Omnibox triggered a prerender but the prerender doesn't match the |
311 // user is navigating to, cancel the prerender. | 324 // one the user is navigating to, then we drop the prerender. |
312 prerender::PrerenderManager* prerender_manager = | 325 if (prerender_ != match.prerender) |
dominich
2012/06/18 15:32:44
This should not be pulled from the match. The prer
gavinp
2012/06/18 16:40:48
We did talk about this at length, and I'm aware we
| |
313 prerender::PrerenderManagerFactory::GetForProfile(profile_); | 326 prerender_ = prerender::PrerenderHandle(); |
dominich
2012/06/18 15:32:44
if this has a side-effect of canceling a prerender
gavinp
2012/06/18 16:40:48
And a runtime error if you try to drop a ref to a
| |
314 // |prerender_manager| can be NULL in incognito mode or if prerendering is | |
315 // otherwise disabled. | |
316 if (prerender_manager && !prerender_manager->IsPrerendering(opened_url)) | |
317 prerender_manager->CancelOmniboxPrerenders(); | |
318 | 327 |
319 const string16 lower_user_text(base::i18n::ToLower(log.text)); | 328 const string16 lower_user_text(base::i18n::ToLower(log.text)); |
320 | 329 |
321 // Traverse transitional matches for those that have a user_text that is a | 330 // Traverse transitional matches for those that have a user_text that is a |
322 // prefix of |lower_user_text|. | 331 // prefix of |lower_user_text|. |
323 std::vector<AutocompleteActionPredictorTable::Row> rows_to_add; | 332 std::vector<AutocompleteActionPredictorTable::Row> rows_to_add; |
324 std::vector<AutocompleteActionPredictorTable::Row> rows_to_update; | 333 std::vector<AutocompleteActionPredictorTable::Row> rows_to_update; |
325 | 334 |
326 for (std::vector<TransitionalMatch>::const_iterator it = | 335 for (std::vector<TransitionalMatch>::const_iterator it = |
327 transitional_matches_.begin(); it != transitional_matches_.end(); | 336 transitional_matches_.begin(); it != transitional_matches_.end(); |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
558 return number_of_hits / (number_of_hits + value.number_of_misses); | 567 return number_of_hits / (number_of_hits + value.number_of_misses); |
559 } | 568 } |
560 | 569 |
561 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() { | 570 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() { |
562 } | 571 } |
563 | 572 |
564 AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() { | 573 AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() { |
565 } | 574 } |
566 | 575 |
567 } // namespace predictors | 576 } // namespace predictors |
OLD | NEW |