OLD | NEW |
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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 bool ignore_limits) override { | 139 bool ignore_limits) override { |
140 std::unique_ptr<TestThrottle> test_throttle( | 140 std::unique_ptr<TestThrottle> test_throttle( |
141 new TestThrottle(throttle_new_requests_, delegate, this)); | 141 new TestThrottle(throttle_new_requests_, delegate, this)); |
142 outstanding_throttles_.insert(test_throttle.get()); | 142 outstanding_throttles_.insert(test_throttle.get()); |
143 return std::move(test_throttle); | 143 return std::move(test_throttle); |
144 } | 144 } |
145 | 145 |
146 void UnthrottleAllRequests() { | 146 void UnthrottleAllRequests() { |
147 std::set<TestThrottle*> outstanding_throttles_copy(outstanding_throttles_); | 147 std::set<TestThrottle*> outstanding_throttles_copy(outstanding_throttles_); |
148 for (auto& throttle : outstanding_throttles_copy) { | 148 for (auto& throttle : outstanding_throttles_copy) { |
149 if (throttle->IsThrottled()) | 149 if (throttle->IsBlocked()) |
150 throttle->Unthrottle(); | 150 throttle->Unthrottle(); |
151 } | 151 } |
152 } | 152 } |
153 | 153 |
154 void set_throttle_new_requests(bool throttle_new_requests) { | 154 void set_throttle_new_requests(bool throttle_new_requests) { |
155 throttle_new_requests_ = throttle_new_requests; | 155 throttle_new_requests_ = throttle_new_requests; |
156 } | 156 } |
157 | 157 |
158 // Includes both throttled and unthrottled throttles. | 158 // Includes both throttled and unthrottled throttles. |
159 size_t num_outstanding_requests() const { | 159 size_t num_outstanding_requests() const { |
160 return outstanding_throttles_.size(); | 160 return outstanding_throttles_.size(); |
161 } | 161 } |
162 | 162 |
163 int num_set_priority_calls() const { return num_set_priority_calls_; } | 163 int num_set_priority_calls() const { return num_set_priority_calls_; } |
164 RequestPriority last_priority_set() const { return last_priority_set_; } | 164 RequestPriority last_priority_set() const { return last_priority_set_; } |
165 void set_priority_change_closure( | 165 void set_priority_change_closure( |
166 const base::Closure& priority_change_closure) { | 166 const base::Closure& priority_change_closure) { |
167 priority_change_closure_ = priority_change_closure; | 167 priority_change_closure_ = priority_change_closure; |
168 } | 168 } |
169 | 169 |
170 private: | 170 private: |
171 class TestThrottle : public NetworkThrottleManager::Throttle { | 171 class TestThrottle : public NetworkThrottleManager::Throttle { |
172 public: | 172 public: |
173 ~TestThrottle() override { throttler_->OnThrottleDestroyed(this); } | 173 ~TestThrottle() override { throttler_->OnThrottleDestroyed(this); } |
174 | 174 |
175 // Throttle | 175 // Throttle |
176 bool IsThrottled() const override { return throttled_; } | 176 bool IsBlocked() const override { return throttled_; } |
| 177 RequestPriority Priority() const override { |
| 178 NOTREACHED(); |
| 179 return IDLE; |
| 180 } |
177 void SetPriority(RequestPriority priority) override { | 181 void SetPriority(RequestPriority priority) override { |
178 throttler_->SetPriorityCalled(priority); | 182 throttler_->SetPriorityCalled(priority); |
179 } | 183 } |
180 | 184 |
181 TestThrottle(bool throttled, | 185 TestThrottle(bool throttled, |
182 ThrottleDelegate* delegate, | 186 ThrottleDelegate* delegate, |
183 TestNetworkStreamThrottler* throttler) | 187 TestNetworkStreamThrottler* throttler) |
184 : throttled_(throttled), delegate_(delegate), throttler_(throttler) {} | 188 : throttled_(throttled), delegate_(delegate), throttler_(throttler) {} |
185 | 189 |
186 void Unthrottle() { | 190 void Unthrottle() { |
187 EXPECT_TRUE(throttled_); | 191 EXPECT_TRUE(throttled_); |
188 | 192 |
189 throttled_ = false; | 193 throttled_ = false; |
190 delegate_->OnThrottleStateChanged(); | 194 delegate_->OnThrottleStateChanged(this); |
191 } | 195 } |
192 | 196 |
193 bool throttled_; | 197 bool throttled_; |
194 ThrottleDelegate* delegate_; | 198 ThrottleDelegate* delegate_; |
195 TestNetworkStreamThrottler* throttler_; | 199 TestNetworkStreamThrottler* throttler_; |
196 }; | 200 }; |
197 | 201 |
198 void OnThrottleDestroyed(TestThrottle* throttle) { | 202 void OnThrottleDestroyed(TestThrottle* throttle) { |
199 EXPECT_NE(0u, outstanding_throttles_.count(throttle)); | 203 EXPECT_NE(0u, outstanding_throttles_.count(throttle)); |
200 outstanding_throttles_.erase(throttle); | 204 outstanding_throttles_.erase(throttle); |
(...skipping 15981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16182 base::RunLoop().RunUntilIdle(); | 16186 base::RunLoop().RunUntilIdle(); |
16183 | 16187 |
16184 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); | 16188 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
16185 HttpRequestHeaders headers; | 16189 HttpRequestHeaders headers; |
16186 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); | 16190 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
16187 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); | 16191 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
16188 } | 16192 } |
16189 #endif // !defined(OS_IOS) | 16193 #endif // !defined(OS_IOS) |
16190 | 16194 |
16191 } // namespace net | 16195 } // namespace net |
OLD | NEW |