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