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

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: More rearranging. 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
« 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/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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "net/http/http_response_headers.h" 46 #include "net/http/http_response_headers.h"
47 #include "net/url_request/url_fetcher.h" 47 #include "net/url_request/url_fetcher.h"
48 #include "net/url_request/url_request_status.h" 48 #include "net/url_request/url_request_status.h"
49 #include "ui/base/l10n/l10n_util.h" 49 #include "ui/base/l10n/l10n_util.h"
50 50
51 using base::Time; 51 using base::Time;
52 using base::TimeDelta; 52 using base::TimeDelta;
53 53
54 namespace { 54 namespace {
55 55
56 // We keep track in a histogram how many suggest requests we send, how
57 // many suggest requests we invalidate (e.g., due to a user typing
58 // another character), and how many replies we receive.
59 enum SuggestRequestsHistogramValue {
60 REQUEST_SENT = 1,
61 REQUEST_INVALIDATED = 2,
62 REPLY_RECEIVED = 3,
Ilya Sherman 2012/08/15 23:36:02 Optional nit: Any particular reason to leave the =
63 MAX_SUGGEST_REQUEST_HISTOGRAM_VALUE
64 };
65
66 // Increments the appropriate value in the histogram by one.
67 void LogOmniboxSuggestRequest(
68 SuggestRequestsHistogramValue request_value) {
69 UMA_HISTOGRAM_ENUMERATION("Omnibox.SuggestRequests", request_value,
70 MAX_SUGGEST_REQUEST_HISTOGRAM_VALUE);
71 }
72
56 bool HasMultipleWords(const string16& text) { 73 bool HasMultipleWords(const string16& text) {
57 base::i18n::BreakIterator i(text, base::i18n::BreakIterator::BREAK_WORD); 74 base::i18n::BreakIterator i(text, base::i18n::BreakIterator::BREAK_WORD);
58 bool found_word = false; 75 bool found_word = false;
59 if (i.Init()) { 76 if (i.Init()) {
60 while (i.Advance()) { 77 while (i.Advance()) {
61 if (i.IsWord()) { 78 if (i.IsWord()) {
62 if (found_word) 79 if (found_word)
63 return true; 80 return true;
64 found_word = true; 81 found_word = true;
65 } 82 }
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 }; 303 };
287 304
288 void SearchProvider::Run() { 305 void SearchProvider::Run() {
289 // Start a new request with the current input. 306 // Start a new request with the current input.
290 DCHECK(!done_); 307 DCHECK(!done_);
291 suggest_results_pending_ = 0; 308 suggest_results_pending_ = 0;
292 time_suggest_request_sent_ = base::TimeTicks::Now(); 309 time_suggest_request_sent_ = base::TimeTicks::Now();
293 const TemplateURL* default_url = providers_.GetDefaultProviderURL(); 310 const TemplateURL* default_url = providers_.GetDefaultProviderURL();
294 if (default_url && !default_url->suggestions_url().empty()) { 311 if (default_url && !default_url->suggestions_url().empty()) {
295 suggest_results_pending_++; 312 suggest_results_pending_++;
313 LogOmniboxSuggestRequest(REQUEST_SENT);
296 default_fetcher_.reset(CreateSuggestFetcher(kDefaultProviderURLFetcherID, 314 default_fetcher_.reset(CreateSuggestFetcher(kDefaultProviderURLFetcherID,
297 default_url->suggestions_url_ref(), input_.text())); 315 default_url->suggestions_url_ref(), input_.text()));
298 } 316 }
299 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); 317 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL();
300 if (keyword_url && !keyword_url->suggestions_url().empty()) { 318 if (keyword_url && !keyword_url->suggestions_url().empty()) {
301 suggest_results_pending_++; 319 suggest_results_pending_++;
320 LogOmniboxSuggestRequest(REQUEST_SENT);
302 keyword_fetcher_.reset(CreateSuggestFetcher(kKeywordProviderURLFetcherID, 321 keyword_fetcher_.reset(CreateSuggestFetcher(kKeywordProviderURLFetcherID,
303 keyword_url->suggestions_url_ref(), keyword_input_text_)); 322 keyword_url->suggestions_url_ref(), keyword_input_text_));
304 } 323 }
305 324
306 // Both the above can fail if the providers have been modified or deleted 325 // Both the above can fail if the providers have been modified or deleted
307 // since the query began. 326 // since the query began.
308 if (suggest_results_pending_ == 0) { 327 if (suggest_results_pending_ == 0) {
309 UpdateDone(); 328 UpdateDone();
310 // We only need to update the listener if we're actually done. 329 // We only need to update the listener if we're actually done.
311 if (done_) 330 if (done_)
(...skipping 13 matching lines...) Expand all
325 void SearchProvider::AddProviderInfo(ProvidersInfo* provider_info) const { 344 void SearchProvider::AddProviderInfo(ProvidersInfo* provider_info) const {
326 provider_info->push_back(metrics::OmniboxEventProto_ProviderInfo()); 345 provider_info->push_back(metrics::OmniboxEventProto_ProviderInfo());
327 metrics::OmniboxEventProto_ProviderInfo& new_entry = provider_info->back(); 346 metrics::OmniboxEventProto_ProviderInfo& new_entry = provider_info->back();
328 new_entry.set_provider(AsOmniboxEventProviderType()); 347 new_entry.set_provider(AsOmniboxEventProviderType());
329 new_entry.set_provider_done(done_); 348 new_entry.set_provider_done(done_);
330 } 349 }
331 350
332 void SearchProvider::OnURLFetchComplete(const net::URLFetcher* source) { 351 void SearchProvider::OnURLFetchComplete(const net::URLFetcher* source) {
333 DCHECK(!done_); 352 DCHECK(!done_);
334 suggest_results_pending_--; 353 suggest_results_pending_--;
354 LogOmniboxSuggestRequest(REPLY_RECEIVED);
335 DCHECK_GE(suggest_results_pending_, 0); // Should never go negative. 355 DCHECK_GE(suggest_results_pending_, 0); // Should never go negative.
336 const net::HttpResponseHeaders* const response_headers = 356 const net::HttpResponseHeaders* const response_headers =
337 source->GetResponseHeaders(); 357 source->GetResponseHeaders();
338 std::string json_data; 358 std::string json_data;
339 source->GetResponseAsString(&json_data); 359 source->GetResponseAsString(&json_data);
340 // JSON is supposed to be UTF-8, but some suggest service providers send JSON 360 // 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 361 // files in non-UTF-8 encodings. The actual encoding is usually specified in
342 // the Content-Type header field. 362 // the Content-Type header field.
343 if (response_headers) { 363 if (response_headers) {
344 std::string charset; 364 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 562 // because they are visible when the TCP connection is established, but the
543 // specific path may reveal private information. 563 // specific path may reveal private information.
544 if (LowerCaseEqualsASCII(input_.scheme(), chrome::kHttpsScheme) && 564 if (LowerCaseEqualsASCII(input_.scheme(), chrome::kHttpsScheme) &&
545 parts.path.is_nonempty()) 565 parts.path.is_nonempty())
546 return false; 566 return false;
547 567
548 return true; 568 return true;
549 } 569 }
550 570
551 void SearchProvider::StopSuggest() { 571 void SearchProvider::StopSuggest() {
572 // Increment the appropriate field in the histogram by the number of
573 // pending requests that were invalidated.
574 for (int i = 0; i < suggest_results_pending_; i++)
575 LogOmniboxSuggestRequest(REQUEST_INVALIDATED);
552 suggest_results_pending_ = 0; 576 suggest_results_pending_ = 0;
553 timer_.Stop(); 577 timer_.Stop();
554 // Stop any in-progress URL fetches. 578 // Stop any in-progress URL fetches.
555 keyword_fetcher_.reset(); 579 keyword_fetcher_.reset();
556 default_fetcher_.reset(); 580 default_fetcher_.reset();
557 } 581 }
558 582
559 void SearchProvider::ClearResults() { 583 void SearchProvider::ClearResults() {
560 keyword_suggest_results_.clear(); 584 keyword_suggest_results_.clear();
561 default_suggest_results_.clear(); 585 default_suggest_results_.clear();
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 ACMatchClassification::NONE, &match.description_class); 1236 ACMatchClassification::NONE, &match.description_class);
1213 return match; 1237 return match;
1214 } 1238 }
1215 1239
1216 void SearchProvider::UpdateDone() { 1240 void SearchProvider::UpdateDone() {
1217 // We're done when there are no more suggest queries pending (this is set to 1 1241 // 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. 1242 // when the timer is started) and we're not waiting on instant.
1219 done_ = ((suggest_results_pending_ == 0) && 1243 done_ = ((suggest_results_pending_ == 0) &&
1220 (instant_finalized_ || !InstantController::IsEnabled(profile_))); 1244 (instant_finalized_ || !InstantController::IsEnabled(profile_)));
1221 } 1245 }
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