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 // This file contains an implementation of the ResourceLoaderBridge class. | 5 // This file contains an implementation of the ResourceLoaderBridge class. |
6 // The class is implemented using net::URLRequest, meaning it is a "simple" | 6 // The class is implemented using net::URLRequest, meaning it is a "simple" |
7 // version that directly issues requests. The more complicated one used in the | 7 // version that directly issues requests. The more complicated one used in the |
8 // browser uses IPC. | 8 // browser uses IPC. |
9 // | 9 // |
10 // Because net::URLRequest only provides an asynchronous resource loading API, | 10 // Because net::URLRequest only provides an asynchronous resource loading API, |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 return; | 384 return; |
385 | 385 |
386 // Continue reading more data, see the comment in NotifyReceivedData. | 386 // Continue reading more data, see the comment in NotifyReceivedData. |
387 g_io_thread->message_loop()->PostTask( | 387 g_io_thread->message_loop()->PostTask( |
388 FROM_HERE, | 388 FROM_HERE, |
389 base::Bind(&RequestProxy::AsyncReadData, this)); | 389 base::Bind(&RequestProxy::AsyncReadData, this)); |
390 | 390 |
391 peer_->OnDownloadedData(bytes_read); | 391 peer_->OnDownloadedData(bytes_read); |
392 } | 392 } |
393 | 393 |
394 void NotifyCompletedRequest(const net::URLRequestStatus& status, | 394 void NotifyCompletedRequest(int error_code, |
395 const std::string& security_info, | 395 const std::string& security_info, |
396 const base::TimeTicks& complete_time) { | 396 const base::TimeTicks& complete_time) { |
397 if (peer_) { | 397 if (peer_) { |
398 peer_->OnCompletedRequest(status, security_info, complete_time); | 398 peer_->OnCompletedRequest(error_code, false, security_info, |
| 399 complete_time); |
399 DropPeer(); // ensure no further notifications | 400 DropPeer(); // ensure no further notifications |
400 } | 401 } |
401 } | 402 } |
402 | 403 |
403 void NotifyUploadProgress(uint64 position, uint64 size) { | 404 void NotifyUploadProgress(uint64 position, uint64 size) { |
404 if (peer_) | 405 if (peer_) |
405 peer_->OnUploadProgress(position, size); | 406 peer_->OnUploadProgress(position, size); |
406 } | 407 } |
407 | 408 |
408 // -------------------------------------------------------------------------- | 409 // -------------------------------------------------------------------------- |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 FROM_HERE, | 522 FROM_HERE, |
522 base::Bind(&RequestProxy::NotifyDownloadedData, this, bytes_read)); | 523 base::Bind(&RequestProxy::NotifyDownloadedData, this, bytes_read)); |
523 return; | 524 return; |
524 } | 525 } |
525 | 526 |
526 owner_loop_->PostTask( | 527 owner_loop_->PostTask( |
527 FROM_HERE, | 528 FROM_HERE, |
528 base::Bind(&RequestProxy::NotifyReceivedData, this, bytes_read)); | 529 base::Bind(&RequestProxy::NotifyReceivedData, this, bytes_read)); |
529 } | 530 } |
530 | 531 |
531 virtual void OnCompletedRequest(const net::URLRequestStatus& status, | 532 virtual void OnCompletedRequest(int error_code, |
532 const std::string& security_info, | 533 const std::string& security_info, |
533 const base::TimeTicks& complete_time) { | 534 const base::TimeTicks& complete_time) { |
534 if (download_to_file_) | 535 if (download_to_file_) |
535 file_stream_.CloseSync(); | 536 file_stream_.CloseSync(); |
536 owner_loop_->PostTask( | 537 owner_loop_->PostTask( |
537 FROM_HERE, | 538 FROM_HERE, |
538 base::Bind(&RequestProxy::NotifyCompletedRequest, this, status, | 539 base::Bind(&RequestProxy::NotifyCompletedRequest, this, error_code, |
539 security_info, complete_time)); | 540 security_info, complete_time)); |
540 } | 541 } |
541 | 542 |
542 // -------------------------------------------------------------------------- | 543 // -------------------------------------------------------------------------- |
543 // net::URLRequest::Delegate implementation: | 544 // net::URLRequest::Delegate implementation: |
544 | 545 |
545 virtual void OnReceivedRedirect(net::URLRequest* request, | 546 virtual void OnReceivedRedirect(net::URLRequest* request, |
546 const GURL& new_url, | 547 const GURL& new_url, |
547 bool* defer_redirect) OVERRIDE { | 548 bool* defer_redirect) OVERRIDE { |
548 DCHECK(request->status().is_success()); | 549 DCHECK(request->status().is_success()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 void Done() { | 593 void Done() { |
593 if (upload_progress_timer_.IsRunning()) { | 594 if (upload_progress_timer_.IsRunning()) { |
594 MaybeUpdateUploadProgress(); | 595 MaybeUpdateUploadProgress(); |
595 upload_progress_timer_.Stop(); | 596 upload_progress_timer_.Stop(); |
596 } | 597 } |
597 DCHECK(request_.get()); | 598 DCHECK(request_.get()); |
598 // If |failed_file_request_status_| is not empty, which means the request | 599 // If |failed_file_request_status_| is not empty, which means the request |
599 // was a file request and encountered an error, then we need to use the | 600 // was a file request and encountered an error, then we need to use the |
600 // |failed_file_request_status_|. Otherwise use request_'s status. | 601 // |failed_file_request_status_|. Otherwise use request_'s status. |
601 OnCompletedRequest(failed_file_request_status_.get() ? | 602 OnCompletedRequest(failed_file_request_status_.get() ? |
602 *failed_file_request_status_ : request_->status(), | 603 failed_file_request_status_->error() : |
| 604 request_->status().error(), |
603 std::string(), base::TimeTicks()); | 605 std::string(), base::TimeTicks()); |
604 request_.reset(); // destroy on the io thread | 606 request_.reset(); // destroy on the io thread |
605 } | 607 } |
606 | 608 |
607 // Called on the IO thread. | 609 // Called on the IO thread. |
608 void MaybeUpdateUploadProgress() { | 610 void MaybeUpdateUploadProgress() { |
609 // If a redirect is received upload is cancelled in net::URLRequest, we | 611 // If a redirect is received upload is cancelled in net::URLRequest, we |
610 // should try to stop the |upload_progress_timer_| timer and return. | 612 // should try to stop the |upload_progress_timer_| timer and return. |
611 if (!request_->has_upload()) { | 613 if (!request_->has_upload()) { |
612 if (upload_progress_timer_.IsRunning()) | 614 if (upload_progress_timer_.IsRunning()) |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 | 817 |
816 virtual void OnReceivedData(int bytes_read) OVERRIDE { | 818 virtual void OnReceivedData(int bytes_read) OVERRIDE { |
817 if (download_to_file_) | 819 if (download_to_file_) |
818 file_stream_.WriteSync(buf_->data(), bytes_read); | 820 file_stream_.WriteSync(buf_->data(), bytes_read); |
819 else | 821 else |
820 result_->data.append(buf_->data(), bytes_read); | 822 result_->data.append(buf_->data(), bytes_read); |
821 AsyncReadData(); // read more (may recurse) | 823 AsyncReadData(); // read more (may recurse) |
822 } | 824 } |
823 | 825 |
824 virtual void OnCompletedRequest( | 826 virtual void OnCompletedRequest( |
825 const net::URLRequestStatus& status, | 827 int error_code, |
826 const std::string& security_info, | 828 const std::string& security_info, |
827 const base::TimeTicks& complete_time) OVERRIDE { | 829 const base::TimeTicks& complete_time) OVERRIDE { |
828 if (download_to_file_) | 830 if (download_to_file_) |
829 file_stream_.CloseSync(); | 831 file_stream_.CloseSync(); |
830 result_->status = status; | 832 result_->error_code = error_code; |
831 event_.Signal(); | 833 event_.Signal(); |
832 } | 834 } |
833 | 835 |
834 protected: | 836 protected: |
835 virtual ~SyncRequestProxy() {} | 837 virtual ~SyncRequestProxy() {} |
836 | 838 |
837 private: | 839 private: |
838 ResourceLoaderBridge::SyncLoadResponse* result_; | 840 ResourceLoaderBridge::SyncLoadResponse* result_; |
839 base::WaitableEvent event_; | 841 base::WaitableEvent event_; |
840 }; | 842 }; |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1130 (http_prefix.SchemeIs("http") || http_prefix.SchemeIs("https"))); | 1132 (http_prefix.SchemeIs("http") || http_prefix.SchemeIs("https"))); |
1131 g_file_over_http_params = new FileOverHTTPParams(file_path_template, | 1133 g_file_over_http_params = new FileOverHTTPParams(file_path_template, |
1132 http_prefix); | 1134 http_prefix); |
1133 } | 1135 } |
1134 | 1136 |
1135 // static | 1137 // static |
1136 webkit_glue::ResourceLoaderBridge* SimpleResourceLoaderBridge::Create( | 1138 webkit_glue::ResourceLoaderBridge* SimpleResourceLoaderBridge::Create( |
1137 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { | 1139 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { |
1138 return new ResourceLoaderBridgeImpl(request_info); | 1140 return new ResourceLoaderBridgeImpl(request_info); |
1139 } | 1141 } |
OLD | NEW |