OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_request_ftp_job.h" | 5 #include "net/url_request/url_request_ftp_job.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "net/base/auth.h" | 10 #include "net/base/auth.h" |
11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
12 #include "net/base/net_util.h" | 12 #include "net/base/net_util.h" |
13 #include "net/ftp/ftp_response_info.h" | 13 #include "net/ftp/ftp_response_info.h" |
14 #include "net/ftp/ftp_transaction_factory.h" | 14 #include "net/ftp/ftp_transaction_factory.h" |
15 #include "net/url_request/url_request.h" | 15 #include "net/url_request/url_request.h" |
16 #include "net/url_request/url_request_context.h" | 16 #include "net/url_request/url_request_context.h" |
17 #include "net/url_request/url_request_error_job.h" | 17 #include "net/url_request/url_request_error_job.h" |
18 | 18 |
19 URLRequestFtpJob::URLRequestFtpJob(net::URLRequest* request) | 19 URLRequestFtpJob::URLRequestFtpJob(net::URLRequest* request) |
20 : URLRequestJob(request), | 20 : net::URLRequestJob(request), |
21 ALLOW_THIS_IN_INITIALIZER_LIST( | 21 ALLOW_THIS_IN_INITIALIZER_LIST( |
22 start_callback_(this, &URLRequestFtpJob::OnStartCompleted)), | 22 start_callback_(this, &URLRequestFtpJob::OnStartCompleted)), |
23 ALLOW_THIS_IN_INITIALIZER_LIST( | 23 ALLOW_THIS_IN_INITIALIZER_LIST( |
24 read_callback_(this, &URLRequestFtpJob::OnReadCompleted)), | 24 read_callback_(this, &URLRequestFtpJob::OnReadCompleted)), |
25 read_in_progress_(false), | 25 read_in_progress_(false), |
26 context_(request->context()), | 26 context_(request->context()), |
27 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 27 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
28 } | 28 } |
29 | 29 |
30 URLRequestFtpJob::~URLRequestFtpJob() { | 30 URLRequestFtpJob::~URLRequestFtpJob() { |
31 } | 31 } |
32 | 32 |
33 // static | 33 // static |
34 URLRequestJob* URLRequestFtpJob::Factory(net::URLRequest* request, | 34 net::URLRequestJob* URLRequestFtpJob::Factory(net::URLRequest* request, |
35 const std::string& scheme) { | 35 const std::string& scheme) { |
36 DCHECK_EQ(scheme, "ftp"); | 36 DCHECK_EQ(scheme, "ftp"); |
37 | 37 |
38 int port = request->url().IntPort(); | 38 int port = request->url().IntPort(); |
39 if (request->url().has_port() && | 39 if (request->url().has_port() && |
40 !net::IsPortAllowedByFtp(port) && !net::IsPortAllowedByOverride(port)) | 40 !net::IsPortAllowedByFtp(port) && !net::IsPortAllowedByOverride(port)) |
41 return new URLRequestErrorJob(request, net::ERR_UNSAFE_PORT); | 41 return new URLRequestErrorJob(request, net::ERR_UNSAFE_PORT); |
42 | 42 |
43 DCHECK(request->context()); | 43 DCHECK(request->context()); |
44 DCHECK(request->context()->ftp_transaction_factory()); | 44 DCHECK(request->context()->ftp_transaction_factory()); |
45 return new URLRequestFtpJob(request); | 45 return new URLRequestFtpJob(request); |
(...skipping 10 matching lines...) Expand all Loading... |
56 void URLRequestFtpJob::Start() { | 56 void URLRequestFtpJob::Start() { |
57 DCHECK(!transaction_.get()); | 57 DCHECK(!transaction_.get()); |
58 request_info_.url = request_->url(); | 58 request_info_.url = request_->url(); |
59 StartTransaction(); | 59 StartTransaction(); |
60 } | 60 } |
61 | 61 |
62 void URLRequestFtpJob::Kill() { | 62 void URLRequestFtpJob::Kill() { |
63 if (!transaction_.get()) | 63 if (!transaction_.get()) |
64 return; | 64 return; |
65 transaction_.reset(); | 65 transaction_.reset(); |
66 URLRequestJob::Kill(); | 66 net::URLRequestJob::Kill(); |
67 method_factory_.RevokeAll(); | 67 method_factory_.RevokeAll(); |
68 } | 68 } |
69 | 69 |
70 net::LoadState URLRequestFtpJob::GetLoadState() const { | 70 net::LoadState URLRequestFtpJob::GetLoadState() const { |
71 return transaction_.get() ? | 71 return transaction_.get() ? |
72 transaction_->GetLoadState() : net::LOAD_STATE_IDLE; | 72 transaction_->GetLoadState() : net::LOAD_STATE_IDLE; |
73 } | 73 } |
74 | 74 |
75 bool URLRequestFtpJob::NeedsAuth() { | 75 bool URLRequestFtpJob::NeedsAuth() { |
76 // Note that we only have to worry about cases where an actual FTP server | 76 // Note that we only have to worry about cases where an actual FTP server |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 } else { | 229 } else { |
230 rv = net::ERR_FAILED; | 230 rv = net::ERR_FAILED; |
231 } | 231 } |
232 // The transaction started synchronously, but we need to notify the | 232 // The transaction started synchronously, but we need to notify the |
233 // net::URLRequest delegate via the message loop. | 233 // net::URLRequest delegate via the message loop. |
234 MessageLoop::current()->PostTask( | 234 MessageLoop::current()->PostTask( |
235 FROM_HERE, | 235 FROM_HERE, |
236 method_factory_.NewRunnableMethod( | 236 method_factory_.NewRunnableMethod( |
237 &URLRequestFtpJob::OnStartCompleted, rv)); | 237 &URLRequestFtpJob::OnStartCompleted, rv)); |
238 } | 238 } |
OLD | NEW |