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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 base::OnStringConversionError::FAIL, | 332 base::OnStringConversionError::FAIL, |
333 &data_16)) | 333 &data_16)) |
334 json_data = UTF16ToUTF8(data_16); | 334 json_data = UTF16ToUTF8(data_16); |
335 } | 335 } |
336 } | 336 } |
337 | 337 |
338 bool is_keyword = (source == keyword_fetcher_.get()); | 338 bool is_keyword = (source == keyword_fetcher_.get()); |
339 SuggestResults* suggest_results = | 339 SuggestResults* suggest_results = |
340 is_keyword ? &keyword_suggest_results_ : &default_suggest_results_; | 340 is_keyword ? &keyword_suggest_results_ : &default_suggest_results_; |
341 | 341 |
342 std::string histogram_name = | 342 const bool request_succeeded = |
343 "Omnibox.SuggestRequest.Failure.GoogleResponseTime"; | 343 source->GetStatus().is_success() && source->GetResponseCode() == 200; |
344 if (source->GetStatus().is_success() && source->GetResponseCode() == 200) { | 344 if (request_succeeded) { |
345 JSONStringValueSerializer deserializer(json_data); | 345 JSONStringValueSerializer deserializer(json_data); |
346 deserializer.set_allow_trailing_comma(true); | 346 deserializer.set_allow_trailing_comma(true); |
347 scoped_ptr<Value> root_val(deserializer.Deserialize(NULL, NULL)); | 347 scoped_ptr<Value> root_val(deserializer.Deserialize(NULL, NULL)); |
348 const string16& input = is_keyword ? keyword_input_text_ : input_.text(); | 348 const string16& input = is_keyword ? keyword_input_text_ : input_.text(); |
349 have_suggest_results_ = root_val.get() && | 349 have_suggest_results_ = root_val.get() && |
350 ParseSuggestResults(root_val.get(), is_keyword, input, suggest_results); | 350 ParseSuggestResults(root_val.get(), is_keyword, input, suggest_results); |
351 histogram_name = "Omnibox.SuggestRequest.Success.GoogleResponseTime"; | |
352 } | 351 } |
353 | 352 |
354 // Record response time for suggest requests sent to Google. We care | 353 // Record response time for suggest requests sent to Google. We care |
355 // only about the common case: the Google default provider used in | 354 // only about the common case: the Google default provider used in |
356 // non-keyword mode. | 355 // non-keyword mode. |
357 const TemplateURL* default_url = providers_.GetDefaultProviderURL(); | 356 const TemplateURL* default_url = providers_.GetDefaultProviderURL(); |
358 if (!is_keyword && default_url && | 357 if (!is_keyword && default_url && |
359 (default_url->prepopulate_id() == SEARCH_ENGINE_GOOGLE)) { | 358 (default_url->prepopulate_id() == SEARCH_ENGINE_GOOGLE)) { |
360 UMA_HISTOGRAM_TIMES(histogram_name, | 359 const base::TimeDelta elapsed_time = |
361 base::TimeTicks::Now() - time_suggest_request_sent_); | 360 base::TimeTicks::Now() - time_suggest_request_sent_; |
| 361 if (request_succeeded) { |
| 362 UMA_HISTOGRAM_TIMES("Omnibox.SuggestRequest.Success.GoogleResponseTime", |
| 363 elapsed_time); |
| 364 } else { |
| 365 UMA_HISTOGRAM_TIMES("Omnibox.SuggestRequest.Failure.GoogleResponseTime", |
| 366 elapsed_time); |
| 367 } |
362 } | 368 } |
363 | 369 |
364 ConvertResultsToAutocompleteMatches(); | 370 ConvertResultsToAutocompleteMatches(); |
365 listener_->OnProviderUpdate(!suggest_results->empty()); | 371 listener_->OnProviderUpdate(!suggest_results->empty()); |
366 } | 372 } |
367 | 373 |
368 SearchProvider::~SearchProvider() { | 374 SearchProvider::~SearchProvider() { |
369 } | 375 } |
370 | 376 |
371 void SearchProvider::DoHistoryQuery(bool minimal_changes) { | 377 void SearchProvider::DoHistoryQuery(bool minimal_changes) { |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
984 | 990 |
985 return match; | 991 return match; |
986 } | 992 } |
987 | 993 |
988 void SearchProvider::UpdateDone() { | 994 void SearchProvider::UpdateDone() { |
989 // We're done when there are no more suggest queries pending (this is set to 1 | 995 // We're done when there are no more suggest queries pending (this is set to 1 |
990 // when the timer is started) and we're not waiting on instant. | 996 // when the timer is started) and we're not waiting on instant. |
991 done_ = ((suggest_results_pending_ == 0) && | 997 done_ = ((suggest_results_pending_ == 0) && |
992 (instant_finalized_ || !InstantController::IsEnabled(profile_))); | 998 (instant_finalized_ || !InstantController::IsEnabled(profile_))); |
993 } | 999 } |
OLD | NEW |