| 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/network_action_predictor.h" | 5 #include "chrome/browser/autocomplete/network_action_predictor.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 123 } |
| 124 | 124 |
| 125 // Given a match, return a recommended action. | 125 // Given a match, return a recommended action. |
| 126 NetworkActionPredictor::Action NetworkActionPredictor::RecommendAction( | 126 NetworkActionPredictor::Action NetworkActionPredictor::RecommendAction( |
| 127 const string16& user_text, | 127 const string16& user_text, |
| 128 const AutocompleteMatch& match) const { | 128 const AutocompleteMatch& match) const { |
| 129 bool is_in_db = false; | 129 bool is_in_db = false; |
| 130 const double confidence = CalculateConfidence(user_text, match, &is_in_db); | 130 const double confidence = CalculateConfidence(user_text, match, &is_in_db); |
| 131 DCHECK(confidence >= 0.0 && confidence <= 1.0); | 131 DCHECK(confidence >= 0.0 && confidence <= 1.0); |
| 132 | 132 |
| 133 UMA_HISTOGRAM_BOOLEAN("NetworkActionPredictor.MatchIsInDb", is_in_db); |
| 134 |
| 133 if (is_in_db) { | 135 if (is_in_db) { |
| 134 // Multiple enties with the same URL are fine as the confidence may be | 136 // Multiple enties with the same URL are fine as the confidence may be |
| 135 // different. | 137 // different. |
| 136 tracked_urls_.push_back(std::make_pair(match.destination_url, confidence)); | 138 tracked_urls_.push_back(std::make_pair(match.destination_url, confidence)); |
| 137 UMA_HISTOGRAM_COUNTS_100("NetworkActionPredictor.Confidence", | 139 UMA_HISTOGRAM_COUNTS_100("NetworkActionPredictor.Confidence", |
| 138 confidence * 100); | 140 confidence * 100); |
| 139 } | 141 } |
| 140 | 142 |
| 141 // Map the confidence to an action. | 143 // Map the confidence to an action. |
| 142 Action action = ACTION_NONE; | 144 Action action = ACTION_NONE; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 157 | 159 |
| 158 // Return true if the suggestion type warrants a TCP/IP preconnection. | 160 // Return true if the suggestion type warrants a TCP/IP preconnection. |
| 159 // i.e., it is now quite likely that the user will select the related domain. | 161 // i.e., it is now quite likely that the user will select the related domain. |
| 160 // static | 162 // static |
| 161 bool NetworkActionPredictor::IsPreconnectable(const AutocompleteMatch& match) { | 163 bool NetworkActionPredictor::IsPreconnectable(const AutocompleteMatch& match) { |
| 162 switch (match.type) { | 164 switch (match.type) { |
| 163 // Matches using the user's default search engine. | 165 // Matches using the user's default search engine. |
| 164 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED: | 166 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED: |
| 165 case AutocompleteMatch::SEARCH_HISTORY: | 167 case AutocompleteMatch::SEARCH_HISTORY: |
| 166 case AutocompleteMatch::SEARCH_SUGGEST: | 168 case AutocompleteMatch::SEARCH_SUGGEST: |
| 167 // A match that uses a non-default search engine (e.g. for tab-to-search). | 169 // A match that uses a non-default search engine (e.g. for tab-to-search). |
| 168 case AutocompleteMatch::SEARCH_OTHER_ENGINE: | 170 case AutocompleteMatch::SEARCH_OTHER_ENGINE: |
| 169 return true; | 171 return true; |
| 170 | 172 |
| 171 default: | 173 default: |
| 172 return false; | 174 return false; |
| 173 } | 175 } |
| 174 } | 176 } |
| 175 | 177 |
| 176 void NetworkActionPredictor::Shutdown() { | 178 void NetworkActionPredictor::Shutdown() { |
| 177 db_->OnPredictorDestroyed(); | 179 db_->OnPredictorDestroyed(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 default: | 221 default: |
| 220 NOTREACHED() << "Unexpected notification observed."; | 222 NOTREACHED() << "Unexpected notification observed."; |
| 221 break; | 223 break; |
| 222 } | 224 } |
| 223 } | 225 } |
| 224 | 226 |
| 225 void NetworkActionPredictor::OnOmniboxOpenedUrl(const AutocompleteLog& log) { | 227 void NetworkActionPredictor::OnOmniboxOpenedUrl(const AutocompleteLog& log) { |
| 226 if (log.text.length() < kMinimumUserTextLength) | 228 if (log.text.length() < kMinimumUserTextLength) |
| 227 return; | 229 return; |
| 228 | 230 |
| 229 UMA_HISTOGRAM_COUNTS("NetworkActionPredictor.NavigationCount", 1); | 231 const AutocompleteMatch& match = log.result.match_at(log.selected_index); |
| 230 | 232 |
| 231 const GURL& opened_url = | 233 UMA_HISTOGRAM_BOOLEAN("Prerender.OmniboxNavigationsCouldPrerender", |
| 232 log.result.match_at(log.selected_index).destination_url; | 234 prerender::IsOmniboxEnabled(profile_)); |
| 235 |
| 236 const GURL& opened_url = match.destination_url; |
| 233 | 237 |
| 234 const string16 lower_user_text(base::i18n::ToLower(log.text)); | 238 const string16 lower_user_text(base::i18n::ToLower(log.text)); |
| 235 | 239 |
| 236 BeginTransaction(); | 240 BeginTransaction(); |
| 237 // Traverse transitional matches for those that have a user_text that is a | 241 // Traverse transitional matches for those that have a user_text that is a |
| 238 // prefix of |lower_user_text|. | 242 // prefix of |lower_user_text|. |
| 239 for (std::vector<TransitionalMatch>::const_iterator it = | 243 for (std::vector<TransitionalMatch>::const_iterator it = |
| 240 transitional_matches_.begin(); it != transitional_matches_.end(); | 244 transitional_matches_.begin(); it != transitional_matches_.end(); |
| 241 ++it) { | 245 ++it) { |
| 242 if (!StartsWith(lower_user_text, it->user_text, true)) | 246 if (!StartsWith(lower_user_text, it->user_text, true)) |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 | 473 |
| 470 content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE, | 474 content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE, |
| 471 base::Bind(&NetworkActionPredictorDatabase::CommitTransaction, db_)); | 475 base::Bind(&NetworkActionPredictorDatabase::CommitTransaction, db_)); |
| 472 } | 476 } |
| 473 | 477 |
| 474 NetworkActionPredictor::TransitionalMatch::TransitionalMatch() { | 478 NetworkActionPredictor::TransitionalMatch::TransitionalMatch() { |
| 475 } | 479 } |
| 476 | 480 |
| 477 NetworkActionPredictor::TransitionalMatch::~TransitionalMatch() { | 481 NetworkActionPredictor::TransitionalMatch::~TransitionalMatch() { |
| 478 } | 482 } |
| OLD | NEW |