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

Side by Side Diff: components/sync/engine/net/http_bridge.cc

Issue 2380143002: [Sync] Enable Compression from Client to Server by experiment (Closed)
Patch Set: rebase Created 4 years, 2 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/sync/engine/net/http_bridge.h" 5 #include "components/sync/engine/net/http_bridge.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 10 matching lines...) Expand all
21 #include "net/base/load_flags.h" 21 #include "net/base/load_flags.h"
22 #include "net/base/net_errors.h" 22 #include "net/base/net_errors.h"
23 #include "net/http/http_cache.h" 23 #include "net/http/http_cache.h"
24 #include "net/http/http_network_layer.h" 24 #include "net/http/http_network_layer.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/url_request/static_http_user_agent_settings.h" 27 #include "net/url_request/static_http_user_agent_settings.h"
28 #include "net/url_request/url_fetcher.h" 28 #include "net/url_request/url_fetcher.h"
29 #include "net/url_request/url_request_job_factory_impl.h" 29 #include "net/url_request/url_request_job_factory_impl.h"
30 #include "net/url_request/url_request_status.h" 30 #include "net/url_request/url_request_status.h"
31 #include "third_party/zlib/google/compression_utils.h"
31 32
32 namespace syncer { 33 namespace syncer {
33 34
34 namespace { 35 namespace {
35 36
36 // It's possible for an http request to be silently stalled. We set a time 37 // It's possible for an http request to be silently stalled. We set a time
37 // limit for all http requests, beyond which the request is cancelled and 38 // limit for all http requests, beyond which the request is cancelled and
38 // treated as a transient failure. 39 // treated as a transient failure.
39 const int kMaxHttpRequestTimeSeconds = 60 * 5; // 5 minutes. 40 const int kMaxHttpRequestTimeSeconds = 60 * 5; // 5 minutes.
40 41
(...skipping 14 matching lines...) Expand all
55 int64_t compressed_content_length, 56 int64_t compressed_content_length,
56 int64_t original_content_length) { 57 int64_t original_content_length) {
57 UMA_HISTOGRAM_COUNTS("Sync.ResponseContentLength.Compressed", 58 UMA_HISTOGRAM_COUNTS("Sync.ResponseContentLength.Compressed",
58 compressed_content_length); 59 compressed_content_length);
59 UMA_HISTOGRAM_COUNTS("Sync.ResponseContentLength.Original", 60 UMA_HISTOGRAM_COUNTS("Sync.ResponseContentLength.Original",
60 original_content_length); 61 original_content_length);
61 } 62 }
62 63
63 } // namespace 64 } // namespace
64 65
66 // Enables compression of messages from client to server.
67 const base::Feature kSyncClientToServerCompression{
68 "EnableSyncClientToServerCompression", base::FEATURE_DISABLED_BY_DEFAULT};
69
65 HttpBridgeFactory::HttpBridgeFactory( 70 HttpBridgeFactory::HttpBridgeFactory(
66 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, 71 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
67 const NetworkTimeUpdateCallback& network_time_update_callback, 72 const NetworkTimeUpdateCallback& network_time_update_callback,
68 CancelationSignal* cancelation_signal) 73 CancelationSignal* cancelation_signal)
69 : request_context_getter_(request_context_getter), 74 : request_context_getter_(request_context_getter),
70 network_time_update_callback_(network_time_update_callback), 75 network_time_update_callback_(network_time_update_callback),
71 cancelation_signal_(cancelation_signal) { 76 cancelation_signal_(cancelation_signal) {
72 // Registration should never fail. This should happen on the UI thread during 77 // Registration should never fail. This should happen on the UI thread during
73 // init. It would be impossible for a shutdown to have been requested at this 78 // init. It would be impossible for a shutdown to have been requested at this
74 // point. 79 // point.
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 DCHECK(request_context_getter_.get()); 238 DCHECK(request_context_getter_.get());
234 fetch_state_.start_time = base::Time::Now(); 239 fetch_state_.start_time = base::Time::Now();
235 fetch_state_.url_poster = 240 fetch_state_.url_poster =
236 net::URLFetcher::Create(url_for_request_, net::URLFetcher::POST, this) 241 net::URLFetcher::Create(url_for_request_, net::URLFetcher::POST, this)
237 .release(); 242 .release();
238 if (!bind_to_tracker_callback_.is_null()) 243 if (!bind_to_tracker_callback_.is_null())
239 bind_to_tracker_callback_.Run(fetch_state_.url_poster); 244 bind_to_tracker_callback_.Run(fetch_state_.url_poster);
240 fetch_state_.url_poster->SetRequestContext(request_context_getter_.get()); 245 fetch_state_.url_poster->SetRequestContext(request_context_getter_.get());
241 fetch_state_.url_poster->SetExtraRequestHeaders(extra_headers_); 246 fetch_state_.url_poster->SetExtraRequestHeaders(extra_headers_);
242 247
243 fetch_state_.url_poster->SetUploadData(content_type_, request_content_); 248 std::string request_to_send;
244 RecordSyncRequestContentLengthHistograms(request_content_.size(), 249 if (base::FeatureList::IsEnabled(kSyncClientToServerCompression)) {
250 compression::GzipCompress(request_content_, &request_to_send);
251 fetch_state_.url_poster->AddExtraRequestHeader("Content-Encoding: gzip");
252 } else {
253 request_to_send = request_content_;
254 }
255 fetch_state_.url_poster->SetUploadData(content_type_, request_to_send);
256 RecordSyncRequestContentLengthHistograms(request_to_send.size(),
245 request_content_.size()); 257 request_content_.size());
246 258
247 fetch_state_.url_poster->AddExtraRequestHeader(base::StringPrintf( 259 fetch_state_.url_poster->AddExtraRequestHeader(base::StringPrintf(
248 "%s: %s", net::HttpRequestHeaders::kUserAgent, user_agent_.c_str())); 260 "%s: %s", net::HttpRequestHeaders::kUserAgent, user_agent_.c_str()));
249 fetch_state_.url_poster->SetLoadFlags( 261 fetch_state_.url_poster->SetLoadFlags(
250 net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE | 262 net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE |
251 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES); 263 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES);
252 264
253 fetch_state_.url_poster->Start(); 265 fetch_state_.url_poster->Start();
254 } 266 }
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 int64_t sane_time_ms = 0; 449 int64_t sane_time_ms = 0;
438 if (base::StringToInt64(sane_time_str, &sane_time_ms)) { 450 if (base::StringToInt64(sane_time_str, &sane_time_ms)) {
439 network_time_update_callback_.Run( 451 network_time_update_callback_.Run(
440 base::Time::FromJsTime(sane_time_ms), 452 base::Time::FromJsTime(sane_time_ms),
441 base::TimeDelta::FromMilliseconds(1), 453 base::TimeDelta::FromMilliseconds(1),
442 fetch_state_.end_time - fetch_state_.start_time); 454 fetch_state_.end_time - fetch_state_.start_time);
443 } 455 }
444 } 456 }
445 457
446 } // namespace syncer 458 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698