| 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->IsBlocked()) | 138 if (throttle->IsThrottled()) |
| 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 IsBlocked() const override { return throttled_; } | 165 bool IsThrottled() const override { return throttled_; } |
| 166 RequestPriority Priority() const override { | |
| 167 NOTREACHED(); | |
| 168 return IDLE; | |
| 169 } | |
| 170 void SetPriority(RequestPriority priority) override { | 166 void SetPriority(RequestPriority priority) override { |
| 171 throttler_->SetPriorityCalled(priority); | 167 throttler_->SetPriorityCalled(priority); |
| 172 } | 168 } |
| 173 | 169 |
| 174 TestThrottle(bool throttled, | 170 TestThrottle(bool throttled, |
| 175 ThrottleDelegate* delegate, | 171 ThrottleDelegate* delegate, |
| 176 TestNetworkStreamThrottler* throttler) | 172 TestNetworkStreamThrottler* throttler) |
| 177 : throttled_(throttled), delegate_(delegate), throttler_(throttler) {} | 173 : throttled_(throttled), delegate_(delegate), throttler_(throttler) {} |
| 178 | 174 |
| 179 void Unthrottle() { | 175 void Unthrottle() { |
| 180 EXPECT_TRUE(throttled_); | 176 EXPECT_TRUE(throttled_); |
| 181 | 177 |
| 182 throttled_ = false; | 178 throttled_ = false; |
| 183 delegate_->OnThrottleUnblocked(this); | 179 delegate_->OnThrottleStateChanged(); |
| 184 } | 180 } |
| 185 | 181 |
| 186 bool throttled_; | 182 bool throttled_; |
| 187 ThrottleDelegate* delegate_; | 183 ThrottleDelegate* delegate_; |
| 188 TestNetworkStreamThrottler* throttler_; | 184 TestNetworkStreamThrottler* throttler_; |
| 189 }; | 185 }; |
| 190 | 186 |
| 191 void OnThrottleDestroyed(TestThrottle* throttle) { | 187 void OnThrottleDestroyed(TestThrottle* throttle) { |
| 192 EXPECT_NE(0u, outstanding_throttles_.count(throttle)); | 188 EXPECT_NE(0u, outstanding_throttles_.count(throttle)); |
| 193 outstanding_throttles_.erase(throttle); | 189 outstanding_throttles_.erase(throttle); |
| (...skipping 16323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16517 base::RunLoop().RunUntilIdle(); | 16513 base::RunLoop().RunUntilIdle(); |
| 16518 | 16514 |
| 16519 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); | 16515 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 16520 HttpRequestHeaders headers; | 16516 HttpRequestHeaders headers; |
| 16521 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); | 16517 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 16522 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); | 16518 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 16523 } | 16519 } |
| 16524 #endif // !defined(OS_IOS) | 16520 #endif // !defined(OS_IOS) |
| 16525 | 16521 |
| 16526 } // namespace net | 16522 } // namespace net |
| OLD | NEW |