diff options
author | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-30 22:30:42 +0000 |
---|---|---|
committer | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-30 22:30:42 +0000 |
commit | 7335ab0c8b9afb8a3c702d97925c1a0278a45ab7 (patch) | |
tree | 164f7ba73256cd36ab67ed1f02992eb740428e87 /net/url_request | |
parent | 07e666801f64a26dd1c68ec3dc64fdd0f16603f7 (diff) | |
download | chromium_src-7335ab0c8b9afb8a3c702d97925c1a0278a45ab7.zip chromium_src-7335ab0c8b9afb8a3c702d97925c1a0278a45ab7.tar.gz chromium_src-7335ab0c8b9afb8a3c702d97925c1a0278a45ab7.tar.bz2 |
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
Diffstat (limited to 'net/url_request')
-rw-r--r-- | net/url_request/url_fetcher_core.cc | 2 | ||||
-rw-r--r-- | net/url_request/url_request.cc | 10 | ||||
-rw-r--r-- | net/url_request/url_request.h | 5 | ||||
-rw-r--r-- | net/url_request/url_request_ftp_job.cc | 4 | ||||
-rw-r--r-- | net/url_request/url_request_ftp_job.h | 2 | ||||
-rw-r--r-- | net/url_request/url_request_http_job.cc | 5 | ||||
-rw-r--r-- | net/url_request/url_request_http_job.h | 2 | ||||
-rw-r--r-- | net/url_request/url_request_job.cc | 4 | ||||
-rw-r--r-- | net/url_request/url_request_job.h | 3 |
9 files changed, 19 insertions, 18 deletions
diff --git a/net/url_request/url_fetcher_core.cc b/net/url_request/url_fetcher_core.cc index 9c64c6e..043d220 100644 --- a/net/url_request/url_fetcher_core.cc +++ b/net/url_request/url_fetcher_core.cc @@ -944,7 +944,7 @@ void URLFetcherCore::DisownFile() { void URLFetcherCore::InformDelegateUploadProgress() { DCHECK(network_task_runner_->BelongsToCurrentThread()); if (request_.get()) { - int64 current = request_->GetUploadProgress(); + int64 current = request_->GetUploadProgress().position(); if (current_upload_bytes_ != current) { current_upload_bytes_ = current; int64 total = -1; diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc index 9084053..cc7bfe6 100644 --- a/net/url_request/url_request.cc +++ b/net/url_request/url_request.cc @@ -149,7 +149,6 @@ URLRequest::URLRequest(const GURL& url, delegate_(delegate), is_pending_(false), redirect_limit_(kMaxRedirects), - final_upload_progress_(0), priority_(LOWEST), identifier_(GenerateURLRequestIdentifier()), blocked_on_delegate_(false), @@ -187,7 +186,6 @@ URLRequest::URLRequest(const GURL& url, delegate_(delegate), is_pending_(false), redirect_limit_(kMaxRedirects), - final_upload_progress_(0), priority_(LOWEST), identifier_(GenerateURLRequestIdentifier()), blocked_on_delegate_(false), @@ -327,12 +325,12 @@ LoadStateWithParam URLRequest::GetLoadState() const { string16()); } -uint64 URLRequest::GetUploadProgress() const { +UploadProgress URLRequest::GetUploadProgress() const { if (!job_) { // We haven't started or the request was cancelled - return 0; + return UploadProgress(); } - if (final_upload_progress_) { + if (final_upload_progress_.position()) { // The first job completed and none of the subsequent series of // GETs when following redirects will upload anything, so we return the // cached results from the initial job, the POST. @@ -793,7 +791,7 @@ int URLRequest::Redirect(const GURL& location, int http_status_code) { url_chain_.push_back(location); --redirect_limit_; - if (!final_upload_progress_) + if (!final_upload_progress_.position()) final_upload_progress_ = job_->GetUploadProgress(); PrepareToRestart(); diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h index 4a2a2e4..cf5b081 100644 --- a/net/url_request/url_request.h +++ b/net/url_request/url_request.h @@ -23,6 +23,7 @@ #include "net/base/net_log.h" #include "net/base/network_delegate.h" #include "net/base/request_priority.h" +#include "net/base/upload_progress.h" #include "net/cookies/canonical_cookie.h" #include "net/http/http_request_headers.h" #include "net/http/http_response_info.h" @@ -455,7 +456,7 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe), } // Returns the current upload progress in bytes. - uint64 GetUploadProgress() const; + UploadProgress GetUploadProgress() const; // Get response header(s) by ID or name. These methods may only be called // once the delegate's OnResponseStarted method has been called. Headers @@ -785,7 +786,7 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe), // Cached value for use after we've orphaned the job handling the // first transaction in a request involving redirects. - uint64 final_upload_progress_; + UploadProgress final_upload_progress_; // The priority level for this request. Objects like ClientSocketPool use // this to determine which URLRequest to allocate sockets to first. diff --git a/net/url_request/url_request_ftp_job.cc b/net/url_request/url_request_ftp_job.cc index e910625..27021a3 100644 --- a/net/url_request/url_request_ftp_job.cc +++ b/net/url_request/url_request_ftp_job.cc @@ -233,8 +233,8 @@ void URLRequestFtpJob::CancelAuth() { weak_factory_.GetWeakPtr(), OK)); } -uint64 URLRequestFtpJob::GetUploadProgress() const { - return 0; +UploadProgress URLRequestFtpJob::GetUploadProgress() const { + return UploadProgress(); } bool URLRequestFtpJob::ReadRawData(IOBuffer* buf, diff --git a/net/url_request/url_request_ftp_job.h b/net/url_request/url_request_ftp_job.h index 6deaf0a..d05e3d8 100644 --- a/net/url_request/url_request_ftp_job.h +++ b/net/url_request/url_request_ftp_job.h @@ -61,7 +61,7 @@ class URLRequestFtpJob : public URLRequestJob { virtual void CancelAuth() OVERRIDE; // TODO(ibrar): Yet to give another look at this function. - virtual uint64 GetUploadProgress() const OVERRIDE; + virtual UploadProgress GetUploadProgress() const OVERRIDE; virtual bool ReadRawData(IOBuffer* buf, int buf_size, int *bytes_read) OVERRIDE; diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc index 52d5dae..309f0fb 100644 --- a/net/url_request/url_request_http_job.cc +++ b/net/url_request/url_request_http_job.cc @@ -1021,8 +1021,9 @@ LoadState URLRequestHttpJob::GetLoadState() const { transaction_->GetLoadState() : LOAD_STATE_IDLE; } -uint64 URLRequestHttpJob::GetUploadProgress() const { - return transaction_.get() ? transaction_->GetUploadProgress().position() : 0; +UploadProgress URLRequestHttpJob::GetUploadProgress() const { + return transaction_.get() ? + transaction_->GetUploadProgress() : UploadProgress(); } bool URLRequestHttpJob::GetMimeType(std::string* mime_type) const { diff --git a/net/url_request/url_request_http_job.h b/net/url_request/url_request_http_job.h index 063d399..8ee24b2 100644 --- a/net/url_request/url_request_http_job.h +++ b/net/url_request/url_request_http_job.h @@ -78,7 +78,7 @@ class URLRequestHttpJob : public URLRequestJob { virtual void Start() OVERRIDE; virtual void Kill() OVERRIDE; virtual LoadState GetLoadState() const OVERRIDE; - virtual uint64 GetUploadProgress() const OVERRIDE; + virtual UploadProgress GetUploadProgress() const OVERRIDE; virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; virtual bool GetCharset(std::string* charset) OVERRIDE; virtual void GetResponseInfo(HttpResponseInfo* info) OVERRIDE; diff --git a/net/url_request/url_request_job.cc b/net/url_request/url_request_job.cc index 9ba5578..66fc9f3 100644 --- a/net/url_request/url_request_job.cc +++ b/net/url_request/url_request_job.cc @@ -106,8 +106,8 @@ LoadState URLRequestJob::GetLoadState() const { return LOAD_STATE_IDLE; } -uint64 URLRequestJob::GetUploadProgress() const { - return 0; +UploadProgress URLRequestJob::GetUploadProgress() const { + return UploadProgress(); } bool URLRequestJob::GetCharset(std::string* charset) { diff --git a/net/url_request/url_request_job.h b/net/url_request/url_request_job.h index 6e3dbba..0af7fa1 100644 --- a/net/url_request/url_request_job.h +++ b/net/url_request/url_request_job.h @@ -17,6 +17,7 @@ #include "net/base/host_port_pair.h" #include "net/base/load_states.h" #include "net/base/net_export.h" +#include "net/base/upload_progress.h" #include "net/cookies/canonical_cookie.h" namespace net { @@ -99,7 +100,7 @@ class NET_EXPORT URLRequestJob : public base::RefCounted<URLRequestJob>, virtual LoadState GetLoadState() const; // Called to get the upload progress in bytes. - virtual uint64 GetUploadProgress() const; + virtual UploadProgress GetUploadProgress() const; // Called to fetch the charset for this request. Only makes sense for some // types of requests. Returns true on success. Calling this on a type that |