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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 return; | 391 return; |
392 | 392 |
393 // Continue reading more data, see the comment in NotifyReceivedData. | 393 // Continue reading more data, see the comment in NotifyReceivedData. |
394 g_io_thread->message_loop()->PostTask( | 394 g_io_thread->message_loop()->PostTask( |
395 FROM_HERE, | 395 FROM_HERE, |
396 base::Bind(&RequestProxy::AsyncReadData, this)); | 396 base::Bind(&RequestProxy::AsyncReadData, this)); |
397 | 397 |
398 peer_->OnDownloadedData(bytes_read); | 398 peer_->OnDownloadedData(bytes_read); |
399 } | 399 } |
400 | 400 |
401 void NotifyCompletedRequest(const net::URLRequestStatus& status, | 401 void NotifyCompletedRequest(int error_code, |
402 const std::string& security_info, | 402 const std::string& security_info, |
403 const base::TimeTicks& complete_time) { | 403 const base::TimeTicks& complete_time) { |
404 if (peer_) { | 404 if (peer_) { |
405 peer_->OnCompletedRequest(status, security_info, complete_time); | 405 peer_->OnCompletedRequest(error_code, false, security_info, |
| 406 complete_time); |
406 DropPeer(); // ensure no further notifications | 407 DropPeer(); // ensure no further notifications |
407 } | 408 } |
408 } | 409 } |
409 | 410 |
410 void NotifyUploadProgress(uint64 position, uint64 size) { | 411 void NotifyUploadProgress(uint64 position, uint64 size) { |
411 if (peer_) | 412 if (peer_) |
412 peer_->OnUploadProgress(position, size); | 413 peer_->OnUploadProgress(position, size); |
413 } | 414 } |
414 | 415 |
415 // -------------------------------------------------------------------------- | 416 // -------------------------------------------------------------------------- |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 FROM_HERE, | 527 FROM_HERE, |
527 base::Bind(&RequestProxy::NotifyDownloadedData, this, bytes_read)); | 528 base::Bind(&RequestProxy::NotifyDownloadedData, this, bytes_read)); |
528 return; | 529 return; |
529 } | 530 } |
530 | 531 |
531 owner_loop_->PostTask( | 532 owner_loop_->PostTask( |
532 FROM_HERE, | 533 FROM_HERE, |
533 base::Bind(&RequestProxy::NotifyReceivedData, this, bytes_read)); | 534 base::Bind(&RequestProxy::NotifyReceivedData, this, bytes_read)); |
534 } | 535 } |
535 | 536 |
536 virtual void OnCompletedRequest(const net::URLRequestStatus& status, | 537 virtual void OnCompletedRequest(int error_code, |
537 const std::string& security_info, | 538 const std::string& security_info, |
538 const base::TimeTicks& complete_time) { | 539 const base::TimeTicks& complete_time) { |
539 if (download_to_file_) | 540 if (download_to_file_) |
540 file_stream_.CloseSync(); | 541 file_stream_.CloseSync(); |
541 owner_loop_->PostTask( | 542 owner_loop_->PostTask( |
542 FROM_HERE, | 543 FROM_HERE, |
543 base::Bind(&RequestProxy::NotifyCompletedRequest, this, status, | 544 base::Bind(&RequestProxy::NotifyCompletedRequest, this, error_code, |
544 security_info, complete_time)); | 545 security_info, complete_time)); |
545 } | 546 } |
546 | 547 |
547 // -------------------------------------------------------------------------- | 548 // -------------------------------------------------------------------------- |
548 // net::URLRequest::Delegate implementation: | 549 // net::URLRequest::Delegate implementation: |
549 | 550 |
550 virtual void OnReceivedRedirect(net::URLRequest* request, | 551 virtual void OnReceivedRedirect(net::URLRequest* request, |
551 const GURL& new_url, | 552 const GURL& new_url, |
552 bool* defer_redirect) OVERRIDE { | 553 bool* defer_redirect) OVERRIDE { |
553 DCHECK(request->status().is_success()); | 554 DCHECK(request->status().is_success()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 void Done() { | 598 void Done() { |
598 if (upload_progress_timer_.IsRunning()) { | 599 if (upload_progress_timer_.IsRunning()) { |
599 MaybeUpdateUploadProgress(); | 600 MaybeUpdateUploadProgress(); |
600 upload_progress_timer_.Stop(); | 601 upload_progress_timer_.Stop(); |
601 } | 602 } |
602 DCHECK(request_.get()); | 603 DCHECK(request_.get()); |
603 // If |failed_file_request_status_| is not empty, which means the request | 604 // If |failed_file_request_status_| is not empty, which means the request |
604 // was a file request and encountered an error, then we need to use the | 605 // was a file request and encountered an error, then we need to use the |
605 // |failed_file_request_status_|. Otherwise use request_'s status. | 606 // |failed_file_request_status_|. Otherwise use request_'s status. |
606 OnCompletedRequest(failed_file_request_status_.get() ? | 607 OnCompletedRequest(failed_file_request_status_.get() ? |
607 *failed_file_request_status_ : request_->status(), | 608 failed_file_request_status_->error() : |
| 609 request_->status().error(), |
608 std::string(), base::TimeTicks()); | 610 std::string(), base::TimeTicks()); |
609 request_.reset(); // destroy on the io thread | 611 request_.reset(); // destroy on the io thread |
610 } | 612 } |
611 | 613 |
612 // Called on the IO thread. | 614 // Called on the IO thread. |
613 void MaybeUpdateUploadProgress() { | 615 void MaybeUpdateUploadProgress() { |
614 // If a redirect is received upload is cancelled in net::URLRequest, we | 616 // If a redirect is received upload is cancelled in net::URLRequest, we |
615 // should try to stop the |upload_progress_timer_| timer and return. | 617 // should try to stop the |upload_progress_timer_| timer and return. |
616 if (!request_->has_upload()) { | 618 if (!request_->has_upload()) { |
617 if (upload_progress_timer_.IsRunning()) | 619 if (upload_progress_timer_.IsRunning()) |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 | 819 |
818 virtual void OnReceivedData(int bytes_read) OVERRIDE { | 820 virtual void OnReceivedData(int bytes_read) OVERRIDE { |
819 if (download_to_file_) | 821 if (download_to_file_) |
820 file_stream_.WriteSync(buf_->data(), bytes_read); | 822 file_stream_.WriteSync(buf_->data(), bytes_read); |
821 else | 823 else |
822 result_->data.append(buf_->data(), bytes_read); | 824 result_->data.append(buf_->data(), bytes_read); |
823 AsyncReadData(); // read more (may recurse) | 825 AsyncReadData(); // read more (may recurse) |
824 } | 826 } |
825 | 827 |
826 virtual void OnCompletedRequest( | 828 virtual void OnCompletedRequest( |
827 const net::URLRequestStatus& status, | 829 int error_code, |
828 const std::string& security_info, | 830 const std::string& security_info, |
829 const base::TimeTicks& complete_time) OVERRIDE { | 831 const base::TimeTicks& complete_time) OVERRIDE { |
830 if (download_to_file_) | 832 if (download_to_file_) |
831 file_stream_.CloseSync(); | 833 file_stream_.CloseSync(); |
832 result_->status = status; | 834 result_->error_code = error_code; |
833 event_.Signal(); | 835 event_.Signal(); |
834 } | 836 } |
835 | 837 |
836 protected: | 838 protected: |
837 virtual ~SyncRequestProxy() {} | 839 virtual ~SyncRequestProxy() {} |
838 | 840 |
839 private: | 841 private: |
840 ResourceLoaderBridge::SyncLoadResponse* result_; | 842 ResourceLoaderBridge::SyncLoadResponse* result_; |
841 base::WaitableEvent event_; | 843 base::WaitableEvent event_; |
842 }; | 844 }; |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 (http_prefix.SchemeIs("http") || http_prefix.SchemeIs("https"))); | 1107 (http_prefix.SchemeIs("http") || http_prefix.SchemeIs("https"))); |
1106 g_file_over_http_params = new FileOverHTTPParams(file_path_template, | 1108 g_file_over_http_params = new FileOverHTTPParams(file_path_template, |
1107 http_prefix); | 1109 http_prefix); |
1108 } | 1110 } |
1109 | 1111 |
1110 // static | 1112 // static |
1111 webkit_glue::ResourceLoaderBridge* SimpleResourceLoaderBridge::Create( | 1113 webkit_glue::ResourceLoaderBridge* SimpleResourceLoaderBridge::Create( |
1112 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { | 1114 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { |
1113 return new ResourceLoaderBridgeImpl(request_info); | 1115 return new ResourceLoaderBridgeImpl(request_info); |
1114 } | 1116 } |
OLD | NEW |