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