diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-31 21:33:05 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-31 21:33:05 +0000 |
commit | d651cbcd0ca777450e439799bfeb84490a8a8903 (patch) | |
tree | 6f794d53a880d411d03c26e9a614507b306bc7f9 | |
parent | 43136484cef449391d1740c3ea03c3cfc85cc885 (diff) | |
download | chromium_src-d651cbcd0ca777450e439799bfeb84490a8a8903.zip chromium_src-d651cbcd0ca777450e439799bfeb84490a8a8903.tar.gz chromium_src-d651cbcd0ca777450e439799bfeb84490a8a8903.tar.bz2 |
Make ResourceHandler be non-refcounted. Eliminate the OnRequestClosed
method in favor of ~ResourceHandler.
This required making a couple ResourceHandlers support weak pointers.
The only non-trivial changes are related to DownloadResourceHandler.
The StartOnUIThread method becomes a static StartDownloadOnUIThread
method, and the call to SetDownloadID and CallStartedCB are now hidden
behind a Callback<void(DownloadId)>, which gets posted to the IO thread.
R=rdsmith@chromium.org,jam@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10455009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139874 0039d316-1c4b-4281-b951-d872f2087c98
30 files changed, 224 insertions, 285 deletions
diff --git a/content/browser/download/download_request_handle.cc b/content/browser/download/download_request_handle.cc index 06d704b..31158305 100644 --- a/content/browser/download/download_request_handle.cc +++ b/content/browser/download/download_request_handle.cc @@ -24,10 +24,11 @@ DownloadRequestHandle::DownloadRequestHandle() request_id_(-1) { } -DownloadRequestHandle::DownloadRequestHandle(DownloadResourceHandler* handler, - int child_id, - int render_view_id, - int request_id) +DownloadRequestHandle::DownloadRequestHandle( + const base::WeakPtr<DownloadResourceHandler>& handler, + int child_id, + int render_view_id, + int request_id) : handler_(handler), child_id_(child_id), render_view_id_(render_view_id), @@ -59,27 +60,21 @@ DownloadManager* DownloadRequestHandle::GetDownloadManager() const { } void DownloadRequestHandle::PauseRequest() const { - if (handler_) { - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&DownloadResourceHandler::PauseRequest, handler_)); - } + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&DownloadResourceHandler::PauseRequest, handler_)); } void DownloadRequestHandle::ResumeRequest() const { - if (handler_) { - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&DownloadResourceHandler::ResumeRequest, handler_)); - } + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&DownloadResourceHandler::ResumeRequest, handler_)); } void DownloadRequestHandle::CancelRequest() const { - if (handler_) { - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&DownloadResourceHandler::CancelRequest, handler_)); - } + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&DownloadResourceHandler::CancelRequest, handler_)); } std::string DownloadRequestHandle::DebugString() const { diff --git a/content/browser/download/download_request_handle.h b/content/browser/download/download_request_handle.h index bda955b..a94deb0 100644 --- a/content/browser/download/download_request_handle.h +++ b/content/browser/download/download_request_handle.h @@ -9,7 +9,7 @@ #include <string> #include "base/compiler_specific.h" -#include "base/memory/ref_counted.h" +#include "base/memory/weak_ptr.h" #include "content/browser/download/download_resource_handler.h" #include "content/common/content_export.h" @@ -59,7 +59,7 @@ class CONTENT_EXPORT DownloadRequestHandle DownloadRequestHandle(); // Note that |rdh| is required to be non-null. - DownloadRequestHandle(DownloadResourceHandler* handler, + DownloadRequestHandle(const base::WeakPtr<DownloadResourceHandler>& handler, int child_id, int render_view_id, int request_id); @@ -73,7 +73,7 @@ class CONTENT_EXPORT DownloadRequestHandle virtual std::string DebugString() const OVERRIDE; private: - scoped_refptr<DownloadResourceHandler> handler_; + base::WeakPtr<DownloadResourceHandler> handler_; // The ID of the child process that started the download. int child_id_; diff --git a/content/browser/download/download_resource_handler.cc b/content/browser/download/download_resource_handler.cc index 757e274..37f5b16 100644 --- a/content/browser/download/download_resource_handler.cc +++ b/content/browser/download/download_resource_handler.cc @@ -44,11 +44,43 @@ void CallStartedCBOnUIThread( DownloadId id, net::Error error) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + if (started_cb.is_null()) return; started_cb.Run(id, error); } +void StartDownloadOnUIThread( + const scoped_refptr<DownloadFileManager>& download_file_manager, + scoped_ptr<DownloadCreateInfo> info, + const DownloadRequestHandle& handle, + const base::Callback<void(DownloadId)>& set_download_id_callback) { + DownloadId download_id; + + DownloadManager* download_manager = handle.GetDownloadManager(); + if (download_manager) { + // The download manager may be NULL in unittests or if the page closed + // right after starting the download. + download_id = download_manager->delegate()->GetNextId(); + info->download_id = download_id; + + // NOTE: StartDownload triggers creation of the download destination file + // that will hold the downloaded data. The set_download_id_callback + // unblocks the DownloadResourceHandler to begin forwarding network data to + // the download destination file. The sequence of these two steps is + // critical as creation of the downloaded destination file has to happen + // before we attempt to append data to it. Both of those operations happen + // on the FILE thread. + + download_file_manager->StartDownload(info.release(), handle); + } + + BrowserThread::PostTask( + BrowserThread::IO, + FROM_HERE, + base::Bind(set_download_id_callback, download_id)); +} + } // namespace DownloadResourceHandler::DownloadResourceHandler( @@ -60,8 +92,7 @@ DownloadResourceHandler::DownloadResourceHandler( net::URLRequest* request, const DownloadResourceHandler::OnStartedCallback& started_cb, const content::DownloadSaveInfo& save_info) - : download_id_(DownloadId::Invalid()), - global_id_(render_process_host_id, request_id), + : global_id_(render_process_host_id, request_id), render_view_id_(render_view_id), content_length_(0), download_file_manager_(download_file_manager), @@ -134,7 +165,7 @@ bool DownloadResourceHandler::OnResponseStarted( info->remote_address = request_->GetSocketAddress().host(); download_stats::RecordDownloadMimeType(info->mime_type); - DownloadRequestHandle request_handle(this, global_id_.child_id, + DownloadRequestHandle request_handle(AsWeakPtr(), global_id_.child_id, render_view_id_, global_id_.request_id); // Get the last modified time and etag. @@ -167,9 +198,14 @@ bool DownloadResourceHandler::OnResponseStarted( info->save_info = save_info_; BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - base::Bind(&DownloadResourceHandler::StartOnUIThread, this, - base::Passed(&info), request_handle)); + BrowserThread::UI, + FROM_HERE, + base::Bind( + &StartDownloadOnUIThread, + download_file_manager_, + base::Passed(&info), + request_handle, + base::Bind(&DownloadResourceHandler::SetDownloadID, AsWeakPtr()))); return true; } @@ -219,7 +255,7 @@ bool DownloadResourceHandler::OnReadCompleted(int request_id, int* bytes_read, return true; } - if (download_id_ == DownloadId::Invalid()) { + if (!download_id_.IsValid()) { // We can't start saving the data before we create the file on disk and // have a download id. The request will be un-paused in // DownloadFileManager::CreateDownloadFile. @@ -286,8 +322,8 @@ bool DownloadResourceHandler::OnResponseCompleted( BrowserThread::PostTaskAndReply( BrowserThread::UI, FROM_HERE, base::Bind(&base::DoNothing), - base::Bind(&DownloadResourceHandler::OnResponseCompletedInternal, this, - request_id, status, security_info, response)); + base::Bind(&DownloadResourceHandler::OnResponseCompletedInternal, + AsWeakPtr(), request_id, status, security_info, response)); } // Can't trust request_ being value after this point. request_ = NULL; @@ -361,46 +397,15 @@ void DownloadResourceHandler::OnResponseCompletedInternal( read_buffer_ = NULL; } -void DownloadResourceHandler::OnRequestClosed() { - UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", - base::TimeTicks::Now() - download_start_time_); -} - -void DownloadResourceHandler::StartOnUIThread( - scoped_ptr<DownloadCreateInfo> info, - const DownloadRequestHandle& handle) { - DownloadManager* download_manager = handle.GetDownloadManager(); - if (!download_manager) { - // NULL in unittests or if the page closed right after starting the - // download. - CallStartedCB(download_id_, net::ERR_ACCESS_DENIED); - return; - } - DownloadId download_id = download_manager->delegate()->GetNextId(); - info->download_id = download_id; - - // NOTE: StartDownload triggers creation of the download destination file - // that will hold the downloaded data. SetDownloadID unblocks the - // DownloadResourceHandler to begin forwarding network data to the download - // destination file. The sequence of these two steps is critical as creation - // of the downloaded destination file has to happen before we attempt to - // append data to it. Both of those operations happen on the FILE thread. - - download_file_manager_->StartDownload(info.release(), handle); - - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&DownloadResourceHandler::SetDownloadID, this, - download_id)); - - CallStartedCB(download_id, net::OK); -} - -void DownloadResourceHandler::SetDownloadID(content::DownloadId id) { +void DownloadResourceHandler::SetDownloadID(DownloadId id) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); download_id_ = id; MaybeResumeRequest(); + + CallStartedCB( + download_id_, + download_id_.IsValid() ? net::OK : net::ERR_ACCESS_DENIED); } // If the content-length header is not present (or contains something other @@ -479,6 +484,9 @@ DownloadResourceHandler::~DownloadResourceHandler() { // If it goes through, it will likely be because OnWillStart() returned // false somewhere in the chain of resource handlers. CallStartedCB(download_id_, net::ERR_ACCESS_DENIED); + + UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", + base::TimeTicks::Now() - download_start_time_); } void DownloadResourceHandler::CheckWriteProgressLater() { @@ -497,7 +505,7 @@ void DownloadResourceHandler::MaybeResumeRequest() { if (pause_count_ > 0) return; - if (download_id_ == DownloadId::Invalid()) + if (!download_id_.IsValid()) return; if (buffer_.get() && (buffer_->size() > kLoadsToWrite)) return; diff --git a/content/browser/download/download_resource_handler.h b/content/browser/download/download_resource_handler.h index 66b69b7..0ddbb3a 100644 --- a/content/browser/download/download_resource_handler.h +++ b/content/browser/download/download_resource_handler.h @@ -32,7 +32,9 @@ class URLRequest; } // namespace net // Forwards data to the download thread. -class DownloadResourceHandler : public ResourceHandler { +class DownloadResourceHandler + : public ResourceHandler, + public base::SupportsWeakPtr<DownloadResourceHandler> { public: typedef content::DownloadUrlParameters::OnStartedCallback OnStartedCallback; @@ -81,7 +83,6 @@ class DownloadResourceHandler : public ResourceHandler { virtual bool OnResponseCompleted(int request_id, const net::URLRequestStatus& status, const std::string& security_info) OVERRIDE; - virtual void OnRequestClosed() OVERRIDE; void PauseRequest(); void ResumeRequest(); @@ -102,9 +103,6 @@ class DownloadResourceHandler : public ResourceHandler { void MaybeResumeRequest(); void CallStartedCB(content::DownloadId id, net::Error error); - // Generates a DownloadId and calls DownloadFileManager. - void StartOnUIThread(scoped_ptr<DownloadCreateInfo> info, - const DownloadRequestHandle& handle); void SetDownloadID(content::DownloadId id); // If the content-length header is not present (or contains something other @@ -120,7 +118,7 @@ class DownloadResourceHandler : public ResourceHandler { scoped_refptr<net::IOBuffer> read_buffer_; std::string content_disposition_; int64 content_length_; - DownloadFileManager* download_file_manager_; + scoped_refptr<DownloadFileManager> download_file_manager_; net::URLRequest* request_; // This is used only on the UI thread. OnStartedCallback started_cb_; diff --git a/content/browser/download/save_file_resource_handler.cc b/content/browser/download/save_file_resource_handler.cc index 613db2b..e22e9ec 100644 --- a/content/browser/download/save_file_resource_handler.cc +++ b/content/browser/download/save_file_resource_handler.cc @@ -27,6 +27,9 @@ SaveFileResourceHandler::SaveFileResourceHandler(int render_process_host_id, save_manager_(manager) { } +SaveFileResourceHandler::~SaveFileResourceHandler() { +} + bool SaveFileResourceHandler::OnUploadProgress(int request_id, uint64 position, uint64 size) { @@ -106,12 +109,7 @@ bool SaveFileResourceHandler::OnResponseCompleted( return true; } -void SaveFileResourceHandler::OnRequestClosed() { -} - void SaveFileResourceHandler::set_content_length( const std::string& content_length) { base::StringToInt64(content_length, &content_length_); } - -SaveFileResourceHandler::~SaveFileResourceHandler() {} diff --git a/content/browser/download/save_file_resource_handler.h b/content/browser/download/save_file_resource_handler.h index 468991c..7541fb6 100644 --- a/content/browser/download/save_file_resource_handler.h +++ b/content/browser/download/save_file_resource_handler.h @@ -20,6 +20,7 @@ class SaveFileResourceHandler : public ResourceHandler { int render_view_id, const GURL& url, SaveFileManager* manager); + virtual ~SaveFileResourceHandler(); // ResourceHandler Implementation: virtual bool OnUploadProgress(int request_id, @@ -58,8 +59,6 @@ class SaveFileResourceHandler : public ResourceHandler { const net::URLRequestStatus& status, const std::string& security_info) OVERRIDE; - virtual void OnRequestClosed() OVERRIDE; - // If the content-length header is not present (or contains something other // than numbers), StringToInt64 returns 0, which indicates 'unknown size' and // is handled correctly by the SaveManager. @@ -70,8 +69,6 @@ class SaveFileResourceHandler : public ResourceHandler { } private: - virtual ~SaveFileResourceHandler(); - int save_id_; int render_process_id_; int render_view_id_; diff --git a/content/browser/renderer_host/async_resource_handler.cc b/content/browser/renderer_host/async_resource_handler.cc index 75762ac..d08b84f 100644 --- a/content/browser/renderer_host/async_resource_handler.cc +++ b/content/browser/renderer_host/async_resource_handler.cc @@ -275,9 +275,6 @@ bool AsyncResourceHandler::OnResponseCompleted( return true; } -void AsyncResourceHandler::OnRequestClosed() { -} - // static void AsyncResourceHandler::GlobalCleanup() { if (g_spare_read_buffer) { diff --git a/content/browser/renderer_host/async_resource_handler.h b/content/browser/renderer_host/async_resource_handler.h index 09cc6a2..7c5da0e 100644 --- a/content/browser/renderer_host/async_resource_handler.h +++ b/content/browser/renderer_host/async_resource_handler.h @@ -25,6 +25,7 @@ class AsyncResourceHandler : public ResourceHandler { int routing_id, const GURL& url, ResourceDispatcherHostImpl* rdh); + virtual ~AsyncResourceHandler(); // ResourceHandler implementation: virtual bool OnUploadProgress(int request_id, @@ -50,15 +51,12 @@ class AsyncResourceHandler : public ResourceHandler { virtual bool OnResponseCompleted(int request_id, const net::URLRequestStatus& status, const std::string& security_info) OVERRIDE; - virtual void OnRequestClosed() OVERRIDE; virtual void OnDataDownloaded(int request_id, int bytes_downloaded) OVERRIDE; static void GlobalCleanup(); private: - virtual ~AsyncResourceHandler(); - scoped_refptr<SharedIOBuffer> read_buffer_; scoped_refptr<ResourceMessageFilter> filter_; int routing_id_; diff --git a/content/browser/renderer_host/buffered_resource_handler.cc b/content/browser/renderer_host/buffered_resource_handler.cc index 2d700bc..4b43691 100644 --- a/content/browser/renderer_host/buffered_resource_handler.cc +++ b/content/browser/renderer_host/buffered_resource_handler.cc @@ -62,10 +62,10 @@ void RecordSnifferMetrics(bool sniffing_blocked, } // namespace BufferedResourceHandler::BufferedResourceHandler( - ResourceHandler* handler, + scoped_ptr<ResourceHandler> next_handler, ResourceDispatcherHostImpl* host, net::URLRequest* request) - : LayeredResourceHandler(handler), + : LayeredResourceHandler(next_handler.Pass()), host_(host), request_(request), read_buffer_size_(0), @@ -95,11 +95,6 @@ bool BufferedResourceHandler::OnResponseStarted( return true; } -void BufferedResourceHandler::OnRequestClosed() { - request_ = NULL; - next_handler_->OnRequestClosed(); -} - // We'll let the original event handler provide a buffer, and reuse it for // subsequent reads until we're done buffering. bool BufferedResourceHandler::OnWillRead(int request_id, net::IOBuffer** buf, @@ -277,12 +272,12 @@ bool BufferedResourceHandler::CompleteResponseStarted(int request_id, return false; } - X509UserCertResourceHandler* x509_cert_handler = + scoped_ptr<ResourceHandler> handler( new X509UserCertResourceHandler(request_, info->GetChildID(), - info->GetRouteID()); + info->GetRouteID())); - return UseAlternateResourceHandler(request_id, x509_cert_handler, defer); + return UseAlternateResourceHandler(request_id, handler.Pass(), defer); } if (info->allow_download() && ShouldDownload(NULL)) { @@ -301,7 +296,7 @@ bool BufferedResourceHandler::CompleteResponseStarted(int request_id, info->set_is_download(true); - scoped_refptr<ResourceHandler> handler( + scoped_ptr<ResourceHandler> handler( host_->CreateResourceHandlerForDownload( request_, info->GetContext(), @@ -312,7 +307,7 @@ bool BufferedResourceHandler::CompleteResponseStarted(int request_id, DownloadSaveInfo(), DownloadResourceHandler::OnStartedCallback())); - return UseAlternateResourceHandler(request_id, handler, defer); + return UseAlternateResourceHandler(request_id, handler.Pass(), defer); } if (*defer) @@ -328,7 +323,7 @@ bool BufferedResourceHandler::ShouldWaitForPlugins() { // Get the plugins asynchronously. PluginServiceImpl::GetInstance()->GetPlugins( - base::Bind(&BufferedResourceHandler::OnPluginsLoaded, this)); + base::Bind(&BufferedResourceHandler::OnPluginsLoaded, AsWeakPtr())); return true; } @@ -381,7 +376,7 @@ bool BufferedResourceHandler::ShouldDownload(bool* need_plugin_list) { bool BufferedResourceHandler::UseAlternateResourceHandler( int request_id, - ResourceHandler* handler, + scoped_ptr<ResourceHandler> handler, bool* defer) { // Inform the original ResourceHandler that this will be handled entirely by // the new ResourceHandler. @@ -401,7 +396,7 @@ bool BufferedResourceHandler::UseAlternateResourceHandler( // This is handled entirely within the new ResourceHandler, so just reset the // original ResourceHandler. - next_handler_ = handler; + next_handler_ = handler.Pass(); next_handler_needs_response_started_ = true; next_handler_needs_will_read_ = true; diff --git a/content/browser/renderer_host/buffered_resource_handler.h b/content/browser/renderer_host/buffered_resource_handler.h index 3e7698d..3642199 100644 --- a/content/browser/renderer_host/buffered_resource_handler.h +++ b/content/browser/renderer_host/buffered_resource_handler.h @@ -9,6 +9,7 @@ #include <string> #include <vector> +#include "base/memory/weak_ptr.h" #include "content/browser/renderer_host/layered_resource_handler.h" namespace net { @@ -23,11 +24,14 @@ namespace content { class ResourceDispatcherHostImpl; // Used to buffer a request until enough data has been received. -class BufferedResourceHandler : public LayeredResourceHandler { +class BufferedResourceHandler + : public LayeredResourceHandler, + public base::SupportsWeakPtr<BufferedResourceHandler> { public: - BufferedResourceHandler(ResourceHandler* handler, + BufferedResourceHandler(scoped_ptr<ResourceHandler> next_handler, ResourceDispatcherHostImpl* host, net::URLRequest* request); + virtual ~BufferedResourceHandler(); // ResourceHandler implementation: virtual bool OnResponseStarted(int request_id, @@ -39,11 +43,8 @@ class BufferedResourceHandler : public LayeredResourceHandler { int min_size) OVERRIDE; virtual bool OnReadCompleted(int request_id, int* bytes_read, bool* defer) OVERRIDE; - virtual void OnRequestClosed() OVERRIDE; private: - virtual ~BufferedResourceHandler(); - // Returns true if we should delay OnResponseStarted forwarding. bool DelayResponse(); @@ -70,7 +71,8 @@ class BufferedResourceHandler : public LayeredResourceHandler { // will be handled entirely by the new ResourceHandler |handler|. A // reference to |handler| is acquired. Returns false to indicate an error, // which will result in the request being cancelled. - bool UseAlternateResourceHandler(int request_id, ResourceHandler* handler, + bool UseAlternateResourceHandler(int request_id, + scoped_ptr<ResourceHandler> handler, bool* defer); // Forwards any queued events to |next_handler_|. Returns false to indicate diff --git a/content/browser/renderer_host/cross_site_resource_handler.cc b/content/browser/renderer_host/cross_site_resource_handler.cc index c0f6b86..99f4245 100644 --- a/content/browser/renderer_host/cross_site_resource_handler.cc +++ b/content/browser/renderer_host/cross_site_resource_handler.cc @@ -36,11 +36,11 @@ void OnCrossSiteResponseHelper(int render_process_id, } // namespace CrossSiteResourceHandler::CrossSiteResourceHandler( - ResourceHandler* handler, + scoped_ptr<ResourceHandler> next_handler, int render_process_host_id, int render_view_id, ResourceDispatcherHostImpl* rdh) - : LayeredResourceHandler(handler), + : LayeredResourceHandler(next_handler.Pass()), render_process_host_id_(render_process_host_id), render_view_id_(render_view_id), has_started_response_(false), @@ -52,6 +52,9 @@ CrossSiteResourceHandler::CrossSiteResourceHandler( rdh_(rdh) { } +CrossSiteResourceHandler::~CrossSiteResourceHandler() { +} + bool CrossSiteResourceHandler::OnRequestRedirected( int request_id, const GURL& new_url, @@ -191,8 +194,6 @@ void CrossSiteResourceHandler::ResumeResponse() { } } -CrossSiteResourceHandler::~CrossSiteResourceHandler() {} - // Prepare to render the cross-site response in a new RenderViewHost, by // telling the old RenderViewHost to run its onunload handler. void CrossSiteResourceHandler::StartCrossSiteTransition( diff --git a/content/browser/renderer_host/cross_site_resource_handler.h b/content/browser/renderer_host/cross_site_resource_handler.h index d8cef7d..a286344 100644 --- a/content/browser/renderer_host/cross_site_resource_handler.h +++ b/content/browser/renderer_host/cross_site_resource_handler.h @@ -20,10 +20,11 @@ struct GlobalRequestID; // after we determine that a response is safe and not a download. class CrossSiteResourceHandler : public LayeredResourceHandler { public: - CrossSiteResourceHandler(ResourceHandler* handler, + CrossSiteResourceHandler(scoped_ptr<ResourceHandler> next_handler, int render_process_host_id, int render_view_id, ResourceDispatcherHostImpl* rdh); + virtual ~CrossSiteResourceHandler(); // ResourceHandler implementation: virtual bool OnRequestRedirected(int request_id, @@ -45,8 +46,6 @@ class CrossSiteResourceHandler : public LayeredResourceHandler { void ResumeResponse(); private: - virtual ~CrossSiteResourceHandler(); - // Prepare to render the cross-site response in a new RenderViewHost, by // telling the old RenderViewHost to run its onunload handler. void StartCrossSiteTransition( diff --git a/content/browser/renderer_host/doomed_resource_handler.cc b/content/browser/renderer_host/doomed_resource_handler.cc index ca19f20..d2e6bbb 100644 --- a/content/browser/renderer_host/doomed_resource_handler.cc +++ b/content/browser/renderer_host/doomed_resource_handler.cc @@ -4,10 +4,11 @@ #include "content/browser/renderer_host/doomed_resource_handler.h" -#include "net/url_request/url_request.h" +#include "net/url_request/url_request_status.h" -DoomedResourceHandler::DoomedResourceHandler(ResourceHandler* old_handler) - : old_handler_(old_handler) { +DoomedResourceHandler::DoomedResourceHandler( + scoped_ptr<ResourceHandler> old_handler) + : old_handler_(old_handler.Pass()) { } DoomedResourceHandler::~DoomedResourceHandler() { @@ -67,9 +68,6 @@ bool DoomedResourceHandler::OnResponseCompleted( return true; } -void DoomedResourceHandler::OnRequestClosed() { -} - void DoomedResourceHandler::OnDataDownloaded(int request_id, int bytes_downloaded) { NOTREACHED(); diff --git a/content/browser/renderer_host/doomed_resource_handler.h b/content/browser/renderer_host/doomed_resource_handler.h index 047e289..d079d9ec 100644 --- a/content/browser/renderer_host/doomed_resource_handler.h +++ b/content/browser/renderer_host/doomed_resource_handler.h @@ -6,7 +6,7 @@ #define CONTENT_BROWSER_RENDERER_HOST_DOOMED_RESOURCE_HANDLER_H_ #pragma once -#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" #include "content/browser/renderer_host/resource_handler.h" // ResourceHandler that DCHECKs on all events but canceling and failing of @@ -18,7 +18,8 @@ class DoomedResourceHandler : public ResourceHandler { // does not lose its last reference and gets destroyed by being substituted. // Therefore, we retain a reference to |old_handler| that prevents the // destruction. - explicit DoomedResourceHandler(ResourceHandler* old_handler); + explicit DoomedResourceHandler(scoped_ptr<ResourceHandler> old_handler); + virtual ~DoomedResourceHandler(); // ResourceHandler implementation: virtual bool OnUploadProgress(int request_id, @@ -44,14 +45,11 @@ class DoomedResourceHandler : public ResourceHandler { virtual bool OnResponseCompleted(int request_id, const net::URLRequestStatus& status, const std::string& security_info) OVERRIDE; - virtual void OnRequestClosed() OVERRIDE; virtual void OnDataDownloaded(int request_id, int bytes_downloaded) OVERRIDE; private: - virtual ~DoomedResourceHandler(); - - scoped_refptr<ResourceHandler> old_handler_; + scoped_ptr<ResourceHandler> old_handler_; DISALLOW_COPY_AND_ASSIGN(DoomedResourceHandler); }; diff --git a/content/browser/renderer_host/layered_resource_handler.cc b/content/browser/renderer_host/layered_resource_handler.cc index 49b7042..110f9dc 100644 --- a/content/browser/renderer_host/layered_resource_handler.cc +++ b/content/browser/renderer_host/layered_resource_handler.cc @@ -8,13 +8,17 @@ namespace content { -LayeredResourceHandler::LayeredResourceHandler(ResourceHandler* next_handler) - : next_handler_(next_handler) { +LayeredResourceHandler::LayeredResourceHandler( + scoped_ptr<ResourceHandler> next_handler) + : next_handler_(next_handler.Pass()) { +} + +LayeredResourceHandler::~LayeredResourceHandler() { } bool LayeredResourceHandler::OnUploadProgress(int request_id, uint64 position, uint64 size) { - DCHECK(next_handler_); + DCHECK(next_handler_.get()); return next_handler_->OnUploadProgress(request_id, position, size); } @@ -22,32 +26,32 @@ bool LayeredResourceHandler::OnRequestRedirected(int request_id, const GURL& url, ResourceResponse* response, bool* defer) { - DCHECK(next_handler_); + DCHECK(next_handler_.get()); return next_handler_->OnRequestRedirected(request_id, url, response, defer); } bool LayeredResourceHandler::OnResponseStarted(int request_id, ResourceResponse* response, bool* defer) { - DCHECK(next_handler_); + DCHECK(next_handler_.get()); return next_handler_->OnResponseStarted(request_id, response, defer); } bool LayeredResourceHandler::OnWillStart(int request_id, const GURL& url, bool* defer) { - DCHECK(next_handler_); + DCHECK(next_handler_.get()); return next_handler_->OnWillStart(request_id, url, defer); } bool LayeredResourceHandler::OnWillRead(int request_id, net::IOBuffer** buf, int* buf_size, int min_size) { - DCHECK(next_handler_); + DCHECK(next_handler_.get()); return next_handler_->OnWillRead(request_id, buf, buf_size, min_size); } bool LayeredResourceHandler::OnReadCompleted(int request_id, int* bytes_read, bool* defer) { - DCHECK(next_handler_); + DCHECK(next_handler_.get()); return next_handler_->OnReadCompleted(request_id, bytes_read, defer); } @@ -55,22 +59,14 @@ bool LayeredResourceHandler::OnResponseCompleted( int request_id, const net::URLRequestStatus& status, const std::string& security_info) { - DCHECK(next_handler_); + DCHECK(next_handler_.get()); return next_handler_->OnResponseCompleted(request_id, status, security_info); } -void LayeredResourceHandler::OnRequestClosed() { - DCHECK(next_handler_); - next_handler_->OnRequestClosed(); -} - void LayeredResourceHandler::OnDataDownloaded(int request_id, int bytes_downloaded) { - DCHECK(next_handler_); + DCHECK(next_handler_.get()); next_handler_->OnDataDownloaded(request_id, bytes_downloaded); } -LayeredResourceHandler::~LayeredResourceHandler() { -} - } // namespace content diff --git a/content/browser/renderer_host/layered_resource_handler.h b/content/browser/renderer_host/layered_resource_handler.h index 0037174..5fbe6a8 100644 --- a/content/browser/renderer_host/layered_resource_handler.h +++ b/content/browser/renderer_host/layered_resource_handler.h @@ -6,6 +6,7 @@ #define CONTENT_BROWSER_RENDERER_HOST_LAYERED_RESOURCE_HANDLER_H_ #pragma once +#include "base/memory/scoped_ptr.h" #include "content/browser/renderer_host/resource_handler.h" #include "content/common/content_export.h" @@ -15,7 +16,8 @@ namespace content { // class is intended to be subclassed. class CONTENT_EXPORT LayeredResourceHandler : public ResourceHandler { public: - LayeredResourceHandler(ResourceHandler* next_handler); + explicit LayeredResourceHandler(scoped_ptr<ResourceHandler> next_handler); + virtual ~LayeredResourceHandler(); // ResourceHandler implementation: virtual bool OnUploadProgress(int request_id, uint64 position, @@ -35,13 +37,9 @@ class CONTENT_EXPORT LayeredResourceHandler : public ResourceHandler { virtual bool OnResponseCompleted(int request_id, const net::URLRequestStatus& status, const std::string& security_info) OVERRIDE; - virtual void OnRequestClosed() OVERRIDE; virtual void OnDataDownloaded(int request_id, int bytes_downloaded) OVERRIDE; - protected: - virtual ~LayeredResourceHandler(); - - scoped_refptr<ResourceHandler> next_handler_; + scoped_ptr<ResourceHandler> next_handler_; }; } // namespace content diff --git a/content/browser/renderer_host/redirect_to_file_resource_handler.cc b/content/browser/renderer_host/redirect_to_file_resource_handler.cc index 8f32dbd..00de4f5 100644 --- a/content/browser/renderer_host/redirect_to_file_resource_handler.cc +++ b/content/browser/renderer_host/redirect_to_file_resource_handler.cc @@ -27,10 +27,10 @@ namespace content { static const int kReadBufSize = 32768; RedirectToFileResourceHandler::RedirectToFileResourceHandler( - ResourceHandler* next_handler, + scoped_ptr<ResourceHandler> next_handler, int process_id, ResourceDispatcherHostImpl* host) - : LayeredResourceHandler(next_handler), + : LayeredResourceHandler(next_handler.Pass()), ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), host_(host), process_id_(process_id), @@ -39,10 +39,22 @@ RedirectToFileResourceHandler::RedirectToFileResourceHandler( buf_write_pending_(false), write_cursor_(0), write_callback_pending_(false), - request_was_closed_(false), completed_during_write_(false) { } +RedirectToFileResourceHandler::~RedirectToFileResourceHandler() { + // It is possible for |file_stream_| to be NULL if the URLRequest was closed + // before the temporary file creation finished. + if (file_stream_.get()) { + // We require this explicit call to Close since file_stream_ was constructed + // directly from a PlatformFile. + // Close() performs file IO. crbug.com/112474. + base::ThreadRestrictions::ScopedAllowIO allow_io; + file_stream_->CloseSync(); + file_stream_.reset(); + } +} + bool RedirectToFileResourceHandler::OnResponseStarted( int request_id, content::ResourceResponse* response, @@ -133,37 +145,10 @@ bool RedirectToFileResourceHandler::OnResponseCompleted( return next_handler_->OnResponseCompleted(request_id, status, security_info); } -void RedirectToFileResourceHandler::OnRequestClosed() { - DCHECK(!request_was_closed_); - request_was_closed_ = true; - - // It is possible for |file_stream_| to be NULL if the request was closed - // before the temporary file creation finished. - if (file_stream_.get()) { - // We require this explicit call to Close since file_stream_ was constructed - // directly from a PlatformFile. - // Close() performs file IO. crbug.com/112474. - base::ThreadRestrictions::ScopedAllowIO allow_io; - file_stream_->CloseSync(); - file_stream_.reset(); - } - deletable_file_ = NULL; - next_handler_->OnRequestClosed(); -} - -RedirectToFileResourceHandler::~RedirectToFileResourceHandler() { - DCHECK(!file_stream_.get()); -} - void RedirectToFileResourceHandler::DidCreateTemporaryFile( base::PlatformFileError /*error_code*/, base::PassPlatformFile file_handle, const FilePath& file_path) { - if (request_was_closed_) { - // If the request was already closed, then don't bother allocating the - // file_stream_ (otherwise we will leak it). - return; - } deletable_file_ = ShareableFileReference::GetOrCreate( file_path, ShareableFileReference::DELETE_ON_FINAL_RELEASE, BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); diff --git a/content/browser/renderer_host/redirect_to_file_resource_handler.h b/content/browser/renderer_host/redirect_to_file_resource_handler.h index 1e80237..bd5254f 100644 --- a/content/browser/renderer_host/redirect_to_file_resource_handler.h +++ b/content/browser/renderer_host/redirect_to_file_resource_handler.h @@ -30,9 +30,10 @@ class ResourceDispatcherHostImpl; class RedirectToFileResourceHandler : public LayeredResourceHandler { public: RedirectToFileResourceHandler( - ResourceHandler* next_handler, + scoped_ptr<ResourceHandler> next_handler, int process_id, ResourceDispatcherHostImpl* resource_dispatcher_host); + virtual ~RedirectToFileResourceHandler(); // ResourceHandler implementation: virtual bool OnResponseStarted(int request_id, @@ -51,10 +52,8 @@ class RedirectToFileResourceHandler : public LayeredResourceHandler { virtual bool OnResponseCompleted(int request_id, const net::URLRequestStatus& status, const std::string& security_info) OVERRIDE; - virtual void OnRequestClosed() OVERRIDE; private: - virtual ~RedirectToFileResourceHandler(); void DidCreateTemporaryFile(base::PlatformFileError error_code, base::PassPlatformFile file_handle, const FilePath& file_path); diff --git a/content/browser/renderer_host/resource_dispatcher_host_impl.cc b/content/browser/renderer_host/resource_dispatcher_host_impl.cc index ee6051b..595090b 100644 --- a/content/browser/renderer_host/resource_dispatcher_host_impl.cc +++ b/content/browser/renderer_host/resource_dispatcher_host_impl.cc @@ -35,7 +35,6 @@ #include "content/browser/renderer_host/async_resource_handler.h" #include "content/browser/renderer_host/buffered_resource_handler.h" #include "content/browser/renderer_host/cross_site_resource_handler.h" -#include "content/browser/renderer_host/doomed_resource_handler.h" #include "content/browser/renderer_host/redirect_to_file_resource_handler.h" #include "content/browser/renderer_host/render_view_host_delegate.h" #include "content/browser/renderer_host/render_view_host_impl.h" @@ -522,7 +521,7 @@ net::Error ResourceDispatcherHostImpl::BeginDownload( // From this point forward, the |DownloadResourceHandler| is responsible for // |started_callback|. - scoped_refptr<ResourceHandler> handler( + scoped_ptr<ResourceHandler> handler( CreateResourceHandlerForDownload(request.get(), context, child_id, route_id, request_id_, is_content_initiated, save_info, @@ -535,7 +534,7 @@ net::Error ResourceDispatcherHostImpl::BeginDownload( } ResourceRequestInfoImpl* extra_info = - CreateRequestInfo(handler, child_id, route_id, true, context); + CreateRequestInfo(handler.Pass(), child_id, route_id, true, context); extra_info->AssociateWithRequest(request.get()); // Request takes ownership. request->set_delegate(this); @@ -559,7 +558,7 @@ void ResourceDispatcherHostImpl::Shutdown() { base::Unretained(this))); } -scoped_refptr<ResourceHandler> +scoped_ptr<ResourceHandler> ResourceDispatcherHostImpl::CreateResourceHandlerForDownload( net::URLRequest* request, ResourceContext* context, @@ -569,7 +568,7 @@ ResourceDispatcherHostImpl::CreateResourceHandlerForDownload( bool is_content_initiated, const DownloadSaveInfo& save_info, const DownloadResourceHandler::OnStartedCallback& started_cb) { - scoped_refptr<ResourceHandler> handler( + scoped_ptr<ResourceHandler> handler( new DownloadResourceHandler(child_id, route_id, request_id, request->url(), download_file_manager_.get(), request, started_cb, save_info)); @@ -578,11 +577,12 @@ ResourceDispatcherHostImpl::CreateResourceHandlerForDownload( delegate_->DownloadStarting(request, context, child_id, route_id, request_id, is_content_initiated, &throttles); if (!throttles.empty()) { - handler = new ThrottlingResourceHandler(this, handler, child_id, - request_id, throttles.Pass()); + handler.reset( + new ThrottlingResourceHandler(this, handler.Pass(), child_id, + request_id, throttles.Pass())); } } - return handler; + return handler.Pass(); } // static @@ -775,23 +775,26 @@ void ResourceDispatcherHostImpl::BeginRequest( } // Construct the event handler. - scoped_refptr<ResourceHandler> handler; + scoped_ptr<ResourceHandler> handler; if (sync_result) { - handler = new SyncResourceHandler( - filter_, request_data.url, sync_result, this); + handler.reset(new SyncResourceHandler( + filter_, request_data.url, sync_result, this)); } else { - handler = new AsyncResourceHandler( - filter_, route_id, request_data.url, this); + handler.reset(new AsyncResourceHandler( + filter_, route_id, request_data.url, this)); } // The RedirectToFileResourceHandler depends on being next in the chain. - if (request_data.download_to_file) - handler = new RedirectToFileResourceHandler(handler, child_id, this); + if (request_data.download_to_file) { + handler.reset( + new RedirectToFileResourceHandler(handler.Pass(), child_id, this)); + } if (HandleExternalProtocol( - request_id, child_id, route_id, request_data.url, - request_data.resource_type, - *resource_context->GetRequestContext()->job_factory(), handler)) { + request_id, child_id, route_id, request_data.url, + request_data.resource_type, + *resource_context->GetRequestContext()->job_factory(), + handler.get())) { return; } @@ -870,11 +873,12 @@ void ResourceDispatcherHostImpl::BeginRequest( HasPendingCrossSiteRequest(child_id, route_id)) { // Wrap the event handler to be sure the current page's onunload handler // has a chance to run before we render the new page. - handler = new CrossSiteResourceHandler(handler, child_id, route_id, this); + handler.reset( + new CrossSiteResourceHandler(handler.Pass(), child_id, route_id, this)); } // Insert a buffered event handler before the actual one. - handler = new BufferedResourceHandler(handler, this, request); + handler.reset(new BufferedResourceHandler(handler.Pass(), this, request)); ScopedVector<ResourceThrottle> throttles; if (delegate_) { @@ -896,8 +900,9 @@ void ResourceDispatcherHostImpl::BeginRequest( } if (!throttles.empty()) { - handler = new ThrottlingResourceHandler(this, handler, child_id, request_id, - throttles.Pass()); + handler.reset( + new ThrottlingResourceHandler(this, handler.Pass(), child_id, + request_id, throttles.Pass())); } bool allow_download = request_data.allow_download && @@ -905,7 +910,7 @@ void ResourceDispatcherHostImpl::BeginRequest( // Make extra info and read footer (contains request ID). ResourceRequestInfoImpl* extra_info = new ResourceRequestInfoImpl( - handler, + handler.Pass(), process_type, child_id, route_id, @@ -1072,13 +1077,13 @@ void ResourceDispatcherHostImpl::OnFollowRedirect( } ResourceRequestInfoImpl* ResourceDispatcherHostImpl::CreateRequestInfo( - ResourceHandler* handler, + scoped_ptr<ResourceHandler> handler, int child_id, int route_id, bool download, ResourceContext* context) { return new ResourceRequestInfoImpl( - handler, + handler.Pass(), PROCESS_TYPE_RENDERER, child_id, route_id, @@ -1150,7 +1155,7 @@ void ResourceDispatcherHostImpl::BeginSaveFile( base::debug::Alias(url_buf); CHECK(ContainsKey(active_resource_contexts_, context)); - scoped_refptr<ResourceHandler> handler( + scoped_ptr<ResourceHandler> handler( new SaveFileResourceHandler(child_id, route_id, url, @@ -1179,7 +1184,7 @@ void ResourceDispatcherHostImpl::BeginSaveFile( // Since we're just saving some resources we need, disallow downloading. ResourceRequestInfoImpl* extra_info = - CreateRequestInfo(handler, child_id, route_id, false, context); + CreateRequestInfo(handler.Pass(), child_id, route_id, false, context); extra_info->AssociateWithRequest(request); // Request takes ownership. BeginRequestInternal(request); @@ -1257,16 +1262,14 @@ void ResourceDispatcherHostImpl::MarkAsTransferredNavigation( info->GetRequestID()); transferred_navigations_[transferred_request_id] = transferred_request; - // If a URLRequest is transferred to a new RenderViewHost, its + // If an URLRequest is transferred to a new RenderViewHost, its // ResourceHandler should not receive any notifications because it may // depend on the state of the old RVH. We set a ResourceHandler that only // allows canceling requests, because on shutdown of the RDH all pending // requests are canceled. The RVH of requests that are being transferred may // be gone by that time. If the request is resumed, the ResoureHandlers are // substituted again. - scoped_refptr<ResourceHandler> transferred_resource_handler( - new DoomedResourceHandler(info->resource_handler())); - info->set_resource_handler(transferred_resource_handler.get()); + info->InsertDoomedResourceHandler(); } int ResourceDispatcherHostImpl::GetOutstandingRequestsMemoryCost( diff --git a/content/browser/renderer_host/resource_dispatcher_host_impl.h b/content/browser/renderer_host/resource_dispatcher_host_impl.h index f7c6274..39b1c21 100644 --- a/content/browser/renderer_host/resource_dispatcher_host_impl.h +++ b/content/browser/renderer_host/resource_dispatcher_host_impl.h @@ -258,7 +258,7 @@ class CONTENT_EXPORT ResourceDispatcherHostImpl return delegate_; } - scoped_refptr<ResourceHandler> CreateResourceHandlerForDownload( + scoped_ptr<ResourceHandler> CreateResourceHandlerForDownload( net::URLRequest* request, ResourceContext* context, int child_id, @@ -411,7 +411,7 @@ class CONTENT_EXPORT ResourceDispatcherHostImpl // Creates ResourceRequestInfoImpl for a download or page save. // |download| should be true if the request is a file download. ResourceRequestInfoImpl* CreateRequestInfo( - ResourceHandler* handler, + scoped_ptr<ResourceHandler> handler, int child_id, int route_id, bool download, diff --git a/content/browser/renderer_host/resource_handler.h b/content/browser/renderer_host/resource_handler.h index 5888245..4979c81e76 100644 --- a/content/browser/renderer_host/resource_handler.h +++ b/content/browser/renderer_host/resource_handler.h @@ -16,6 +16,7 @@ #include <string> #include "base/message_loop_helpers.h" +#include "base/threading/non_thread_safe.h" #include "content/common/content_export.h" #include "content/public/browser/browser_thread.h" @@ -30,13 +31,14 @@ class IOBuffer; class URLRequestStatus; } // namespace net -// The resource dispatcher host uses this interface to push load events to the -// renderer, allowing for differences in the types of IPC messages generated. -// See the implementations of this interface defined below. +// The resource dispatcher host uses this interface to process network events +// for an URLRequest instance. A ResourceHandler's lifetime is bound to its +// associated URLRequest. class CONTENT_EXPORT ResourceHandler - : public base::RefCountedThreadSafe< - ResourceHandler, content::BrowserThread::DeleteOnIOThread> { + : public NON_EXPORTED_BASE(base::NonThreadSafe) { public: + virtual ~ResourceHandler() {} + // Called as upload progress is made. The return value is ignored. virtual bool OnUploadProgress(int request_id, uint64 position, @@ -95,23 +97,11 @@ class CONTENT_EXPORT ResourceHandler const net::URLRequestStatus& status, const std::string& security_info) = 0; - // Signals that the request is closed (i.e. about to be deleted). This is a - // signal that the associated net::URLRequest isn't valid anymore. - virtual void OnRequestClosed() = 0; - // This notification is synthesized by the RedirectToFileResourceHandler // to indicate progress of 'download_to_file' requests. OnReadCompleted // calls are consumed by the RedirectToFileResourceHandler and replaced // with OnDataDownloaded calls. virtual void OnDataDownloaded(int request_id, int bytes_downloaded) {} - - protected: - friend class content::BrowserThread; - friend class base::RefCountedThreadSafe< - ResourceHandler, content::BrowserThread::DeleteOnIOThread>; - friend class base::DeleteHelper<ResourceHandler>; - - virtual ~ResourceHandler() {} }; #endif // CONTENT_BROWSER_RENDERER_HOST_RESOURCE_HANDLER_H_ diff --git a/content/browser/renderer_host/resource_request_info_impl.cc b/content/browser/renderer_host/resource_request_info_impl.cc index 57ab066..be72592 100644 --- a/content/browser/renderer_host/resource_request_info_impl.cc +++ b/content/browser/renderer_host/resource_request_info_impl.cc @@ -4,7 +4,7 @@ #include "content/browser/renderer_host/resource_request_info_impl.h" -#include "content/browser/renderer_host/resource_handler.h" +#include "content/browser/renderer_host/doomed_resource_handler.h" #include "content/browser/ssl/ssl_client_auth_handler.h" #include "content/browser/worker_host/worker_service_impl.h" #include "content/common/net/url_request_user_data.h" @@ -30,7 +30,7 @@ void ResourceRequestInfo::AllocateForTesting( ResourceContext* context) { ResourceRequestInfoImpl* info = new ResourceRequestInfoImpl( - NULL, // handler + scoped_ptr<ResourceHandler>(), // handler PROCESS_TYPE_RENDERER, // process_type -1, // child_id MSG_ROUTING_NONE, // route_id @@ -81,7 +81,7 @@ const ResourceRequestInfoImpl* ResourceRequestInfoImpl::ForRequest( } ResourceRequestInfoImpl::ResourceRequestInfoImpl( - ResourceHandler* handler, + scoped_ptr<ResourceHandler> handler, ProcessType process_type, int child_id, int route_id, @@ -99,7 +99,7 @@ ResourceRequestInfoImpl::ResourceRequestInfoImpl( bool has_user_gesture, WebKit::WebReferrerPolicy referrer_policy, ResourceContext* context) - : resource_handler_(handler), + : resource_handler_(handler.Pass()), cross_site_handler_(NULL), process_type_(process_type), child_id_(child_id), @@ -130,8 +130,9 @@ ResourceRequestInfoImpl::ResourceRequestInfoImpl( } ResourceRequestInfoImpl::~ResourceRequestInfoImpl() { - if (resource_handler_) - resource_handler_->OnRequestClosed(); + // Run ResourceHandler destructor before we tear-down the rest of our state + // as the ResourceHandler may want to inspect some of our other members. + resource_handler_.reset(); } ResourceContext* ResourceRequestInfoImpl::GetContext() const { @@ -214,9 +215,9 @@ void ResourceRequestInfoImpl::AssociateWithRequest(net::URLRequest* request) { } } -void ResourceRequestInfoImpl::set_resource_handler( - ResourceHandler* resource_handler) { - resource_handler_ = resource_handler; +void ResourceRequestInfoImpl::InsertDoomedResourceHandler() { + resource_handler_.reset( + new DoomedResourceHandler(resource_handler_.Pass())); } void ResourceRequestInfoImpl::set_login_delegate( diff --git a/content/browser/renderer_host/resource_request_info_impl.h b/content/browser/renderer_host/resource_request_info_impl.h index b823f93..92de95e 100644 --- a/content/browser/renderer_host/resource_request_info_impl.h +++ b/content/browser/renderer_host/resource_request_info_impl.h @@ -10,6 +10,7 @@ #include "base/basictypes.h" #include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" #include "base/supports_user_data.h" #include "base/time.h" #include "content/public/browser/resource_request_info.h" @@ -47,7 +48,7 @@ class ResourceRequestInfoImpl : public ResourceRequestInfo, // This will take a reference to the handler. CONTENT_EXPORT ResourceRequestInfoImpl( - ResourceHandler* handler, + scoped_ptr<ResourceHandler> handler, ProcessType process_type, int child_id, int route_id, @@ -87,7 +88,9 @@ class ResourceRequestInfoImpl : public ResourceRequestInfo, // Top-level ResourceHandler servicing this request. ResourceHandler* resource_handler() { return resource_handler_.get(); } - void set_resource_handler(ResourceHandler* resource_handler); + + // Inserts a DoomedResourceHandler in front of the existing ResourceHandler. + void InsertDoomedResourceHandler(); // CrossSiteResourceHandler for this request, if it is a cross-site request. // (NULL otherwise.) This handler is part of the chain of ResourceHandlers @@ -210,7 +213,7 @@ class ResourceRequestInfoImpl : public ResourceRequestInfo, int paused_read_bytes() const { return paused_read_bytes_; } void set_paused_read_bytes(int bytes) { paused_read_bytes_ = bytes; } - scoped_refptr<ResourceHandler> resource_handler_; + scoped_ptr<ResourceHandler> resource_handler_; // Non-owning, may be NULL. CrossSiteResourceHandler* cross_site_handler_; diff --git a/content/browser/renderer_host/sync_resource_handler.cc b/content/browser/renderer_host/sync_resource_handler.cc index 8a7c934..5c149b7 100644 --- a/content/browser/renderer_host/sync_resource_handler.cc +++ b/content/browser/renderer_host/sync_resource_handler.cc @@ -29,6 +29,10 @@ SyncResourceHandler::SyncResourceHandler( } SyncResourceHandler::~SyncResourceHandler() { + if (result_message_) { + result_message_->set_reply_error(); + filter_->Send(result_message_); + } } bool SyncResourceHandler::OnUploadProgress(int request_id, @@ -123,12 +127,4 @@ bool SyncResourceHandler::OnResponseCompleted( return true; } -void SyncResourceHandler::OnRequestClosed() { - if (!result_message_) - return; - - result_message_->set_reply_error(); - filter_->Send(result_message_); -} - } // namespace content diff --git a/content/browser/renderer_host/sync_resource_handler.h b/content/browser/renderer_host/sync_resource_handler.h index c2c1446..f07e7e1 100644 --- a/content/browser/renderer_host/sync_resource_handler.h +++ b/content/browser/renderer_host/sync_resource_handler.h @@ -32,6 +32,7 @@ class SyncResourceHandler : public ResourceHandler { const GURL& url, IPC::Message* result_message, ResourceDispatcherHostImpl* resource_dispatcher_host); + virtual ~SyncResourceHandler(); virtual bool OnUploadProgress(int request_id, uint64 position, @@ -56,13 +57,10 @@ class SyncResourceHandler : public ResourceHandler { virtual bool OnResponseCompleted(int request_id, const net::URLRequestStatus& status, const std::string& security_info) OVERRIDE; - virtual void OnRequestClosed() OVERRIDE; private: enum { kReadBufSize = 3840 }; - virtual ~SyncResourceHandler(); - scoped_refptr<net::IOBuffer> read_buffer_; SyncLoadResult result_; diff --git a/content/browser/renderer_host/throttling_resource_handler.cc b/content/browser/renderer_host/throttling_resource_handler.cc index a07d278..cef6b38 100644 --- a/content/browser/renderer_host/throttling_resource_handler.cc +++ b/content/browser/renderer_host/throttling_resource_handler.cc @@ -12,11 +12,11 @@ namespace content { ThrottlingResourceHandler::ThrottlingResourceHandler( ResourceDispatcherHostImpl* host, - ResourceHandler* next_handler, + scoped_ptr<ResourceHandler> next_handler, int child_id, int request_id, ScopedVector<ResourceThrottle> throttles) - : LayeredResourceHandler(next_handler), + : LayeredResourceHandler(next_handler.Pass()), deferred_stage_(DEFERRED_NONE), host_(host), child_id_(child_id), @@ -27,6 +27,9 @@ ThrottlingResourceHandler::ThrottlingResourceHandler( throttles_[i]->set_controller(this); } +ThrottlingResourceHandler::~ThrottlingResourceHandler() { +} + bool ThrottlingResourceHandler::OnRequestRedirected(int request_id, const GURL& new_url, ResourceResponse* response, @@ -93,11 +96,6 @@ bool ThrottlingResourceHandler::OnResponseStarted( return next_handler_->OnResponseStarted(request_id, response, defer); } -void ThrottlingResourceHandler::OnRequestClosed() { - throttles_.reset(); - next_handler_->OnRequestClosed(); -} - void ThrottlingResourceHandler::Cancel() { host_->CancelRequest(child_id_, request_id_, false); } @@ -120,9 +118,6 @@ void ThrottlingResourceHandler::Resume() { deferred_stage_ = DEFERRED_NONE; } -ThrottlingResourceHandler::~ThrottlingResourceHandler() { -} - void ThrottlingResourceHandler::ResumeStart() { GURL url = deferred_url_; deferred_url_ = GURL(); diff --git a/content/browser/renderer_host/throttling_resource_handler.h b/content/browser/renderer_host/throttling_resource_handler.h index 3b2b71c..358b1fa 100644 --- a/content/browser/renderer_host/throttling_resource_handler.h +++ b/content/browser/renderer_host/throttling_resource_handler.h @@ -24,10 +24,11 @@ class ThrottlingResourceHandler : public LayeredResourceHandler, public: // Takes ownership of the ResourceThrottle instances. ThrottlingResourceHandler(ResourceDispatcherHostImpl* host, - ResourceHandler* next_handler, + scoped_ptr<ResourceHandler> next_handler, int child_id, int request_id, ScopedVector<ResourceThrottle> throttles); + virtual ~ThrottlingResourceHandler(); // LayeredResourceHandler overrides: virtual bool OnRequestRedirected(int request_id, const GURL& url, @@ -38,15 +39,12 @@ class ThrottlingResourceHandler : public LayeredResourceHandler, bool* defer) OVERRIDE; virtual bool OnWillStart(int request_id, const GURL& url, bool* defer) OVERRIDE; - virtual void OnRequestClosed() OVERRIDE; // ResourceThrottleController implementation: virtual void Cancel() OVERRIDE; virtual void Resume() OVERRIDE; private: - virtual ~ThrottlingResourceHandler(); - void ResumeStart(); void ResumeRedirect(); void ResumeResponse(); diff --git a/content/browser/renderer_host/transfer_navigation_resource_throttle.h b/content/browser/renderer_host/transfer_navigation_resource_throttle.h index e30d444..c13d0a8 100644 --- a/content/browser/renderer_host/transfer_navigation_resource_throttle.h +++ b/content/browser/renderer_host/transfer_navigation_resource_throttle.h @@ -21,13 +21,12 @@ class URLRequest; class TransferNavigationResourceThrottle : public content::ResourceThrottle { public: explicit TransferNavigationResourceThrottle(net::URLRequest* request); + virtual ~TransferNavigationResourceThrottle(); // content::ResourceThrottle implementation: virtual void WillRedirectRequest(const GURL& new_url, bool* defer) OVERRIDE; private: - virtual ~TransferNavigationResourceThrottle(); - net::URLRequest* request_; DISALLOW_COPY_AND_ASSIGN(TransferNavigationResourceThrottle); diff --git a/content/browser/renderer_host/x509_user_cert_resource_handler.cc b/content/browser/renderer_host/x509_user_cert_resource_handler.cc index 747a82b..e563666 100644 --- a/content/browser/renderer_host/x509_user_cert_resource_handler.cc +++ b/content/browser/renderer_host/x509_user_cert_resource_handler.cc @@ -28,6 +28,9 @@ X509UserCertResourceHandler::X509UserCertResourceHandler( render_view_id_(render_view_id) { } +X509UserCertResourceHandler::~X509UserCertResourceHandler() { +} + bool X509UserCertResourceHandler::OnUploadProgress(int request_id, uint64 position, uint64 size) { @@ -111,12 +114,6 @@ bool X509UserCertResourceHandler::OnResponseCompleted( return true; } -void X509UserCertResourceHandler::OnRequestClosed() { -} - -X509UserCertResourceHandler::~X509UserCertResourceHandler() { -} - void X509UserCertResourceHandler::AssembleResource() { size_t assembled_bytes = 0; resource_buffer_ = content::AssembleData(buffer_, &assembled_bytes); diff --git a/content/browser/renderer_host/x509_user_cert_resource_handler.h b/content/browser/renderer_host/x509_user_cert_resource_handler.h index 9dcfa50..0cb65658 100644 --- a/content/browser/renderer_host/x509_user_cert_resource_handler.h +++ b/content/browser/renderer_host/x509_user_cert_resource_handler.h @@ -29,6 +29,7 @@ class X509UserCertResourceHandler : public ResourceHandler { X509UserCertResourceHandler(net::URLRequest* request, int render_process_host_id, int render_view_id); + virtual ~X509UserCertResourceHandler(); virtual bool OnUploadProgress(int request_id, uint64 position, @@ -66,11 +67,7 @@ class X509UserCertResourceHandler : public ResourceHandler { const net::URLRequestStatus& urs, const std::string& sec_info) OVERRIDE; - virtual void OnRequestClosed() OVERRIDE; - private: - virtual ~X509UserCertResourceHandler(); - void AssembleResource(); GURL url_; |