| 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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 request_->set_context(g_request_context); | 325 request_->set_context(g_request_context); |
| 326 SimpleAppCacheSystem::SetExtraRequestInfo( | 326 SimpleAppCacheSystem::SetExtraRequestInfo( |
| 327 request_.get(), params->appcache_host_id, params->request_type); | 327 request_.get(), params->appcache_host_id, params->request_type); |
| 328 | 328 |
| 329 download_to_file_ = params->download_to_file; | 329 download_to_file_ = params->download_to_file; |
| 330 if (download_to_file_) { | 330 if (download_to_file_) { |
| 331 FilePath path; | 331 FilePath path; |
| 332 if (file_util::CreateTemporaryFile(&path)) { | 332 if (file_util::CreateTemporaryFile(&path)) { |
| 333 downloaded_file_ = DeletableFileReference::GetOrCreate( | 333 downloaded_file_ = DeletableFileReference::GetOrCreate( |
| 334 path, base::MessageLoopProxy::current()); | 334 path, base::MessageLoopProxy::current()); |
| 335 file_stream_.Open( | 335 file_stream_.OpenSync( |
| 336 path, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE); | 336 path, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE); |
| 337 } | 337 } |
| 338 } | 338 } |
| 339 | 339 |
| 340 request_->Start(); | 340 request_->Start(); |
| 341 | 341 |
| 342 if (request_->has_upload() && | 342 if (request_->has_upload() && |
| 343 params->load_flags & net::LOAD_ENABLE_UPLOAD_PROGRESS) { | 343 params->load_flags & net::LOAD_ENABLE_UPLOAD_PROGRESS) { |
| 344 upload_progress_timer_.Start(FROM_HERE, | 344 upload_progress_timer_.Start(FROM_HERE, |
| 345 base::TimeDelta::FromMilliseconds(kUpdateUploadProgressIntervalMsec), | 345 base::TimeDelta::FromMilliseconds(kUpdateUploadProgressIntervalMsec), |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 | 419 |
| 420 owner_loop_->PostTask( | 420 owner_loop_->PostTask( |
| 421 FROM_HERE, | 421 FROM_HERE, |
| 422 base::Bind(&RequestProxy::NotifyReceivedData, this, bytes_read)); | 422 base::Bind(&RequestProxy::NotifyReceivedData, this, bytes_read)); |
| 423 } | 423 } |
| 424 | 424 |
| 425 virtual void OnCompletedRequest(const net::URLRequestStatus& status, | 425 virtual void OnCompletedRequest(const net::URLRequestStatus& status, |
| 426 const std::string& security_info, | 426 const std::string& security_info, |
| 427 const base::TimeTicks& complete_time) { | 427 const base::TimeTicks& complete_time) { |
| 428 if (download_to_file_) | 428 if (download_to_file_) |
| 429 file_stream_.Close(); | 429 file_stream_.CloseSync(); |
| 430 owner_loop_->PostTask( | 430 owner_loop_->PostTask( |
| 431 FROM_HERE, | 431 FROM_HERE, |
| 432 base::Bind(&RequestProxy::NotifyCompletedRequest, this, status, | 432 base::Bind(&RequestProxy::NotifyCompletedRequest, this, status, |
| 433 security_info, complete_time)); | 433 security_info, complete_time)); |
| 434 } | 434 } |
| 435 | 435 |
| 436 // -------------------------------------------------------------------------- | 436 // -------------------------------------------------------------------------- |
| 437 // net::URLRequest::Delegate implementation: | 437 // net::URLRequest::Delegate implementation: |
| 438 | 438 |
| 439 virtual void OnReceivedRedirect(net::URLRequest* request, | 439 virtual void OnReceivedRedirect(net::URLRequest* request, |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 file_stream_.Write(buf_->data(), bytes_read, net::CompletionCallback()); | 725 file_stream_.Write(buf_->data(), bytes_read, net::CompletionCallback()); |
| 726 else | 726 else |
| 727 result_->data.append(buf_->data(), bytes_read); | 727 result_->data.append(buf_->data(), bytes_read); |
| 728 AsyncReadData(); // read more (may recurse) | 728 AsyncReadData(); // read more (may recurse) |
| 729 } | 729 } |
| 730 | 730 |
| 731 virtual void OnCompletedRequest(const net::URLRequestStatus& status, | 731 virtual void OnCompletedRequest(const net::URLRequestStatus& status, |
| 732 const std::string& security_info, | 732 const std::string& security_info, |
| 733 const base::TimeTicks& complete_time) { | 733 const base::TimeTicks& complete_time) { |
| 734 if (download_to_file_) | 734 if (download_to_file_) |
| 735 file_stream_.Close(); | 735 file_stream_.CloseSync(); |
| 736 result_->status = status; | 736 result_->status = status; |
| 737 event_.Signal(); | 737 event_.Signal(); |
| 738 } | 738 } |
| 739 | 739 |
| 740 private: | 740 private: |
| 741 ResourceLoaderBridge::SyncLoadResponse* result_; | 741 ResourceLoaderBridge::SyncLoadResponse* result_; |
| 742 base::WaitableEvent event_; | 742 base::WaitableEvent event_; |
| 743 }; | 743 }; |
| 744 | 744 |
| 745 //----------------------------------------------------------------------------- | 745 //----------------------------------------------------------------------------- |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1033 (http_prefix.SchemeIs("http") || http_prefix.SchemeIs("https"))); | 1033 (http_prefix.SchemeIs("http") || http_prefix.SchemeIs("https"))); |
| 1034 g_file_over_http_params = new FileOverHTTPParams(file_path_template, | 1034 g_file_over_http_params = new FileOverHTTPParams(file_path_template, |
| 1035 http_prefix); | 1035 http_prefix); |
| 1036 } | 1036 } |
| 1037 | 1037 |
| 1038 // static | 1038 // static |
| 1039 webkit_glue::ResourceLoaderBridge* SimpleResourceLoaderBridge::Create( | 1039 webkit_glue::ResourceLoaderBridge* SimpleResourceLoaderBridge::Create( |
| 1040 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { | 1040 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { |
| 1041 return new ResourceLoaderBridgeImpl(request_info); | 1041 return new ResourceLoaderBridgeImpl(request_info); |
| 1042 } | 1042 } |
| OLD | NEW |