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 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "net/base/load_flags.h" | 16 #include "net/base/load_flags.h" |
17 #include "net/log/net_log.h" | 17 #include "net/log/net_log.h" |
| 18 #include "net/log/net_log_event_type.h" |
| 19 #include "net/log/net_log_source_type.h" |
18 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
19 #include "net/url_request/url_request_context.h" | 21 #include "net/url_request/url_request_context.h" |
20 #include "net/url_request/url_request_throttler_manager.h" | 22 #include "net/url_request/url_request_throttler_manager.h" |
21 | 23 |
22 namespace net { | 24 namespace net { |
23 | 25 |
24 const int URLRequestThrottlerEntry::kDefaultSlidingWindowPeriodMs = 2000; | 26 const int URLRequestThrottlerEntry::kDefaultSlidingWindowPeriodMs = 2000; |
25 const int URLRequestThrottlerEntry::kDefaultMaxSendThreshold = 20; | 27 const int URLRequestThrottlerEntry::kDefaultMaxSendThreshold = 20; |
26 | 28 |
27 // This set of back-off parameters will (at maximum values, i.e. without | 29 // This set of back-off parameters will (at maximum values, i.e. without |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 URLRequestThrottlerEntry::URLRequestThrottlerEntry( | 66 URLRequestThrottlerEntry::URLRequestThrottlerEntry( |
65 URLRequestThrottlerManager* manager, | 67 URLRequestThrottlerManager* manager, |
66 const std::string& url_id) | 68 const std::string& url_id) |
67 : sliding_window_period_( | 69 : sliding_window_period_( |
68 base::TimeDelta::FromMilliseconds(kDefaultSlidingWindowPeriodMs)), | 70 base::TimeDelta::FromMilliseconds(kDefaultSlidingWindowPeriodMs)), |
69 max_send_threshold_(kDefaultMaxSendThreshold), | 71 max_send_threshold_(kDefaultMaxSendThreshold), |
70 is_backoff_disabled_(false), | 72 is_backoff_disabled_(false), |
71 backoff_entry_(&backoff_policy_), | 73 backoff_entry_(&backoff_policy_), |
72 manager_(manager), | 74 manager_(manager), |
73 url_id_(url_id), | 75 url_id_(url_id), |
74 net_log_(BoundNetLog::Make( | 76 net_log_( |
75 manager->net_log(), NetLog::SOURCE_EXPONENTIAL_BACKOFF_THROTTLING)) { | 77 BoundNetLog::Make(manager->net_log(), |
| 78 NetLogSourceType::EXPONENTIAL_BACKOFF_THROTTLING)) { |
76 DCHECK(manager_); | 79 DCHECK(manager_); |
77 Initialize(); | 80 Initialize(); |
78 } | 81 } |
79 | 82 |
80 URLRequestThrottlerEntry::URLRequestThrottlerEntry( | 83 URLRequestThrottlerEntry::URLRequestThrottlerEntry( |
81 URLRequestThrottlerManager* manager, | 84 URLRequestThrottlerManager* manager, |
82 const std::string& url_id, | 85 const std::string& url_id, |
83 int sliding_window_period_ms, | 86 int sliding_window_period_ms, |
84 int max_send_threshold, | 87 int max_send_threshold, |
85 int initial_backoff_ms, | 88 int initial_backoff_ms, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 148 |
146 void URLRequestThrottlerEntry::DetachManager() { | 149 void URLRequestThrottlerEntry::DetachManager() { |
147 manager_ = NULL; | 150 manager_ = NULL; |
148 } | 151 } |
149 | 152 |
150 bool URLRequestThrottlerEntry::ShouldRejectRequest( | 153 bool URLRequestThrottlerEntry::ShouldRejectRequest( |
151 const URLRequest& request) const { | 154 const URLRequest& request) const { |
152 bool reject_request = false; | 155 bool reject_request = false; |
153 if (!is_backoff_disabled_ && !ExplicitUserRequest(request.load_flags()) && | 156 if (!is_backoff_disabled_ && !ExplicitUserRequest(request.load_flags()) && |
154 GetBackoffEntry()->ShouldRejectRequest()) { | 157 GetBackoffEntry()->ShouldRejectRequest()) { |
155 net_log_.AddEvent( | 158 net_log_.AddEvent(NetLogEventType::THROTTLING_REJECTED_REQUEST, |
156 NetLog::TYPE_THROTTLING_REJECTED_REQUEST, | 159 base::Bind(&NetLogRejectedRequestCallback, &url_id_, |
157 base::Bind(&NetLogRejectedRequestCallback, | 160 GetBackoffEntry()->failure_count(), |
158 &url_id_, | 161 GetBackoffEntry()->GetTimeUntilRelease())); |
159 GetBackoffEntry()->failure_count(), | |
160 GetBackoffEntry()->GetTimeUntilRelease())); | |
161 reject_request = true; | 162 reject_request = true; |
162 } | 163 } |
163 | 164 |
164 int reject_count = reject_request ? 1 : 0; | 165 int reject_count = reject_request ? 1 : 0; |
165 UMA_HISTOGRAM_ENUMERATION( | 166 UMA_HISTOGRAM_ENUMERATION( |
166 "Throttling.RequestThrottled", reject_count, 2); | 167 "Throttling.RequestThrottled", reject_count, 2); |
167 | 168 |
168 return reject_request; | 169 return reject_request; |
169 } | 170 } |
170 | 171 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 BackoffEntry* URLRequestThrottlerEntry::GetBackoffEntry() { | 284 BackoffEntry* URLRequestThrottlerEntry::GetBackoffEntry() { |
284 return &backoff_entry_; | 285 return &backoff_entry_; |
285 } | 286 } |
286 | 287 |
287 // static | 288 // static |
288 bool URLRequestThrottlerEntry::ExplicitUserRequest(const int load_flags) { | 289 bool URLRequestThrottlerEntry::ExplicitUserRequest(const int load_flags) { |
289 return (load_flags & LOAD_MAYBE_USER_GESTURE) != 0; | 290 return (load_flags & LOAD_MAYBE_USER_GESTURE) != 0; |
290 } | 291 } |
291 | 292 |
292 } // namespace net | 293 } // namespace net |
OLD | NEW |