| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/autofill/core/browser/autofill_download_manager.h" | 5 #include "components/autofill/core/browser/autofill_download_manager.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "components/autofill/core/browser/autofill_driver.h" | 12 #include "components/autofill/core/browser/autofill_driver.h" |
| 13 #include "components/autofill/core/browser/autofill_metrics.h" | 13 #include "components/autofill/core/browser/autofill_metrics.h" |
| 14 #include "components/autofill/core/browser/autofill_xml_parser.h" | 14 #include "components/autofill/core/browser/autofill_xml_parser.h" |
| 15 #include "components/autofill/core/browser/form_structure.h" | 15 #include "components/autofill/core/browser/form_structure.h" |
| 16 #include "components/autofill/core/common/autofill_pref_names.h" | 16 #include "components/autofill/core/common/autofill_pref_names.h" |
| 17 #include "components/compression/compression_utils.h" | 17 #include "components/compression/compression_utils.h" |
| 18 #include "components/data_use_measurement/core/data_use_user_data.h" | 18 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 19 #include "components/variations/net/variations_http_header_provider.h" | 19 #include "components/variations/net/variations_http_header_provider.h" |
| 20 #include "net/base/load_flags.h" | 20 #include "net/base/load_flags.h" |
| 21 #include "net/http/http_request_headers.h" | 21 #include "net/http/http_request_headers.h" |
| 22 #include "net/http/http_response_headers.h" | 22 #include "net/http/http_response_headers.h" |
| 23 #include "net/url_request/url_fetcher.h" | 23 #include "net/url_request/url_fetcher.h" |
| 24 #include "third_party/webrtc/libjingle/xmllite/xmlparser.h" | |
| 25 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 26 | 25 |
| 27 namespace autofill { | 26 namespace autofill { |
| 28 | 27 |
| 29 namespace { | 28 namespace { |
| 30 | 29 |
| 31 const char kAutofillQueryServerNameStartInHeader[] = "GFE/"; | 30 const char kAutofillQueryServerNameStartInHeader[] = "GFE/"; |
| 32 const size_t kMaxFormCacheSize = 16; | 31 const size_t kMaxFormCacheSize = 16; |
| 33 const size_t kMaxFieldsPerQueryRequest = 100; | 32 const size_t kMaxFieldsPerQueryRequest = 100; |
| 34 | 33 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 111 } |
| 113 | 112 |
| 114 request_data.request_type = AutofillDownloadManager::REQUEST_QUERY; | 113 request_data.request_type = AutofillDownloadManager::REQUEST_QUERY; |
| 115 AutofillMetrics::LogServerQueryMetric(AutofillMetrics::QUERY_SENT); | 114 AutofillMetrics::LogServerQueryMetric(AutofillMetrics::QUERY_SENT); |
| 116 | 115 |
| 117 std::string query_data; | 116 std::string query_data; |
| 118 if (CheckCacheForQueryRequest(request_data.form_signatures, &query_data)) { | 117 if (CheckCacheForQueryRequest(request_data.form_signatures, &query_data)) { |
| 119 VLOG(1) << "AutofillDownloadManager: query request has been retrieved " | 118 VLOG(1) << "AutofillDownloadManager: query request has been retrieved " |
| 120 << "from the cache, form signatures: " | 119 << "from the cache, form signatures: " |
| 121 << GetCombinedSignature(request_data.form_signatures); | 120 << GetCombinedSignature(request_data.form_signatures); |
| 122 observer_->OnLoadedServerPredictions(query_data, | 121 observer_->OnLoadedServerPredictions(std::move(query_data), |
| 123 request_data.form_signatures); | 122 request_data.form_signatures); |
| 124 return true; | 123 return true; |
| 125 } | 124 } |
| 126 | 125 |
| 127 return StartRequest(form_xml, request_data); | 126 return StartRequest(form_xml, request_data); |
| 128 } | 127 } |
| 129 | 128 |
| 130 bool AutofillDownloadManager::StartUploadRequest( | 129 bool AutofillDownloadManager::StartUploadRequest( |
| 131 const FormStructure& form, | 130 const FormStructure& form, |
| 132 bool form_was_autofilled, | 131 bool form_was_autofilled, |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 observer_->OnServerRequestError(it->second.form_signatures[0], | 334 observer_->OnServerRequestError(it->second.form_signatures[0], |
| 336 it->second.request_type, | 335 it->second.request_type, |
| 337 source->GetResponseCode()); | 336 source->GetResponseCode()); |
| 338 } else { | 337 } else { |
| 339 std::string response_body; | 338 std::string response_body; |
| 340 source->GetResponseAsString(&response_body); | 339 source->GetResponseAsString(&response_body); |
| 341 VLOG(1) << "AutofillDownloadManager: " << request_type | 340 VLOG(1) << "AutofillDownloadManager: " << request_type |
| 342 << " request has succeeded with response body: " << response_body; | 341 << " request has succeeded with response body: " << response_body; |
| 343 if (it->second.request_type == AutofillDownloadManager::REQUEST_QUERY) { | 342 if (it->second.request_type == AutofillDownloadManager::REQUEST_QUERY) { |
| 344 CacheQueryRequest(it->second.form_signatures, response_body); | 343 CacheQueryRequest(it->second.form_signatures, response_body); |
| 345 observer_->OnLoadedServerPredictions(response_body, | 344 observer_->OnLoadedServerPredictions(std::move(response_body), |
| 346 it->second.form_signatures); | 345 it->second.form_signatures); |
| 347 } else { | 346 } else { |
| 348 double new_positive_upload_rate = 0; | 347 double new_positive_upload_rate = 0; |
| 349 double new_negative_upload_rate = 0; | 348 double new_negative_upload_rate = 0; |
| 350 AutofillUploadXmlParser parse_handler(&new_positive_upload_rate, | 349 if (ParseAutofillUploadXml(std::move(response_body), |
| 351 &new_negative_upload_rate); | 350 &new_positive_upload_rate, |
| 352 buzz::XmlParser parser(&parse_handler); | 351 &new_negative_upload_rate)) { |
| 353 parser.Parse(response_body.data(), response_body.length(), true); | |
| 354 if (parse_handler.succeeded()) { | |
| 355 SetPositiveUploadRate(new_positive_upload_rate); | 352 SetPositiveUploadRate(new_positive_upload_rate); |
| 356 SetNegativeUploadRate(new_negative_upload_rate); | 353 SetNegativeUploadRate(new_negative_upload_rate); |
| 357 } | 354 } |
| 358 | 355 |
| 359 observer_->OnUploadedPossibleFieldTypes(); | 356 observer_->OnUploadedPossibleFieldTypes(); |
| 360 } | 357 } |
| 361 } | 358 } |
| 362 delete it->first; | 359 delete it->first; |
| 363 url_fetchers_.erase(it); | 360 url_fetchers_.erase(it); |
| 364 } | 361 } |
| 365 | 362 |
| 366 } // namespace autofill | 363 } // namespace autofill |
| OLD | NEW |