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/test_url_fetcher_factory.h" | 5 #include "net/url_request/test_url_fetcher_factory.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/threading/sequenced_task_runner_handle.h" |
17 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
18 #include "base/threading/thread_task_runner_handle.h" | |
19 #include "net/base/host_port_pair.h" | 19 #include "net/base/host_port_pair.h" |
20 #include "net/base/io_buffer.h" | 20 #include "net/base/io_buffer.h" |
21 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
22 #include "net/base/upload_data_stream.h" | 22 #include "net/base/upload_data_stream.h" |
23 #include "net/http/http_response_headers.h" | 23 #include "net/http/http_response_headers.h" |
24 #include "net/url_request/url_fetcher_delegate.h" | 24 #include "net/url_request/url_fetcher_delegate.h" |
25 #include "net/url_request/url_fetcher_impl.h" | 25 #include "net/url_request/url_fetcher_impl.h" |
26 #include "net/url_request/url_fetcher_response_writer.h" | 26 #include "net/url_request/url_fetcher_response_writer.h" |
27 #include "net/url_request/url_request_status.h" | 27 #include "net/url_request/url_request_status.h" |
28 | 28 |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 set_status(URLRequestStatus(status, error)); | 382 set_status(URLRequestStatus(status, error)); |
383 set_response_code(response_code); | 383 set_response_code(response_code); |
384 SetResponseString(response_data); | 384 SetResponseString(response_data); |
385 response_bytes_ = response_data.size(); | 385 response_bytes_ = response_data.size(); |
386 } | 386 } |
387 | 387 |
388 FakeURLFetcher::~FakeURLFetcher() {} | 388 FakeURLFetcher::~FakeURLFetcher() {} |
389 | 389 |
390 void FakeURLFetcher::Start() { | 390 void FakeURLFetcher::Start() { |
391 TestURLFetcher::Start(); | 391 TestURLFetcher::Start(); |
392 base::ThreadTaskRunnerHandle::Get()->PostTask( | 392 base::SequencedTaskRunnerHandle::Get()->PostTask( |
393 FROM_HERE, | 393 FROM_HERE, |
394 base::Bind(&FakeURLFetcher::RunDelegate, weak_factory_.GetWeakPtr())); | 394 base::Bind(&FakeURLFetcher::RunDelegate, weak_factory_.GetWeakPtr())); |
395 } | 395 } |
396 | 396 |
397 void FakeURLFetcher::RunDelegate() { | 397 void FakeURLFetcher::RunDelegate() { |
398 // OnURLFetchDownloadProgress may delete this URLFetcher. We keep track of | 398 // OnURLFetchDownloadProgress may delete this URLFetcher. We keep track of |
399 // this with a weak pointer, and only call OnURLFetchComplete if this still | 399 // this with a weak pointer, and only call OnURLFetchComplete if this still |
400 // exists. | 400 // exists. |
401 auto weak_this = weak_factory_.GetWeakPtr(); | 401 auto weak_this = weak_factory_.GetWeakPtr(); |
402 delegate()->OnURLFetchDownloadProgress(this, response_bytes_, response_bytes_, | 402 delegate()->OnURLFetchDownloadProgress(this, response_bytes_, response_bytes_, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 | 482 |
483 std::unique_ptr<URLFetcher> URLFetcherImplFactory::CreateURLFetcher( | 483 std::unique_ptr<URLFetcher> URLFetcherImplFactory::CreateURLFetcher( |
484 int id, | 484 int id, |
485 const GURL& url, | 485 const GURL& url, |
486 URLFetcher::RequestType request_type, | 486 URLFetcher::RequestType request_type, |
487 URLFetcherDelegate* d) { | 487 URLFetcherDelegate* d) { |
488 return std::unique_ptr<URLFetcher>(new URLFetcherImpl(url, request_type, d)); | 488 return std::unique_ptr<URLFetcher>(new URLFetcherImpl(url, request_type, d)); |
489 } | 489 } |
490 | 490 |
491 } // namespace net | 491 } // namespace net |
OLD | NEW |