summaryrefslogtreecommitdiffstats
path: root/sync
diff options
context:
space:
mode:
authorgangwu <gangwu@chromium.org>2016-01-20 13:40:09 -0800
committerCommit bot <commit-bot@chromium.org>2016-01-20 21:41:13 +0000
commit790cc806fc0e7e1a8a52db624c87ca50750bb718 (patch)
tree3373c932e40abd4d5c78a036c509a5a36af2234c /sync
parentc322747e22e29321e4a573f8352b3a0459af17dd (diff)
downloadchromium_src-790cc806fc0e7e1a8a52db624c87ca50750bb718.zip
chromium_src-790cc806fc0e7e1a8a52db624c87ca50750bb718.tar.gz
chromium_src-790cc806fc0e7e1a8a52db624c87ca50750bb718.tar.bz2
Remove sync request compression.
BUG=509728,515695 Review URL: https://codereview.chromium.org/1605173002 Cr-Commit-Position: refs/heads/master@{#370498}
Diffstat (limited to 'sync')
-rw-r--r--sync/internal_api/http_bridge.cc98
-rw-r--r--sync/internal_api/http_bridge_unittest.cc109
2 files changed, 5 insertions, 202 deletions
diff --git a/sync/internal_api/http_bridge.cc b/sync/internal_api/http_bridge.cc
index b02ede8..2fbe40e 100644
--- a/sync/internal_api/http_bridge.cc
+++ b/sync/internal_api/http_bridge.cc
@@ -29,7 +29,6 @@
#include "net/url_request/url_request_job_factory_impl.h"
#include "net/url_request/url_request_status.h"
#include "sync/internal_api/public/base/cancelation_signal.h"
-#include "third_party/zlib/zlib.h"
namespace syncer {
@@ -68,87 +67,6 @@ void RecordSyncResponseContentLengthHistograms(
original_content_length);
}
-// -----------------------------------------------------------------------------
-// The rest of the code in the anon namespace is copied from
-// components/compression/compression_utils.cc
-// TODO(gangwu): crbug.com/515695. The following code is copied from
-// components/compression/compression_utils.cc. We copied them because if we
-// reference them, we will get cycle dependency warning. Once the functions
-// have been moved from //component to //base, we can remove the following
-// functions.
-//------------------------------------------------------------------------------
-// The difference in bytes between a zlib header and a gzip header.
-const size_t kGzipZlibHeaderDifferenceBytes = 16;
-
-// Pass an integer greater than the following get a gzip header instead of a
-// zlib header when calling deflateInit2() and inflateInit2().
-const int kWindowBitsToGetGzipHeader = 16;
-
-// This describes the amount of memory zlib uses to compress data. It can go
-// from 1 to 9, with 8 being the default. For details, see:
-// http://www.zlib.net/manual.html (search for memLevel).
-const int kZlibMemoryLevel = 8;
-
-// This code is taken almost verbatim from third_party/zlib/compress.c. The only
-// difference is deflateInit2() is called which sets the window bits to be > 16.
-// That causes a gzip header to be emitted rather than a zlib header.
-int GzipCompressHelper(Bytef* dest,
- uLongf* dest_length,
- const Bytef* source,
- uLong source_length) {
- z_stream stream;
-
- stream.next_in = bit_cast<Bytef*>(source);
- stream.avail_in = static_cast<uInt>(source_length);
- stream.next_out = dest;
- stream.avail_out = static_cast<uInt>(*dest_length);
- if (static_cast<uLong>(stream.avail_out) != *dest_length)
- return Z_BUF_ERROR;
-
- stream.zalloc = static_cast<alloc_func>(0);
- stream.zfree = static_cast<free_func>(0);
- stream.opaque = static_cast<voidpf>(0);
-
- gz_header gzip_header;
- memset(&gzip_header, 0, sizeof(gzip_header));
- int err = deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
- MAX_WBITS + kWindowBitsToGetGzipHeader,
- kZlibMemoryLevel, Z_DEFAULT_STRATEGY);
- if (err != Z_OK)
- return err;
-
- err = deflateSetHeader(&stream, &gzip_header);
- if (err != Z_OK)
- return err;
-
- err = deflate(&stream, Z_FINISH);
- if (err != Z_STREAM_END) {
- deflateEnd(&stream);
- return err == Z_OK ? Z_BUF_ERROR : err;
- }
- *dest_length = stream.total_out;
-
- err = deflateEnd(&stream);
- return err;
-}
-
-bool GzipCompress(const std::string& input, std::string* output) {
- const uLongf input_size = static_cast<uLongf>(input.size());
- std::vector<Bytef> compressed_data(kGzipZlibHeaderDifferenceBytes +
- compressBound(input_size));
-
- uLongf compressed_size = static_cast<uLongf>(compressed_data.size());
- if (GzipCompressHelper(&compressed_data.front(), &compressed_size,
- bit_cast<const Bytef*>(input.data()),
- input_size) != Z_OK) {
- return false;
- }
-
- compressed_data.resize(compressed_size);
- output->assign(compressed_data.begin(), compressed_data.end());
- return true;
-}
-
} // namespace
HttpBridgeFactory::HttpBridgeFactory(
@@ -331,21 +249,15 @@ void HttpBridge::MakeAsynchronousPost() {
fetch_state_.url_poster->SetRequestContext(request_context_getter_.get());
fetch_state_.url_poster->SetExtraRequestHeaders(extra_headers_);
- int64_t compressed_content_size = 0;
- if (IsSyncHttpContentCompressionEnabled()) {
- std::string compressed_request_content;
- GzipCompress(request_content_, &compressed_request_content);
- compressed_content_size = compressed_request_content.size();
- fetch_state_.url_poster->SetUploadData(content_type_,
- compressed_request_content);
- fetch_state_.url_poster->AddExtraRequestHeader("Content-Encoding: gzip");
- } else {
- fetch_state_.url_poster->SetUploadData(content_type_, request_content_);
+ if (!IsSyncHttpContentCompressionEnabled()) {
+ // We set "accept-encoding" here to avoid URLRequestHttpJob adding "gzip"
+ // into "accept-encoding" later.
fetch_state_.url_poster->AddExtraRequestHeader(base::StringPrintf(
"%s: %s", net::HttpRequestHeaders::kAcceptEncoding, "deflate"));
}
- RecordSyncRequestContentLengthHistograms(compressed_content_size,
+ fetch_state_.url_poster->SetUploadData(content_type_, request_content_);
+ RecordSyncRequestContentLengthHistograms(request_content_.size(),
request_content_.size());
fetch_state_.url_poster->AddExtraRequestHeader(base::StringPrintf(
diff --git a/sync/internal_api/http_bridge_unittest.cc b/sync/internal_api/http_bridge_unittest.cc
index 206adcb..1c83634 100644
--- a/sync/internal_api/http_bridge_unittest.cc
+++ b/sync/internal_api/http_bridge_unittest.cc
@@ -31,83 +31,6 @@ namespace {
const base::FilePath::CharType kDocRoot[] =
FILE_PATH_LITERAL("chrome/test/data");
-// -----------------------------------------------------------------------------
-// The rest of the code in the anon namespace is copied from
-// components/compression/compression_utils.cc
-// TODO(gangwu): crbug.com/515695. The following codes are copied from
-// components/compression/compression_utils.cc, we copied them because if we
-// reference them, we will get cycle dependency warning. Once the functions
-// have been moved from //component to //base, we can remove the following
-// functions.
-//------------------------------------------------------------------------------
-// Pass an integer greater than the following get a gzip header instead of a
-// zlib header when calling deflateInit2() and inflateInit2().
-const int kWindowBitsToGetGzipHeader = 16;
-
-// This code is taken almost verbatim from third_party/zlib/uncompr.c. The only
-// difference is inflateInit2() is called which sets the window bits to be > 16.
-// That causes a gzip header to be parsed rather than a zlib header.
-int GzipUncompressHelper(Bytef* dest,
- uLongf* dest_length,
- const Bytef* source,
- uLong source_length) {
- z_stream stream;
-
- stream.next_in = bit_cast<Bytef*>(source);
- stream.avail_in = static_cast<uInt>(source_length);
- if (static_cast<uLong>(stream.avail_in) != source_length)
- return Z_BUF_ERROR;
-
- stream.next_out = dest;
- stream.avail_out = static_cast<uInt>(*dest_length);
- if (static_cast<uLong>(stream.avail_out) != *dest_length)
- return Z_BUF_ERROR;
-
- stream.zalloc = static_cast<alloc_func>(0);
- stream.zfree = static_cast<free_func>(0);
-
- int err = inflateInit2(&stream, MAX_WBITS + kWindowBitsToGetGzipHeader);
- if (err != Z_OK)
- return err;
-
- err = inflate(&stream, Z_FINISH);
- if (err != Z_STREAM_END) {
- inflateEnd(&stream);
- if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
- return Z_DATA_ERROR;
- return err;
- }
- *dest_length = stream.total_out;
-
- err = inflateEnd(&stream);
- return err;
-}
-
-// Returns the uncompressed size from GZIP-compressed |compressed_data|.
-uint32_t GetUncompressedSize(const std::string& compressed_data) {
- // The uncompressed size is stored in the last 4 bytes of |input| in LE.
- uint32_t size;
- if (compressed_data.length() < sizeof(size))
- return 0;
- memcpy(&size, &compressed_data[compressed_data.length() - sizeof(size)],
- sizeof(size));
- return base::ByteSwapToLE32(size);
-}
-
-bool GzipUncompress(const std::string& input, std::string* output) {
- std::string uncompressed_output;
- uLongf uncompressed_size = static_cast<uLongf>(GetUncompressedSize(input));
- uncompressed_output.resize(uncompressed_size);
- if (GzipUncompressHelper(bit_cast<Bytef*>(uncompressed_output.data()),
- &uncompressed_size,
- bit_cast<const Bytef*>(input.data()),
- static_cast<uLongf>(input.length())) == Z_OK) {
- output->swap(uncompressed_output);
- return true;
- }
- return false;
-}
-
} // namespace
const char kUserAgent[] = "user-agent";
@@ -330,37 +253,6 @@ TEST_F(MAYBE_SyncHttpBridgeTest, TestMakeSynchronousPostLiveWithPayload) {
EXPECT_EQ(payload, std::string(http_bridge->GetResponseContent()));
}
-// Full round-trip test of the HttpBridge with compressed data, check if the
-// data is correctly compressed.
-TEST_F(MAYBE_SyncHttpBridgeTest, CompressedRequestPayloadCheck) {
- ASSERT_TRUE(test_server_.Start());
-
- scoped_refptr<HttpBridge> http_bridge(BuildBridge());
-
- std::string payload = "this should be echoed back";
- GURL echo = test_server_.GetURL("/echo");
- http_bridge->SetURL(echo.spec().c_str(), echo.IntPort());
- http_bridge->SetPostPayload("application/x-www-form-urlencoded",
- payload.length(), payload.c_str());
- int os_error = 0;
- int response_code = 0;
- base::FieldTrialList field_trial_list(new base::MockEntropyProvider());
- base::FieldTrialList::CreateFieldTrial("SyncHttpContentCompression",
- "Enabled");
- bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code);
- EXPECT_TRUE(success);
- EXPECT_EQ(200, response_code);
- EXPECT_EQ(0, os_error);
-
- EXPECT_NE(payload.length() + 1,
- static_cast<size_t>(http_bridge->GetResponseContentLength()));
- std::string compressed_payload(http_bridge->GetResponseContent(),
- http_bridge->GetResponseContentLength());
- std::string uncompressed_payload;
- GzipUncompress(compressed_payload, &uncompressed_payload);
- EXPECT_EQ(payload, uncompressed_payload);
-}
-
// Full round-trip test of the HttpBridge with compression, check if header
// fields("Content-Encoding" ,"Accept-Encoding" and user agent) are set
// correctly.
@@ -388,7 +280,6 @@ TEST_F(MAYBE_SyncHttpBridgeTest, CompressedRequestHeaderCheck) {
std::string response(http_bridge->GetResponseContent(),
http_bridge->GetResponseContentLength());
- EXPECT_NE(std::string::npos, response.find("Content-Encoding: gzip"));
EXPECT_NE(std::string::npos,
response.find(base::StringPrintf(
"%s: %s", net::HttpRequestHeaders::kAcceptEncoding,