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