| 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_manager.h" | 5 #include "net/url_request/url_request_throttler_manager.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/metrics/histogram_samples.h" | 8 #include "base/metrics/histogram_samples.h" |
| 9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 void InitPolicy() { | 57 void InitPolicy() { |
| 58 // Some tests become flaky if we have jitter. | 58 // Some tests become flaky if we have jitter. |
| 59 backoff_policy_.jitter_factor = 0.0; | 59 backoff_policy_.jitter_factor = 0.0; |
| 60 | 60 |
| 61 // This lets us avoid having to make multiple failures initially (this | 61 // This lets us avoid having to make multiple failures initially (this |
| 62 // logic is already tested in the BackoffEntry unit tests). | 62 // logic is already tested in the BackoffEntry unit tests). |
| 63 backoff_policy_.num_errors_to_ignore = 0; | 63 backoff_policy_.num_errors_to_ignore = 0; |
| 64 } | 64 } |
| 65 | 65 |
| 66 virtual const BackoffEntry* GetBackoffEntry() const OVERRIDE { | 66 virtual const BackoffEntry* GetBackoffEntry() const override { |
| 67 return &mock_backoff_entry_; | 67 return &mock_backoff_entry_; |
| 68 } | 68 } |
| 69 | 69 |
| 70 virtual BackoffEntry* GetBackoffEntry() OVERRIDE { | 70 virtual BackoffEntry* GetBackoffEntry() override { |
| 71 return &mock_backoff_entry_; | 71 return &mock_backoff_entry_; |
| 72 } | 72 } |
| 73 | 73 |
| 74 static bool ExplicitUserRequest(int load_flags) { | 74 static bool ExplicitUserRequest(int load_flags) { |
| 75 return URLRequestThrottlerEntry::ExplicitUserRequest(load_flags); | 75 return URLRequestThrottlerEntry::ExplicitUserRequest(load_flags); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void ResetToBlank(const TimeTicks& time_now) { | 78 void ResetToBlank(const TimeTicks& time_now) { |
| 79 fake_time_now_ = time_now; | 79 fake_time_now_ = time_now; |
| 80 mock_backoff_entry_.set_fake_now(time_now); | 80 mock_backoff_entry_.set_fake_now(time_now); |
| 81 | 81 |
| 82 GetBackoffEntry()->Reset(); | 82 GetBackoffEntry()->Reset(); |
| 83 GetBackoffEntry()->SetCustomReleaseTime(time_now); | 83 GetBackoffEntry()->SetCustomReleaseTime(time_now); |
| 84 set_sliding_window_release_time(time_now); | 84 set_sliding_window_release_time(time_now); |
| 85 } | 85 } |
| 86 | 86 |
| 87 // Overridden for tests. | 87 // Overridden for tests. |
| 88 virtual TimeTicks ImplGetTimeNow() const OVERRIDE { return fake_time_now_; } | 88 virtual TimeTicks ImplGetTimeNow() const override { return fake_time_now_; } |
| 89 | 89 |
| 90 void set_exponential_backoff_release_time( | 90 void set_exponential_backoff_release_time( |
| 91 const base::TimeTicks& release_time) { | 91 const base::TimeTicks& release_time) { |
| 92 GetBackoffEntry()->SetCustomReleaseTime(release_time); | 92 GetBackoffEntry()->SetCustomReleaseTime(release_time); |
| 93 } | 93 } |
| 94 | 94 |
| 95 base::TimeTicks sliding_window_release_time() const { | 95 base::TimeTicks sliding_window_release_time() const { |
| 96 return URLRequestThrottlerEntry::sliding_window_release_time(); | 96 return URLRequestThrottlerEntry::sliding_window_release_time(); |
| 97 } | 97 } |
| 98 | 98 |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 } | 523 } |
| 524 | 524 |
| 525 scoped_refptr<URLRequestThrottlerEntryInterface> entry_after = | 525 scoped_refptr<URLRequestThrottlerEntryInterface> entry_after = |
| 526 manager.RegisterRequestUrl(GURL("http://www.example.com/")); | 526 manager.RegisterRequestUrl(GURL("http://www.example.com/")); |
| 527 EXPECT_FALSE(entry_after->ShouldRejectRequest( | 527 EXPECT_FALSE(entry_after->ShouldRejectRequest( |
| 528 *request_, context_.network_delegate())); | 528 *request_, context_.network_delegate())); |
| 529 } | 529 } |
| 530 } | 530 } |
| 531 | 531 |
| 532 } // namespace net | 532 } // namespace net |
| OLD | NEW |