| 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 29 matching lines...) Expand all Loading... |
| 40 // avoid false positives. It should help avoid back-off from kicking in e.g. | 40 // avoid false positives. It should help avoid back-off from kicking in e.g. |
| 41 // on flaky connections. | 41 // on flaky connections. |
| 42 const int URLRequestThrottlerEntry::kDefaultNumErrorsToIgnore = 2; | 42 const int URLRequestThrottlerEntry::kDefaultNumErrorsToIgnore = 2; |
| 43 const int URLRequestThrottlerEntry::kDefaultInitialDelayMs = 700; | 43 const int URLRequestThrottlerEntry::kDefaultInitialDelayMs = 700; |
| 44 const double URLRequestThrottlerEntry::kDefaultMultiplyFactor = 1.4; | 44 const double URLRequestThrottlerEntry::kDefaultMultiplyFactor = 1.4; |
| 45 const double URLRequestThrottlerEntry::kDefaultJitterFactor = 0.4; | 45 const double URLRequestThrottlerEntry::kDefaultJitterFactor = 0.4; |
| 46 const int URLRequestThrottlerEntry::kDefaultMaximumBackoffMs = 15 * 60 * 1000; | 46 const int URLRequestThrottlerEntry::kDefaultMaximumBackoffMs = 15 * 60 * 1000; |
| 47 const int URLRequestThrottlerEntry::kDefaultEntryLifetimeMs = 2 * 60 * 1000; | 47 const int URLRequestThrottlerEntry::kDefaultEntryLifetimeMs = 2 * 60 * 1000; |
| 48 | 48 |
| 49 // Returns NetLog parameters when a request is rejected by throttling. | 49 // Returns NetLog parameters when a request is rejected by throttling. |
| 50 base::Value* NetLogRejectedRequestCallback( | 50 scoped_ptr<base::Value> NetLogRejectedRequestCallback( |
| 51 const std::string* url_id, | 51 const std::string* url_id, |
| 52 int num_failures, | 52 int num_failures, |
| 53 const base::TimeDelta& release_after, | 53 const base::TimeDelta& release_after, |
| 54 NetLogCaptureMode /* capture_mode */) { | 54 NetLogCaptureMode /* capture_mode */) { |
| 55 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 55 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 56 dict->SetString("url", *url_id); | 56 dict->SetString("url", *url_id); |
| 57 dict->SetInteger("num_failures", num_failures); | 57 dict->SetInteger("num_failures", num_failures); |
| 58 dict->SetInteger("release_after_ms", | 58 dict->SetInteger("release_after_ms", |
| 59 static_cast<int>(release_after.InMilliseconds())); | 59 static_cast<int>(release_after.InMilliseconds())); |
| 60 return dict.release(); | 60 return dict.Pass(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 URLRequestThrottlerEntry::URLRequestThrottlerEntry( | 63 URLRequestThrottlerEntry::URLRequestThrottlerEntry( |
| 64 URLRequestThrottlerManager* manager, | 64 URLRequestThrottlerManager* manager, |
| 65 const std::string& url_id) | 65 const std::string& url_id) |
| 66 : sliding_window_period_( | 66 : sliding_window_period_( |
| 67 base::TimeDelta::FromMilliseconds(kDefaultSlidingWindowPeriodMs)), | 67 base::TimeDelta::FromMilliseconds(kDefaultSlidingWindowPeriodMs)), |
| 68 max_send_threshold_(kDefaultMaxSendThreshold), | 68 max_send_threshold_(kDefaultMaxSendThreshold), |
| 69 is_backoff_disabled_(false), | 69 is_backoff_disabled_(false), |
| 70 backoff_entry_(&backoff_policy_), | 70 backoff_entry_(&backoff_policy_), |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 BackoffEntry* URLRequestThrottlerEntry::GetBackoffEntry() { | 284 BackoffEntry* URLRequestThrottlerEntry::GetBackoffEntry() { |
| 285 return &backoff_entry_; | 285 return &backoff_entry_; |
| 286 } | 286 } |
| 287 | 287 |
| 288 // static | 288 // static |
| 289 bool URLRequestThrottlerEntry::ExplicitUserRequest(const int load_flags) { | 289 bool URLRequestThrottlerEntry::ExplicitUserRequest(const int load_flags) { |
| 290 return (load_flags & LOAD_MAYBE_USER_GESTURE) != 0; | 290 return (load_flags & LOAD_MAYBE_USER_GESTURE) != 0; |
| 291 } | 291 } |
| 292 | 292 |
| 293 } // namespace net | 293 } // namespace net |
| OLD | NEW |