| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 // Continue reading more data, see the comment in NotifyReceivedData. | 281 // Continue reading more data, see the comment in NotifyReceivedData. |
| 282 g_io_thread->message_loop()->PostTask( | 282 g_io_thread->message_loop()->PostTask( |
| 283 FROM_HERE, | 283 FROM_HERE, |
| 284 base::Bind(&RequestProxy::AsyncReadData, this)); | 284 base::Bind(&RequestProxy::AsyncReadData, this)); |
| 285 | 285 |
| 286 peer_->OnDownloadedData(bytes_read); | 286 peer_->OnDownloadedData(bytes_read); |
| 287 } | 287 } |
| 288 | 288 |
| 289 void NotifyCompletedRequest(const net::URLRequestStatus& status, | 289 void NotifyCompletedRequest(const net::URLRequestStatus& status, |
| 290 const std::string& security_info, | 290 const std::string& security_info, |
| 291 const base::Time& complete_time) { | 291 const base::TimeTicks& complete_time) { |
| 292 if (peer_) { | 292 if (peer_) { |
| 293 peer_->OnCompletedRequest(status, security_info, complete_time); | 293 peer_->OnCompletedRequest(status, security_info, complete_time); |
| 294 DropPeer(); // ensure no further notifications | 294 DropPeer(); // ensure no further notifications |
| 295 } | 295 } |
| 296 } | 296 } |
| 297 | 297 |
| 298 void NotifyUploadProgress(uint64 position, uint64 size) { | 298 void NotifyUploadProgress(uint64 position, uint64 size) { |
| 299 if (peer_) | 299 if (peer_) |
| 300 peer_->OnUploadProgress(position, size); | 300 peer_->OnUploadProgress(position, size); |
| 301 } | 301 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 return; | 416 return; |
| 417 } | 417 } |
| 418 | 418 |
| 419 owner_loop_->PostTask( | 419 owner_loop_->PostTask( |
| 420 FROM_HERE, | 420 FROM_HERE, |
| 421 base::Bind(&RequestProxy::NotifyReceivedData, this, bytes_read)); | 421 base::Bind(&RequestProxy::NotifyReceivedData, this, bytes_read)); |
| 422 } | 422 } |
| 423 | 423 |
| 424 virtual void OnCompletedRequest(const net::URLRequestStatus& status, | 424 virtual void OnCompletedRequest(const net::URLRequestStatus& status, |
| 425 const std::string& security_info, | 425 const std::string& security_info, |
| 426 const base::Time& complete_time) { | 426 const base::TimeTicks& complete_time) { |
| 427 if (download_to_file_) | 427 if (download_to_file_) |
| 428 file_stream_.Close(); | 428 file_stream_.Close(); |
| 429 owner_loop_->PostTask( | 429 owner_loop_->PostTask( |
| 430 FROM_HERE, | 430 FROM_HERE, |
| 431 base::Bind(&RequestProxy::NotifyCompletedRequest, this, status, | 431 base::Bind(&RequestProxy::NotifyCompletedRequest, this, status, |
| 432 security_info, complete_time)); | 432 security_info, complete_time)); |
| 433 } | 433 } |
| 434 | 434 |
| 435 // -------------------------------------------------------------------------- | 435 // -------------------------------------------------------------------------- |
| 436 // net::URLRequest::Delegate implementation: | 436 // net::URLRequest::Delegate implementation: |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 if (upload_progress_timer_.IsRunning()) { | 512 if (upload_progress_timer_.IsRunning()) { |
| 513 MaybeUpdateUploadProgress(); | 513 MaybeUpdateUploadProgress(); |
| 514 upload_progress_timer_.Stop(); | 514 upload_progress_timer_.Stop(); |
| 515 } | 515 } |
| 516 DCHECK(request_.get()); | 516 DCHECK(request_.get()); |
| 517 // If |failed_file_request_status_| is not empty, which means the request | 517 // If |failed_file_request_status_| is not empty, which means the request |
| 518 // was a file request and encountered an error, then we need to use the | 518 // was a file request and encountered an error, then we need to use the |
| 519 // |failed_file_request_status_|. Otherwise use request_'s status. | 519 // |failed_file_request_status_|. Otherwise use request_'s status. |
| 520 OnCompletedRequest(failed_file_request_status_.get() ? | 520 OnCompletedRequest(failed_file_request_status_.get() ? |
| 521 *failed_file_request_status_ : request_->status(), | 521 *failed_file_request_status_ : request_->status(), |
| 522 std::string(), base::Time()); | 522 std::string(), base::TimeTicks()); |
| 523 request_.reset(); // destroy on the io thread | 523 request_.reset(); // destroy on the io thread |
| 524 } | 524 } |
| 525 | 525 |
| 526 // Called on the IO thread. | 526 // Called on the IO thread. |
| 527 void MaybeUpdateUploadProgress() { | 527 void MaybeUpdateUploadProgress() { |
| 528 // If a redirect is received upload is cancelled in net::URLRequest, we | 528 // If a redirect is received upload is cancelled in net::URLRequest, we |
| 529 // should try to stop the |upload_progress_timer_| timer and return. | 529 // should try to stop the |upload_progress_timer_| timer and return. |
| 530 if (!request_->has_upload()) { | 530 if (!request_->has_upload()) { |
| 531 if (upload_progress_timer_.IsRunning()) | 531 if (upload_progress_timer_.IsRunning()) |
| 532 upload_progress_timer_.Stop(); | 532 upload_progress_timer_.Stop(); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 virtual void OnReceivedData(int bytes_read) { | 722 virtual void OnReceivedData(int bytes_read) { |
| 723 if (download_to_file_) | 723 if (download_to_file_) |
| 724 file_stream_.Write(buf_->data(), bytes_read, net::CompletionCallback()); | 724 file_stream_.Write(buf_->data(), bytes_read, net::CompletionCallback()); |
| 725 else | 725 else |
| 726 result_->data.append(buf_->data(), bytes_read); | 726 result_->data.append(buf_->data(), bytes_read); |
| 727 AsyncReadData(); // read more (may recurse) | 727 AsyncReadData(); // read more (may recurse) |
| 728 } | 728 } |
| 729 | 729 |
| 730 virtual void OnCompletedRequest(const net::URLRequestStatus& status, | 730 virtual void OnCompletedRequest(const net::URLRequestStatus& status, |
| 731 const std::string& security_info, | 731 const std::string& security_info, |
| 732 const base::Time& complete_time) { | 732 const base::TimeTicks& complete_time) { |
| 733 if (download_to_file_) | 733 if (download_to_file_) |
| 734 file_stream_.Close(); | 734 file_stream_.Close(); |
| 735 result_->status = status; | 735 result_->status = status; |
| 736 event_.Signal(); | 736 event_.Signal(); |
| 737 } | 737 } |
| 738 | 738 |
| 739 private: | 739 private: |
| 740 ResourceLoaderBridge::SyncLoadResponse* result_; | 740 ResourceLoaderBridge::SyncLoadResponse* result_; |
| 741 base::WaitableEvent event_; | 741 base::WaitableEvent event_; |
| 742 }; | 742 }; |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1032 (http_prefix.SchemeIs("http") || http_prefix.SchemeIs("https"))); | 1032 (http_prefix.SchemeIs("http") || http_prefix.SchemeIs("https"))); |
| 1033 g_file_over_http_params = new FileOverHTTPParams(file_path_template, | 1033 g_file_over_http_params = new FileOverHTTPParams(file_path_template, |
| 1034 http_prefix); | 1034 http_prefix); |
| 1035 } | 1035 } |
| 1036 | 1036 |
| 1037 // static | 1037 // static |
| 1038 webkit_glue::ResourceLoaderBridge* SimpleResourceLoaderBridge::Create( | 1038 webkit_glue::ResourceLoaderBridge* SimpleResourceLoaderBridge::Create( |
| 1039 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { | 1039 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { |
| 1040 return new ResourceLoaderBridgeImpl(request_info); | 1040 return new ResourceLoaderBridgeImpl(request_info); |
| 1041 } | 1041 } |
| OLD | NEW |