| 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> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 } | 84 } |
| 85 NOTREACHED(); | 85 NOTREACHED(); |
| 86 return std::string(); | 86 return std::string(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 GURL GetRequestUrl(AutofillDownloadManager::RequestType request_type) { | 89 GURL GetRequestUrl(AutofillDownloadManager::RequestType request_type) { |
| 90 return GURL("https://clients1.google.com/tbproxy/af/" + | 90 return GURL("https://clients1.google.com/tbproxy/af/" + |
| 91 RequestTypeToString(request_type) + "?client=" + kClientName); | 91 RequestTypeToString(request_type) + "?client=" + kClientName); |
| 92 } | 92 } |
| 93 | 93 |
| 94 std::ostream& operator<<(std::ostream& out, |
| 95 const autofill::AutofillQueryContents& query) { |
| 96 out << "client_version: " << query.client_version(); |
| 97 for (const auto& form : query.form()) { |
| 98 out << "\nForm\n signature: " << form.signature(); |
| 99 for (const auto& field : form.field()) { |
| 100 out << "\n Field\n signature: " << field.signature(); |
| 101 if (!field.name().empty()) |
| 102 out << "\n name: " << field.name(); |
| 103 if (!field.type().empty()) |
| 104 out << "\n type: " << field.type(); |
| 105 if (!field.label().empty()) |
| 106 out << "\n label: " << field.label(); |
| 107 } |
| 108 } |
| 109 return out; |
| 110 } |
| 111 |
| 112 std::ostream& operator<<(std::ostream& out, |
| 113 const autofill::AutofillUploadContents& upload) { |
| 114 out << "client_version: " << upload.client_version() << "\n"; |
| 115 out << "form_signature: " << upload.form_signature() << "\n"; |
| 116 out << "data_present: " << upload.data_present() << "\n"; |
| 117 out << "submission: " << upload.submission() << "\n"; |
| 118 if (!upload.action_signature()) |
| 119 out << "action_signature: " << upload.action_signature() << "\n"; |
| 120 if (!upload.login_form_signature()) |
| 121 out << "login_form_signature: " << upload.login_form_signature() << "\n"; |
| 122 if (!upload.form_name().empty()) |
| 123 out << "form_name: " << upload.form_name() << "\n"; |
| 124 |
| 125 for (const auto& field : upload.field()) { |
| 126 out << "\n Field" |
| 127 << "\n signature: " << field.signature() |
| 128 << "\n autofill_type: " << field.autofill_type(); |
| 129 if (!field.name().empty()) |
| 130 out << "\n name: " << field.name(); |
| 131 if (!field.autocomplete().empty()) |
| 132 out << "\n autocomplete: " << field.autocomplete(); |
| 133 if (!field.type().empty()) |
| 134 out << "\n type: " << field.type(); |
| 135 if (!field.label().empty()) |
| 136 out << "\n label: " << field.label(); |
| 137 } |
| 138 return out; |
| 139 } |
| 140 |
| 94 } // namespace | 141 } // namespace |
| 95 | 142 |
| 96 struct AutofillDownloadManager::FormRequestData { | 143 struct AutofillDownloadManager::FormRequestData { |
| 97 std::vector<std::string> form_signatures; | 144 std::vector<std::string> form_signatures; |
| 98 RequestType request_type; | 145 RequestType request_type; |
| 99 std::string payload; | 146 std::string payload; |
| 100 }; | 147 }; |
| 101 | 148 |
| 102 AutofillDownloadManager::AutofillDownloadManager(AutofillDriver* driver, | 149 AutofillDownloadManager::AutofillDownloadManager(AutofillDriver* driver, |
| 103 Observer* observer) | 150 Observer* observer) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 std::string query_data; | 187 std::string query_data; |
| 141 if (CheckCacheForQueryRequest(request_data.form_signatures, &query_data)) { | 188 if (CheckCacheForQueryRequest(request_data.form_signatures, &query_data)) { |
| 142 VLOG(1) << "AutofillDownloadManager: query request has been retrieved " | 189 VLOG(1) << "AutofillDownloadManager: query request has been retrieved " |
| 143 << "from the cache, form signatures: " | 190 << "from the cache, form signatures: " |
| 144 << GetCombinedSignature(request_data.form_signatures); | 191 << GetCombinedSignature(request_data.form_signatures); |
| 145 observer_->OnLoadedServerPredictions(std::move(query_data), | 192 observer_->OnLoadedServerPredictions(std::move(query_data), |
| 146 request_data.form_signatures); | 193 request_data.form_signatures); |
| 147 return true; | 194 return true; |
| 148 } | 195 } |
| 149 | 196 |
| 197 VLOG(1) << "Sending Autofill Query Request:\n" << query; |
| 198 |
| 150 return StartRequest(request_data); | 199 return StartRequest(request_data); |
| 151 } | 200 } |
| 152 | 201 |
| 153 bool AutofillDownloadManager::StartUploadRequest( | 202 bool AutofillDownloadManager::StartUploadRequest( |
| 154 const FormStructure& form, | 203 const FormStructure& form, |
| 155 bool form_was_autofilled, | 204 bool form_was_autofilled, |
| 156 const ServerFieldTypeSet& available_field_types, | 205 const ServerFieldTypeSet& available_field_types, |
| 157 const std::string& login_form_signature, | 206 const std::string& login_form_signature, |
| 158 bool observed_submission) { | 207 bool observed_submission) { |
| 159 AutofillUploadContents upload; | 208 AutofillUploadContents upload; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 170 VLOG(1) << "AutofillDownloadManager: Upload request is ignored."; | 219 VLOG(1) << "AutofillDownloadManager: Upload request is ignored."; |
| 171 // If we ever need notification that upload was skipped, add it here. | 220 // If we ever need notification that upload was skipped, add it here. |
| 172 return false; | 221 return false; |
| 173 } | 222 } |
| 174 | 223 |
| 175 FormRequestData request_data; | 224 FormRequestData request_data; |
| 176 request_data.form_signatures.push_back(form.FormSignature()); | 225 request_data.form_signatures.push_back(form.FormSignature()); |
| 177 request_data.request_type = AutofillDownloadManager::REQUEST_UPLOAD; | 226 request_data.request_type = AutofillDownloadManager::REQUEST_UPLOAD; |
| 178 request_data.payload = payload; | 227 request_data.payload = payload; |
| 179 | 228 |
| 229 VLOG(1) << "Sending Autofill Upload Request:\n" << upload; |
| 230 |
| 180 return StartRequest(request_data); | 231 return StartRequest(request_data); |
| 181 } | 232 } |
| 182 | 233 |
| 183 bool AutofillDownloadManager::StartRequest( | 234 bool AutofillDownloadManager::StartRequest( |
| 184 const FormRequestData& request_data) { | 235 const FormRequestData& request_data) { |
| 185 net::URLRequestContextGetter* request_context = | 236 net::URLRequestContextGetter* request_context = |
| 186 driver_->GetURLRequestContext(); | 237 driver_->GetURLRequestContext(); |
| 187 DCHECK(request_context); | 238 DCHECK(request_context); |
| 188 GURL request_url = GetRequestUrl(request_data.request_type); | 239 GURL request_url = GetRequestUrl(request_data.request_type); |
| 189 | 240 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 213 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | | 264 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | |
| 214 net::LOAD_DO_NOT_SEND_COOKIES); | 265 net::LOAD_DO_NOT_SEND_COOKIES); |
| 215 // Add Chrome experiment state and GZIP encoding to the request headers. | 266 // Add Chrome experiment state and GZIP encoding to the request headers. |
| 216 net::HttpRequestHeaders headers; | 267 net::HttpRequestHeaders headers; |
| 217 headers.SetHeaderIfMissing("content-encoding", "gzip"); | 268 headers.SetHeaderIfMissing("content-encoding", "gzip"); |
| 218 variations::AppendVariationHeaders( | 269 variations::AppendVariationHeaders( |
| 219 fetcher->GetOriginalURL(), driver_->IsOffTheRecord(), false, &headers); | 270 fetcher->GetOriginalURL(), driver_->IsOffTheRecord(), false, &headers); |
| 220 fetcher->SetExtraRequestHeaders(headers.ToString()); | 271 fetcher->SetExtraRequestHeaders(headers.ToString()); |
| 221 fetcher->Start(); | 272 fetcher->Start(); |
| 222 | 273 |
| 223 VLOG(1) << "Sending AutofillDownloadManager " | |
| 224 << RequestTypeToString(request_data.request_type) | |
| 225 << " request (compressed to " << compression_ratio << "%)"; | |
| 226 | |
| 227 return true; | 274 return true; |
| 228 } | 275 } |
| 229 | 276 |
| 230 void AutofillDownloadManager::CacheQueryRequest( | 277 void AutofillDownloadManager::CacheQueryRequest( |
| 231 const std::vector<std::string>& forms_in_query, | 278 const std::vector<std::string>& forms_in_query, |
| 232 const std::string& query_data) { | 279 const std::string& query_data) { |
| 233 std::string signature = GetCombinedSignature(forms_in_query); | 280 std::string signature = GetCombinedSignature(forms_in_query); |
| 234 for (auto it = cached_forms_.begin(); it != cached_forms_.end(); ++it) { | 281 for (auto it = cached_forms_.begin(); it != cached_forms_.end(); ++it) { |
| 235 if (it->first == signature) { | 282 if (it->first == signature) { |
| 236 // We hit the cache, move to the first position and return. | 283 // We hit the cache, move to the first position and return. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 | 352 |
| 306 VLOG(1) << "AutofillDownloadManager: " << request_type | 353 VLOG(1) << "AutofillDownloadManager: " << request_type |
| 307 << " request has failed with response " | 354 << " request has failed with response " |
| 308 << source->GetResponseCode(); | 355 << source->GetResponseCode(); |
| 309 observer_->OnServerRequestError(it->second.form_signatures[0], | 356 observer_->OnServerRequestError(it->second.form_signatures[0], |
| 310 it->second.request_type, | 357 it->second.request_type, |
| 311 source->GetResponseCode()); | 358 source->GetResponseCode()); |
| 312 } else { | 359 } else { |
| 313 std::string response_body; | 360 std::string response_body; |
| 314 source->GetResponseAsString(&response_body); | 361 source->GetResponseAsString(&response_body); |
| 315 VLOG(1) << "AutofillDownloadManager: " << request_type | |
| 316 << " request has succeeded."; | |
| 317 if (it->second.request_type == AutofillDownloadManager::REQUEST_QUERY) { | 362 if (it->second.request_type == AutofillDownloadManager::REQUEST_QUERY) { |
| 318 CacheQueryRequest(it->second.form_signatures, response_body); | 363 CacheQueryRequest(it->second.form_signatures, response_body); |
| 319 observer_->OnLoadedServerPredictions(std::move(response_body), | 364 observer_->OnLoadedServerPredictions(std::move(response_body), |
| 320 it->second.form_signatures); | 365 it->second.form_signatures); |
| 321 } else { | 366 } else { |
| 367 VLOG(1) << "AutofillDownloadManager: upload request has succeeded."; |
| 322 observer_->OnUploadedPossibleFieldTypes(); | 368 observer_->OnUploadedPossibleFieldTypes(); |
| 323 } | 369 } |
| 324 } | 370 } |
| 325 delete it->first; | 371 delete it->first; |
| 326 url_fetchers_.erase(it); | 372 url_fetchers_.erase(it); |
| 327 } | 373 } |
| 328 | 374 |
| 329 } // namespace autofill | 375 } // namespace autofill |
| OLD | NEW |