| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/url_request/url_fetcher_impl.h" | 5 #include "net/url_request/url_fetcher_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 // if there has already been a request for |url|. | 245 // if there has already been a request for |url|. |
| 246 void AddThrottlerEntry(const GURL& url, | 246 void AddThrottlerEntry(const GURL& url, |
| 247 const std::string& url_id, | 247 const std::string& url_id, |
| 248 int sliding_window_period_ms, | 248 int sliding_window_period_ms, |
| 249 int max_send_threshold, | 249 int max_send_threshold, |
| 250 int initial_backoff_ms, | 250 int initial_backoff_ms, |
| 251 double multiply_factor, | 251 double multiply_factor, |
| 252 double jitter_factor, | 252 double jitter_factor, |
| 253 int maximum_backoff_ms, | 253 int maximum_backoff_ms, |
| 254 bool reserve_sending_time_for_next_request) { | 254 bool reserve_sending_time_for_next_request) { |
| 255 if (!network_task_runner_->RunsTasksOnCurrentThread()) { | 255 if (!network_task_runner_->RunsTasksInCurrentSequence()) { |
| 256 network_task_runner_->PostTask( | 256 network_task_runner_->PostTask( |
| 257 FROM_HERE, | 257 FROM_HERE, |
| 258 base::Bind(&FetcherTestURLRequestContextGetter::AddThrottlerEntry, | 258 base::Bind(&FetcherTestURLRequestContextGetter::AddThrottlerEntry, |
| 259 this, url, url_id, sliding_window_period_ms, | 259 this, url, url_id, sliding_window_period_ms, |
| 260 max_send_threshold, initial_backoff_ms, multiply_factor, | 260 max_send_threshold, initial_backoff_ms, multiply_factor, |
| 261 jitter_factor, maximum_backoff_ms, | 261 jitter_factor, maximum_backoff_ms, |
| 262 reserve_sending_time_for_next_request)); | 262 reserve_sending_time_for_next_request)); |
| 263 return; | 263 return; |
| 264 } | 264 } |
| 265 scoped_refptr<URLRequestThrottlerEntry> entry(new URLRequestThrottlerEntry( | 265 scoped_refptr<URLRequestThrottlerEntry> entry(new URLRequestThrottlerEntry( |
| 266 GetURLRequestContext()->throttler_manager(), url_id, | 266 GetURLRequestContext()->throttler_manager(), url_id, |
| 267 sliding_window_period_ms, max_send_threshold, initial_backoff_ms, | 267 sliding_window_period_ms, max_send_threshold, initial_backoff_ms, |
| 268 multiply_factor, jitter_factor, maximum_backoff_ms)); | 268 multiply_factor, jitter_factor, maximum_backoff_ms)); |
| 269 | 269 |
| 270 GetURLRequestContext()->throttler_manager()->OverrideEntryForTests( | 270 GetURLRequestContext()->throttler_manager()->OverrideEntryForTests( |
| 271 url, entry.get()); | 271 url, entry.get()); |
| 272 | 272 |
| 273 if (reserve_sending_time_for_next_request) | 273 if (reserve_sending_time_for_next_request) |
| 274 entry->ReserveSendingTimeForNextRequest(base::TimeTicks()); | 274 entry->ReserveSendingTimeForNextRequest(base::TimeTicks()); |
| 275 } | 275 } |
| 276 | 276 |
| 277 // Tells the getter to act as if the URLRequestContext is about to be shut | 277 // Tells the getter to act as if the URLRequestContext is about to be shut |
| 278 // down. | 278 // down. |
| 279 void Shutdown() { | 279 void Shutdown() { |
| 280 if (!network_task_runner_->RunsTasksOnCurrentThread()) { | 280 if (!network_task_runner_->RunsTasksInCurrentSequence()) { |
| 281 network_task_runner_->PostTask( | 281 network_task_runner_->PostTask( |
| 282 FROM_HERE, | 282 FROM_HERE, |
| 283 base::Bind(&FetcherTestURLRequestContextGetter::Shutdown, this)); | 283 base::Bind(&FetcherTestURLRequestContextGetter::Shutdown, this)); |
| 284 return; | 284 return; |
| 285 } | 285 } |
| 286 | 286 |
| 287 shutting_down_ = true; | 287 shutting_down_ = true; |
| 288 NotifyContextShuttingDown(); | 288 NotifyContextShuttingDown(); |
| 289 // Should now be safe to destroy the context. Context will check it has no | 289 // Should now be safe to destroy the context. Context will check it has no |
| 290 // pending requests. | 290 // pending requests. |
| (...skipping 1282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1573 EXPECT_EQ(-1, delegate.fetcher()->GetResponseCode()); | 1573 EXPECT_EQ(-1, delegate.fetcher()->GetResponseCode()); |
| 1574 EXPECT_FALSE(delegate.fetcher()->GetResponseHeaders()); | 1574 EXPECT_FALSE(delegate.fetcher()->GetResponseHeaders()); |
| 1575 std::string data; | 1575 std::string data; |
| 1576 EXPECT_TRUE(delegate.fetcher()->GetResponseAsString(&data)); | 1576 EXPECT_TRUE(delegate.fetcher()->GetResponseAsString(&data)); |
| 1577 EXPECT_TRUE(data.empty()); | 1577 EXPECT_TRUE(data.empty()); |
| 1578 } | 1578 } |
| 1579 | 1579 |
| 1580 } // namespace | 1580 } // namespace |
| 1581 | 1581 |
| 1582 } // namespace net | 1582 } // namespace net |
| OLD | NEW |