Chromium Code Reviews| 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_log.h" | 18 #include "chrome/browser/autocomplete/autocomplete_log.h" |
| 19 #include "chrome/browser/autocomplete/autocomplete_match.h" | 19 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 20 #include "chrome/browser/autocomplete/autocomplete_result.h" | 20 #include "chrome/browser/autocomplete/autocomplete_result.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 i->destination_url) == match_it->urls.end()) { | 147 i->destination_url) == match_it->urls.end()) { |
| 147 match_it->urls.push_back(i->destination_url); | 148 match_it->urls.push_back(i->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 const gfx::Size& size) { | |
| 161 prerender_handle_.reset(); | |
|
dominich
2012/07/12 16:16:48
I'm not a fan of the double reset. Would something
mmenke
2012/07/12 16:26:51
This affects the final status. Resetting the old
gavinp
2012/07/13 12:02:22
Added a comment explaining why the reset first is
| |
| 162 if (prerender::PrerenderManager* prerender_manager = | |
| 163 prerender::PrerenderManagerFactory::GetForProfile(profile_)) { | |
| 164 prerender_handle_.reset( | |
| 165 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 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 550 return number_of_hits / (number_of_hits + value.number_of_misses); | 564 return number_of_hits / (number_of_hits + value.number_of_misses); |
| 551 } | 565 } |
| 552 | 566 |
| 553 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() { | 567 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() { |
| 554 } | 568 } |
| 555 | 569 |
| 556 AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() { | 570 AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() { |
| 557 } | 571 } |
| 558 | 572 |
| 559 } // namespace predictors | 573 } // namespace predictors |
| OLD | NEW |