Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "net/base/load_flags.h" | |
| 15 #include "net/base/net_log.h" | 16 #include "net/base/net_log.h" |
| 16 #include "net/url_request/url_request_throttler_header_interface.h" | 17 #include "net/url_request/url_request_throttler_header_interface.h" |
| 17 #include "net/url_request/url_request_throttler_manager.h" | 18 #include "net/url_request/url_request_throttler_manager.h" |
| 18 | 19 |
| 19 namespace net { | 20 namespace net { |
| 20 | 21 |
| 21 const int URLRequestThrottlerEntry::kDefaultSlidingWindowPeriodMs = 2000; | 22 const int URLRequestThrottlerEntry::kDefaultSlidingWindowPeriodMs = 2000; |
| 22 const int URLRequestThrottlerEntry::kDefaultMaxSendThreshold = 20; | 23 const int URLRequestThrottlerEntry::kDefaultMaxSendThreshold = 20; |
| 23 | 24 |
| 24 // This set of back-off parameters will (at maximum values, i.e. without | 25 // This set of back-off parameters will (at maximum values, i.e. without |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 } | 172 } |
| 172 | 173 |
| 173 void URLRequestThrottlerEntry::DisableBackoffThrottling() { | 174 void URLRequestThrottlerEntry::DisableBackoffThrottling() { |
| 174 is_backoff_disabled_ = true; | 175 is_backoff_disabled_ = true; |
| 175 } | 176 } |
| 176 | 177 |
| 177 void URLRequestThrottlerEntry::DetachManager() { | 178 void URLRequestThrottlerEntry::DetachManager() { |
| 178 manager_ = NULL; | 179 manager_ = NULL; |
| 179 } | 180 } |
| 180 | 181 |
| 181 bool URLRequestThrottlerEntry::IsDuringExponentialBackoff() const { | 182 bool URLRequestThrottlerEntry::ShouldRejectRequest(int load_flags) const { |
| 182 bool reject_request = false; | 183 bool reject_request = false; |
| 183 if (!is_backoff_disabled_ && GetBackoffEntry()->ShouldRejectRequest()) { | 184 if (!is_backoff_disabled_ && !ExplicitUserRequest(load_flags) && |
| 185 GetBackoffEntry()->ShouldRejectRequest()) { | |
| 184 int num_failures = GetBackoffEntry()->failure_count(); | 186 int num_failures = GetBackoffEntry()->failure_count(); |
| 185 int release_after_ms = | 187 int release_after_ms = |
| 186 (GetBackoffEntry()->GetReleaseTime() - base::TimeTicks::Now()) | 188 (GetBackoffEntry()->GetReleaseTime() - base::TimeTicks::Now()) |
| 187 .InMilliseconds(); | 189 .InMilliseconds(); |
| 188 | 190 |
| 189 net_log_.AddEvent( | 191 net_log_.AddEvent( |
| 190 NetLog::TYPE_THROTTLING_REJECTED_REQUEST, | 192 NetLog::TYPE_THROTTLING_REJECTED_REQUEST, |
| 191 make_scoped_refptr( | 193 make_scoped_refptr( |
| 192 new RejectedRequestParameters(url_id_, | 194 new RejectedRequestParameters(url_id_, |
| 193 num_failures, | 195 num_failures, |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 } | 439 } |
| 438 | 440 |
| 439 const BackoffEntry* URLRequestThrottlerEntry::GetBackoffEntry() const { | 441 const BackoffEntry* URLRequestThrottlerEntry::GetBackoffEntry() const { |
| 440 return &backoff_entry_; | 442 return &backoff_entry_; |
| 441 } | 443 } |
| 442 | 444 |
| 443 BackoffEntry* URLRequestThrottlerEntry::GetBackoffEntry() { | 445 BackoffEntry* URLRequestThrottlerEntry::GetBackoffEntry() { |
| 444 return &backoff_entry_; | 446 return &backoff_entry_; |
| 445 } | 447 } |
| 446 | 448 |
| 449 // static | |
| 450 bool URLRequestThrottlerEntry::ExplicitUserRequest(const int load_flags) { | |
| 451 return (load_flags & (LOAD_MAYBE_USER_GESTURE)) != 0; | |
|
yzshen1
2011/08/05 21:50:41
nit: the inner parentheses seem unnecessary.
Jói
2011/08/08 17:09:45
Done.
| |
| 452 } | |
| 453 | |
| 447 } // namespace net | 454 } // namespace net |
| OLD | NEW |