summaryrefslogtreecommitdiffstats
path: root/components/autofill
diff options
context:
space:
mode:
authormathp <mathp@chromium.org>2015-11-11 14:28:59 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-11 22:30:00 +0000
commitec37100afb64a758d8fe4f4600385c23a0fa385e (patch)
treef5fb46f057f1e41c6a4f79edcda76071c0c69573 /components/autofill
parentf2bfe56ff56152e21033992105c31437a3b150fe (diff)
downloadchromium_src-ec37100afb64a758d8fe4f4600385c23a0fa385e.zip
chromium_src-ec37100afb64a758d8fe4f4600385c23a0fa385e.tar.gz
chromium_src-ec37100afb64a758d8fe4f4600385c23a0fa385e.tar.bz2
[Autofill] Use GZIP compression for Autofill outbound requests
BUG=553607 TEST=AutofillDownloadTest Review URL: https://codereview.chromium.org/1428373005 Cr-Commit-Position: refs/heads/master@{#359175}
Diffstat (limited to 'components/autofill')
-rw-r--r--components/autofill/core/DEPS1
-rw-r--r--components/autofill/core/browser/BUILD.gn2
-rw-r--r--components/autofill/core/browser/autofill_download_manager.cc16
-rw-r--r--components/autofill/core/browser/autofill_download_manager.h1
-rw-r--r--components/autofill/core/browser/autofill_download_manager_unittest.cc124
-rw-r--r--components/autofill/core/browser/autofill_metrics.cc16
-rw-r--r--components/autofill/core/browser/autofill_metrics.h7
7 files changed, 165 insertions, 2 deletions
diff --git a/components/autofill/core/DEPS b/components/autofill/core/DEPS
index 2ee4fb8..5af6466 100644
--- a/components/autofill/core/DEPS
+++ b/components/autofill/core/DEPS
@@ -1,4 +1,5 @@
include_rules = [
+ "+components/compression",
"+components/os_crypt",
"+components/pref_registry",
"+components/rappor",
diff --git a/components/autofill/core/browser/BUILD.gn b/components/autofill/core/browser/BUILD.gn
index 28ad3c5..7ac95fe 100644
--- a/components/autofill/core/browser/BUILD.gn
+++ b/components/autofill/core/browser/BUILD.gn
@@ -149,6 +149,7 @@ source_set("browser") {
"//base:i18n",
"//base:prefs",
"//components/autofill/core/common",
+ "//components/compression",
"//components/data_use_measurement/core",
"//components/infobars/core",
"//components/keyed_service/core",
@@ -275,6 +276,7 @@ source_set("unit_tests") {
"//base:prefs_test_support",
"//base/test:test_support",
"//components/autofill/core/common",
+ "//components/compression",
"//components/os_crypt",
"//components/rappor:test_support",
"//components/resources",
diff --git a/components/autofill/core/browser/autofill_download_manager.cc b/components/autofill/core/browser/autofill_download_manager.cc
index 565b2b7..4f2a391 100644
--- a/components/autofill/core/browser/autofill_download_manager.cc
+++ b/components/autofill/core/browser/autofill_download_manager.cc
@@ -14,6 +14,7 @@
#include "components/autofill/core/browser/autofill_xml_parser.h"
#include "components/autofill/core/browser/form_structure.h"
#include "components/autofill/core/common/autofill_pref_names.h"
+#include "components/compression/compression_utils.h"
#include "components/data_use_measurement/core/data_use_user_data.h"
#include "components/variations/net/variations_http_header_provider.h"
#include "net/base/load_flags.h"
@@ -193,6 +194,16 @@ bool AutofillDownloadManager::StartRequest(
DCHECK(request_context);
GURL request_url = GetRequestUrl(request_data.request_type);
+ std::string compressed_data;
+ if (!compression::GzipCompress(form_xml, &compressed_data)) {
+ NOTREACHED();
+ return false;
+ }
+
+ AutofillMetrics::LogPayloadCompressionRatio(
+ static_cast<int>(100 * compressed_data.size() / form_xml.size()),
+ request_data.request_type);
+
// Id is ignored for regular chrome, in unit test id's for fake fetcher
// factory will be 0, 1, 2, ...
net::URLFetcher* fetcher =
@@ -203,11 +214,12 @@ bool AutofillDownloadManager::StartRequest(
url_fetchers_[fetcher] = request_data;
fetcher->SetAutomaticallyRetryOn5xx(false);
fetcher->SetRequestContext(request_context);
- fetcher->SetUploadData("text/plain", form_xml);
+ fetcher->SetUploadData("text/xml", compressed_data);
fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
net::LOAD_DO_NOT_SEND_COOKIES);
- // Add Chrome experiment state to the request headers.
+ // Add Chrome experiment state and GZIP encoding to the request headers.
net::HttpRequestHeaders headers;
+ headers.SetHeaderIfMissing("content-encoding", "gzip");
variations::VariationsHttpHeaderProvider::GetInstance()->AppendHeaders(
fetcher->GetOriginalURL(), driver_->IsOffTheRecord(), false, &headers);
fetcher->SetExtraRequestHeaders(headers.ToString());
diff --git a/components/autofill/core/browser/autofill_download_manager.h b/components/autofill/core/browser/autofill_download_manager.h
index eaf7b49..e1c8b9f 100644
--- a/components/autofill/core/browser/autofill_download_manager.h
+++ b/components/autofill/core/browser/autofill_download_manager.h
@@ -91,6 +91,7 @@ class AutofillDownloadManager : public net::URLFetcherDelegate {
private:
friend class AutofillDownloadTest;
FRIEND_TEST_ALL_PREFIXES(AutofillDownloadTest, QueryAndUploadTest);
+ FRIEND_TEST_ALL_PREFIXES(AutofillDownloadTest, UploadRequestIsGzipped);
struct FormRequestData;
typedef std::list<std::pair<std::string, std::string> > QueryRequestCache;
diff --git a/components/autofill/core/browser/autofill_download_manager_unittest.cc b/components/autofill/core/browser/autofill_download_manager_unittest.cc
index b5ba01c..042aba1 100644
--- a/components/autofill/core/browser/autofill_download_manager_unittest.cc
+++ b/components/autofill/core/browser/autofill_download_manager_unittest.cc
@@ -20,6 +20,8 @@
#include "components/autofill/core/browser/form_structure.h"
#include "components/autofill/core/browser/test_autofill_driver.h"
#include "components/autofill/core/common/form_data.h"
+#include "components/compression/compression_utils.h"
+#include "net/http/http_request_headers.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "net/url_request/url_request_status.h"
#include "net/url_request/url_request_test_util.h"
@@ -45,6 +47,13 @@ void FakeOnURLFetchComplete(net::TestURLFetcher* fetcher,
fetcher->delegate()->OnURLFetchComplete(fetcher);
}
+// Compresses |data| and returns the result.
+std::string Compress(const std::string& data) {
+ std::string compressed_data;
+ EXPECT_TRUE(compression::GzipCompress(data, &compressed_data));
+ return compressed_data;
+}
+
} // namespace
// This tests AutofillDownloadManager. AutofillDownloadTest implements
@@ -548,4 +557,119 @@ TEST_F(AutofillDownloadTest, CacheQueryTest) {
EXPECT_EQ(responses[0], responses_.front().response);
}
+TEST_F(AutofillDownloadTest, QueryRequestIsGzipped) {
+ // Expected query (uncompressed for visual verification).
+ const char* kExpectedQueryXml =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<autofillquery clientversion=\"6.1.1715.1442/en (GGLL)\">"
+ "<form signature=\"14546501144368603154\">"
+ "<field signature=\"239111655\"/>"
+ "<field signature=\"3763331450\"/>"
+ "<field signature=\"3494530716\"/>"
+ "</form></autofillquery>";
+
+ // Create and register factory.
+ net::TestURLFetcherFactory factory;
+
+ FormData form;
+
+ FormFieldData field;
+ field.form_control_type = "text";
+
+ field.label = ASCIIToUTF16("username");
+ field.name = ASCIIToUTF16("username");
+ form.fields.push_back(field);
+
+ field.label = ASCIIToUTF16("First Name");
+ field.name = ASCIIToUTF16("firstname");
+ form.fields.push_back(field);
+
+ field.label = ASCIIToUTF16("Last Name");
+ field.name = ASCIIToUTF16("lastname");
+ form.fields.push_back(field);
+
+ FormStructure* form_structure = new FormStructure(form);
+ ScopedVector<FormStructure> form_structures;
+ form_structures.push_back(form_structure);
+
+ base::HistogramTester histogram;
+ // Request with id 0.
+ EXPECT_TRUE(download_manager_.StartQueryRequest(form_structures.get()));
+ histogram.ExpectUniqueSample("Autofill.ServerQueryResponse",
+ AutofillMetrics::QUERY_SENT, 1);
+
+ // Request payload is gzipped.
+ net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
+ ASSERT_TRUE(fetcher);
+ EXPECT_EQ(Compress(kExpectedQueryXml), fetcher->upload_data());
+
+ // Proper content-encoding header is defined.
+ net::HttpRequestHeaders headers;
+ fetcher->GetExtraRequestHeaders(&headers);
+ std::string header;
+ EXPECT_TRUE(headers.GetHeader("content-encoding", &header));
+ EXPECT_EQ("gzip", header);
+
+ // Expect that the compression is logged.
+ histogram.ExpectUniqueSample("Autofill.PayloadCompressionRatio.Query", 73, 1);
+}
+
+TEST_F(AutofillDownloadTest, UploadRequestIsGzipped) {
+ // Expected upload (uncompressed for visual verification).
+ const char* kExpectedUploadXml =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\""
+ " formsignature=\"14546501144368603154\" autofillused=\"true\""
+ " datapresent=\"\"/>";
+
+ // Create and register factory.
+ net::TestURLFetcherFactory factory;
+
+ FormData form;
+
+ FormFieldData field;
+ field.form_control_type = "text";
+
+ field.label = ASCIIToUTF16("username");
+ field.name = ASCIIToUTF16("username");
+ form.fields.push_back(field);
+
+ field.label = ASCIIToUTF16("First Name");
+ field.name = ASCIIToUTF16("firstname");
+ form.fields.push_back(field);
+
+ field.label = ASCIIToUTF16("Last Name");
+ field.name = ASCIIToUTF16("lastname");
+ form.fields.push_back(field);
+
+ FormStructure* form_structure = new FormStructure(form);
+ ScopedVector<FormStructure> form_structures;
+ form_structures.push_back(form_structure);
+
+ // Set upload to 100% so requests happen.
+ download_manager_.SetPositiveUploadRate(1.0);
+ download_manager_.SetNegativeUploadRate(1.0);
+
+ base::HistogramTester histogram;
+ // Request with id 0.
+ EXPECT_TRUE(download_manager_.StartUploadRequest(
+ *(form_structures[0]), true, ServerFieldTypeSet(), std::string()));
+
+ // Request payload is gzipped.
+ net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
+ ASSERT_TRUE(fetcher);
+ EXPECT_EQ(Compress(kExpectedUploadXml), fetcher->upload_data());
+
+ // Proper content-encoding header is defined.
+ net::HttpRequestHeaders headers;
+ fetcher->GetExtraRequestHeaders(&headers);
+ std::string header;
+ EXPECT_TRUE(headers.GetHeader("content-encoding", &header));
+ EXPECT_EQ("gzip", header);
+
+ // Expect that the compression is logged.
+ histogram.ExpectUniqueSample("Autofill.PayloadCompressionRatio.Upload", 92,
+ 1);
+}
+
} // namespace autofill
diff --git a/components/autofill/core/browser/autofill_metrics.cc b/components/autofill/core/browser/autofill_metrics.cc
index 8639612..e5a62fe 100644
--- a/components/autofill/core/browser/autofill_metrics.cc
+++ b/components/autofill/core/browser/autofill_metrics.cc
@@ -648,6 +648,22 @@ void AutofillMetrics::LogAutofillFormSubmittedState(
AUTOFILL_FORM_SUBMITTED_STATE_ENUM_SIZE);
}
+// static
+void AutofillMetrics::LogPayloadCompressionRatio(
+ int compression_ratio,
+ AutofillDownloadManager::RequestType type) {
+ switch (type) {
+ case AutofillDownloadManager::REQUEST_QUERY:
+ UMA_HISTOGRAM_PERCENTAGE("Autofill.PayloadCompressionRatio.Query",
+ compression_ratio);
+ break;
+ case AutofillDownloadManager::REQUEST_UPLOAD:
+ UMA_HISTOGRAM_PERCENTAGE("Autofill.PayloadCompressionRatio.Upload",
+ compression_ratio);
+ break;
+ }
+}
+
AutofillMetrics::FormEventLogger::FormEventLogger(bool is_for_credit_card)
: is_for_credit_card_(is_for_credit_card),
is_server_data_available_(false),
diff --git a/components/autofill/core/browser/autofill_metrics.h b/components/autofill/core/browser/autofill_metrics.h
index b806a72..f0b5f8d 100644
--- a/components/autofill/core/browser/autofill_metrics.h
+++ b/components/autofill/core/browser/autofill_metrics.h
@@ -10,6 +10,7 @@
#include "base/basictypes.h"
#include "components/autofill/core/browser/autofill_client.h"
+#include "components/autofill/core/browser/autofill_download_manager.h"
#include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/credit_card.h"
#include "components/autofill/core/browser/field_types.h"
@@ -591,6 +592,12 @@ class AutofillMetrics {
// state of the form.
static void LogAutofillFormSubmittedState(AutofillFormSubmittedState state);
+ // Log the compression ratio obtained by compressing with gzip. Logs for the
+ // query or upload request, depending on |type|.
+ static void LogPayloadCompressionRatio(
+ int compression_ratio,
+ AutofillDownloadManager::RequestType type);
+
// Utility to autofill form events in the relevant histograms depending on
// the presence of server and/or local data.
class FormEventLogger {