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

Side by Side Diff: chrome/browser/autofill/autofill_download.cc

Issue 6213002: Propagate correct data to the Toolbar servers (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/autofill/autofill_download.h" 5 #include "chrome/browser/autofill/autofill_download.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 94
95 // Check if we need to upload form. 95 // Check if we need to upload form.
96 double upload_rate = form_was_matched ? GetPositiveUploadRate() : 96 double upload_rate = form_was_matched ? GetPositiveUploadRate() :
97 GetNegativeUploadRate(); 97 GetNegativeUploadRate();
98 if (base::RandDouble() > upload_rate) { 98 if (base::RandDouble() > upload_rate) {
99 VLOG(1) << "AutoFillDownloadManager: Upload request is ignored"; 99 VLOG(1) << "AutoFillDownloadManager: Upload request is ignored";
100 // If we ever need notification that upload was skipped, add it here. 100 // If we ever need notification that upload was skipped, add it here.
101 return false; 101 return false;
102 } 102 }
103 std::string form_xml; 103 std::string form_xml;
104 if (!form.EncodeUploadRequest(form_was_matched, &form_xml)) 104 if (!form.EncodeUploadRequest(form_was_matched,
105 ConvertPresenceBitsToString().c_str(),
106 &form_xml))
105 return false; 107 return false;
106 108
107 FormRequestData request_data; 109 FormRequestData request_data;
108 request_data.form_signatures.push_back(form.FormSignature()); 110 request_data.form_signatures.push_back(form.FormSignature());
109 request_data.request_type = AutoFillDownloadManager::REQUEST_UPLOAD; 111 request_data.request_type = AutoFillDownloadManager::REQUEST_UPLOAD;
110 112
111 return StartRequest(form_xml, request_data); 113 return StartRequest(form_xml, request_data);
112 } 114 }
113 115
114 bool AutoFillDownloadManager::CancelRequest( 116 bool AutoFillDownloadManager::CancelRequest(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 if (rate == negative_upload_rate_) 155 if (rate == negative_upload_rate_)
154 return; 156 return;
155 negative_upload_rate_ = rate; 157 negative_upload_rate_ = rate;
156 DCHECK_GE(rate, 0.0); 158 DCHECK_GE(rate, 0.0);
157 DCHECK_LE(rate, 1.0); 159 DCHECK_LE(rate, 1.0);
158 DCHECK(profile_); 160 DCHECK(profile_);
159 PrefService* preferences = profile_->GetPrefs(); 161 PrefService* preferences = profile_->GetPrefs();
160 preferences->SetReal(prefs::kAutoFillNegativeUploadRate, rate); 162 preferences->SetReal(prefs::kAutoFillNegativeUploadRate, rate);
161 } 163 }
162 164
165 void AutoFillDownloadManager::ClearPresence() {
166 // Determine all of the field types that were autofilled. Pack bits into
167 // |presence_bitfield|. The necessary size for |presence_bitfield| is
168 // ceil((MAX_VALID_FIELD_TYPE + 7) / 8) bytes (uint8).
169 presence_bitfield_.resize((MAX_VALID_FIELD_TYPE + 0x7) >> 3);
170 for (size_t i = 0; i < presence_bitfield_.size(); ++i)
171 presence_bitfield_[i] = 0;
172 }
173
174 void AutoFillDownloadManager::SetPresenceBit(AutoFillFieldType field_type) {
175 DCHECK(presence_bitfield_.size() > (static_cast<size_t>(field_type) >> 3));
176 // Set bit in the bitfield: byte |field_type| / 8, bit in byte
177 // |field_type| % 8 from the left.
178 presence_bitfield_[field_type >> 3] |= (0x80 >> (field_type & 7));
179 }
180
181 std::string AutoFillDownloadManager::ConvertPresenceBitsToString() {
182 std::string data_presence;
183 data_presence.reserve(presence_bitfield_.size() * 2 + 1);
184 // Skip leading zeroes. If all mask is 0 - return empty string.
185 size_t data_end = presence_bitfield_.size();
186 for (; data_end > 0 && !presence_bitfield_[data_end - 1]; --data_end) {
187 }
188 // Print all non-zero bytes into the string.
189 for (size_t i = 0; i < data_end; ++i) {
190 base::StringAppendF(&data_presence, "%02x", presence_bitfield_[i]);
191 }
192 return data_presence;
193 }
194
163 bool AutoFillDownloadManager::StartRequest( 195 bool AutoFillDownloadManager::StartRequest(
164 const std::string& form_xml, 196 const std::string& form_xml,
165 const FormRequestData& request_data) { 197 const FormRequestData& request_data) {
166 std::string request_url; 198 std::string request_url;
167 if (request_data.request_type == AutoFillDownloadManager::REQUEST_QUERY) 199 if (request_data.request_type == AutoFillDownloadManager::REQUEST_QUERY)
168 request_url = AUTO_FILL_QUERY_SERVER_REQUEST_URL; 200 request_url = AUTO_FILL_QUERY_SERVER_REQUEST_URL;
169 else 201 else
170 request_url = AUTO_FILL_UPLOAD_SERVER_REQUEST_URL; 202 request_url = AUTO_FILL_UPLOAD_SERVER_REQUEST_URL;
171 203
172 if (!request_url.compare(DISABLED_REQUEST_URL) && !is_testing_) { 204 if (!request_url.compare(DISABLED_REQUEST_URL) && !is_testing_) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 SetNegativeUploadRate(new_negative_upload_rate); 296 SetNegativeUploadRate(new_negative_upload_rate);
265 } 297 }
266 298
267 if (observer_) 299 if (observer_)
268 observer_->OnUploadedAutoFillHeuristics(it->second.form_signatures[0]); 300 observer_->OnUploadedAutoFillHeuristics(it->second.form_signatures[0]);
269 } 301 }
270 } 302 }
271 delete it->first; 303 delete it->first;
272 url_fetchers_.erase(it); 304 url_fetchers_.erase(it);
273 } 305 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698