| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 bool ignore_limits) override { | 127 bool ignore_limits) override { |
| 128 std::unique_ptr<TestThrottle> test_throttle( | 128 std::unique_ptr<TestThrottle> test_throttle( |
| 129 new TestThrottle(throttle_new_requests_, delegate, this)); | 129 new TestThrottle(throttle_new_requests_, delegate, this)); |
| 130 outstanding_throttles_.insert(test_throttle.get()); | 130 outstanding_throttles_.insert(test_throttle.get()); |
| 131 return std::move(test_throttle); | 131 return std::move(test_throttle); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void UnthrottleAllRequests() { | 134 void UnthrottleAllRequests() { |
| 135 std::set<TestThrottle*> outstanding_throttles_copy(outstanding_throttles_); | 135 std::set<TestThrottle*> outstanding_throttles_copy(outstanding_throttles_); |
| 136 for (auto& throttle : outstanding_throttles_copy) { | 136 for (auto& throttle : outstanding_throttles_copy) { |
| 137 if (throttle->IsThrottled()) | 137 if (throttle->IsBlocked()) |
| 138 throttle->Unthrottle(); | 138 throttle->Unthrottle(); |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 void set_throttle_new_requests(bool throttle_new_requests) { | 142 void set_throttle_new_requests(bool throttle_new_requests) { |
| 143 throttle_new_requests_ = throttle_new_requests; | 143 throttle_new_requests_ = throttle_new_requests; |
| 144 } | 144 } |
| 145 | 145 |
| 146 // Includes both throttled and unthrottled throttles. | 146 // Includes both throttled and unthrottled throttles. |
| 147 size_t num_outstanding_requests() const { | 147 size_t num_outstanding_requests() const { |
| 148 return outstanding_throttles_.size(); | 148 return outstanding_throttles_.size(); |
| 149 } | 149 } |
| 150 | 150 |
| 151 int num_set_priority_calls() const { return num_set_priority_calls_; } | 151 int num_set_priority_calls() const { return num_set_priority_calls_; } |
| 152 RequestPriority last_priority_set() const { return last_priority_set_; } | 152 RequestPriority last_priority_set() const { return last_priority_set_; } |
| 153 void set_priority_change_closure( | 153 void set_priority_change_closure( |
| 154 const base::Closure& priority_change_closure) { | 154 const base::Closure& priority_change_closure) { |
| 155 priority_change_closure_ = priority_change_closure; | 155 priority_change_closure_ = priority_change_closure; |
| 156 } | 156 } |
| 157 | 157 |
| 158 private: | 158 private: |
| 159 class TestThrottle : public NetworkThrottleManager::Throttle { | 159 class TestThrottle : public NetworkThrottleManager::Throttle { |
| 160 public: | 160 public: |
| 161 ~TestThrottle() override { throttler_->OnThrottleDestroyed(this); } | 161 ~TestThrottle() override { throttler_->OnThrottleDestroyed(this); } |
| 162 | 162 |
| 163 // Throttle | 163 // Throttle |
| 164 bool IsThrottled() const override { return throttled_; } | 164 bool IsBlocked() const override { return throttled_; } |
| 165 RequestPriority Priority() const override { |
| 166 NOTREACHED(); |
| 167 return IDLE; |
| 168 } |
| 165 void SetPriority(RequestPriority priority) override { | 169 void SetPriority(RequestPriority priority) override { |
| 166 throttler_->SetPriorityCalled(priority); | 170 throttler_->SetPriorityCalled(priority); |
| 167 } | 171 } |
| 168 | 172 |
| 169 TestThrottle(bool throttled, | 173 TestThrottle(bool throttled, |
| 170 ThrottleDelegate* delegate, | 174 ThrottleDelegate* delegate, |
| 171 TestNetworkStreamThrottler* throttler) | 175 TestNetworkStreamThrottler* throttler) |
| 172 : throttled_(throttled), delegate_(delegate), throttler_(throttler) {} | 176 : throttled_(throttled), delegate_(delegate), throttler_(throttler) {} |
| 173 | 177 |
| 174 void Unthrottle() { | 178 void Unthrottle() { |
| 175 EXPECT_TRUE(throttled_); | 179 EXPECT_TRUE(throttled_); |
| 176 | 180 |
| 177 throttled_ = false; | 181 throttled_ = false; |
| 178 delegate_->OnThrottleStateChanged(); | 182 delegate_->OnThrottleStateChanged(this); |
| 179 } | 183 } |
| 180 | 184 |
| 181 bool throttled_; | 185 bool throttled_; |
| 182 ThrottleDelegate* delegate_; | 186 ThrottleDelegate* delegate_; |
| 183 TestNetworkStreamThrottler* throttler_; | 187 TestNetworkStreamThrottler* throttler_; |
| 184 }; | 188 }; |
| 185 | 189 |
| 186 void OnThrottleDestroyed(TestThrottle* throttle) { | 190 void OnThrottleDestroyed(TestThrottle* throttle) { |
| 187 EXPECT_NE(0u, outstanding_throttles_.count(throttle)); | 191 EXPECT_NE(0u, outstanding_throttles_.count(throttle)); |
| 188 outstanding_throttles_.erase(throttle); | 192 outstanding_throttles_.erase(throttle); |
| (...skipping 15691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15880 base::RunLoop().RunUntilIdle(); | 15884 base::RunLoop().RunUntilIdle(); |
| 15881 | 15885 |
| 15882 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); | 15886 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 15883 HttpRequestHeaders headers; | 15887 HttpRequestHeaders headers; |
| 15884 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); | 15888 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 15885 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); | 15889 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 15886 } | 15890 } |
| 15887 #endif // !defined(OS_IOS) | 15891 #endif // !defined(OS_IOS) |
| 15888 | 15892 |
| 15889 } // namespace net | 15893 } // namespace net |
| OLD | NEW |