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/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 Loading... |
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 // *** ADD NEW ENUMS AFTER ALL PREVIOUSLY DEFINED ONES! *** |
| 60 // (excluding the end-of-list enum value) |
| 61 // We do not want values of existing enums to change or else it screws |
| 62 // up the statistics. |
| 63 enum SuggestRequestsHistogramValue { |
| 64 REQUEST_SENT = 1, |
| 65 REQUEST_INVALIDATED, |
| 66 REPLY_RECEIVED, |
| 67 MAX_SUGGEST_REQUEST_HISTOGRAM_VALUE |
| 68 }; |
| 69 |
| 70 // Increments the appropriate value in the histogram by one. |
| 71 void LogOmniboxSuggestRequest( |
| 72 SuggestRequestsHistogramValue request_value) { |
| 73 UMA_HISTOGRAM_ENUMERATION("Omnibox.SuggestRequests", request_value, |
| 74 MAX_SUGGEST_REQUEST_HISTOGRAM_VALUE); |
| 75 } |
| 76 |
56 bool HasMultipleWords(const string16& text) { | 77 bool HasMultipleWords(const string16& text) { |
57 base::i18n::BreakIterator i(text, base::i18n::BreakIterator::BREAK_WORD); | 78 base::i18n::BreakIterator i(text, base::i18n::BreakIterator::BREAK_WORD); |
58 bool found_word = false; | 79 bool found_word = false; |
59 if (i.Init()) { | 80 if (i.Init()) { |
60 while (i.Advance()) { | 81 while (i.Advance()) { |
61 if (i.IsWord()) { | 82 if (i.IsWord()) { |
62 if (found_word) | 83 if (found_word) |
63 return true; | 84 return true; |
64 found_word = true; | 85 found_word = true; |
65 } | 86 } |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 }; | 307 }; |
287 | 308 |
288 void SearchProvider::Run() { | 309 void SearchProvider::Run() { |
289 // Start a new request with the current input. | 310 // Start a new request with the current input. |
290 DCHECK(!done_); | 311 DCHECK(!done_); |
291 suggest_results_pending_ = 0; | 312 suggest_results_pending_ = 0; |
292 time_suggest_request_sent_ = base::TimeTicks::Now(); | 313 time_suggest_request_sent_ = base::TimeTicks::Now(); |
293 const TemplateURL* default_url = providers_.GetDefaultProviderURL(); | 314 const TemplateURL* default_url = providers_.GetDefaultProviderURL(); |
294 if (default_url && !default_url->suggestions_url().empty()) { | 315 if (default_url && !default_url->suggestions_url().empty()) { |
295 suggest_results_pending_++; | 316 suggest_results_pending_++; |
| 317 LogOmniboxSuggestRequest(REQUEST_SENT); |
296 default_fetcher_.reset(CreateSuggestFetcher(kDefaultProviderURLFetcherID, | 318 default_fetcher_.reset(CreateSuggestFetcher(kDefaultProviderURLFetcherID, |
297 default_url->suggestions_url_ref(), input_.text())); | 319 default_url->suggestions_url_ref(), input_.text())); |
298 } | 320 } |
299 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); | 321 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); |
300 if (keyword_url && !keyword_url->suggestions_url().empty()) { | 322 if (keyword_url && !keyword_url->suggestions_url().empty()) { |
301 suggest_results_pending_++; | 323 suggest_results_pending_++; |
| 324 LogOmniboxSuggestRequest(REQUEST_SENT); |
302 keyword_fetcher_.reset(CreateSuggestFetcher(kKeywordProviderURLFetcherID, | 325 keyword_fetcher_.reset(CreateSuggestFetcher(kKeywordProviderURLFetcherID, |
303 keyword_url->suggestions_url_ref(), keyword_input_text_)); | 326 keyword_url->suggestions_url_ref(), keyword_input_text_)); |
304 } | 327 } |
305 | 328 |
306 // Both the above can fail if the providers have been modified or deleted | 329 // Both the above can fail if the providers have been modified or deleted |
307 // since the query began. | 330 // since the query began. |
308 if (suggest_results_pending_ == 0) { | 331 if (suggest_results_pending_ == 0) { |
309 UpdateDone(); | 332 UpdateDone(); |
310 // We only need to update the listener if we're actually done. | 333 // We only need to update the listener if we're actually done. |
311 if (done_) | 334 if (done_) |
(...skipping 13 matching lines...) Expand all Loading... |
325 void SearchProvider::AddProviderInfo(ProvidersInfo* provider_info) const { | 348 void SearchProvider::AddProviderInfo(ProvidersInfo* provider_info) const { |
326 provider_info->push_back(metrics::OmniboxEventProto_ProviderInfo()); | 349 provider_info->push_back(metrics::OmniboxEventProto_ProviderInfo()); |
327 metrics::OmniboxEventProto_ProviderInfo& new_entry = provider_info->back(); | 350 metrics::OmniboxEventProto_ProviderInfo& new_entry = provider_info->back(); |
328 new_entry.set_provider(AsOmniboxEventProviderType()); | 351 new_entry.set_provider(AsOmniboxEventProviderType()); |
329 new_entry.set_provider_done(done_); | 352 new_entry.set_provider_done(done_); |
330 } | 353 } |
331 | 354 |
332 void SearchProvider::OnURLFetchComplete(const net::URLFetcher* source) { | 355 void SearchProvider::OnURLFetchComplete(const net::URLFetcher* source) { |
333 DCHECK(!done_); | 356 DCHECK(!done_); |
334 suggest_results_pending_--; | 357 suggest_results_pending_--; |
| 358 LogOmniboxSuggestRequest(REPLY_RECEIVED); |
335 DCHECK_GE(suggest_results_pending_, 0); // Should never go negative. | 359 DCHECK_GE(suggest_results_pending_, 0); // Should never go negative. |
336 const net::HttpResponseHeaders* const response_headers = | 360 const net::HttpResponseHeaders* const response_headers = |
337 source->GetResponseHeaders(); | 361 source->GetResponseHeaders(); |
338 std::string json_data; | 362 std::string json_data; |
339 source->GetResponseAsString(&json_data); | 363 source->GetResponseAsString(&json_data); |
340 // JSON is supposed to be UTF-8, but some suggest service providers send JSON | 364 // 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 | 365 // files in non-UTF-8 encodings. The actual encoding is usually specified in |
342 // the Content-Type header field. | 366 // the Content-Type header field. |
343 if (response_headers) { | 367 if (response_headers) { |
344 std::string charset; | 368 std::string charset; |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 // because they are visible when the TCP connection is established, but the | 566 // because they are visible when the TCP connection is established, but the |
543 // specific path may reveal private information. | 567 // specific path may reveal private information. |
544 if (LowerCaseEqualsASCII(input_.scheme(), chrome::kHttpsScheme) && | 568 if (LowerCaseEqualsASCII(input_.scheme(), chrome::kHttpsScheme) && |
545 parts.path.is_nonempty()) | 569 parts.path.is_nonempty()) |
546 return false; | 570 return false; |
547 | 571 |
548 return true; | 572 return true; |
549 } | 573 } |
550 | 574 |
551 void SearchProvider::StopSuggest() { | 575 void SearchProvider::StopSuggest() { |
| 576 // Increment the appropriate field in the histogram by the number of |
| 577 // pending requests that were invalidated. |
| 578 for (int i = 0; i < suggest_results_pending_; i++) |
| 579 LogOmniboxSuggestRequest(REQUEST_INVALIDATED); |
552 suggest_results_pending_ = 0; | 580 suggest_results_pending_ = 0; |
553 timer_.Stop(); | 581 timer_.Stop(); |
554 // Stop any in-progress URL fetches. | 582 // Stop any in-progress URL fetches. |
555 keyword_fetcher_.reset(); | 583 keyword_fetcher_.reset(); |
556 default_fetcher_.reset(); | 584 default_fetcher_.reset(); |
557 } | 585 } |
558 | 586 |
559 void SearchProvider::ClearResults() { | 587 void SearchProvider::ClearResults() { |
560 keyword_suggest_results_.clear(); | 588 keyword_suggest_results_.clear(); |
561 default_suggest_results_.clear(); | 589 default_suggest_results_.clear(); |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1212 ACMatchClassification::NONE, &match.description_class); | 1240 ACMatchClassification::NONE, &match.description_class); |
1213 return match; | 1241 return match; |
1214 } | 1242 } |
1215 | 1243 |
1216 void SearchProvider::UpdateDone() { | 1244 void SearchProvider::UpdateDone() { |
1217 // We're done when there are no more suggest queries pending (this is set to 1 | 1245 // 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. | 1246 // when the timer is started) and we're not waiting on instant. |
1219 done_ = ((suggest_results_pending_ == 0) && | 1247 done_ = ((suggest_results_pending_ == 0) && |
1220 (instant_finalized_ || !InstantController::IsEnabled(profile_))); | 1248 (instant_finalized_ || !InstantController::IsEnabled(profile_))); |
1221 } | 1249 } |
OLD | NEW |