| 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/zero_suggest_provider.h" | 5 #include "chrome/browser/autocomplete/zero_suggest_provider.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/i18n/case_conversion.h" | 8 #include "base/i18n/case_conversion.h" |
| 9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 void ZeroSuggestProvider::OnURLFetchComplete(const net::URLFetcher* source) { | 126 void ZeroSuggestProvider::OnURLFetchComplete(const net::URLFetcher* source) { |
| 127 have_pending_request_ = false; | 127 have_pending_request_ = false; |
| 128 LogOmniboxZeroSuggestRequest(ZERO_SUGGEST_REPLY_RECEIVED); | 128 LogOmniboxZeroSuggestRequest(ZERO_SUGGEST_REPLY_RECEIVED); |
| 129 | 129 |
| 130 std::string json_data; | 130 std::string json_data; |
| 131 source->GetResponseAsString(&json_data); | 131 source->GetResponseAsString(&json_data); |
| 132 const bool request_succeeded = | 132 const bool request_succeeded = |
| 133 source->GetStatus().is_success() && source->GetResponseCode() == 200; | 133 source->GetStatus().is_success() && source->GetResponseCode() == 200; |
| 134 | 134 |
| 135 if (request_succeeded) { | 135 if (request_succeeded) { |
| 136 JSONStringValueSerializer deserializer(json_data); | 136 scoped_ptr<Value> data(SearchProvider::DeserializeJsonData(json_data)); |
| 137 deserializer.set_allow_trailing_comma(true); | |
| 138 scoped_ptr<Value> data(deserializer.Deserialize(NULL, NULL)); | |
| 139 if (data.get()) | 137 if (data.get()) |
| 140 ParseSuggestResults(*data.get()); | 138 ParseSuggestResults(*data.get()); |
| 141 } | 139 } |
| 142 done_ = true; | 140 done_ = true; |
| 143 | 141 |
| 144 ConvertResultsToAutocompleteMatches(); | 142 ConvertResultsToAutocompleteMatches(); |
| 145 if (!matches_.empty()) | 143 if (!matches_.empty()) |
| 146 listener_->OnProviderUpdate(true); | 144 listener_->OnProviderUpdate(true); |
| 147 } | 145 } |
| 148 | 146 |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 match.is_history_what_you_typed_match = false; | 453 match.is_history_what_you_typed_match = false; |
| 456 match.allowed_to_be_default_match = true; | 454 match.allowed_to_be_default_match = true; |
| 457 | 455 |
| 458 // The placeholder suggestion for the current URL has high relevance so | 456 // The placeholder suggestion for the current URL has high relevance so |
| 459 // that it is in the first suggestion slot and inline autocompleted. It | 457 // that it is in the first suggestion slot and inline autocompleted. It |
| 460 // gets dropped as soon as the user types something. | 458 // gets dropped as soon as the user types something. |
| 461 match.relevance = verbatim_relevance_; | 459 match.relevance = verbatim_relevance_; |
| 462 | 460 |
| 463 return match; | 461 return match; |
| 464 } | 462 } |
| OLD | NEW |