Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(711)

Side by Side Diff: net/http/http_network_transaction_unittest.cc

Issue 2130493002: Implement THROTTLED priority semantics. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@NetworkStreamThrottler
Patch Set: Incorporated comments and substantially simplified state storage. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/http/http_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include <math.h> // ceil 7 #include <math.h> // ceil
8 #include <stdarg.h> 8 #include <stdarg.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 bool ignore_limits) override { 126 bool ignore_limits) override {
127 std::unique_ptr<TestThrottle> test_throttle( 127 std::unique_ptr<TestThrottle> test_throttle(
128 new TestThrottle(throttle_new_requests_, delegate, this)); 128 new TestThrottle(throttle_new_requests_, delegate, this));
129 outstanding_throttles_.insert(test_throttle.get()); 129 outstanding_throttles_.insert(test_throttle.get());
130 return std::move(test_throttle); 130 return std::move(test_throttle);
131 } 131 }
132 132
133 void UnthrottleAllRequests() { 133 void UnthrottleAllRequests() {
134 std::set<TestThrottle*> outstanding_throttles_copy(outstanding_throttles_); 134 std::set<TestThrottle*> outstanding_throttles_copy(outstanding_throttles_);
135 for (auto& throttle : outstanding_throttles_copy) { 135 for (auto& throttle : outstanding_throttles_copy) {
136 if (throttle->IsThrottled()) 136 if (throttle->IsBlocked())
137 throttle->Unthrottle(); 137 throttle->Unthrottle();
138 } 138 }
139 } 139 }
140 140
141 void set_throttle_new_requests(bool throttle_new_requests) { 141 void set_throttle_new_requests(bool throttle_new_requests) {
142 throttle_new_requests_ = throttle_new_requests; 142 throttle_new_requests_ = throttle_new_requests;
143 } 143 }
144 144
145 // Includes both throttled and unthrottled throttles. 145 // Includes both throttled and unthrottled throttles.
146 size_t num_outstanding_requests() const { 146 size_t num_outstanding_requests() const {
147 return outstanding_throttles_.size(); 147 return outstanding_throttles_.size();
148 } 148 }
149 149
150 int num_set_priority_calls() const { return num_set_priority_calls_; } 150 int num_set_priority_calls() const { return num_set_priority_calls_; }
151 RequestPriority last_priority_set() const { return last_priority_set_; } 151 RequestPriority last_priority_set() const { return last_priority_set_; }
152 void set_priority_change_closure( 152 void set_priority_change_closure(
153 const base::Closure& priority_change_closure) { 153 const base::Closure& priority_change_closure) {
154 priority_change_closure_ = priority_change_closure; 154 priority_change_closure_ = priority_change_closure;
155 } 155 }
156 156
157 private: 157 private:
158 class TestThrottle : public NetworkThrottleManager::Throttle { 158 class TestThrottle : public NetworkThrottleManager::Throttle {
159 public: 159 public:
160 ~TestThrottle() override { throttler_->OnThrottleDestroyed(this); } 160 ~TestThrottle() override { throttler_->OnThrottleDestroyed(this); }
161 161
162 // Throttle 162 // Throttle
163 bool IsThrottled() const override { return throttled_; } 163 bool IsBlocked() const override { return throttled_; }
164 RequestPriority Priority() const override {
165 NOTREACHED();
166 return IDLE;
167 }
164 void SetPriority(RequestPriority priority) override { 168 void SetPriority(RequestPriority priority) override {
165 throttler_->SetPriorityCalled(priority); 169 throttler_->SetPriorityCalled(priority);
166 } 170 }
167 171
168 TestThrottle(bool throttled, 172 TestThrottle(bool throttled,
169 ThrottleDelegate* delegate, 173 ThrottleDelegate* delegate,
170 TestNetworkStreamThrottler* throttler) 174 TestNetworkStreamThrottler* throttler)
171 : throttled_(throttled), delegate_(delegate), throttler_(throttler) {} 175 : throttled_(throttled), delegate_(delegate), throttler_(throttler) {}
172 176
173 void Unthrottle() { 177 void Unthrottle() {
174 EXPECT_TRUE(throttled_); 178 EXPECT_TRUE(throttled_);
175 179
176 throttled_ = false; 180 throttled_ = false;
177 delegate_->OnThrottleStateChanged(); 181 delegate_->OnThrottleStateChanged(this);
178 } 182 }
179 183
180 bool throttled_; 184 bool throttled_;
181 ThrottleDelegate* delegate_; 185 ThrottleDelegate* delegate_;
182 TestNetworkStreamThrottler* throttler_; 186 TestNetworkStreamThrottler* throttler_;
183 }; 187 };
184 188
185 void OnThrottleDestroyed(TestThrottle* throttle) { 189 void OnThrottleDestroyed(TestThrottle* throttle) {
186 EXPECT_NE(0u, outstanding_throttles_.count(throttle)); 190 EXPECT_NE(0u, outstanding_throttles_.count(throttle));
187 outstanding_throttles_.erase(throttle); 191 outstanding_throttles_.erase(throttle);
(...skipping 15634 matching lines...) Expand 10 before | Expand all | Expand 10 after
15822 base::RunLoop().RunUntilIdle(); 15826 base::RunLoop().RunUntilIdle();
15823 15827
15824 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); 15828 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy);
15825 HttpRequestHeaders headers; 15829 HttpRequestHeaders headers;
15826 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); 15830 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers));
15827 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); 15831 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding));
15828 } 15832 }
15829 #endif // !defined(OS_IOS) 15833 #endif // !defined(OS_IOS)
15830 15834
15831 } // namespace net 15835 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698