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 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 BackoffEntry* GetBackoffEntry() override { return &mock_backoff_entry_; } |
71 return &mock_backoff_entry_; | |
72 } | |
73 | 71 |
74 static bool ExplicitUserRequest(int load_flags) { | 72 static bool ExplicitUserRequest(int load_flags) { |
75 return URLRequestThrottlerEntry::ExplicitUserRequest(load_flags); | 73 return URLRequestThrottlerEntry::ExplicitUserRequest(load_flags); |
76 } | 74 } |
77 | 75 |
78 void ResetToBlank(const TimeTicks& time_now) { | 76 void ResetToBlank(const TimeTicks& time_now) { |
79 fake_time_now_ = time_now; | 77 fake_time_now_ = time_now; |
80 mock_backoff_entry_.set_fake_now(time_now); | 78 mock_backoff_entry_.set_fake_now(time_now); |
81 | 79 |
82 GetBackoffEntry()->Reset(); | 80 GetBackoffEntry()->Reset(); |
83 GetBackoffEntry()->SetCustomReleaseTime(time_now); | 81 GetBackoffEntry()->SetCustomReleaseTime(time_now); |
84 set_sliding_window_release_time(time_now); | 82 set_sliding_window_release_time(time_now); |
85 } | 83 } |
86 | 84 |
87 // Overridden for tests. | 85 // Overridden for tests. |
88 virtual TimeTicks ImplGetTimeNow() const override { return fake_time_now_; } | 86 TimeTicks ImplGetTimeNow() const override { return fake_time_now_; } |
89 | 87 |
90 void set_exponential_backoff_release_time( | 88 void set_exponential_backoff_release_time( |
91 const base::TimeTicks& release_time) { | 89 const base::TimeTicks& release_time) { |
92 GetBackoffEntry()->SetCustomReleaseTime(release_time); | 90 GetBackoffEntry()->SetCustomReleaseTime(release_time); |
93 } | 91 } |
94 | 92 |
95 base::TimeTicks sliding_window_release_time() const { | 93 base::TimeTicks sliding_window_release_time() const { |
96 return URLRequestThrottlerEntry::sliding_window_release_time(); | 94 return URLRequestThrottlerEntry::sliding_window_release_time(); |
97 } | 95 } |
98 | 96 |
99 void set_sliding_window_release_time( | 97 void set_sliding_window_release_time( |
100 const base::TimeTicks& release_time) { | 98 const base::TimeTicks& release_time) { |
101 URLRequestThrottlerEntry::set_sliding_window_release_time( | 99 URLRequestThrottlerEntry::set_sliding_window_release_time( |
102 release_time); | 100 release_time); |
103 } | 101 } |
104 | 102 |
105 TimeTicks fake_time_now_; | 103 TimeTicks fake_time_now_; |
106 MockBackoffEntry mock_backoff_entry_; | 104 MockBackoffEntry mock_backoff_entry_; |
107 | 105 |
108 protected: | 106 protected: |
109 virtual ~MockURLRequestThrottlerEntry() {} | 107 ~MockURLRequestThrottlerEntry() override {} |
110 }; | 108 }; |
111 | 109 |
112 class MockURLRequestThrottlerManager : public URLRequestThrottlerManager { | 110 class MockURLRequestThrottlerManager : public URLRequestThrottlerManager { |
113 public: | 111 public: |
114 MockURLRequestThrottlerManager() : create_entry_index_(0) {} | 112 MockURLRequestThrottlerManager() : create_entry_index_(0) {} |
115 | 113 |
116 // Method to process the URL using URLRequestThrottlerManager protected | 114 // Method to process the URL using URLRequestThrottlerManager protected |
117 // method. | 115 // method. |
118 std::string DoGetUrlIdFromUrl(const GURL& url) { return GetIdFromUrl(url); } | 116 std::string DoGetUrlIdFromUrl(const GURL& url) { return GetIdFromUrl(url); } |
119 | 117 |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 } | 521 } |
524 | 522 |
525 scoped_refptr<URLRequestThrottlerEntryInterface> entry_after = | 523 scoped_refptr<URLRequestThrottlerEntryInterface> entry_after = |
526 manager.RegisterRequestUrl(GURL("http://www.example.com/")); | 524 manager.RegisterRequestUrl(GURL("http://www.example.com/")); |
527 EXPECT_FALSE(entry_after->ShouldRejectRequest( | 525 EXPECT_FALSE(entry_after->ShouldRejectRequest( |
528 *request_, context_.network_delegate())); | 526 *request_, context_.network_delegate())); |
529 } | 527 } |
530 } | 528 } |
531 | 529 |
532 } // namespace net | 530 } // namespace net |
OLD | NEW |