Chromium Code Reviews| 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& s, | |
|
Roger McFarlane (Chromium)
2016/01/22 21:52:30
maybe rename s to out or stream
Mathieu
2016/01/22 22:15:12
Done.
| |
| 95 const autofill::AutofillQueryContents& query) { | |
| 96 s << "client_version: " << query.client_version(); | |
| 97 for (const auto& form : query.form()) { | |
| 98 s << "\nForm\n signature: " << form.signature(); | |
| 99 for (const auto& field : form.field()) { | |
| 100 s << "\n Field" | |
| 101 << "\n signature: " << field.signature(); | |
|
Roger McFarlane (Chromium)
2016/01/22 21:52:30
nit: will this fit merged with the previous line?
Mathieu
2016/01/22 22:15:12
Done.
| |
| 102 if (!field.name().empty()) | |
| 103 s << "\n name: " << field.name(); | |
| 104 if (!field.type().empty()) | |
| 105 s << "\n type: " << field.type(); | |
| 106 if (!field.label().empty()) | |
| 107 s << "\n label: " << field.label(); | |
| 108 } | |
| 109 } | |
| 110 return s; | |
| 111 } | |
| 112 | |
| 113 std::ostream& operator<<(std::ostream& s, | |
| 114 const autofill::AutofillUploadContents& upload) { | |
| 115 s << "client_version: " << upload.client_version() << "\n"; | |
| 116 s << "form_signature: " << upload.form_signature() << "\n"; | |
| 117 s << "data_present: " << upload.data_present() << "\n"; | |
| 118 s << "submission: " << upload.submission() << "\n"; | |
| 119 if (!upload.action_signature()) | |
| 120 s << "action_signature: " << upload.action_signature() << "\n"; | |
| 121 if (!upload.login_form_signature()) | |
| 122 s << "login_form_signature: " << upload.login_form_signature() << "\n"; | |
| 123 if (!upload.form_name().empty()) | |
| 124 s << "form_name: " << upload.form_name() << "\n"; | |
| 125 | |
| 126 for (const auto& field : upload.field()) { | |
| 127 s << "\n Field" | |
| 128 << "\n signature: " << field.signature() | |
| 129 << "\n autofill_type: " << field.autofill_type(); | |
|
Roger McFarlane (Chromium)
2016/01/22 21:52:30
this is a number or a string?
FieldType_Name(fiel
Mathieu
2016/01/22 22:15:12
Unfortunately it's not a proto in Chromium, it's a
| |
| 130 if (!field.name().empty()) | |
| 131 s << "\n name: " << field.name(); | |
| 132 if (!field.autocomplete().empty()) | |
| 133 s << "\n autocomplete: " << field.autocomplete(); | |
| 134 if (!field.type().empty()) | |
| 135 s << "\n type: " << field.type(); | |
| 136 if (!field.label().empty()) | |
| 137 s << "\n label: " << field.label(); | |
| 138 } | |
| 139 return s; | |
| 140 } | |
| 141 | |
| 94 } // namespace | 142 } // namespace |
| 95 | 143 |
| 96 struct AutofillDownloadManager::FormRequestData { | 144 struct AutofillDownloadManager::FormRequestData { |
| 97 std::vector<std::string> form_signatures; | 145 std::vector<std::string> form_signatures; |
| 98 RequestType request_type; | 146 RequestType request_type; |
| 99 std::string payload; | 147 std::string payload; |
| 100 }; | 148 }; |
| 101 | 149 |
| 102 AutofillDownloadManager::AutofillDownloadManager(AutofillDriver* driver, | 150 AutofillDownloadManager::AutofillDownloadManager(AutofillDriver* driver, |
| 103 Observer* observer) | 151 Observer* observer) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 std::string query_data; | 188 std::string query_data; |
| 141 if (CheckCacheForQueryRequest(request_data.form_signatures, &query_data)) { | 189 if (CheckCacheForQueryRequest(request_data.form_signatures, &query_data)) { |
| 142 VLOG(1) << "AutofillDownloadManager: query request has been retrieved " | 190 VLOG(1) << "AutofillDownloadManager: query request has been retrieved " |
| 143 << "from the cache, form signatures: " | 191 << "from the cache, form signatures: " |
| 144 << GetCombinedSignature(request_data.form_signatures); | 192 << GetCombinedSignature(request_data.form_signatures); |
| 145 observer_->OnLoadedServerPredictions(std::move(query_data), | 193 observer_->OnLoadedServerPredictions(std::move(query_data), |
| 146 request_data.form_signatures); | 194 request_data.form_signatures); |
| 147 return true; | 195 return true; |
| 148 } | 196 } |
| 149 | 197 |
| 198 VLOG(1) << "Sending Autofill Query Request:\n" << query; | |
| 199 | |
| 150 return StartRequest(request_data); | 200 return StartRequest(request_data); |
| 151 } | 201 } |
| 152 | 202 |
| 153 bool AutofillDownloadManager::StartUploadRequest( | 203 bool AutofillDownloadManager::StartUploadRequest( |
| 154 const FormStructure& form, | 204 const FormStructure& form, |
| 155 bool form_was_autofilled, | 205 bool form_was_autofilled, |
| 156 const ServerFieldTypeSet& available_field_types, | 206 const ServerFieldTypeSet& available_field_types, |
| 157 const std::string& login_form_signature, | 207 const std::string& login_form_signature, |
| 158 bool observed_submission) { | 208 bool observed_submission) { |
| 159 AutofillUploadContents upload; | 209 AutofillUploadContents upload; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 170 VLOG(1) << "AutofillDownloadManager: Upload request is ignored."; | 220 VLOG(1) << "AutofillDownloadManager: Upload request is ignored."; |
| 171 // If we ever need notification that upload was skipped, add it here. | 221 // If we ever need notification that upload was skipped, add it here. |
| 172 return false; | 222 return false; |
| 173 } | 223 } |
| 174 | 224 |
| 175 FormRequestData request_data; | 225 FormRequestData request_data; |
| 176 request_data.form_signatures.push_back(form.FormSignature()); | 226 request_data.form_signatures.push_back(form.FormSignature()); |
| 177 request_data.request_type = AutofillDownloadManager::REQUEST_UPLOAD; | 227 request_data.request_type = AutofillDownloadManager::REQUEST_UPLOAD; |
| 178 request_data.payload = payload; | 228 request_data.payload = payload; |
| 179 | 229 |
| 230 VLOG(1) << "Sending Autofill Upload Request:\n" << upload; | |
| 231 | |
| 180 return StartRequest(request_data); | 232 return StartRequest(request_data); |
| 181 } | 233 } |
| 182 | 234 |
| 183 bool AutofillDownloadManager::StartRequest( | 235 bool AutofillDownloadManager::StartRequest( |
| 184 const FormRequestData& request_data) { | 236 const FormRequestData& request_data) { |
| 185 net::URLRequestContextGetter* request_context = | 237 net::URLRequestContextGetter* request_context = |
| 186 driver_->GetURLRequestContext(); | 238 driver_->GetURLRequestContext(); |
| 187 DCHECK(request_context); | 239 DCHECK(request_context); |
| 188 GURL request_url = GetRequestUrl(request_data.request_type); | 240 GURL request_url = GetRequestUrl(request_data.request_type); |
| 189 | 241 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 213 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | | 265 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | |
| 214 net::LOAD_DO_NOT_SEND_COOKIES); | 266 net::LOAD_DO_NOT_SEND_COOKIES); |
| 215 // Add Chrome experiment state and GZIP encoding to the request headers. | 267 // Add Chrome experiment state and GZIP encoding to the request headers. |
| 216 net::HttpRequestHeaders headers; | 268 net::HttpRequestHeaders headers; |
| 217 headers.SetHeaderIfMissing("content-encoding", "gzip"); | 269 headers.SetHeaderIfMissing("content-encoding", "gzip"); |
| 218 variations::AppendVariationHeaders( | 270 variations::AppendVariationHeaders( |
| 219 fetcher->GetOriginalURL(), driver_->IsOffTheRecord(), false, &headers); | 271 fetcher->GetOriginalURL(), driver_->IsOffTheRecord(), false, &headers); |
| 220 fetcher->SetExtraRequestHeaders(headers.ToString()); | 272 fetcher->SetExtraRequestHeaders(headers.ToString()); |
| 221 fetcher->Start(); | 273 fetcher->Start(); |
| 222 | 274 |
| 223 VLOG(1) << "Sending AutofillDownloadManager " | |
| 224 << RequestTypeToString(request_data.request_type) | |
| 225 << " request (compressed to " << compression_ratio << "%)"; | |
| 226 | |
| 227 return true; | 275 return true; |
| 228 } | 276 } |
| 229 | 277 |
| 230 void AutofillDownloadManager::CacheQueryRequest( | 278 void AutofillDownloadManager::CacheQueryRequest( |
| 231 const std::vector<std::string>& forms_in_query, | 279 const std::vector<std::string>& forms_in_query, |
| 232 const std::string& query_data) { | 280 const std::string& query_data) { |
| 233 std::string signature = GetCombinedSignature(forms_in_query); | 281 std::string signature = GetCombinedSignature(forms_in_query); |
| 234 for (auto it = cached_forms_.begin(); it != cached_forms_.end(); ++it) { | 282 for (auto it = cached_forms_.begin(); it != cached_forms_.end(); ++it) { |
| 235 if (it->first == signature) { | 283 if (it->first == signature) { |
| 236 // We hit the cache, move to the first position and return. | 284 // We hit the cache, move to the first position and return. |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 it->second.form_signatures); | 368 it->second.form_signatures); |
| 321 } else { | 369 } else { |
| 322 observer_->OnUploadedPossibleFieldTypes(); | 370 observer_->OnUploadedPossibleFieldTypes(); |
| 323 } | 371 } |
| 324 } | 372 } |
| 325 delete it->first; | 373 delete it->first; |
| 326 url_fetchers_.erase(it); | 374 url_fetchers_.erase(it); |
| 327 } | 375 } |
| 328 | 376 |
| 329 } // namespace autofill | 377 } // namespace autofill |
| OLD | NEW |