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

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

Issue 10832323: Adds a UMA histogram to monitor omnibox suggest requests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reactored according to Ilya's suggestions. Created 8 years, 4 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
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/search_provider.h" 5 #include "chrome/browser/autocomplete/search_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 }; 286 };
287 287
288 void SearchProvider::Run() { 288 void SearchProvider::Run() {
289 // Start a new request with the current input. 289 // Start a new request with the current input.
290 DCHECK(!done_); 290 DCHECK(!done_);
291 suggest_results_pending_ = 0; 291 suggest_results_pending_ = 0;
292 time_suggest_request_sent_ = base::TimeTicks::Now(); 292 time_suggest_request_sent_ = base::TimeTicks::Now();
293 const TemplateURL* default_url = providers_.GetDefaultProviderURL(); 293 const TemplateURL* default_url = providers_.GetDefaultProviderURL();
294 if (default_url && !default_url->suggestions_url().empty()) { 294 if (default_url && !default_url->suggestions_url().empty()) {
295 suggest_results_pending_++; 295 suggest_results_pending_++;
296 LogOmniboxSuggestRequest(REQUEST_SENT);
296 default_fetcher_.reset(CreateSuggestFetcher(kDefaultProviderURLFetcherID, 297 default_fetcher_.reset(CreateSuggestFetcher(kDefaultProviderURLFetcherID,
297 default_url->suggestions_url_ref(), input_.text())); 298 default_url->suggestions_url_ref(), input_.text()));
298 } 299 }
299 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); 300 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL();
300 if (keyword_url && !keyword_url->suggestions_url().empty()) { 301 if (keyword_url && !keyword_url->suggestions_url().empty()) {
301 suggest_results_pending_++; 302 suggest_results_pending_++;
303 LogOmniboxSuggestRequest(REQUEST_SENT);
302 keyword_fetcher_.reset(CreateSuggestFetcher(kKeywordProviderURLFetcherID, 304 keyword_fetcher_.reset(CreateSuggestFetcher(kKeywordProviderURLFetcherID,
303 keyword_url->suggestions_url_ref(), keyword_input_text_)); 305 keyword_url->suggestions_url_ref(), keyword_input_text_));
304 } 306 }
305 307
306 // Both the above can fail if the providers have been modified or deleted 308 // Both the above can fail if the providers have been modified or deleted
307 // since the query began. 309 // since the query began.
308 if (suggest_results_pending_ == 0) { 310 if (suggest_results_pending_ == 0) {
309 UpdateDone(); 311 UpdateDone();
310 // We only need to update the listener if we're actually done. 312 // We only need to update the listener if we're actually done.
311 if (done_) 313 if (done_)
(...skipping 13 matching lines...) Expand all
325 void SearchProvider::AddProviderInfo(ProvidersInfo* provider_info) const { 327 void SearchProvider::AddProviderInfo(ProvidersInfo* provider_info) const {
326 provider_info->push_back(metrics::OmniboxEventProto_ProviderInfo()); 328 provider_info->push_back(metrics::OmniboxEventProto_ProviderInfo());
327 metrics::OmniboxEventProto_ProviderInfo& new_entry = provider_info->back(); 329 metrics::OmniboxEventProto_ProviderInfo& new_entry = provider_info->back();
328 new_entry.set_provider(AsOmniboxEventProviderType()); 330 new_entry.set_provider(AsOmniboxEventProviderType());
329 new_entry.set_provider_done(done_); 331 new_entry.set_provider_done(done_);
330 } 332 }
331 333
332 void SearchProvider::OnURLFetchComplete(const net::URLFetcher* source) { 334 void SearchProvider::OnURLFetchComplete(const net::URLFetcher* source) {
333 DCHECK(!done_); 335 DCHECK(!done_);
334 suggest_results_pending_--; 336 suggest_results_pending_--;
337 LogOmniboxSuggestRequest(REPLY_RECEIVED);
335 DCHECK_GE(suggest_results_pending_, 0); // Should never go negative. 338 DCHECK_GE(suggest_results_pending_, 0); // Should never go negative.
336 const net::HttpResponseHeaders* const response_headers = 339 const net::HttpResponseHeaders* const response_headers =
337 source->GetResponseHeaders(); 340 source->GetResponseHeaders();
338 std::string json_data; 341 std::string json_data;
339 source->GetResponseAsString(&json_data); 342 source->GetResponseAsString(&json_data);
340 // JSON is supposed to be UTF-8, but some suggest service providers send JSON 343 // JSON is supposed to be UTF-8, but some suggest service providers send JSON
341 // files in non-UTF-8 encodings. The actual encoding is usually specified in 344 // files in non-UTF-8 encodings. The actual encoding is usually specified in
342 // the Content-Type header field. 345 // the Content-Type header field.
343 if (response_headers) { 346 if (response_headers) {
344 std::string charset; 347 std::string charset;
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 // because they are visible when the TCP connection is established, but the 545 // because they are visible when the TCP connection is established, but the
543 // specific path may reveal private information. 546 // specific path may reveal private information.
544 if (LowerCaseEqualsASCII(input_.scheme(), chrome::kHttpsScheme) && 547 if (LowerCaseEqualsASCII(input_.scheme(), chrome::kHttpsScheme) &&
545 parts.path.is_nonempty()) 548 parts.path.is_nonempty())
546 return false; 549 return false;
547 550
548 return true; 551 return true;
549 } 552 }
550 553
551 void SearchProvider::StopSuggest() { 554 void SearchProvider::StopSuggest() {
555 // Increment the appropriate field in the histogram by the number of
556 // pending requests that were invalidated.
557 for (int i = 0; i < suggest_results_pending_; i++)
558 LogOmniboxSuggestRequest(REQUEST_INVALIDATED);
552 suggest_results_pending_ = 0; 559 suggest_results_pending_ = 0;
553 timer_.Stop(); 560 timer_.Stop();
554 // Stop any in-progress URL fetches. 561 // Stop any in-progress URL fetches.
555 keyword_fetcher_.reset(); 562 keyword_fetcher_.reset();
556 default_fetcher_.reset(); 563 default_fetcher_.reset();
557 } 564 }
558 565
559 void SearchProvider::ClearResults() { 566 void SearchProvider::ClearResults() {
560 keyword_suggest_results_.clear(); 567 keyword_suggest_results_.clear();
561 default_suggest_results_.clear(); 568 default_suggest_results_.clear();
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 ACMatchClassification::NONE, &match.description_class); 1219 ACMatchClassification::NONE, &match.description_class);
1213 return match; 1220 return match;
1214 } 1221 }
1215 1222
1216 void SearchProvider::UpdateDone() { 1223 void SearchProvider::UpdateDone() {
1217 // We're done when there are no more suggest queries pending (this is set to 1 1224 // We're done when there are no more suggest queries pending (this is set to 1
1218 // when the timer is started) and we're not waiting on instant. 1225 // when the timer is started) and we're not waiting on instant.
1219 done_ = ((suggest_results_pending_ == 0) && 1226 done_ = ((suggest_results_pending_ == 0) &&
1220 (instant_finalized_ || !InstantController::IsEnabled(profile_))); 1227 (instant_finalized_ || !InstantController::IsEnabled(profile_)));
1221 } 1228 }
1229
1230 // static
1231 void SearchProvider::LogOmniboxSuggestRequest(
1232 const SuggestRequestsHistogramValue request_value) {
1233 UMA_HISTOGRAM_ENUMERATION("Omnibox.SuggestRequests", request_value,
1234 MAX_SUGGEST_REQUEST_HISTOGRAM_VALUE);
Ilya Sherman 2012/08/15 23:17:37 Optional nit: I think it would be slightly cleaner
Mark P 2012/08/15 23:28:30 Done.
1235 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698