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" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 GURL GetRequestUrl(AutofillDownloadManager::RequestType request_type) { | 59 GURL GetRequestUrl(AutofillDownloadManager::RequestType request_type) { |
60 return GURL("https://clients1.google.com/tbproxy/af/" + | 60 return GURL("https://clients1.google.com/tbproxy/af/" + |
61 RequestTypeToString(request_type) + "?client=" + kClientName); | 61 RequestTypeToString(request_type) + "?client=" + kClientName); |
62 } | 62 } |
63 | 63 |
64 } // namespace | 64 } // namespace |
65 | 65 |
66 struct AutofillDownloadManager::FormRequestData { | 66 struct AutofillDownloadManager::FormRequestData { |
67 std::vector<std::string> form_signatures; | 67 std::vector<std::string> form_signatures; |
68 std::vector<FormStructure*> queried_forms; | |
69 RequestType request_type; | 68 RequestType request_type; |
70 }; | 69 }; |
71 | 70 |
72 AutofillDownloadManager::AutofillDownloadManager(AutofillDriver* driver, | 71 AutofillDownloadManager::AutofillDownloadManager(AutofillDriver* driver, |
73 PrefService* pref_service, | 72 PrefService* pref_service, |
74 Observer* observer) | 73 Observer* observer) |
75 : driver_(driver), | 74 : driver_(driver), |
76 pref_service_(pref_service), | 75 pref_service_(pref_service), |
77 observer_(observer), | 76 observer_(observer), |
78 max_form_cache_size_(kMaxFormCacheSize), | 77 max_form_cache_size_(kMaxFormCacheSize), |
(...skipping 22 matching lines...) Expand all Loading... |
101 } | 100 } |
102 | 101 |
103 // Do not send the request if it contains more fields than the server can | 102 // Do not send the request if it contains more fields than the server can |
104 // accept. | 103 // accept. |
105 if (CountActiveFieldsInForms(forms) > kMaxFieldsPerQueryRequest) | 104 if (CountActiveFieldsInForms(forms) > kMaxFieldsPerQueryRequest) |
106 return false; | 105 return false; |
107 | 106 |
108 std::string form_xml; | 107 std::string form_xml; |
109 FormRequestData request_data; | 108 FormRequestData request_data; |
110 if (!FormStructure::EncodeQueryRequest(forms, &request_data.form_signatures, | 109 if (!FormStructure::EncodeQueryRequest(forms, &request_data.form_signatures, |
111 &request_data.queried_forms, | |
112 &form_xml)) { | 110 &form_xml)) { |
113 return false; | 111 return false; |
114 } | 112 } |
115 | 113 |
116 request_data.request_type = AutofillDownloadManager::REQUEST_QUERY; | 114 request_data.request_type = AutofillDownloadManager::REQUEST_QUERY; |
117 AutofillMetrics::LogServerQueryMetric(AutofillMetrics::QUERY_SENT); | 115 AutofillMetrics::LogServerQueryMetric(AutofillMetrics::QUERY_SENT); |
118 | 116 |
119 std::string query_data; | 117 std::string query_data; |
120 if (CheckCacheForQueryRequest(request_data.form_signatures, &query_data)) { | 118 if (CheckCacheForQueryRequest(request_data.form_signatures, &query_data)) { |
121 VLOG(1) << "AutofillDownloadManager: query request has been retrieved " | 119 VLOG(1) << "AutofillDownloadManager: query request has been retrieved " |
122 << "from the cache, form signatures: " | 120 << "from the cache, form signatures: " |
123 << GetCombinedSignature(request_data.form_signatures); | 121 << GetCombinedSignature(request_data.form_signatures); |
124 observer_->OnLoadedServerPredictions(query_data, | 122 observer_->OnLoadedServerPredictions(query_data, |
125 request_data.queried_forms); | 123 request_data.form_signatures); |
126 return true; | 124 return true; |
127 } | 125 } |
128 | 126 |
129 return StartRequest(form_xml, request_data); | 127 return StartRequest(form_xml, request_data); |
130 } | 128 } |
131 | 129 |
132 bool AutofillDownloadManager::StartUploadRequest( | 130 bool AutofillDownloadManager::StartUploadRequest( |
133 const FormStructure& form, | 131 const FormStructure& form, |
134 bool form_was_autofilled, | 132 bool form_was_autofilled, |
135 const ServerFieldTypeSet& available_field_types, | 133 const ServerFieldTypeSet& available_field_types, |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 it->second.request_type, | 336 it->second.request_type, |
339 source->GetResponseCode()); | 337 source->GetResponseCode()); |
340 } else { | 338 } else { |
341 std::string response_body; | 339 std::string response_body; |
342 source->GetResponseAsString(&response_body); | 340 source->GetResponseAsString(&response_body); |
343 VLOG(1) << "AutofillDownloadManager: " << request_type | 341 VLOG(1) << "AutofillDownloadManager: " << request_type |
344 << " request has succeeded with response body: " << response_body; | 342 << " request has succeeded with response body: " << response_body; |
345 if (it->second.request_type == AutofillDownloadManager::REQUEST_QUERY) { | 343 if (it->second.request_type == AutofillDownloadManager::REQUEST_QUERY) { |
346 CacheQueryRequest(it->second.form_signatures, response_body); | 344 CacheQueryRequest(it->second.form_signatures, response_body); |
347 observer_->OnLoadedServerPredictions(response_body, | 345 observer_->OnLoadedServerPredictions(response_body, |
348 it->second.queried_forms); | 346 it->second.form_signatures); |
349 } else { | 347 } else { |
350 double new_positive_upload_rate = 0; | 348 double new_positive_upload_rate = 0; |
351 double new_negative_upload_rate = 0; | 349 double new_negative_upload_rate = 0; |
352 AutofillUploadXmlParser parse_handler(&new_positive_upload_rate, | 350 AutofillUploadXmlParser parse_handler(&new_positive_upload_rate, |
353 &new_negative_upload_rate); | 351 &new_negative_upload_rate); |
354 buzz::XmlParser parser(&parse_handler); | 352 buzz::XmlParser parser(&parse_handler); |
355 parser.Parse(response_body.data(), response_body.length(), true); | 353 parser.Parse(response_body.data(), response_body.length(), true); |
356 if (parse_handler.succeeded()) { | 354 if (parse_handler.succeeded()) { |
357 SetPositiveUploadRate(new_positive_upload_rate); | 355 SetPositiveUploadRate(new_positive_upload_rate); |
358 SetNegativeUploadRate(new_negative_upload_rate); | 356 SetNegativeUploadRate(new_negative_upload_rate); |
359 } | 357 } |
360 | 358 |
361 observer_->OnUploadedPossibleFieldTypes(); | 359 observer_->OnUploadedPossibleFieldTypes(); |
362 } | 360 } |
363 } | 361 } |
364 delete it->first; | 362 delete it->first; |
365 url_fetchers_.erase(it); | 363 url_fetchers_.erase(it); |
366 } | 364 } |
367 | 365 |
368 } // namespace autofill | 366 } // namespace autofill |
OLD | NEW |