From 7335ab0c8b9afb8a3c702d97925c1a0278a45ab7 Mon Sep 17 00:00:00 2001 From: "hashimoto@chromium.org" Date: Thu, 30 Aug 2012 22:30:42 +0000 Subject: Stop using ScopedAllowIO in content::ResourceDispatcherHostImpl Summary: UploadData::GetContentLengthSync() call is removed from ResourceDispatcherHostImpl. The return type of net::URLRequest::GetUploadProgress() is changed from uint64 to net::UploadProgress. A new member 'upload_size' is added to AutomationURLResponse for Chrome Frame. content::ResourceDispatcherHostImpl has been using UploadData::GetContentLengthSync() which needs ScopedAllowIO. To stop using ScopedAllowIO, there were three options considered. 1. Use asynchronous version UploadData::GetContentLength() which does not need ScopedAllowIO. pros: Changes would be minimal and straight-forward. cons: GetContentLength() is also called in UploadDataStream::Init(). If we start reusing the value, there is no need to call the same method here. 2. Communicate the upload data size to ResourceDispatcherHost by adding an event OnRequestBodyInitialized() to URLRequest::Delegate. pros: No duplicated GetContentLength() call here and in UploadDataStream::Init(). cons: Complicated interface. 3. Return upload data size as well as upload progress from URLRequest::GetUploadProgress(). pros: No duplicated GetContentLength() call here and in UploadDataStream::Init(). Simple interface. Making sense because upload progress and upload size are almost always used together (see ResourceHandler::OnUploadProgress and DOM ProgressEvent as examples). cons: Polling upload data size may imply that the size may change. We've decided to go with #3. The return type of net::URLRequest::GetUploadProgress() is changed from uint64 to net::UploadProgress, and URLRequest::GetUploadProgress() is used to get the upload size from ResourceDispatcherHostImpl instead of UploadData::GetContentLengthSync(). In Chrome Frame, URLRequestAutomationJob is used instead of URLRequestHttpJob and UploadDataStream is not initialized in the browser process. This is problematic since we cannot know the size of upload data without UploadDataStream. To deal with this, a new member 'upload_size' is added to AutomationURLResponse and the value is used to implement URLRequestAutomationJob::GetUploadProgress(). BUG=112607 TEST=Can upload files Review URL: https://chromiumcodereview.appspot.com/10825073 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@154286 0039d316-1c4b-4281-b951-d872f2087c98 --- .../tools/test_shell/simple_resource_loader_bridge.cc | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'webkit') diff --git a/webkit/tools/test_shell/simple_resource_loader_bridge.cc b/webkit/tools/test_shell/simple_resource_loader_bridge.cc index d233da6..a6becac 100644 --- a/webkit/tools/test_shell/simple_resource_loader_bridge.cc +++ b/webkit/tools/test_shell/simple_resource_loader_bridge.cc @@ -618,32 +618,29 @@ class RequestProxy return; } - // GetContentLengthSync() may perform file IO, but it's ok here, as file - // IO is not prohibited in IOThread defined in the file. - uint64 size = request_->get_upload_mutable()->GetContentLengthSync(); - uint64 position = request_->GetUploadProgress(); - if (position == last_upload_position_) + net::UploadProgress progress = request_->GetUploadProgress(); + if (progress.position() == last_upload_position_) return; // no progress made since last time const uint64 kHalfPercentIncrements = 200; const base::TimeDelta kOneSecond = base::TimeDelta::FromMilliseconds(1000); - uint64 amt_since_last = position - last_upload_position_; + uint64 amt_since_last = progress.position() - last_upload_position_; base::TimeDelta time_since_last = base::TimeTicks::Now() - last_upload_ticks_; - bool is_finished = (size == position); - bool enough_new_progress = (amt_since_last > (size / + bool is_finished = (progress.size() == progress.position()); + bool enough_new_progress = (amt_since_last > (progress.size() / kHalfPercentIncrements)); bool too_much_time_passed = time_since_last > kOneSecond; if (is_finished || enough_new_progress || too_much_time_passed) { owner_loop_->PostTask( FROM_HERE, - base::Bind(&RequestProxy::NotifyUploadProgress, this, position, - size)); + base::Bind(&RequestProxy::NotifyUploadProgress, this, + progress.position(), progress.size())); last_upload_ticks_ = base::TimeTicks::Now(); - last_upload_position_ = position; + last_upload_position_ = progress.position(); } } -- cgit v1.1