Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: net/url_request/url_request_ftp_job.cc

Issue 10537056: Replaced static URLRequestFtpJob factory with non-static protocol handler for FTP jobs. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_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/host_port_pair.h" 11 #include "net/base/host_port_pair.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 #include "net/base/net_util.h" 13 #include "net/base/net_util.h"
14 #include "net/ftp/ftp_response_info.h" 14 #include "net/ftp/ftp_response_info.h"
15 #include "net/ftp/ftp_transaction_factory.h" 15 #include "net/ftp/ftp_transaction_factory.h"
16 #include "net/url_request/url_request.h" 16 #include "net/url_request/url_request.h"
17 #include "net/url_request/url_request_context.h" 17 #include "net/url_request/url_request_context.h"
18 #include "net/url_request/url_request_error_job.h" 18 #include "net/url_request/url_request_error_job.h"
19 19
20 namespace net { 20 namespace net {
21 21
22 URLRequestFtpJob::URLRequestFtpJob(URLRequest* request) 22 URLRequestFtpJob::URLRequestFtpJob(
23 URLRequest* request,
24 NetworkDelegate* network_delegate,
25 FtpTransactionFactory* ftp_transaction_factory,
26 FtpAuthCache* ftp_auth_cache)
23 : URLRequestJob(request), 27 : URLRequestJob(request),
24 read_in_progress_(false), 28 read_in_progress_(false),
25 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 29 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
30 network_delegate_(network_delegate),
31 ftp_transaction_factory_(ftp_transaction_factory),
32 ftp_auth_cache_(ftp_auth_cache) {
33 DCHECK(ftp_transaction_factory);
34 DCHECK(ftp_auth_cache);
35 DCHECK(network_delegate);
26 } 36 }
27 37
28 // static 38 // static
29 URLRequestJob* URLRequestFtpJob::Factory(URLRequest* request, 39 URLRequestJob* URLRequestFtpJob::Factory(URLRequest* request,
30 const std::string& scheme) { 40 const std::string& scheme) {
31 DCHECK_EQ(scheme, "ftp"); 41 DCHECK_EQ(scheme, "ftp");
32 42
33 int port = request->url().IntPort(); 43 int port = request->url().IntPort();
34 if (request->url().has_port() && 44 if (request->url().has_port() &&
35 !IsPortAllowedByFtp(port) && !IsPortAllowedByOverride(port)) 45 !IsPortAllowedByFtp(port) && !IsPortAllowedByOverride(port))
36 return new URLRequestErrorJob(request, ERR_UNSAFE_PORT); 46 return new URLRequestErrorJob(request, ERR_UNSAFE_PORT);
37 47
38 DCHECK(request->context()); 48 return new URLRequestFtpJob(request,
Paweł Hajdan Jr. 2012/06/07 19:30:21 Please keep the DCHECKs. In fact, add even more: f
erikwright (departed) 2012/06/07 19:40:40 I'm indifferent as to DCHECKing network_delegate e
shalev 2012/06/21 20:04:55 Done.
39 DCHECK(request->context()->ftp_transaction_factory()); 49 request->context()->network_delegate(),
40 return new URLRequestFtpJob(request); 50 request->context()->ftp_transaction_factory(),
51 request->context()->ftp_auth_cache());
41 } 52 }
42 53
43 bool URLRequestFtpJob::GetMimeType(std::string* mime_type) const { 54 bool URLRequestFtpJob::GetMimeType(std::string* mime_type) const {
44 if (transaction_->GetResponseInfo()->is_directory_listing) { 55 if (transaction_->GetResponseInfo()->is_directory_listing) {
45 *mime_type = "text/vnd.chromium.ftp-dir"; 56 *mime_type = "text/vnd.chromium.ftp-dir";
46 return true; 57 return true;
47 } 58 }
48 return false; 59 return false;
49 } 60 }
50 61
51 HostPortPair URLRequestFtpJob::GetSocketAddress() const { 62 HostPortPair URLRequestFtpJob::GetSocketAddress() const {
52 if (!transaction_.get()) { 63 if (!transaction_.get()) {
53 return HostPortPair(); 64 return HostPortPair();
54 } 65 }
55 return transaction_->GetResponseInfo()->socket_address; 66 return transaction_->GetResponseInfo()->socket_address;
56 } 67 }
57 68
58 URLRequestFtpJob::~URLRequestFtpJob() { 69 URLRequestFtpJob::~URLRequestFtpJob() {
59 } 70 }
60 71
61 void URLRequestFtpJob::StartTransaction() { 72 void URLRequestFtpJob::StartTransaction() {
62 // Create a transaction. 73 // Create a transaction.
63 DCHECK(!transaction_.get()); 74 DCHECK(!transaction_.get());
64 DCHECK(request_->context()); 75 DCHECK(ftp_transaction_factory_);
erikwright (departed) 2012/06/07 19:14:51 Remove.
shalev 2012/06/21 20:04:55 Done.
shalev 2012/06/21 20:04:55 Done.
65 DCHECK(request_->context()->ftp_transaction_factory());
66 76
67 transaction_.reset( 77 transaction_.reset(ftp_transaction_factory_->CreateTransaction());
68 request_->context()->ftp_transaction_factory()->CreateTransaction());
69 78
70 // No matter what, we want to report our status as IO pending since we will 79 // No matter what, we want to report our status as IO pending since we will
71 // be notifying our consumer asynchronously via OnStartCompleted. 80 // be notifying our consumer asynchronously via OnStartCompleted.
72 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); 81 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
73 int rv; 82 int rv;
74 if (transaction_.get()) { 83 if (transaction_.get()) {
75 rv = transaction_->Start( 84 rv = transaction_->Start(
76 &request_info_, 85 &request_info_,
77 base::Bind(&URLRequestFtpJob::OnStartCompleted, 86 base::Bind(&URLRequestFtpJob::OnStartCompleted,
78 base::Unretained(this)), 87 base::Unretained(this)),
(...skipping 18 matching lines...) Expand all
97 // FTP obviously doesn't have HTTP Content-Length header. We have to pass 106 // FTP obviously doesn't have HTTP Content-Length header. We have to pass
98 // the content size information manually. 107 // the content size information manually.
99 set_expected_content_size( 108 set_expected_content_size(
100 transaction_->GetResponseInfo()->expected_content_size); 109 transaction_->GetResponseInfo()->expected_content_size);
101 110
102 if (result == OK) { 111 if (result == OK) {
103 NotifyHeadersComplete(); 112 NotifyHeadersComplete();
104 } else if (transaction_->GetResponseInfo()->needs_auth) { 113 } else if (transaction_->GetResponseInfo()->needs_auth) {
105 GURL origin = request_->url().GetOrigin(); 114 GURL origin = request_->url().GetOrigin();
106 if (server_auth_ && server_auth_->state == AUTH_STATE_HAVE_AUTH) { 115 if (server_auth_ && server_auth_->state == AUTH_STATE_HAVE_AUTH) {
107 request_->context()->ftp_auth_cache()->Remove( 116 ftp_auth_cache_->Remove(origin, server_auth_->credentials);
108 origin, server_auth_->credentials);
109 } else if (!server_auth_) { 117 } else if (!server_auth_) {
110 server_auth_ = new AuthData(); 118 server_auth_ = new AuthData();
111 } 119 }
112 server_auth_->state = AUTH_STATE_NEED_AUTH; 120 server_auth_->state = AUTH_STATE_NEED_AUTH;
113 121
114 FtpAuthCache::Entry* cached_auth = 122 FtpAuthCache::Entry* cached_auth =
115 request_->context()->ftp_auth_cache()->Lookup(origin); 123 ftp_auth_cache_->Lookup(origin);
116
117 if (cached_auth) { 124 if (cached_auth) {
118 // Retry using cached auth data. 125 // Retry using cached auth data.
119 SetAuth(cached_auth->credentials); 126 SetAuth(cached_auth->credentials);
120 } else { 127 } else {
121 // Prompt for a username/password. 128 // Prompt for a username/password.
122 NotifyHeadersComplete(); 129 NotifyHeadersComplete();
123 } 130 }
124 } else { 131 } else {
125 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); 132 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result));
126 } 133 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 DCHECK(auth_info->scheme.empty()); 204 DCHECK(auth_info->scheme.empty());
198 DCHECK(auth_info->realm.empty()); 205 DCHECK(auth_info->realm.empty());
199 result->swap(auth_info); 206 result->swap(auth_info);
200 } 207 }
201 208
202 void URLRequestFtpJob::SetAuth(const AuthCredentials& credentials) { 209 void URLRequestFtpJob::SetAuth(const AuthCredentials& credentials) {
203 DCHECK(NeedsAuth()); 210 DCHECK(NeedsAuth());
204 server_auth_->state = AUTH_STATE_HAVE_AUTH; 211 server_auth_->state = AUTH_STATE_HAVE_AUTH;
205 server_auth_->credentials = credentials; 212 server_auth_->credentials = credentials;
206 213
207 request_->context()->ftp_auth_cache()->Add(request_->url().GetOrigin(), 214 ftp_auth_cache_->Add(request_->url().GetOrigin(),
208 server_auth_->credentials); 215 server_auth_->credentials);
209 216
210 RestartTransactionWithAuth(); 217 RestartTransactionWithAuth();
211 } 218 }
212 219
213 void URLRequestFtpJob::CancelAuth() { 220 void URLRequestFtpJob::CancelAuth() {
214 DCHECK(NeedsAuth()); 221 DCHECK(NeedsAuth());
215 server_auth_->state = AUTH_STATE_CANCELED; 222 server_auth_->state = AUTH_STATE_CANCELED;
216 223
217 // Once the auth is cancelled, we proceed with the request as though 224 // Once the auth is cancelled, we proceed with the request as though
218 // there were no auth. Schedule this for later so that we don't cause 225 // there were no auth. Schedule this for later so that we don't cause
(...skipping 26 matching lines...) Expand all
245 if (rv == ERR_IO_PENDING) { 252 if (rv == ERR_IO_PENDING) {
246 read_in_progress_ = true; 253 read_in_progress_ = true;
247 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); 254 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
248 } else { 255 } else {
249 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); 256 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv));
250 } 257 }
251 return false; 258 return false;
252 } 259 }
253 260
254 } // namespace net 261 } // namespace net
OLDNEW
« net/url_request/url_request_ftp_job.h ('K') | « net/url_request/url_request_ftp_job.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698