diff options
25 files changed, 99 insertions, 115 deletions
diff --git a/chrome/browser/automation/url_request_automation_job.cc b/chrome/browser/automation/url_request_automation_job.cc index f7cd433..a5c790d 100644 --- a/chrome/browser/automation/url_request_automation_job.cc +++ b/chrome/browser/automation/url_request_automation_job.cc @@ -65,6 +65,7 @@ URLRequestAutomationJob::URLRequestAutomationJob( redirect_status_(0), request_id_(request_id), is_pending_(is_pending), + upload_size_(0), ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { DVLOG(1) << "URLRequestAutomationJob create. Count: " << ++instance_count_; DCHECK(message_filter_ != NULL); @@ -232,17 +233,15 @@ bool URLRequestAutomationJob::IsRedirectResponse( return true; } -uint64 URLRequestAutomationJob::GetUploadProgress() const { +net::UploadProgress URLRequestAutomationJob::GetUploadProgress() const { + uint64 progress = 0; if (request_ && request_->status().is_success()) { // We don't support incremental progress notifications in ChromeFrame. When // we receive a response for the POST request from Chromeframe, it means // that the upload is fully complete. - const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_); - if (info) { - return info->GetUploadSize(); - } + progress = upload_size_; } - return 0; + return net::UploadProgress(progress, upload_size_); } net::HostPortPair URLRequestAutomationJob::GetSocketAddress() const { @@ -305,6 +304,7 @@ void URLRequestAutomationJob::OnRequestStarted( response.headers.size())); } socket_address_ = response.socket_address; + upload_size_ = response.upload_size; NotifyHeadersComplete(); } diff --git a/chrome/browser/automation/url_request_automation_job.h b/chrome/browser/automation/url_request_automation_job.h index ec7cce7..9c12f59 100644 --- a/chrome/browser/automation/url_request_automation_job.h +++ b/chrome/browser/automation/url_request_automation_job.h @@ -48,7 +48,7 @@ class URLRequestAutomationJob : public net::URLRequestJob { virtual void GetResponseInfo(net::HttpResponseInfo* info); virtual int GetResponseCode() const; virtual bool IsRedirectResponse(GURL* location, int* http_status_code); - virtual uint64 GetUploadProgress() const; + virtual net::UploadProgress GetUploadProgress() const; virtual net::HostPortPair GetSocketAddress() const; // Peek and process automation messages for URL requests. @@ -130,6 +130,9 @@ class URLRequestAutomationJob : public net::URLRequestJob { // Contains the ip address and port of the destination host. net::HostPortPair socket_address_; + // Size of the upload data appended to the request. + uint64 upload_size_; + base::WeakPtrFactory<URLRequestAutomationJob> weak_factory_; DISALLOW_COPY_AND_ASSIGN(URLRequestAutomationJob); diff --git a/chrome/common/automation_messages.h b/chrome/common/automation_messages.h index 1d880249..1d86150 100644 --- a/chrome/common/automation_messages.h +++ b/chrome/common/automation_messages.h @@ -51,6 +51,7 @@ IPC_STRUCT_BEGIN(AutomationURLResponse) IPC_STRUCT_MEMBER(std::string, redirect_url) IPC_STRUCT_MEMBER(int, redirect_status) IPC_STRUCT_MEMBER(net::HostPortPair, socket_address) + IPC_STRUCT_MEMBER(uint64, upload_size) IPC_STRUCT_END() IPC_STRUCT_BEGIN(ExternalTabSettings) diff --git a/chrome_frame/chrome_frame_automation.cc b/chrome_frame/chrome_frame_automation.cc index 12f14cf..c4fe26a 100644 --- a/chrome_frame/chrome_frame_automation.cc +++ b/chrome_frame/chrome_frame_automation.cc @@ -1305,10 +1305,11 @@ void ChromeFrameAutomationClient::OnUnload(bool* should_unload) { // PluginUrlRequestDelegate implementation. // Forward network related responses to Chrome. -void ChromeFrameAutomationClient::OnResponseStarted(int request_id, - const char* mime_type, const char* headers, int size, +void ChromeFrameAutomationClient::OnResponseStarted( + int request_id, const char* mime_type, const char* headers, int size, base::Time last_modified, const std::string& redirect_url, - int redirect_status, const net::HostPortPair& socket_address) { + int redirect_status, const net::HostPortPair& socket_address, + uint64 upload_size) { AutomationURLResponse response; response.mime_type = mime_type; if (headers) @@ -1318,6 +1319,7 @@ void ChromeFrameAutomationClient::OnResponseStarted(int request_id, response.redirect_url = redirect_url; response.redirect_status = redirect_status; response.socket_address = socket_address; + response.upload_size = upload_size; automation_server_->Send(new AutomationMsg_RequestStarted( tab_->handle(), request_id, response)); diff --git a/chrome_frame/chrome_frame_automation.h b/chrome_frame/chrome_frame_automation.h index 0c778b7..8d591fc 100644 --- a/chrome_frame/chrome_frame_automation.h +++ b/chrome_frame/chrome_frame_automation.h @@ -457,10 +457,11 @@ class ChromeFrameAutomationClient // PluginUrlRequestDelegate implementation. Simply adds tab's handle // as parameter and forwards to Chrome via IPC. - virtual void OnResponseStarted(int request_id, const char* mime_type, - const char* headers, int size, base::Time last_modified, - const std::string& redirect_url, int redirect_status, - const net::HostPortPair& socket_address); + virtual void OnResponseStarted( + int request_id, const char* mime_type, const char* headers, int size, + base::Time last_modified, const std::string& redirect_url, + int redirect_status, const net::HostPortPair& socket_address, + uint64 upload_size); virtual void OnReadComplete(int request_id, const std::string& data); virtual void OnResponseEnd(int request_id, const net::URLRequestStatus& status); diff --git a/chrome_frame/plugin_url_request.h b/chrome_frame/plugin_url_request.h index 879620c..bd14655 100644 --- a/chrome_frame/plugin_url_request.h +++ b/chrome_frame/plugin_url_request.h @@ -25,10 +25,11 @@ class PluginUrlRequestManager; class DECLSPEC_NOVTABLE PluginUrlRequestDelegate { // NOLINT public: - virtual void OnResponseStarted(int request_id, const char* mime_type, - const char* headers, int size, base::Time last_modified, - const std::string& redirect_url, int redirect_status, - const net::HostPortPair& socket_address) = 0; + virtual void OnResponseStarted( + int request_id, const char* mime_type, const char* headers, int size, + base::Time last_modified, const std::string& redirect_url, + int redirect_status, const net::HostPortPair& socket_address, + uint64 upload_size) = 0; virtual void OnReadComplete(int request_id, const std::string& data) = 0; virtual void OnResponseEnd(int request_id, const net::URLRequestStatus& status) = 0; @@ -169,11 +170,6 @@ class PluginUrlRequest { url_ = url; } - void ClearPostData() { - upload_data_.Release(); - post_data_len_ = 0; - } - void SendData(); bool enable_frame_busting_; diff --git a/chrome_frame/test/automation_client_mock.h b/chrome_frame/test/automation_client_mock.h index 4cd89dc..1debab7 100644 --- a/chrome_frame/test/automation_client_mock.h +++ b/chrome_frame/test/automation_client_mock.h @@ -67,7 +67,7 @@ struct MockCFDelegate : public ChromeFrameDelegateImpl { void ReplyStarted(int request_id, const char* headers) { request_delegate_->OnResponseStarted(request_id, "text/html", headers, - 0, base::Time::Now(), EmptyString(), 0, net::HostPortPair()); + 0, base::Time::Now(), EmptyString(), 0, net::HostPortPair(), 0); } void ReplyData(int request_id, const std::string* data) { diff --git a/chrome_frame/test/url_request_test.cc b/chrome_frame/test/url_request_test.cc index b1fb6b2..6c1790f 100644 --- a/chrome_frame/test/url_request_test.cc +++ b/chrome_frame/test/url_request_test.cc @@ -39,10 +39,10 @@ static void AppendToStream(IStream* s, void* buffer, ULONG cb) { class MockUrlDelegate : public PluginUrlRequestDelegate { public: - MOCK_METHOD8(OnResponseStarted, void(int request_id, const char* mime_type, + MOCK_METHOD9(OnResponseStarted, void(int request_id, const char* mime_type, const char* headers, int size, base::Time last_modified, const std::string& redirect_url, int redirect_status, - const net::HostPortPair& socket_address)); + const net::HostPortPair& socket_address, uint64 upload_size)); MOCK_METHOD2(OnReadComplete, void(int request_id, const std::string& data)); MOCK_METHOD2(OnResponseEnd, void(int request_id, const net::URLRequestStatus& status)); @@ -89,7 +89,7 @@ TEST(UrlmonUrlRequestTest, Simple1) { testing::InSequence s; EXPECT_CALL(mock, OnResponseStarted(1, testing::_, testing::_, testing::_, testing::_, testing::_, testing::_, - testing::_)) + testing::_, testing::_)) .Times(1) .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor( &request, &UrlmonUrlRequest::Read, 512)))); @@ -138,7 +138,7 @@ TEST(UrlmonUrlRequestTest, Head) { testing::InSequence s; EXPECT_CALL(mock, OnResponseStarted(1, testing::_, testing::_, testing::_, testing::_, testing::_, testing::_, - testing::_)) + testing::_, testing::_)) .Times(1) .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor( &request, &UrlmonUrlRequest::Read, 512)))); @@ -183,7 +183,7 @@ TEST(UrlmonUrlRequestTest, UnreachableUrl) { EXPECT_CALL(mock, OnResponseStarted(1, testing::_, testing::StartsWith("HTTP/1.1 404"), testing::_, testing::_, testing::_, - testing::_, testing::_)) + testing::_, testing::_, testing::_)) .Times(1) .WillOnce(QUIT_LOOP_SOON(loop, base::TimeDelta::FromSeconds(2))); @@ -222,7 +222,7 @@ TEST(UrlmonUrlRequestTest, ZeroLengthResponse) { // Expect headers EXPECT_CALL(mock, OnResponseStarted(1, testing::_, testing::_, testing::_, testing::_, testing::_, testing::_, - testing::_)) + testing::_, testing::_)) .Times(1) .WillOnce(QUIT_LOOP(loop)); @@ -272,7 +272,8 @@ TEST(UrlmonUrlRequestManagerTest, Simple1) { r1.load_flags = 0; EXPECT_CALL(mock, OnResponseStarted(1, testing::_, testing::_, testing::_, - testing::_, testing::_, testing::_, testing::_)) + testing::_, testing::_, testing::_, testing::_, + testing::_)) .Times(1) .WillOnce(ManagerRead(&loop, mgr.get(), 1, 512)); @@ -308,7 +309,8 @@ TEST(UrlmonUrlRequestManagerTest, Abort1) { r1.load_flags = 0; EXPECT_CALL(mock, OnResponseStarted(1, testing::_, testing::_, testing::_, - testing::_, testing::_, testing::_, testing::_)) + testing::_, testing::_, testing::_, testing::_, + testing::_)) .Times(1) .WillOnce(testing::DoAll( ManagerEndRequest(&loop, mgr.get(), 1), diff --git a/chrome_frame/urlmon_url_request.cc b/chrome_frame/urlmon_url_request.cc index b2ed8c7..bf441b3 100644 --- a/chrome_frame/urlmon_url_request.cc +++ b/chrome_frame/urlmon_url_request.cc @@ -691,13 +691,14 @@ STDMETHODIMP UrlmonUrlRequest::OnResponse(DWORD dwResponseCode, headers_received_ = true; DCHECK_NE(id(), -1); delegate_->OnResponseStarted(id(), - "", // mime_type - raw_headers.c_str(), // headers - 0, // size - base::Time(), // last_modified - status_.get_redirection().utf8_url, - status_.get_redirection().http_code, - socket_address_); + "", // mime_type + raw_headers.c_str(), // headers + 0, // size + base::Time(), // last_modified + status_.get_redirection().utf8_url, + status_.get_redirection().http_code, + socket_address_, + post_data_len()); return S_OK; } @@ -1323,10 +1324,11 @@ void UrlmonUrlRequestManager::StopAllRequestsHelper( request_map_lock->Release(); } -void UrlmonUrlRequestManager::OnResponseStarted(int request_id, - const char* mime_type, const char* headers, int size, +void UrlmonUrlRequestManager::OnResponseStarted( + int request_id, const char* mime_type, const char* headers, int size, base::Time last_modified, const std::string& redirect_url, - int redirect_status, const net::HostPortPair& socket_address) { + int redirect_status, const net::HostPortPair& socket_address, + uint64 upload_size) { DCHECK_NE(request_id, -1); DVLOG(1) << __FUNCTION__; @@ -1339,8 +1341,9 @@ void UrlmonUrlRequestManager::OnResponseStarted(int request_id, } DCHECK(request != NULL); #endif // NDEBUG - delegate_->OnResponseStarted(request_id, mime_type, headers, size, - last_modified, redirect_url, redirect_status, socket_address); + delegate_->OnResponseStarted( + request_id, mime_type, headers, size, last_modified, redirect_url, + redirect_status, socket_address, upload_size); } void UrlmonUrlRequestManager::OnReadComplete(int request_id, diff --git a/chrome_frame/urlmon_url_request.h b/chrome_frame/urlmon_url_request.h index 037de1d..b74b881 100644 --- a/chrome_frame/urlmon_url_request.h +++ b/chrome_frame/urlmon_url_request.h @@ -96,12 +96,11 @@ class UrlmonUrlRequestManager virtual void SetCookiesForUrl(const GURL& url, const std::string& cookie); // PluginUrlRequestDelegate implementation - virtual void OnResponseStarted(int request_id, const char* mime_type, - const char* headers, int size, - base::Time last_modified, - const std::string& redirect_url, - int redirect_status, - const net::HostPortPair& socket_address); + virtual void OnResponseStarted( + int request_id, const char* mime_type, const char* headers, int size, + base::Time last_modified, const std::string& redirect_url, + int redirect_status, const net::HostPortPair& socket_address, + uint64 upload_size); virtual void OnReadComplete(int request_id, const std::string& data); virtual void OnResponseEnd(int request_id, const net::URLRequestStatus& status); diff --git a/content/browser/renderer_host/resource_dispatcher_host_impl.cc b/content/browser/renderer_host/resource_dispatcher_host_impl.cc index 2059938..450641e 100644 --- a/content/browser/renderer_host/resource_dispatcher_host_impl.cc +++ b/content/browser/renderer_host/resource_dispatcher_host_impl.cc @@ -21,7 +21,6 @@ #include "base/shared_memory.h" #include "base/stl_util.h" #include "base/third_party/dynamic_annotations/dynamic_annotations.h" -#include "base/threading/thread_restrictions.h" #include "content/browser/appcache/chrome_appcache_service.h" #include "content/browser/cert_store_impl.h" #include "content/browser/child_process_security_policy_impl.h" @@ -958,14 +957,10 @@ void ResourceDispatcherHostImpl::BeginRequest( request->set_priority(DetermineRequestPriority(request_data.resource_type)); // Resolve elements from request_body and prepare upload data. - uint64 upload_size = 0; if (request_data.request_body) { request->set_upload( request_data.request_body->ResolveElementsAndCreateUploadData( GetBlobStorageControllerForResourceContext(resource_context))); - // This results in performing file IO. crbug.com/112607. - base::ThreadRestrictions::ScopedAllowIO allow_io; - upload_size = request->get_upload_mutable()->GetContentLengthSync(); } bool allow_download = request_data.allow_download && @@ -985,7 +980,6 @@ void ResourceDispatcherHostImpl::BeginRequest( request_data.parent_frame_id, request_data.resource_type, request_data.transition_type, - upload_size, false, // is download allow_download, request_data.has_user_gesture, @@ -1185,7 +1179,6 @@ ResourceRequestInfoImpl* ResourceDispatcherHostImpl::CreateRequestInfo( -1, // parent_frame_id ResourceType::SUB_RESOURCE, PAGE_TRANSITION_LINK, - 0, // upload_size download, // is_download download, // allow_download false, // has_user_gesture @@ -1592,7 +1585,7 @@ void ResourceDispatcherHostImpl::UpdateLoadStates() { for (i = pending_loaders_.begin(); i != pending_loaders_.end(); ++i) { net::URLRequest* request = i->second->request(); ResourceRequestInfoImpl* info = i->second->GetRequestInfo(); - uint64 upload_size = info->GetUploadSize(); + uint64 upload_size = request->GetUploadProgress().size(); if (request->GetLoadState().state != net::LOAD_STATE_SENDING_REQUEST) upload_size = 0; std::pair<int, int> key(info->GetChildID(), info->GetRouteID()); @@ -1604,6 +1597,7 @@ void ResourceDispatcherHostImpl::UpdateLoadStates() { net::URLRequest* request = i->second->request(); ResourceRequestInfoImpl* info = i->second->GetRequestInfo(); net::LoadStateWithParam load_state = request->GetLoadState(); + net::UploadProgress progress = request->GetUploadProgress(); // We also poll for upload progress on this timer and send upload // progress ipc messages to the plugin process. @@ -1614,7 +1608,7 @@ void ResourceDispatcherHostImpl::UpdateLoadStates() { // If a request is uploading data, ignore all other requests so that the // upload progress takes priority for being shown in the status bar. if (largest_upload_size.find(key) != largest_upload_size.end() && - info->GetUploadSize() < largest_upload_size[key]) + progress.size() < largest_upload_size[key]) continue; net::LoadStateWithParam to_insert = load_state; @@ -1628,8 +1622,8 @@ void ResourceDispatcherHostImpl::UpdateLoadStates() { LoadInfo& load_info = info_map[key]; load_info.url = request->url(); load_info.load_state = to_insert; - load_info.upload_size = info->GetUploadSize(); - load_info.upload_position = request->GetUploadProgress(); + load_info.upload_size = progress.size(); + load_info.upload_position = progress.position(); } if (info_map.empty()) diff --git a/content/browser/renderer_host/resource_loader.cc b/content/browser/renderer_host/resource_loader.cc index e928724..0cbc455 100644 --- a/content/browser/renderer_host/resource_loader.cc +++ b/content/browser/renderer_host/resource_loader.cc @@ -107,31 +107,32 @@ void ResourceLoader::ReportUploadProgress() { if (waiting_for_upload_progress_ack_) return; // Send one progress event at a time. - uint64 size = info->GetUploadSize(); - if (!size) + net::UploadProgress progress = request_->GetUploadProgress(); + if (!progress.size()) return; // Nothing to upload. - uint64 position = request_->GetUploadProgress(); - if (position == last_upload_position_) + if (progress.position() == last_upload_position_) return; // No progress made since last time. const uint64 kHalfPercentIncrements = 200; const TimeDelta kOneSecond = TimeDelta::FromMilliseconds(1000); - uint64 amt_since_last = position - last_upload_position_; + uint64 amt_since_last = progress.position() - last_upload_position_; TimeDelta time_since_last = TimeTicks::Now() - last_upload_ticks_; - bool is_finished = (size == position); - bool enough_new_progress = (amt_since_last > (size / kHalfPercentIncrements)); + 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) { if (request_->load_flags() & net::LOAD_ENABLE_UPLOAD_PROGRESS) { - handler_->OnUploadProgress(info->GetRequestID(), position, size); + handler_->OnUploadProgress( + info->GetRequestID(), progress.position(), progress.size()); waiting_for_upload_progress_ack_ = true; } last_upload_ticks_ = TimeTicks::Now(); - last_upload_position_ = position; + last_upload_position_ = progress.position(); } } diff --git a/content/browser/renderer_host/resource_request_info_impl.cc b/content/browser/renderer_host/resource_request_info_impl.cc index c063d1d..c1f2437 100644 --- a/content/browser/renderer_host/resource_request_info_impl.cc +++ b/content/browser/renderer_host/resource_request_info_impl.cc @@ -41,7 +41,6 @@ void ResourceRequestInfo::AllocateForTesting( 0, // parent_frame_id resource_type, // resource_type PAGE_TRANSITION_LINK, // transition_type - 0, // upload_size false, // is_download true, // allow_download false, // has_user_gesture @@ -91,7 +90,6 @@ ResourceRequestInfoImpl::ResourceRequestInfoImpl( int64 parent_frame_id, ResourceType::Type resource_type, PageTransition transition_type, - uint64 upload_size, bool is_download, bool allow_download, bool has_user_gesture, @@ -113,7 +111,6 @@ ResourceRequestInfoImpl::ResourceRequestInfoImpl( has_user_gesture_(has_user_gesture), resource_type_(resource_type), transition_type_(transition_type), - upload_size_(upload_size), memory_cost_(0), referrer_policy_(referrer_policy), context_(context) { @@ -166,10 +163,6 @@ WebKit::WebReferrerPolicy ResourceRequestInfoImpl::GetReferrerPolicy() const { return referrer_policy_; } -uint64 ResourceRequestInfoImpl::GetUploadSize() const { - return upload_size_; -} - bool ResourceRequestInfoImpl::HasUserGesture() const { return has_user_gesture_; } diff --git a/content/browser/renderer_host/resource_request_info_impl.h b/content/browser/renderer_host/resource_request_info_impl.h index b21944c..f2bc718 100644 --- a/content/browser/renderer_host/resource_request_info_impl.h +++ b/content/browser/renderer_host/resource_request_info_impl.h @@ -54,7 +54,6 @@ class ResourceRequestInfoImpl : public ResourceRequestInfo, int64 parent_frame_id, ResourceType::Type resource_type, PageTransition transition_type, - uint64 upload_size, bool is_download, bool allow_download, bool has_user_gesture, @@ -74,7 +73,6 @@ class ResourceRequestInfoImpl : public ResourceRequestInfo, virtual int64 GetParentFrameID() const OVERRIDE; virtual ResourceType::Type GetResourceType() const OVERRIDE; virtual WebKit::WebReferrerPolicy GetReferrerPolicy() const OVERRIDE; - virtual uint64 GetUploadSize() const OVERRIDE; virtual bool HasUserGesture() const OVERRIDE; virtual bool GetAssociatedRenderView(int* render_process_id, int* render_view_id) const OVERRIDE; @@ -113,8 +111,6 @@ class ResourceRequestInfoImpl : public ResourceRequestInfo, PageTransition transition_type() const { return transition_type_; } - void set_upload_size(uint64 upload_size) { upload_size_ = upload_size; } - // The approximate in-memory size (bytes) that we credited this request // as consuming in |outstanding_requests_memory_cost_map_|. int memory_cost() const { return memory_cost_; } @@ -146,7 +142,6 @@ class ResourceRequestInfoImpl : public ResourceRequestInfo, bool has_user_gesture_; ResourceType::Type resource_type_; PageTransition transition_type_; - uint64 upload_size_; int memory_cost_; scoped_refptr<webkit_blob::BlobData> requested_blob_data_; WebKit::WebReferrerPolicy referrer_policy_; diff --git a/content/public/browser/resource_request_info.h b/content/public/browser/resource_request_info.h index 18db167..61cac09 100644 --- a/content/public/browser/resource_request_info.h +++ b/content/public/browser/resource_request_info.h @@ -80,10 +80,6 @@ class ResourceRequestInfo { // Returns the associated referrer policy. virtual WebKit::WebReferrerPolicy GetReferrerPolicy() const = 0; - // When there is upload data, this is the byte count of that data. When there - // is no upload, this will be 0. - virtual uint64 GetUploadSize() const = 0; - // True if the request was initiated by a user action (like a tap to follow // a link). virtual bool HasUserGesture() const = 0; 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 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(); } } |