Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: chrome/browser/autocomplete/network_action_predictor.cc

Issue 9153004: More fine grained understanding of Omnibox navigation counts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 HistoryService* history_service = 50 HistoryService* history_service =
51 profile->GetHistoryService(Profile::EXPLICIT_ACCESS); 51 profile->GetHistoryService(Profile::EXPLICIT_ACCESS);
52 if (!history_service) 52 if (!history_service)
53 return false; 53 return false;
54 54
55 history::URLDatabase* url_db = history_service->InMemoryDatabase(); 55 history::URLDatabase* url_db = history_service->InMemoryDatabase();
56 return url_db && (url_db->GetRowForURL(match.destination_url, url_row) != 0); 56 return url_db && (url_db->GetRowForURL(match.destination_url, url_row) != 0);
57 } 57 }
58 58
59 // Return true if the suggestion type is a 'search' type.
60 bool IsSearchType(const AutocompleteMatch::Type& type) {
Peter Kasting 2012/01/09 20:47:37 Nit: I wonder if this is consistent with other pla
dominich 2012/01/09 22:43:43 Hmm. On the other side of this, when we swap in th
Peter Kasting 2012/01/09 22:51:30 In the abstract, yes; the fact that we have many o
61 switch (type) {
62 // Matches using the user's default search engine.
63 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED:
64 case AutocompleteMatch::SEARCH_HISTORY:
65 case AutocompleteMatch::SEARCH_SUGGEST:
66 // A match that uses a non-default search engine (e.g. for tab-to-search).
Peter Kasting 2012/01/09 20:47:37 Nit: Unindent 2.
dominich 2012/01/09 22:43:43 Done.
67 case AutocompleteMatch::SEARCH_OTHER_ENGINE:
68 return true;
69
70 default:
71 return false;
72 }
73 }
74
59 } 75 }
60 76
61 const int NetworkActionPredictor::kMaximumDaysToKeepEntry = 14; 77 const int NetworkActionPredictor::kMaximumDaysToKeepEntry = 14;
62 78
63 NetworkActionPredictor::NetworkActionPredictor(Profile* profile) 79 NetworkActionPredictor::NetworkActionPredictor(Profile* profile)
64 : profile_(profile), 80 : profile_(profile),
65 db_(new NetworkActionPredictorDatabase(profile)), 81 db_(new NetworkActionPredictorDatabase(profile)),
66 initialized_(false) { 82 initialized_(false) {
67 content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE, 83 content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE,
68 base::Bind(&NetworkActionPredictorDatabase::Initialize, db_)); 84 base::Bind(&NetworkActionPredictorDatabase::Initialize, db_));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 for (int i = 0; i < LAST_PREDICT_ACTION; ++i) { 159 for (int i = 0; i < LAST_PREDICT_ACTION; ++i) {
144 if (confidence >= kConfidenceCutoff[i]) { 160 if (confidence >= kConfidenceCutoff[i]) {
145 action = static_cast<Action>(i); 161 action = static_cast<Action>(i);
146 break; 162 break;
147 } 163 }
148 } 164 }
149 165
150 // Downgrade prerender to preconnect if this is a search match or if omnibox 166 // Downgrade prerender to preconnect if this is a search match or if omnibox
151 // prerendering is disabled. 167 // prerendering is disabled.
152 if (action == ACTION_PRERENDER && 168 if (action == ACTION_PRERENDER &&
153 ((match.type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED || 169 (IsPreconnectable(match) || !prerender::IsOmniboxEnabled(profile_))) {
154 match.type == AutocompleteMatch::SEARCH_SUGGEST ||
155 match.type == AutocompleteMatch::SEARCH_OTHER_ENGINE) ||
156 !prerender::IsOmniboxEnabled(profile_))) {
157 action = ACTION_PRECONNECT; 170 action = ACTION_PRECONNECT;
158 } 171 }
159 172
160 return action; 173 return action;
161 } 174 }
162 175
163 // Return true if the suggestion type warrants a TCP/IP preconnection. 176 // Return true if the suggestion type warrants a TCP/IP preconnection.
164 // i.e., it is now quite likely that the user will select the related domain. 177 // i.e., it is now quite likely that the user will select the related domain.
165 // static 178 // static
166 bool NetworkActionPredictor::IsPreconnectable(const AutocompleteMatch& match) { 179 bool NetworkActionPredictor::IsPreconnectable(const AutocompleteMatch& match) {
167 switch (match.type) { 180 return IsSearchType(match.type);
168 // Matches using the user's default search engine.
169 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED:
170 case AutocompleteMatch::SEARCH_HISTORY:
171 case AutocompleteMatch::SEARCH_SUGGEST:
172 // A match that uses a non-default search engine (e.g. for tab-to-search).
173 case AutocompleteMatch::SEARCH_OTHER_ENGINE:
174 return true;
175
176 default:
177 return false;
178 }
179 } 181 }
180 182
181 void NetworkActionPredictor::Shutdown() { 183 void NetworkActionPredictor::Shutdown() {
182 db_->OnPredictorDestroyed(); 184 db_->OnPredictorDestroyed();
183 } 185 }
184 186
185 void NetworkActionPredictor::Observe( 187 void NetworkActionPredictor::Observe(
186 int type, 188 int type,
187 const content::NotificationSource& source, 189 const content::NotificationSource& source,
188 const content::NotificationDetails& details) { 190 const content::NotificationDetails& details) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 default: 226 default:
225 NOTREACHED() << "Unexpected notification observed."; 227 NOTREACHED() << "Unexpected notification observed.";
226 break; 228 break;
227 } 229 }
228 } 230 }
229 231
230 void NetworkActionPredictor::OnOmniboxOpenedUrl(const AutocompleteLog& log) { 232 void NetworkActionPredictor::OnOmniboxOpenedUrl(const AutocompleteLog& log) {
231 if (log.text.length() < kMinimumUserTextLength) 233 if (log.text.length() < kMinimumUserTextLength)
232 return; 234 return;
233 235
234 UMA_HISTOGRAM_COUNTS("NetworkActionPredictor.NavigationCount", 1); 236 const AutocompleteMatch& match = log.result.match_at(log.selected_index);
235 237
236 const GURL& opened_url = 238 UMA_HISTOGRAM_BOOLEAN("Prerender.OmniboxNavigationsCouldPrerender",
237 log.result.match_at(log.selected_index).destination_url; 239 prerender::IsOmniboxEnabled(profile_) && !IsSearchType(match.type));
240
241 const GURL& opened_url = match.destination_url;
238 242
239 const string16 lower_user_text(base::i18n::ToLower(log.text)); 243 const string16 lower_user_text(base::i18n::ToLower(log.text));
240 244
241 BeginTransaction(); 245 BeginTransaction();
242 // Traverse transitional matches for those that have a user_text that is a 246 // Traverse transitional matches for those that have a user_text that is a
243 // prefix of |lower_user_text|. 247 // prefix of |lower_user_text|.
244 for (std::vector<TransitionalMatch>::const_iterator it = 248 for (std::vector<TransitionalMatch>::const_iterator it =
245 transitional_matches_.begin(); it != transitional_matches_.end(); 249 transitional_matches_.begin(); it != transitional_matches_.end();
246 ++it) { 250 ++it) {
247 if (!StartsWith(lower_user_text, it->user_text, true)) 251 if (!StartsWith(lower_user_text, it->user_text, true))
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 478
475 content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE, 479 content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE,
476 base::Bind(&NetworkActionPredictorDatabase::CommitTransaction, db_)); 480 base::Bind(&NetworkActionPredictorDatabase::CommitTransaction, db_));
477 } 481 }
478 482
479 NetworkActionPredictor::TransitionalMatch::TransitionalMatch() { 483 NetworkActionPredictor::TransitionalMatch::TransitionalMatch() {
480 } 484 }
481 485
482 NetworkActionPredictor::TransitionalMatch::~TransitionalMatch() { 486 NetworkActionPredictor::TransitionalMatch::~TransitionalMatch() {
483 } 487 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698