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