| OLD | NEW |
| 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 |
| 11 #include "base/bit_cast.h" | 11 #include "base/bit_cast.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/metrics/sparse_histogram.h" | 14 #include "base/metrics/sparse_histogram.h" |
| 15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "components/sync/base/cancelation_signal.h" | 19 #include "components/sync/base/cancelation_signal.h" |
| 20 #include "net/base/load_flags.h" | 20 #include "net/base/load_flags.h" |
| 21 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
| 22 #include "net/http/http_cache.h" | 22 #include "net/http/http_cache.h" |
| 23 #include "net/http/http_network_layer.h" | 23 #include "net/http/http_network_layer.h" |
| 24 #include "net/http/http_request_headers.h" | 24 #include "net/http/http_request_headers.h" |
| 25 #include "net/http/http_response_headers.h" | 25 #include "net/http/http_response_headers.h" |
| 26 #include "net/url_request/static_http_user_agent_settings.h" | 26 #include "net/url_request/static_http_user_agent_settings.h" |
| 27 #include "net/url_request/url_fetcher.h" | 27 #include "net/url_request/url_fetcher.h" |
| 28 #include "net/url_request/url_request_job_factory_impl.h" | 28 #include "net/url_request/url_request_job_factory_impl.h" |
| 29 #include "net/url_request/url_request_status.h" | 29 #include "net/url_request/url_request_status.h" |
| 30 #include "third_party/zlib/google/compression_utils.h" |
| 30 | 31 |
| 31 namespace syncer { | 32 namespace syncer { |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 // It's possible for an http request to be silently stalled. We set a time | 36 // It's possible for an http request to be silently stalled. We set a time |
| 36 // limit for all http requests, beyond which the request is cancelled and | 37 // limit for all http requests, beyond which the request is cancelled and |
| 37 // treated as a transient failure. | 38 // treated as a transient failure. |
| 38 const int kMaxHttpRequestTimeSeconds = 60 * 5; // 5 minutes. | 39 const int kMaxHttpRequestTimeSeconds = 60 * 5; // 5 minutes. |
| 39 | 40 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 54 int64_t compressed_content_length, | 55 int64_t compressed_content_length, |
| 55 int64_t original_content_length) { | 56 int64_t original_content_length) { |
| 56 UMA_HISTOGRAM_COUNTS("Sync.ResponseContentLength.Compressed", | 57 UMA_HISTOGRAM_COUNTS("Sync.ResponseContentLength.Compressed", |
| 57 compressed_content_length); | 58 compressed_content_length); |
| 58 UMA_HISTOGRAM_COUNTS("Sync.ResponseContentLength.Original", | 59 UMA_HISTOGRAM_COUNTS("Sync.ResponseContentLength.Original", |
| 59 original_content_length); | 60 original_content_length); |
| 60 } | 61 } |
| 61 | 62 |
| 62 } // namespace | 63 } // namespace |
| 63 | 64 |
| 65 // Enables compression of messages from client to server. |
| 66 const base::Feature kSyncClientToServerCompression{ |
| 67 "EnableSyncClientToServerCompression", base::FEATURE_DISABLED_BY_DEFAULT}; |
| 68 |
| 64 HttpBridgeFactory::HttpBridgeFactory( | 69 HttpBridgeFactory::HttpBridgeFactory( |
| 65 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, | 70 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, |
| 66 const NetworkTimeUpdateCallback& network_time_update_callback, | 71 const NetworkTimeUpdateCallback& network_time_update_callback, |
| 67 CancelationSignal* cancelation_signal) | 72 CancelationSignal* cancelation_signal) |
| 68 : request_context_getter_(request_context_getter), | 73 : request_context_getter_(request_context_getter), |
| 69 network_time_update_callback_(network_time_update_callback), | 74 network_time_update_callback_(network_time_update_callback), |
| 70 cancelation_signal_(cancelation_signal) { | 75 cancelation_signal_(cancelation_signal) { |
| 71 // Registration should never fail. This should happen on the UI thread during | 76 // Registration should never fail. This should happen on the UI thread during |
| 72 // init. It would be impossible for a shutdown to have been requested at this | 77 // init. It would be impossible for a shutdown to have been requested at this |
| 73 // point. | 78 // point. |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 DCHECK(request_context_getter_.get()); | 236 DCHECK(request_context_getter_.get()); |
| 232 fetch_state_.start_time = base::Time::Now(); | 237 fetch_state_.start_time = base::Time::Now(); |
| 233 fetch_state_.url_poster = | 238 fetch_state_.url_poster = |
| 234 net::URLFetcher::Create(url_for_request_, net::URLFetcher::POST, this) | 239 net::URLFetcher::Create(url_for_request_, net::URLFetcher::POST, this) |
| 235 .release(); | 240 .release(); |
| 236 if (!bind_to_tracker_callback_.is_null()) | 241 if (!bind_to_tracker_callback_.is_null()) |
| 237 bind_to_tracker_callback_.Run(fetch_state_.url_poster); | 242 bind_to_tracker_callback_.Run(fetch_state_.url_poster); |
| 238 fetch_state_.url_poster->SetRequestContext(request_context_getter_.get()); | 243 fetch_state_.url_poster->SetRequestContext(request_context_getter_.get()); |
| 239 fetch_state_.url_poster->SetExtraRequestHeaders(extra_headers_); | 244 fetch_state_.url_poster->SetExtraRequestHeaders(extra_headers_); |
| 240 | 245 |
| 241 fetch_state_.url_poster->SetUploadData(content_type_, request_content_); | 246 std::string request_to_send; |
| 242 RecordSyncRequestContentLengthHistograms(request_content_.size(), | 247 if (base::FeatureList::IsEnabled(kSyncClientToServerCompression)) { |
| 248 compression::GzipCompress(request_content_, &request_to_send); |
| 249 fetch_state_.url_poster->AddExtraRequestHeader("Content-Encoding: gzip"); |
| 250 } else { |
| 251 request_to_send = request_content_; |
| 252 } |
| 253 fetch_state_.url_poster->SetUploadData(content_type_, request_to_send); |
| 254 RecordSyncRequestContentLengthHistograms(request_to_send.size(), |
| 243 request_content_.size()); | 255 request_content_.size()); |
| 244 | 256 |
| 245 fetch_state_.url_poster->AddExtraRequestHeader(base::StringPrintf( | 257 fetch_state_.url_poster->AddExtraRequestHeader(base::StringPrintf( |
| 246 "%s: %s", net::HttpRequestHeaders::kUserAgent, user_agent_.c_str())); | 258 "%s: %s", net::HttpRequestHeaders::kUserAgent, user_agent_.c_str())); |
| 247 fetch_state_.url_poster->SetLoadFlags( | 259 fetch_state_.url_poster->SetLoadFlags( |
| 248 net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE | | 260 net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE | |
| 249 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES); | 261 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES); |
| 250 | 262 |
| 251 fetch_state_.url_poster->Start(); | 263 fetch_state_.url_poster->Start(); |
| 252 } | 264 } |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 int64_t sane_time_ms = 0; | 447 int64_t sane_time_ms = 0; |
| 436 if (base::StringToInt64(sane_time_str, &sane_time_ms)) { | 448 if (base::StringToInt64(sane_time_str, &sane_time_ms)) { |
| 437 network_time_update_callback_.Run( | 449 network_time_update_callback_.Run( |
| 438 base::Time::FromJsTime(sane_time_ms), | 450 base::Time::FromJsTime(sane_time_ms), |
| 439 base::TimeDelta::FromMilliseconds(1), | 451 base::TimeDelta::FromMilliseconds(1), |
| 440 fetch_state_.end_time - fetch_state_.start_time); | 452 fetch_state_.end_time - fetch_state_.start_time); |
| 441 } | 453 } |
| 442 } | 454 } |
| 443 | 455 |
| 444 } // namespace syncer | 456 } // namespace syncer |
| OLD | NEW |