OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "net/url_request/url_request_throttler_entry.h" | 5 #include "net/url_request/url_request_throttler_entry.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 const double URLRequestThrottlerEntry::kDefaultMultiplyFactor = 1.4; | 45 const double URLRequestThrottlerEntry::kDefaultMultiplyFactor = 1.4; |
46 const double URLRequestThrottlerEntry::kDefaultJitterFactor = 0.4; | 46 const double URLRequestThrottlerEntry::kDefaultJitterFactor = 0.4; |
47 const int URLRequestThrottlerEntry::kDefaultMaximumBackoffMs = 15 * 60 * 1000; | 47 const int URLRequestThrottlerEntry::kDefaultMaximumBackoffMs = 15 * 60 * 1000; |
48 const int URLRequestThrottlerEntry::kDefaultEntryLifetimeMs = 2 * 60 * 1000; | 48 const int URLRequestThrottlerEntry::kDefaultEntryLifetimeMs = 2 * 60 * 1000; |
49 const char URLRequestThrottlerEntry::kExponentialThrottlingHeader[] = | 49 const char URLRequestThrottlerEntry::kExponentialThrottlingHeader[] = |
50 "X-Chrome-Exponential-Throttling"; | 50 "X-Chrome-Exponential-Throttling"; |
51 const char URLRequestThrottlerEntry::kExponentialThrottlingDisableValue[] = | 51 const char URLRequestThrottlerEntry::kExponentialThrottlingDisableValue[] = |
52 "disable"; | 52 "disable"; |
53 | 53 |
54 // Returns NetLog parameters when a request is rejected by throttling. | 54 // Returns NetLog parameters when a request is rejected by throttling. |
55 base::Value* NetLogRejectedRequestCallback( | 55 scoped_ptr<base::Value> NetLogRejectedRequestCallback( |
56 const std::string* url_id, | 56 const std::string* url_id, |
57 int num_failures, | 57 int num_failures, |
58 const base::TimeDelta& release_after, | 58 const base::TimeDelta& release_after, |
59 NetLogCaptureMode /* capture_mode */) { | 59 NetLogCaptureMode /* capture_mode */) { |
60 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 60 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
61 dict->SetString("url", *url_id); | 61 dict->SetString("url", *url_id); |
62 dict->SetInteger("num_failures", num_failures); | 62 dict->SetInteger("num_failures", num_failures); |
63 dict->SetInteger("release_after_ms", | 63 dict->SetInteger("release_after_ms", |
64 static_cast<int>(release_after.InMilliseconds())); | 64 static_cast<int>(release_after.InMilliseconds())); |
65 return dict.release(); | 65 return dict.Pass(); |
66 } | 66 } |
67 | 67 |
68 URLRequestThrottlerEntry::URLRequestThrottlerEntry( | 68 URLRequestThrottlerEntry::URLRequestThrottlerEntry( |
69 URLRequestThrottlerManager* manager, | 69 URLRequestThrottlerManager* manager, |
70 const std::string& url_id) | 70 const std::string& url_id) |
71 : sliding_window_period_( | 71 : sliding_window_period_( |
72 base::TimeDelta::FromMilliseconds(kDefaultSlidingWindowPeriodMs)), | 72 base::TimeDelta::FromMilliseconds(kDefaultSlidingWindowPeriodMs)), |
73 max_send_threshold_(kDefaultMaxSendThreshold), | 73 max_send_threshold_(kDefaultMaxSendThreshold), |
74 is_backoff_disabled_(false), | 74 is_backoff_disabled_(false), |
75 backoff_entry_(&backoff_policy_), | 75 backoff_entry_(&backoff_policy_), |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 manager_ = NULL; | 151 manager_ = NULL; |
152 } | 152 } |
153 | 153 |
154 bool URLRequestThrottlerEntry::ShouldRejectRequest( | 154 bool URLRequestThrottlerEntry::ShouldRejectRequest( |
155 const URLRequest& request, | 155 const URLRequest& request, |
156 NetworkDelegate* network_delegate) const { | 156 NetworkDelegate* network_delegate) const { |
157 bool reject_request = false; | 157 bool reject_request = false; |
158 if (!is_backoff_disabled_ && !ExplicitUserRequest(request.load_flags()) && | 158 if (!is_backoff_disabled_ && !ExplicitUserRequest(request.load_flags()) && |
159 (!network_delegate || network_delegate->CanThrottleRequest(request)) && | 159 (!network_delegate || network_delegate->CanThrottleRequest(request)) && |
160 GetBackoffEntry()->ShouldRejectRequest()) { | 160 GetBackoffEntry()->ShouldRejectRequest()) { |
161 net_log_.AddEvent( | 161 net_log_.AddEvent(NetLog::TYPE_THROTTLING_REJECTED_REQUEST, |
162 NetLog::TYPE_THROTTLING_REJECTED_REQUEST, | 162 base::Bind(NetLogRejectedRequestCallback, &url_id_, |
163 base::Bind(&NetLogRejectedRequestCallback, | 163 GetBackoffEntry()->failure_count(), |
164 &url_id_, | 164 GetBackoffEntry()->GetTimeUntilRelease())); |
165 GetBackoffEntry()->failure_count(), | |
166 GetBackoffEntry()->GetTimeUntilRelease())); | |
167 reject_request = true; | 165 reject_request = true; |
168 } | 166 } |
169 | 167 |
170 int reject_count = reject_request ? 1 : 0; | 168 int reject_count = reject_request ? 1 : 0; |
171 UMA_HISTOGRAM_ENUMERATION( | 169 UMA_HISTOGRAM_ENUMERATION( |
172 "Throttling.RequestThrottled", reject_count, 2); | 170 "Throttling.RequestThrottled", reject_count, 2); |
173 | 171 |
174 return reject_request; | 172 return reject_request; |
175 } | 173 } |
176 | 174 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 BackoffEntry* URLRequestThrottlerEntry::GetBackoffEntry() { | 309 BackoffEntry* URLRequestThrottlerEntry::GetBackoffEntry() { |
312 return &backoff_entry_; | 310 return &backoff_entry_; |
313 } | 311 } |
314 | 312 |
315 // static | 313 // static |
316 bool URLRequestThrottlerEntry::ExplicitUserRequest(const int load_flags) { | 314 bool URLRequestThrottlerEntry::ExplicitUserRequest(const int load_flags) { |
317 return (load_flags & LOAD_MAYBE_USER_GESTURE) != 0; | 315 return (load_flags & LOAD_MAYBE_USER_GESTURE) != 0; |
318 } | 316 } |
319 | 317 |
320 } // namespace net | 318 } // namespace net |
OLD | NEW |