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

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

Issue 1624543002: [Autofill] Remove GZIP compression since requests are now in proto (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 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 <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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/numerics/safe_conversions.h" 12 #include "base/numerics/safe_conversions.h"
13 #include "base/rand_util.h" 13 #include "base/rand_util.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/thread_task_runner_handle.h" 16 #include "base/thread_task_runner_handle.h"
17 #include "components/autofill/core/browser/autofill_driver.h" 17 #include "components/autofill/core/browser/autofill_driver.h"
18 #include "components/autofill/core/browser/autofill_metrics.h" 18 #include "components/autofill/core/browser/autofill_metrics.h"
19 #include "components/autofill/core/browser/form_structure.h" 19 #include "components/autofill/core/browser/form_structure.h"
20 #include "components/autofill/core/browser/proto/server.pb.h" 20 #include "components/autofill/core/browser/proto/server.pb.h"
21 #include "components/autofill/core/common/autofill_pref_names.h" 21 #include "components/autofill/core/common/autofill_pref_names.h"
22 #include "components/data_use_measurement/core/data_use_user_data.h" 22 #include "components/data_use_measurement/core/data_use_user_data.h"
23 #include "components/variations/net/variations_http_headers.h" 23 #include "components/variations/net/variations_http_headers.h"
24 #include "net/base/load_flags.h" 24 #include "net/base/load_flags.h"
25 #include "net/http/http_request_headers.h" 25 #include "net/http/http_request_headers.h"
26 #include "net/http/http_response_headers.h" 26 #include "net/http/http_response_headers.h"
27 #include "net/http/http_status_code.h" 27 #include "net/http/http_status_code.h"
28 #include "net/url_request/url_fetcher.h" 28 #include "net/url_request/url_fetcher.h"
29 #include "third_party/zlib/google/compression_utils.h"
30 #include "url/gurl.h" 29 #include "url/gurl.h"
31 30
32 namespace autofill { 31 namespace autofill {
33 32
34 namespace { 33 namespace {
35 34
36 const size_t kMaxFormCacheSize = 16; 35 const size_t kMaxFormCacheSize = 16;
37 const size_t kMaxFieldsPerQueryRequest = 100; 36 const size_t kMaxFieldsPerQueryRequest = 100;
38 37
39 const net::BackoffEntry::Policy kAutofillBackoffPolicy = { 38 const net::BackoffEntry::Policy kAutofillBackoffPolicy = {
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 return StartRequest(request_data); 230 return StartRequest(request_data);
232 } 231 }
233 232
234 bool AutofillDownloadManager::StartRequest( 233 bool AutofillDownloadManager::StartRequest(
235 const FormRequestData& request_data) { 234 const FormRequestData& request_data) {
236 net::URLRequestContextGetter* request_context = 235 net::URLRequestContextGetter* request_context =
237 driver_->GetURLRequestContext(); 236 driver_->GetURLRequestContext();
238 DCHECK(request_context); 237 DCHECK(request_context);
239 GURL request_url = GetRequestUrl(request_data.request_type); 238 GURL request_url = GetRequestUrl(request_data.request_type);
240 239
241 // TODO(crbug.com/580102): Remove the compression step.
242 std::string compressed_data;
243 if (!compression::GzipCompress(request_data.payload, &compressed_data)) {
244 NOTREACHED();
245 return false;
246 }
247
248 const int compression_ratio = base::checked_cast<int>(
249 100 * compressed_data.size() / request_data.payload.size());
250 AutofillMetrics::LogPayloadCompressionRatio(compression_ratio,
251 request_data.request_type);
252
253 // Id is ignored for regular chrome, in unit test id's for fake fetcher 240 // Id is ignored for regular chrome, in unit test id's for fake fetcher
254 // factory will be 0, 1, 2, ... 241 // factory will be 0, 1, 2, ...
255 net::URLFetcher* fetcher = 242 net::URLFetcher* fetcher =
256 net::URLFetcher::Create(fetcher_id_for_unittest_++, request_url, 243 net::URLFetcher::Create(fetcher_id_for_unittest_++, request_url,
257 net::URLFetcher::POST, this).release(); 244 net::URLFetcher::POST, this).release();
258 data_use_measurement::DataUseUserData::AttachToFetcher( 245 data_use_measurement::DataUseUserData::AttachToFetcher(
259 fetcher, data_use_measurement::DataUseUserData::AUTOFILL); 246 fetcher, data_use_measurement::DataUseUserData::AUTOFILL);
260 url_fetchers_[fetcher] = request_data; 247 url_fetchers_[fetcher] = request_data;
261 fetcher->SetAutomaticallyRetryOn5xx(false); 248 fetcher->SetAutomaticallyRetryOn5xx(false);
262 fetcher->SetRequestContext(request_context); 249 fetcher->SetRequestContext(request_context);
263 fetcher->SetUploadData("text/proto", compressed_data); 250 fetcher->SetUploadData("text/proto", request_data.payload);
264 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | 251 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
265 net::LOAD_DO_NOT_SEND_COOKIES); 252 net::LOAD_DO_NOT_SEND_COOKIES);
266 // Add Chrome experiment state and GZIP encoding to the request headers. 253 // Add Chrome experiment state to the request headers.
267 net::HttpRequestHeaders headers; 254 net::HttpRequestHeaders headers;
268 headers.SetHeaderIfMissing("content-encoding", "gzip");
269 variations::AppendVariationHeaders( 255 variations::AppendVariationHeaders(
270 fetcher->GetOriginalURL(), driver_->IsOffTheRecord(), false, &headers); 256 fetcher->GetOriginalURL(), driver_->IsOffTheRecord(), false, &headers);
271 fetcher->SetExtraRequestHeaders(headers.ToString()); 257 fetcher->SetExtraRequestHeaders(headers.ToString());
272 fetcher->Start(); 258 fetcher->Start();
273 259
274 return true; 260 return true;
275 } 261 }
276 262
277 void AutofillDownloadManager::CacheQueryRequest( 263 void AutofillDownloadManager::CacheQueryRequest(
278 const std::vector<std::string>& forms_in_query, 264 const std::vector<std::string>& forms_in_query,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 } else { 352 } else {
367 VLOG(1) << "AutofillDownloadManager: upload request has succeeded."; 353 VLOG(1) << "AutofillDownloadManager: upload request has succeeded.";
368 observer_->OnUploadedPossibleFieldTypes(); 354 observer_->OnUploadedPossibleFieldTypes();
369 } 355 }
370 } 356 }
371 delete it->first; 357 delete it->first;
372 url_fetchers_.erase(it); 358 url_fetchers_.erase(it);
373 } 359 }
374 360
375 } // namespace autofill 361 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698