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 "sync/internal_api/public/http_bridge.h" | 5 #include "sync/internal_api/public/http_bridge.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/bit_cast.h" | 12 #include "base/bit_cast.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
Nicolas Zea
2016/06/08 19:54:22
nit: remove?
Gang Wu
2016/06/08 22:23:26
Done.
| |
16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
17 #include "base/metrics/sparse_histogram.h" | 17 #include "base/metrics/sparse_histogram.h" |
18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
22 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
23 #include "net/base/load_flags.h" | 23 #include "net/base/load_flags.h" |
24 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
25 #include "net/http/http_cache.h" | 25 #include "net/http/http_cache.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
40 // It's possible for an http request to be silently stalled. We set a time | 40 // It's possible for an http request to be silently stalled. We set a time |
41 // limit for all http requests, beyond which the request is cancelled and | 41 // limit for all http requests, beyond which the request is cancelled and |
42 // treated as a transient failure. | 42 // treated as a transient failure. |
43 const int kMaxHttpRequestTimeSeconds = 60 * 5; // 5 minutes. | 43 const int kMaxHttpRequestTimeSeconds = 60 * 5; // 5 minutes. |
44 | 44 |
45 // Helper method for logging timeouts via UMA. | 45 // Helper method for logging timeouts via UMA. |
46 void LogTimeout(bool timed_out) { | 46 void LogTimeout(bool timed_out) { |
47 UMA_HISTOGRAM_BOOLEAN("Sync.URLFetchTimedOut", timed_out); | 47 UMA_HISTOGRAM_BOOLEAN("Sync.URLFetchTimedOut", timed_out); |
48 } | 48 } |
49 | 49 |
50 bool IsSyncHttpContentCompressionEnabled() { | |
51 const std::string group_name = | |
52 base::FieldTrialList::FindFullName("SyncHttpContentCompression"); | |
53 return StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE); | |
54 } | |
55 | |
56 void RecordSyncRequestContentLengthHistograms(int64_t compressed_content_length, | 50 void RecordSyncRequestContentLengthHistograms(int64_t compressed_content_length, |
57 int64_t original_content_length) { | 51 int64_t original_content_length) { |
58 UMA_HISTOGRAM_COUNTS("Sync.RequestContentLength.Compressed", | 52 UMA_HISTOGRAM_COUNTS("Sync.RequestContentLength.Compressed", |
59 compressed_content_length); | 53 compressed_content_length); |
60 UMA_HISTOGRAM_COUNTS("Sync.RequestContentLength.Original", | 54 UMA_HISTOGRAM_COUNTS("Sync.RequestContentLength.Original", |
61 original_content_length); | 55 original_content_length); |
62 } | 56 } |
63 | 57 |
64 void RecordSyncResponseContentLengthHistograms( | 58 void RecordSyncResponseContentLengthHistograms( |
65 int64_t compressed_content_length, | 59 int64_t compressed_content_length, |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 DCHECK(request_context_getter_.get()); | 240 DCHECK(request_context_getter_.get()); |
247 fetch_state_.start_time = base::Time::Now(); | 241 fetch_state_.start_time = base::Time::Now(); |
248 fetch_state_.url_poster = | 242 fetch_state_.url_poster = |
249 net::URLFetcher::Create(url_for_request_, net::URLFetcher::POST, this) | 243 net::URLFetcher::Create(url_for_request_, net::URLFetcher::POST, this) |
250 .release(); | 244 .release(); |
251 if (!bind_to_tracker_callback_.is_null()) | 245 if (!bind_to_tracker_callback_.is_null()) |
252 bind_to_tracker_callback_.Run(fetch_state_.url_poster); | 246 bind_to_tracker_callback_.Run(fetch_state_.url_poster); |
253 fetch_state_.url_poster->SetRequestContext(request_context_getter_.get()); | 247 fetch_state_.url_poster->SetRequestContext(request_context_getter_.get()); |
254 fetch_state_.url_poster->SetExtraRequestHeaders(extra_headers_); | 248 fetch_state_.url_poster->SetExtraRequestHeaders(extra_headers_); |
255 | 249 |
256 if (!IsSyncHttpContentCompressionEnabled()) { | |
257 // We set "accept-encoding" here to avoid URLRequestHttpJob adding "gzip" | |
258 // into "accept-encoding" later. | |
259 fetch_state_.url_poster->AddExtraRequestHeader(base::StringPrintf( | |
260 "%s: %s", net::HttpRequestHeaders::kAcceptEncoding, "deflate")); | |
261 } | |
262 | |
263 fetch_state_.url_poster->SetUploadData(content_type_, request_content_); | 250 fetch_state_.url_poster->SetUploadData(content_type_, request_content_); |
264 RecordSyncRequestContentLengthHistograms(request_content_.size(), | 251 RecordSyncRequestContentLengthHistograms(request_content_.size(), |
265 request_content_.size()); | 252 request_content_.size()); |
266 | 253 |
267 fetch_state_.url_poster->AddExtraRequestHeader(base::StringPrintf( | 254 fetch_state_.url_poster->AddExtraRequestHeader(base::StringPrintf( |
268 "%s: %s", net::HttpRequestHeaders::kUserAgent, user_agent_.c_str())); | 255 "%s: %s", net::HttpRequestHeaders::kUserAgent, user_agent_.c_str())); |
269 fetch_state_.url_poster->SetLoadFlags(net::LOAD_BYPASS_CACHE | | 256 fetch_state_.url_poster->SetLoadFlags(net::LOAD_BYPASS_CACHE | |
270 net::LOAD_DISABLE_CACHE | | 257 net::LOAD_DISABLE_CACHE | |
271 net::LOAD_DO_NOT_SAVE_COOKIES | | 258 net::LOAD_DO_NOT_SAVE_COOKIES | |
272 net::LOAD_DO_NOT_SEND_COOKIES); | 259 net::LOAD_DO_NOT_SEND_COOKIES); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
459 int64_t sane_time_ms = 0; | 446 int64_t sane_time_ms = 0; |
460 if (base::StringToInt64(sane_time_str, &sane_time_ms)) { | 447 if (base::StringToInt64(sane_time_str, &sane_time_ms)) { |
461 network_time_update_callback_.Run( | 448 network_time_update_callback_.Run( |
462 base::Time::FromJsTime(sane_time_ms), | 449 base::Time::FromJsTime(sane_time_ms), |
463 base::TimeDelta::FromMilliseconds(1), | 450 base::TimeDelta::FromMilliseconds(1), |
464 fetch_state_.end_time - fetch_state_.start_time); | 451 fetch_state_.end_time - fetch_state_.start_time); |
465 } | 452 } |
466 } | 453 } |
467 | 454 |
468 } // namespace syncer | 455 } // namespace syncer |
OLD | NEW |