Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: components/autofill/core/browser/autofill_download_manager.cc

Issue 897633004: [Password Generation] Logging for release builds (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 if (!FormStructure::EncodeQueryRequest(forms, &request_data.form_signatures, 91 if (!FormStructure::EncodeQueryRequest(forms, &request_data.form_signatures,
92 &form_xml)) { 92 &form_xml)) {
93 return false; 93 return false;
94 } 94 }
95 95
96 request_data.request_type = AutofillDownloadManager::REQUEST_QUERY; 96 request_data.request_type = AutofillDownloadManager::REQUEST_QUERY;
97 AutofillMetrics::LogServerQueryMetric(AutofillMetrics::QUERY_SENT); 97 AutofillMetrics::LogServerQueryMetric(AutofillMetrics::QUERY_SENT);
98 98
99 std::string query_data; 99 std::string query_data;
100 if (CheckCacheForQueryRequest(request_data.form_signatures, &query_data)) { 100 if (CheckCacheForQueryRequest(request_data.form_signatures, &query_data)) {
101 DVLOG(1) << "AutofillDownloadManager: query request has been retrieved " 101 VLOG(1) << "AutofillDownloadManager: query request has been retrieved "
102 << "from the cache, form signatures: " 102 << "from the cache, form signatures: "
103 << GetCombinedSignature(request_data.form_signatures); 103 << GetCombinedSignature(request_data.form_signatures);
104 observer_->OnLoadedServerPredictions(query_data); 104 observer_->OnLoadedServerPredictions(query_data);
105 return true; 105 return true;
106 } 106 }
107 107
108 return StartRequest(form_xml, request_data); 108 return StartRequest(form_xml, request_data);
109 } 109 }
110 110
111 bool AutofillDownloadManager::StartUploadRequest( 111 bool AutofillDownloadManager::StartUploadRequest(
112 const FormStructure& form, 112 const FormStructure& form,
113 bool form_was_autofilled, 113 bool form_was_autofilled,
114 const ServerFieldTypeSet& available_field_types) { 114 const ServerFieldTypeSet& available_field_types) {
115 std::string form_xml; 115 std::string form_xml;
116 if (!form.EncodeUploadRequest(available_field_types, form_was_autofilled, 116 if (!form.EncodeUploadRequest(available_field_types, form_was_autofilled,
117 &form_xml)) 117 &form_xml))
118 return false; 118 return false;
119 119
120 if (next_upload_request_ > base::Time::Now()) { 120 if (next_upload_request_ > base::Time::Now()) {
121 // We are in back-off mode: do not do the request. 121 // We are in back-off mode: do not do the request.
122 DVLOG(1) << "AutofillDownloadManager: Upload request is throttled."; 122 VLOG(1) << "AutofillDownloadManager: Upload request is throttled.";
123 return false; 123 return false;
124 } 124 }
125 125
126 // Flip a coin to see if we should upload this form. 126 // Flip a coin to see if we should upload this form.
127 double upload_rate = form_was_autofilled ? GetPositiveUploadRate() : 127 double upload_rate = form_was_autofilled ? GetPositiveUploadRate() :
128 GetNegativeUploadRate(); 128 GetNegativeUploadRate();
129 if (form.upload_required() == UPLOAD_NOT_REQUIRED || 129 if (form.upload_required() == UPLOAD_NOT_REQUIRED ||
130 (form.upload_required() == USE_UPLOAD_RATES && 130 (form.upload_required() == USE_UPLOAD_RATES &&
131 base::RandDouble() > upload_rate)) { 131 base::RandDouble() > upload_rate)) {
132 DVLOG(1) << "AutofillDownloadManager: Upload request is ignored."; 132 VLOG(1) << "AutofillDownloadManager: Upload request is ignored.";
133 // If we ever need notification that upload was skipped, add it here. 133 // If we ever need notification that upload was skipped, add it here.
134 return false; 134 return false;
135 } 135 }
136 136
137 FormRequestData request_data; 137 FormRequestData request_data;
138 request_data.form_signatures.push_back(form.FormSignature()); 138 request_data.form_signatures.push_back(form.FormSignature());
139 request_data.request_type = AutofillDownloadManager::REQUEST_UPLOAD; 139 request_data.request_type = AutofillDownloadManager::REQUEST_UPLOAD;
140 140
141 return StartRequest(form_xml, request_data); 141 return StartRequest(form_xml, request_data);
142 } 142 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 fetcher_id_for_unittest_++, request_url, net::URLFetcher::POST, 181 fetcher_id_for_unittest_++, request_url, net::URLFetcher::POST,
182 this); 182 this);
183 url_fetchers_[fetcher] = request_data; 183 url_fetchers_[fetcher] = request_data;
184 fetcher->SetAutomaticallyRetryOn5xx(false); 184 fetcher->SetAutomaticallyRetryOn5xx(false);
185 fetcher->SetRequestContext(request_context); 185 fetcher->SetRequestContext(request_context);
186 fetcher->SetUploadData("text/plain", form_xml); 186 fetcher->SetUploadData("text/plain", form_xml);
187 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | 187 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
188 net::LOAD_DO_NOT_SEND_COOKIES); 188 net::LOAD_DO_NOT_SEND_COOKIES);
189 fetcher->Start(); 189 fetcher->Start();
190 190
191 DVLOG(1) << "Sending AutofillDownloadManager " 191 VLOG(1) << "Sending AutofillDownloadManager "
192 << RequestTypeToString(request_data.request_type) 192 << RequestTypeToString(request_data.request_type)
193 << " request: " << form_xml; 193 << " request: " << form_xml;
194 194
195 return true; 195 return true;
196 } 196 }
197 197
198 void AutofillDownloadManager::CacheQueryRequest( 198 void AutofillDownloadManager::CacheQueryRequest(
199 const std::vector<std::string>& forms_in_query, 199 const std::vector<std::string>& forms_in_query,
200 const std::string& query_data) { 200 const std::string& query_data) {
201 std::string signature = GetCombinedSignature(forms_in_query); 201 std::string signature = GetCombinedSignature(forms_in_query);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 286
287 if (back_off) { 287 if (back_off) {
288 base::Time back_off_time(base::Time::Now() + source->GetBackoffDelay()); 288 base::Time back_off_time(base::Time::Now() + source->GetBackoffDelay());
289 if (it->second.request_type == AutofillDownloadManager::REQUEST_QUERY) { 289 if (it->second.request_type == AutofillDownloadManager::REQUEST_QUERY) {
290 next_query_request_ = back_off_time; 290 next_query_request_ = back_off_time;
291 } else { 291 } else {
292 next_upload_request_ = back_off_time; 292 next_upload_request_ = back_off_time;
293 } 293 }
294 } 294 }
295 295
296 DVLOG(1) << "AutofillDownloadManager: " << request_type 296 VLOG(1) << "AutofillDownloadManager: " << request_type
297 << " request has failed with response " 297 << " request has failed with response "
298 << source->GetResponseCode(); 298 << source->GetResponseCode();
299 observer_->OnServerRequestError(it->second.form_signatures[0], 299 observer_->OnServerRequestError(it->second.form_signatures[0],
300 it->second.request_type, 300 it->second.request_type,
301 source->GetResponseCode()); 301 source->GetResponseCode());
302 } else { 302 } else {
303 std::string response_body; 303 std::string response_body;
304 source->GetResponseAsString(&response_body); 304 source->GetResponseAsString(&response_body);
305 DVLOG(1) << "AutofillDownloadManager: " << request_type 305 VLOG(1) << "AutofillDownloadManager: " << request_type
306 << " request has succeeded with response body: " << response_body; 306 << " request has succeeded with response body: " << response_body;
307 if (it->second.request_type == AutofillDownloadManager::REQUEST_QUERY) { 307 if (it->second.request_type == AutofillDownloadManager::REQUEST_QUERY) {
308 CacheQueryRequest(it->second.form_signatures, response_body); 308 CacheQueryRequest(it->second.form_signatures, response_body);
309 observer_->OnLoadedServerPredictions(response_body); 309 observer_->OnLoadedServerPredictions(response_body);
310 } else { 310 } else {
311 double new_positive_upload_rate = 0; 311 double new_positive_upload_rate = 0;
312 double new_negative_upload_rate = 0; 312 double new_negative_upload_rate = 0;
313 AutofillUploadXmlParser parse_handler(&new_positive_upload_rate, 313 AutofillUploadXmlParser parse_handler(&new_positive_upload_rate,
314 &new_negative_upload_rate); 314 &new_negative_upload_rate);
315 buzz::XmlParser parser(&parse_handler); 315 buzz::XmlParser parser(&parse_handler);
316 parser.Parse(response_body.data(), response_body.length(), true); 316 parser.Parse(response_body.data(), response_body.length(), true);
317 if (parse_handler.succeeded()) { 317 if (parse_handler.succeeded()) {
318 SetPositiveUploadRate(new_positive_upload_rate); 318 SetPositiveUploadRate(new_positive_upload_rate);
319 SetNegativeUploadRate(new_negative_upload_rate); 319 SetNegativeUploadRate(new_negative_upload_rate);
320 } 320 }
321 321
322 observer_->OnUploadedPossibleFieldTypes(); 322 observer_->OnUploadedPossibleFieldTypes();
323 } 323 }
324 } 324 }
325 delete it->first; 325 delete it->first;
326 url_fetchers_.erase(it); 326 url_fetchers_.erase(it);
327 } 327 }
328 328
329 } // namespace autofill 329 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698