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_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" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 // the content size information manually. | 110 // the content size information manually. |
111 set_expected_content_size( | 111 set_expected_content_size( |
112 transaction_->GetResponseInfo()->expected_content_size); | 112 transaction_->GetResponseInfo()->expected_content_size); |
113 } | 113 } |
114 | 114 |
115 if (result == OK) { | 115 if (result == OK) { |
116 NotifyHeadersComplete(); | 116 NotifyHeadersComplete(); |
117 } else if (transaction_.get() && | 117 } else if (transaction_.get() && |
118 transaction_->GetResponseInfo()->needs_auth) { | 118 transaction_->GetResponseInfo()->needs_auth) { |
119 GURL origin = request_->url().GetOrigin(); | 119 GURL origin = request_->url().GetOrigin(); |
120 if (server_auth_ && server_auth_->state == AUTH_STATE_HAVE_AUTH) { | 120 if (server_auth_.get() && server_auth_->state == AUTH_STATE_HAVE_AUTH) { |
121 ftp_auth_cache_->Remove(origin, server_auth_->credentials); | 121 ftp_auth_cache_->Remove(origin, server_auth_->credentials); |
122 } else if (!server_auth_) { | 122 } else if (!server_auth_.get()) { |
123 server_auth_ = new AuthData(); | 123 server_auth_ = new AuthData(); |
124 } | 124 } |
125 server_auth_->state = AUTH_STATE_NEED_AUTH; | 125 server_auth_->state = AUTH_STATE_NEED_AUTH; |
126 | 126 |
127 FtpAuthCache::Entry* cached_auth = ftp_auth_cache_->Lookup(origin); | 127 FtpAuthCache::Entry* cached_auth = ftp_auth_cache_->Lookup(origin); |
128 if (cached_auth) { | 128 if (cached_auth) { |
129 // Retry using cached auth data. | 129 // Retry using cached auth data. |
130 SetAuth(cached_auth->credentials); | 130 SetAuth(cached_auth->credentials); |
131 } else { | 131 } else { |
132 // Prompt for a username/password. | 132 // Prompt for a username/password. |
(...skipping 11 matching lines...) Expand all Loading... |
144 } else if (result < 0) { | 144 } else if (result < 0) { |
145 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); | 145 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); |
146 } else { | 146 } else { |
147 // Clear the IO_PENDING status | 147 // Clear the IO_PENDING status |
148 SetStatus(URLRequestStatus()); | 148 SetStatus(URLRequestStatus()); |
149 } | 149 } |
150 NotifyReadComplete(result); | 150 NotifyReadComplete(result); |
151 } | 151 } |
152 | 152 |
153 void URLRequestFtpJob::RestartTransactionWithAuth() { | 153 void URLRequestFtpJob::RestartTransactionWithAuth() { |
154 DCHECK(server_auth_ && server_auth_->state == AUTH_STATE_HAVE_AUTH); | 154 DCHECK(server_auth_.get() && server_auth_->state == AUTH_STATE_HAVE_AUTH); |
155 | 155 |
156 // No matter what, we want to report our status as IO pending since we will | 156 // No matter what, we want to report our status as IO pending since we will |
157 // be notifying our consumer asynchronously via OnStartCompleted. | 157 // be notifying our consumer asynchronously via OnStartCompleted. |
158 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 158 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
159 | 159 |
160 int rv = transaction_->RestartWithAuth( | 160 int rv = transaction_->RestartWithAuth( |
161 server_auth_->credentials, | 161 server_auth_->credentials, |
162 base::Bind(&URLRequestFtpJob::OnStartCompleted, | 162 base::Bind(&URLRequestFtpJob::OnStartCompleted, |
163 base::Unretained(this))); | 163 base::Unretained(this))); |
164 if (rv == ERR_IO_PENDING) | 164 if (rv == ERR_IO_PENDING) |
(...skipping 22 matching lines...) Expand all Loading... |
187 LoadState URLRequestFtpJob::GetLoadState() const { | 187 LoadState URLRequestFtpJob::GetLoadState() const { |
188 return transaction_.get() ? | 188 return transaction_.get() ? |
189 transaction_->GetLoadState() : LOAD_STATE_IDLE; | 189 transaction_->GetLoadState() : LOAD_STATE_IDLE; |
190 } | 190 } |
191 | 191 |
192 bool URLRequestFtpJob::NeedsAuth() { | 192 bool URLRequestFtpJob::NeedsAuth() { |
193 // Note that we only have to worry about cases where an actual FTP server | 193 // Note that we only have to worry about cases where an actual FTP server |
194 // requires auth (and not a proxy), because connecting to FTP via proxy | 194 // requires auth (and not a proxy), because connecting to FTP via proxy |
195 // effectively means the browser communicates via HTTP, and uses HTTP's | 195 // effectively means the browser communicates via HTTP, and uses HTTP's |
196 // Proxy-Authenticate protocol when proxy servers require auth. | 196 // Proxy-Authenticate protocol when proxy servers require auth. |
197 return server_auth_ && server_auth_->state == AUTH_STATE_NEED_AUTH; | 197 return server_auth_.get() && server_auth_->state == AUTH_STATE_NEED_AUTH; |
198 } | 198 } |
199 | 199 |
200 void URLRequestFtpJob::GetAuthChallengeInfo( | 200 void URLRequestFtpJob::GetAuthChallengeInfo( |
201 scoped_refptr<AuthChallengeInfo>* result) { | 201 scoped_refptr<AuthChallengeInfo>* result) { |
202 DCHECK((server_auth_ != NULL) && | 202 DCHECK((server_auth_.get() != NULL) && |
203 (server_auth_->state == AUTH_STATE_NEED_AUTH)); | 203 (server_auth_->state == AUTH_STATE_NEED_AUTH)); |
204 scoped_refptr<AuthChallengeInfo> auth_info(new AuthChallengeInfo); | 204 scoped_refptr<AuthChallengeInfo> auth_info(new AuthChallengeInfo); |
205 auth_info->is_proxy = false; | 205 auth_info->is_proxy = false; |
206 auth_info->challenger = HostPortPair::FromURL(request_->url()); | 206 auth_info->challenger = HostPortPair::FromURL(request_->url()); |
207 // scheme and realm are kept empty. | 207 // scheme and realm are kept empty. |
208 DCHECK(auth_info->scheme.empty()); | 208 DCHECK(auth_info->scheme.empty()); |
209 DCHECK(auth_info->realm.empty()); | 209 DCHECK(auth_info->realm.empty()); |
210 result->swap(auth_info); | 210 result->swap(auth_info); |
211 } | 211 } |
212 | 212 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 if (rv == ERR_IO_PENDING) { | 255 if (rv == ERR_IO_PENDING) { |
256 read_in_progress_ = true; | 256 read_in_progress_ = true; |
257 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 257 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
258 } else { | 258 } else { |
259 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 259 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
260 } | 260 } |
261 return false; | 261 return false; |
262 } | 262 } |
263 | 263 |
264 } // namespace net | 264 } // namespace net |
OLD | NEW |