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 "content/test/net/url_request_failed_job.h" | 5 #include "content/test/net/url_request_failed_job.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
12 #include "net/url_request/url_request.h" | 12 #include "net/url_request/url_request.h" |
| 13 #include "net/url_request/url_request_context.h" |
13 #include "net/url_request/url_request_filter.h" | 14 #include "net/url_request/url_request_filter.h" |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 const char kMockHostname[] = "mock.failed.request"; | 18 const char kMockHostname[] = "mock.failed.request"; |
18 | 19 |
19 // Gets the numeric net error code from URL of the form: | 20 // Gets the numeric net error code from URL of the form: |
20 // scheme://kMockHostname/error_code. The error code must be a valid | 21 // scheme://kMockHostname/error_code. The error code must be a valid |
21 // net error code, and not net::OK or net::ERR_IO_PENDING. | 22 // net error code, and not net::OK or net::ERR_IO_PENDING. |
22 int GetErrorCode(net::URLRequest* request) { | 23 int GetErrorCode(net::URLRequest* request) { |
(...skipping 12 matching lines...) Expand all Loading... |
35 CHECK_LT(net_error, 0); | 36 CHECK_LT(net_error, 0); |
36 CHECK_NE(net_error, net::ERR_IO_PENDING); | 37 CHECK_NE(net_error, net::ERR_IO_PENDING); |
37 return GURL(scheme + "://" + kMockHostname + "/" + | 38 return GURL(scheme + "://" + kMockHostname + "/" + |
38 base::IntToString(net_error)); | 39 base::IntToString(net_error)); |
39 } | 40 } |
40 | 41 |
41 } // namespace | 42 } // namespace |
42 | 43 |
43 URLRequestFailedJob::URLRequestFailedJob(net::URLRequest* request, | 44 URLRequestFailedJob::URLRequestFailedJob(net::URLRequest* request, |
44 int net_error) | 45 int net_error) |
45 : net::URLRequestJob(request), | 46 : net::URLRequestJob(request, request->context()->network_delegate()), |
46 net_error_(net_error), | 47 net_error_(net_error), |
47 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {} | 48 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {} |
48 | 49 |
49 URLRequestFailedJob::~URLRequestFailedJob() {} | 50 URLRequestFailedJob::~URLRequestFailedJob() {} |
50 | 51 |
51 void URLRequestFailedJob::Start() { | 52 void URLRequestFailedJob::Start() { |
52 MessageLoop::current()->PostTask( | 53 MessageLoop::current()->PostTask( |
53 FROM_HERE, | 54 FROM_HERE, |
54 base::Bind(&URLRequestFailedJob::StartAsync, | 55 base::Bind(&URLRequestFailedJob::StartAsync, |
55 weak_factory_.GetWeakPtr())); | 56 weak_factory_.GetWeakPtr())); |
(...skipping 22 matching lines...) Expand all Loading... |
78 // static | 79 // static |
79 net::URLRequestJob* URLRequestFailedJob::Factory(net::URLRequest* request, | 80 net::URLRequestJob* URLRequestFailedJob::Factory(net::URLRequest* request, |
80 const std::string& scheme) { | 81 const std::string& scheme) { |
81 return new URLRequestFailedJob(request, GetErrorCode(request)); | 82 return new URLRequestFailedJob(request, GetErrorCode(request)); |
82 } | 83 } |
83 | 84 |
84 void URLRequestFailedJob::StartAsync() { | 85 void URLRequestFailedJob::StartAsync() { |
85 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, | 86 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, |
86 net_error_)); | 87 net_error_)); |
87 } | 88 } |
OLD | NEW |