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 "chrome/browser/automation/url_request_automation_job.h" | 5 #include "chrome/browser/automation/url_request_automation_job.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 AutomationResourceMessageFilter* filter, | 58 AutomationResourceMessageFilter* filter, |
59 bool is_pending) | 59 bool is_pending) |
60 : net::URLRequestJob(request, network_delegate), | 60 : net::URLRequestJob(request, network_delegate), |
61 id_(0), | 61 id_(0), |
62 tab_(tab), | 62 tab_(tab), |
63 message_filter_(filter), | 63 message_filter_(filter), |
64 pending_buf_size_(0), | 64 pending_buf_size_(0), |
65 redirect_status_(0), | 65 redirect_status_(0), |
66 request_id_(request_id), | 66 request_id_(request_id), |
67 is_pending_(is_pending), | 67 is_pending_(is_pending), |
| 68 upload_size_(0), |
68 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 69 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
69 DVLOG(1) << "URLRequestAutomationJob create. Count: " << ++instance_count_; | 70 DVLOG(1) << "URLRequestAutomationJob create. Count: " << ++instance_count_; |
70 DCHECK(message_filter_ != NULL); | 71 DCHECK(message_filter_ != NULL); |
71 | 72 |
72 if (message_filter_) { | 73 if (message_filter_) { |
73 id_ = message_filter_->NewAutomationRequestId(); | 74 id_ = message_filter_->NewAutomationRequestId(); |
74 DCHECK_NE(id_, 0); | 75 DCHECK_NE(id_, 0); |
75 } | 76 } |
76 } | 77 } |
77 | 78 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 bool URLRequestAutomationJob::IsRedirectResponse( | 226 bool URLRequestAutomationJob::IsRedirectResponse( |
226 GURL* location, int* http_status_code) { | 227 GURL* location, int* http_status_code) { |
227 if (!net::HttpResponseHeaders::IsRedirectResponseCode(redirect_status_)) | 228 if (!net::HttpResponseHeaders::IsRedirectResponseCode(redirect_status_)) |
228 return false; | 229 return false; |
229 | 230 |
230 *http_status_code = redirect_status_; | 231 *http_status_code = redirect_status_; |
231 *location = GURL(redirect_url_); | 232 *location = GURL(redirect_url_); |
232 return true; | 233 return true; |
233 } | 234 } |
234 | 235 |
235 uint64 URLRequestAutomationJob::GetUploadProgress() const { | 236 net::UploadProgress URLRequestAutomationJob::GetUploadProgress() const { |
| 237 uint64 progress = 0; |
236 if (request_ && request_->status().is_success()) { | 238 if (request_ && request_->status().is_success()) { |
237 // We don't support incremental progress notifications in ChromeFrame. When | 239 // We don't support incremental progress notifications in ChromeFrame. When |
238 // we receive a response for the POST request from Chromeframe, it means | 240 // we receive a response for the POST request from Chromeframe, it means |
239 // that the upload is fully complete. | 241 // that the upload is fully complete. |
240 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_); | 242 progress = upload_size_; |
241 if (info) { | |
242 return info->GetUploadSize(); | |
243 } | |
244 } | 243 } |
245 return 0; | 244 return net::UploadProgress(progress, upload_size_); |
246 } | 245 } |
247 | 246 |
248 net::HostPortPair URLRequestAutomationJob::GetSocketAddress() const { | 247 net::HostPortPair URLRequestAutomationJob::GetSocketAddress() const { |
249 return socket_address_; | 248 return socket_address_; |
250 } | 249 } |
251 | 250 |
252 bool URLRequestAutomationJob::MayFilterMessage(const IPC::Message& message, | 251 bool URLRequestAutomationJob::MayFilterMessage(const IPC::Message& message, |
253 int* request_id) { | 252 int* request_id) { |
254 switch (message.type()) { | 253 switch (message.type()) { |
255 case AutomationMsg_RequestStarted::ID: | 254 case AutomationMsg_RequestStarted::ID: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 redirect_status_ = response.redirect_status; | 297 redirect_status_ = response.redirect_status; |
299 DCHECK(redirect_status_ == 0 || redirect_status_ == 200 || | 298 DCHECK(redirect_status_ == 0 || redirect_status_ == 200 || |
300 (redirect_status_ >= 300 && redirect_status_ < 400)); | 299 (redirect_status_ >= 300 && redirect_status_ < 400)); |
301 | 300 |
302 if (!response.headers.empty()) { | 301 if (!response.headers.empty()) { |
303 headers_ = new net::HttpResponseHeaders( | 302 headers_ = new net::HttpResponseHeaders( |
304 net::HttpUtil::AssembleRawHeaders(response.headers.data(), | 303 net::HttpUtil::AssembleRawHeaders(response.headers.data(), |
305 response.headers.size())); | 304 response.headers.size())); |
306 } | 305 } |
307 socket_address_ = response.socket_address; | 306 socket_address_ = response.socket_address; |
| 307 upload_size_ = response.upload_size; |
308 NotifyHeadersComplete(); | 308 NotifyHeadersComplete(); |
309 } | 309 } |
310 | 310 |
311 void URLRequestAutomationJob::OnDataAvailable( | 311 void URLRequestAutomationJob::OnDataAvailable( |
312 int id, const std::string& bytes) { | 312 int id, const std::string& bytes) { |
313 DVLOG(1) << "URLRequestAutomationJob: " << request_->url().spec() | 313 DVLOG(1) << "URLRequestAutomationJob: " << request_->url().spec() |
314 << " - data available, Size: " << bytes.size(); | 314 << " - data available, Size: " << bytes.size(); |
315 DCHECK(!bytes.empty()); | 315 DCHECK(!bytes.empty()); |
316 | 316 |
317 // The request completed, and we have all the data. | 317 // The request completed, and we have all the data. |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 if (!is_done()) { | 488 if (!is_done()) { |
489 NotifyDone(request_status_); | 489 NotifyDone(request_status_); |
490 } | 490 } |
491 // Reset any pending reads. | 491 // Reset any pending reads. |
492 if (pending_buf_) { | 492 if (pending_buf_) { |
493 pending_buf_ = NULL; | 493 pending_buf_ = NULL; |
494 pending_buf_size_ = 0; | 494 pending_buf_size_ = 0; |
495 NotifyReadComplete(0); | 495 NotifyReadComplete(0); |
496 } | 496 } |
497 } | 497 } |
OLD | NEW |