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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 // Increment bucket 1 in the histogram (number of requests sent). | |
297 UMA_HISTOGRAM_ENUMERATION("Omnibox.SuggestRequests", 1, 4); | |
296 default_fetcher_.reset(CreateSuggestFetcher(kDefaultProviderURLFetcherID, | 298 default_fetcher_.reset(CreateSuggestFetcher(kDefaultProviderURLFetcherID, |
297 default_url->suggestions_url_ref(), input_.text())); | 299 default_url->suggestions_url_ref(), input_.text())); |
298 } | 300 } |
299 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); | 301 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); |
300 if (keyword_url && !keyword_url->suggestions_url().empty()) { | 302 if (keyword_url && !keyword_url->suggestions_url().empty()) { |
301 suggest_results_pending_++; | 303 suggest_results_pending_++; |
304 // Increment bucket 1 in the histogram (number of requests sent). | |
305 UMA_HISTOGRAM_ENUMERATION("Omnibox.SuggestRequests", 1, 4); | |
Ilya Sherman
2012/08/15 22:42:06
To avoid problems from typos and such, there are t
Mark P
2012/08/15 23:09:46
Good idea. Done.
| |
302 keyword_fetcher_.reset(CreateSuggestFetcher(kKeywordProviderURLFetcherID, | 306 keyword_fetcher_.reset(CreateSuggestFetcher(kKeywordProviderURLFetcherID, |
303 keyword_url->suggestions_url_ref(), keyword_input_text_)); | 307 keyword_url->suggestions_url_ref(), keyword_input_text_)); |
304 } | 308 } |
305 | 309 |
306 // Both the above can fail if the providers have been modified or deleted | 310 // Both the above can fail if the providers have been modified or deleted |
307 // since the query began. | 311 // since the query began. |
308 if (suggest_results_pending_ == 0) { | 312 if (suggest_results_pending_ == 0) { |
309 UpdateDone(); | 313 UpdateDone(); |
310 // We only need to update the listener if we're actually done. | 314 // We only need to update the listener if we're actually done. |
311 if (done_) | 315 if (done_) |
(...skipping 13 matching lines...) Expand all Loading... | |
325 void SearchProvider::AddProviderInfo(ProvidersInfo* provider_info) const { | 329 void SearchProvider::AddProviderInfo(ProvidersInfo* provider_info) const { |
326 provider_info->push_back(metrics::OmniboxEventProto_ProviderInfo()); | 330 provider_info->push_back(metrics::OmniboxEventProto_ProviderInfo()); |
327 metrics::OmniboxEventProto_ProviderInfo& new_entry = provider_info->back(); | 331 metrics::OmniboxEventProto_ProviderInfo& new_entry = provider_info->back(); |
328 new_entry.set_provider(AsOmniboxEventProviderType()); | 332 new_entry.set_provider(AsOmniboxEventProviderType()); |
329 new_entry.set_provider_done(done_); | 333 new_entry.set_provider_done(done_); |
330 } | 334 } |
331 | 335 |
332 void SearchProvider::OnURLFetchComplete(const net::URLFetcher* source) { | 336 void SearchProvider::OnURLFetchComplete(const net::URLFetcher* source) { |
333 DCHECK(!done_); | 337 DCHECK(!done_); |
334 suggest_results_pending_--; | 338 suggest_results_pending_--; |
339 // Increment bucket 3 in the histogram (number of requests for which | |
340 // we received a response). | |
341 UMA_HISTOGRAM_ENUMERATION("Omnibox.SuggestRequests", 3, 4); | |
335 DCHECK_GE(suggest_results_pending_, 0); // Should never go negative. | 342 DCHECK_GE(suggest_results_pending_, 0); // Should never go negative. |
336 const net::HttpResponseHeaders* const response_headers = | 343 const net::HttpResponseHeaders* const response_headers = |
337 source->GetResponseHeaders(); | 344 source->GetResponseHeaders(); |
338 std::string json_data; | 345 std::string json_data; |
339 source->GetResponseAsString(&json_data); | 346 source->GetResponseAsString(&json_data); |
340 // JSON is supposed to be UTF-8, but some suggest service providers send JSON | 347 // 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 | 348 // files in non-UTF-8 encodings. The actual encoding is usually specified in |
342 // the Content-Type header field. | 349 // the Content-Type header field. |
343 if (response_headers) { | 350 if (response_headers) { |
344 std::string charset; | 351 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 | 549 // because they are visible when the TCP connection is established, but the |
543 // specific path may reveal private information. | 550 // specific path may reveal private information. |
544 if (LowerCaseEqualsASCII(input_.scheme(), chrome::kHttpsScheme) && | 551 if (LowerCaseEqualsASCII(input_.scheme(), chrome::kHttpsScheme) && |
545 parts.path.is_nonempty()) | 552 parts.path.is_nonempty()) |
546 return false; | 553 return false; |
547 | 554 |
548 return true; | 555 return true; |
549 } | 556 } |
550 | 557 |
551 void SearchProvider::StopSuggest() { | 558 void SearchProvider::StopSuggest() { |
559 // Increment bucket 2 in the histogram by the number of requests pending | |
560 // that were invalidated. | |
561 for (int i = 0; i < suggest_results_pending_; i++) | |
562 UMA_HISTOGRAM_ENUMERATION("Omnibox.SuggestRequests", 2, 4); | |
552 suggest_results_pending_ = 0; | 563 suggest_results_pending_ = 0; |
553 timer_.Stop(); | 564 timer_.Stop(); |
554 // Stop any in-progress URL fetches. | 565 // Stop any in-progress URL fetches. |
555 keyword_fetcher_.reset(); | 566 keyword_fetcher_.reset(); |
556 default_fetcher_.reset(); | 567 default_fetcher_.reset(); |
557 } | 568 } |
558 | 569 |
559 void SearchProvider::ClearResults() { | 570 void SearchProvider::ClearResults() { |
560 keyword_suggest_results_.clear(); | 571 keyword_suggest_results_.clear(); |
561 default_suggest_results_.clear(); | 572 default_suggest_results_.clear(); |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1212 ACMatchClassification::NONE, &match.description_class); | 1223 ACMatchClassification::NONE, &match.description_class); |
1213 return match; | 1224 return match; |
1214 } | 1225 } |
1215 | 1226 |
1216 void SearchProvider::UpdateDone() { | 1227 void SearchProvider::UpdateDone() { |
1217 // We're done when there are no more suggest queries pending (this is set to 1 | 1228 // 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. | 1229 // when the timer is started) and we're not waiting on instant. |
1219 done_ = ((suggest_results_pending_ == 0) && | 1230 done_ = ((suggest_results_pending_ == 0) && |
1220 (instant_finalized_ || !InstantController::IsEnabled(profile_))); | 1231 (instant_finalized_ || !InstantController::IsEnabled(profile_))); |
1221 } | 1232 } |
OLD | NEW |