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

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

Issue 196603015: [Autofill] Cleanup: Remove the --autofill-service-url flag. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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.h" 5 #include "components/autofill/core/browser/autofill_download.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"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "components/autofill/core/browser/autofill_download_url.h"
13 #include "components/autofill/core/browser/autofill_driver.h" 12 #include "components/autofill/core/browser/autofill_driver.h"
14 #include "components/autofill/core/browser/autofill_metrics.h" 13 #include "components/autofill/core/browser/autofill_metrics.h"
15 #include "components/autofill/core/browser/autofill_xml_parser.h" 14 #include "components/autofill/core/browser/autofill_xml_parser.h"
16 #include "components/autofill/core/browser/form_structure.h" 15 #include "components/autofill/core/browser/form_structure.h"
17 #include "components/autofill/core/common/autofill_pref_names.h" 16 #include "components/autofill/core/common/autofill_pref_names.h"
18 #include "net/base/load_flags.h" 17 #include "net/base/load_flags.h"
19 #include "net/http/http_response_headers.h" 18 #include "net/http/http_response_headers.h"
20 #include "net/url_request/url_fetcher.h" 19 #include "net/url_request/url_fetcher.h"
21 #include "third_party/libjingle/source/talk/xmllite/xmlparser.h" 20 #include "third_party/libjingle/source/talk/xmllite/xmlparser.h"
22 #include "url/gurl.h" 21 #include "url/gurl.h"
23 22
24 namespace autofill { 23 namespace autofill {
25 24
26 namespace { 25 namespace {
27 26
28 const char kAutofillQueryServerNameStartInHeader[] = "GFE/"; 27 const char kAutofillQueryServerNameStartInHeader[] = "GFE/";
29 const size_t kMaxFormCacheSize = 16; 28 const size_t kMaxFormCacheSize = 16;
30 29
31 std::string AutofillRequestTypeToString( 30 #if defined(GOOGLE_CHROME_BUILD)
32 AutofillDownloadManager::AutofillRequestType type) { 31 const char kClientName[] = "Google Chrome";
32 #else
33 const char kClientName[] = "Chromium";
34 #endif // defined(GOOGLE_CHROME_BUILD)
35
36 std::string RequestTypeToString(AutofillDownloadManager::RequestType type) {
33 switch (type) { 37 switch (type) {
34 case AutofillDownloadManager::REQUEST_QUERY: 38 case AutofillDownloadManager::REQUEST_QUERY:
35 return "query"; 39 return "query";
36 case AutofillDownloadManager::REQUEST_UPLOAD: 40 case AutofillDownloadManager::REQUEST_UPLOAD:
37 return "upload"; 41 return "upload";
38 } 42 }
39 NOTREACHED(); 43 NOTREACHED();
40 return std::string(); 44 return std::string();
41 } 45 }
42 46
47 GURL GetRequestUrl(AutofillDownloadManager::RequestType request_type) {
48 return GURL("https://clients1.google.com/tbproxy/af/" +
49 RequestTypeToString(request_type) +
50 "?client=" + kClientName);
Evan Stade 2014/03/14 18:35:47 4 more indent i think
Ilya Sherman 2014/03/14 21:53:47 Done (by way of "git cl format" over the CL).
51 }
52
53
43 } // namespace 54 } // namespace
44 55
45 struct AutofillDownloadManager::FormRequestData { 56 struct AutofillDownloadManager::FormRequestData {
46 std::vector<std::string> form_signatures; 57 std::vector<std::string> form_signatures;
47 AutofillRequestType request_type; 58 RequestType request_type;
48 }; 59 };
49 60
50 AutofillDownloadManager::AutofillDownloadManager(AutofillDriver* driver, 61 AutofillDownloadManager::AutofillDownloadManager(AutofillDriver* driver,
51 PrefService* pref_service, 62 PrefService* pref_service,
52 Observer* observer) 63 Observer* observer)
53 : driver_(driver), 64 : driver_(driver),
54 pref_service_(pref_service), 65 pref_service_(pref_service),
55 observer_(observer), 66 observer_(observer),
56 max_form_cache_size_(kMaxFormCacheSize), 67 max_form_cache_size_(kMaxFormCacheSize),
57 next_query_request_(base::Time::Now()), 68 next_query_request_(base::Time::Now()),
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 DCHECK_LE(rate, 1.0); 169 DCHECK_LE(rate, 1.0);
159 pref_service_->SetDouble(prefs::kAutofillNegativeUploadRate, rate); 170 pref_service_->SetDouble(prefs::kAutofillNegativeUploadRate, rate);
160 } 171 }
161 172
162 bool AutofillDownloadManager::StartRequest( 173 bool AutofillDownloadManager::StartRequest(
163 const std::string& form_xml, 174 const std::string& form_xml,
164 const FormRequestData& request_data) { 175 const FormRequestData& request_data) {
165 net::URLRequestContextGetter* request_context = 176 net::URLRequestContextGetter* request_context =
166 driver_->GetURLRequestContext(); 177 driver_->GetURLRequestContext();
167 DCHECK(request_context); 178 DCHECK(request_context);
168 GURL request_url; 179 GURL request_url = GetRequestUrl(request_data.request_type);
169 if (request_data.request_type == AutofillDownloadManager::REQUEST_QUERY)
170 request_url = autofill::GetAutofillQueryUrl();
171 else
172 request_url = autofill::GetAutofillUploadUrl();
173 180
174 // Id is ignored for regular chrome, in unit test id's for fake fetcher 181 // Id is ignored for regular chrome, in unit test id's for fake fetcher
175 // factory will be 0, 1, 2, ... 182 // factory will be 0, 1, 2, ...
176 net::URLFetcher* fetcher = net::URLFetcher::Create( 183 net::URLFetcher* fetcher = net::URLFetcher::Create(
177 fetcher_id_for_unittest_++, request_url, net::URLFetcher::POST, 184 fetcher_id_for_unittest_++, request_url, net::URLFetcher::POST,
178 this); 185 this);
179 url_fetchers_[fetcher] = request_data; 186 url_fetchers_[fetcher] = request_data;
180 fetcher->SetAutomaticallyRetryOn5xx(false); 187 fetcher->SetAutomaticallyRetryOn5xx(false);
181 fetcher->SetRequestContext(request_context); 188 fetcher->SetRequestContext(request_context);
182 fetcher->SetUploadData("text/plain", form_xml); 189 fetcher->SetUploadData("text/plain", form_xml);
183 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | 190 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
184 net::LOAD_DO_NOT_SEND_COOKIES); 191 net::LOAD_DO_NOT_SEND_COOKIES);
185 fetcher->Start(); 192 fetcher->Start();
186 193
187 DVLOG(1) << "Sending AutofillDownloadManager " 194 DVLOG(1) << "Sending AutofillDownloadManager "
188 << AutofillRequestTypeToString(request_data.request_type) 195 << RequestTypeToString(request_data.request_type)
189 << " request: " << form_xml; 196 << " request: " << form_xml;
190 197
191 return true; 198 return true;
192 } 199 }
193 200
194 void AutofillDownloadManager::CacheQueryRequest( 201 void AutofillDownloadManager::CacheQueryRequest(
195 const std::vector<std::string>& forms_in_query, 202 const std::vector<std::string>& forms_in_query,
196 const std::string& query_data) { 203 const std::string& query_data) {
197 std::string signature = GetCombinedSignature(forms_in_query); 204 std::string signature = GetCombinedSignature(forms_in_query);
198 for (QueryRequestCache::iterator it = cached_forms_.begin(); 205 for (QueryRequestCache::iterator it = cached_forms_.begin();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 254
248 void AutofillDownloadManager::OnURLFetchComplete( 255 void AutofillDownloadManager::OnURLFetchComplete(
249 const net::URLFetcher* source) { 256 const net::URLFetcher* source) {
250 std::map<net::URLFetcher *, FormRequestData>::iterator it = 257 std::map<net::URLFetcher *, FormRequestData>::iterator it =
251 url_fetchers_.find(const_cast<net::URLFetcher*>(source)); 258 url_fetchers_.find(const_cast<net::URLFetcher*>(source));
252 if (it == url_fetchers_.end()) { 259 if (it == url_fetchers_.end()) {
253 // Looks like crash on Mac is possibly caused with callback entering here 260 // Looks like crash on Mac is possibly caused with callback entering here
254 // with unknown fetcher when network is refreshed. 261 // with unknown fetcher when network is refreshed.
255 return; 262 return;
256 } 263 }
257 std::string type_of_request( 264 std::string request_type(RequestTypeToString(it->second.request_type));
258 AutofillRequestTypeToString(it->second.request_type));
259 const int kHttpResponseOk = 200; 265 const int kHttpResponseOk = 200;
260 const int kHttpInternalServerError = 500; 266 const int kHttpInternalServerError = 500;
261 const int kHttpBadGateway = 502; 267 const int kHttpBadGateway = 502;
262 const int kHttpServiceUnavailable = 503; 268 const int kHttpServiceUnavailable = 503;
263 269
264 CHECK(it->second.form_signatures.size()); 270 CHECK(it->second.form_signatures.size());
265 if (source->GetResponseCode() != kHttpResponseOk) { 271 if (source->GetResponseCode() != kHttpResponseOk) {
266 bool back_off = false; 272 bool back_off = false;
267 std::string server_header; 273 std::string server_header;
268 switch (source->GetResponseCode()) { 274 switch (source->GetResponseCode()) {
(...skipping 14 matching lines...) Expand all
283 289
284 if (back_off) { 290 if (back_off) {
285 base::Time back_off_time(base::Time::Now() + source->GetBackoffDelay()); 291 base::Time back_off_time(base::Time::Now() + source->GetBackoffDelay());
286 if (it->second.request_type == AutofillDownloadManager::REQUEST_QUERY) { 292 if (it->second.request_type == AutofillDownloadManager::REQUEST_QUERY) {
287 next_query_request_ = back_off_time; 293 next_query_request_ = back_off_time;
288 } else { 294 } else {
289 next_upload_request_ = back_off_time; 295 next_upload_request_ = back_off_time;
290 } 296 }
291 } 297 }
292 298
293 DVLOG(1) << "AutofillDownloadManager: " << type_of_request 299 DVLOG(1) << "AutofillDownloadManager: " << request_type
294 << " request has failed with response " 300 << " request has failed with response "
295 << source->GetResponseCode(); 301 << source->GetResponseCode();
296 observer_->OnServerRequestError(it->second.form_signatures[0], 302 observer_->OnServerRequestError(it->second.form_signatures[0],
297 it->second.request_type, 303 it->second.request_type,
298 source->GetResponseCode()); 304 source->GetResponseCode());
299 } else { 305 } else {
300 std::string response_body; 306 std::string response_body;
301 source->GetResponseAsString(&response_body); 307 source->GetResponseAsString(&response_body);
302 DVLOG(1) << "AutofillDownloadManager: " << type_of_request 308 DVLOG(1) << "AutofillDownloadManager: " << request_type
303 << " request has succeeded with response body: " 309 << " request has succeeded with response body: "
304 << response_body; 310 << response_body;
305 if (it->second.request_type == AutofillDownloadManager::REQUEST_QUERY) { 311 if (it->second.request_type == AutofillDownloadManager::REQUEST_QUERY) {
306 CacheQueryRequest(it->second.form_signatures, response_body); 312 CacheQueryRequest(it->second.form_signatures, response_body);
307 observer_->OnLoadedServerPredictions(response_body); 313 observer_->OnLoadedServerPredictions(response_body);
308 } else { 314 } else {
309 double new_positive_upload_rate = 0; 315 double new_positive_upload_rate = 0;
310 double new_negative_upload_rate = 0; 316 double new_negative_upload_rate = 0;
311 AutofillUploadXmlParser parse_handler(&new_positive_upload_rate, 317 AutofillUploadXmlParser parse_handler(&new_positive_upload_rate,
312 &new_negative_upload_rate); 318 &new_negative_upload_rate);
313 buzz::XmlParser parser(&parse_handler); 319 buzz::XmlParser parser(&parse_handler);
314 parser.Parse(response_body.data(), response_body.length(), true); 320 parser.Parse(response_body.data(), response_body.length(), true);
315 if (parse_handler.succeeded()) { 321 if (parse_handler.succeeded()) {
316 SetPositiveUploadRate(new_positive_upload_rate); 322 SetPositiveUploadRate(new_positive_upload_rate);
317 SetNegativeUploadRate(new_negative_upload_rate); 323 SetNegativeUploadRate(new_negative_upload_rate);
318 } 324 }
319 325
320 observer_->OnUploadedPossibleFieldTypes(); 326 observer_->OnUploadedPossibleFieldTypes();
321 } 327 }
322 } 328 }
323 delete it->first; 329 delete it->first;
324 url_fetchers_.erase(it); 330 url_fetchers_.erase(it);
325 } 331 }
326 332
327 } // namespace autofill 333 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_download.h ('k') | components/autofill/core/browser/autofill_download_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698