Chromium Code Reviews| Index: content/browser/loader/resource_handler.h |
| diff --git a/content/browser/loader/resource_handler.h b/content/browser/loader/resource_handler.h |
| index a6cc6822c691fc0ae706d25ae566b7bc65fb4655..2a34e1c4319b1273f6f5f4b42756c0fdb91970d2 100644 |
| --- a/content/browser/loader/resource_handler.h |
| +++ b/content/browser/loader/resource_handler.h |
| @@ -12,6 +12,7 @@ |
| #ifndef CONTENT_BROWSER_LOADER_RESOURCE_HANDLER_H_ |
| #define CONTENT_BROWSER_LOADER_RESOURCE_HANDLER_H_ |
| +#include <memory> |
| #include <string> |
| #include "base/compiler_specific.h" |
| @@ -19,6 +20,7 @@ |
| #include "base/memory/ref_counted.h" |
| #include "base/threading/non_thread_safe.h" |
| #include "content/common/content_export.h" |
| +#include "content/public/browser/resource_controller.h" |
| class GURL; |
| @@ -30,7 +32,6 @@ struct RedirectInfo; |
| } // namespace net |
| namespace content { |
| -class ResourceController; |
| class ResourceMessageFilter; |
| class ResourceRequestInfoImpl; |
| struct ResourceResponse; |
| @@ -43,30 +44,27 @@ class CONTENT_EXPORT ResourceHandler |
| public: |
| virtual ~ResourceHandler(); |
| - // Sets the controller for this handler. |
| - virtual void SetController(ResourceController* controller); |
| - |
| - // The request was redirected to a new URL. |*defer| has an initial value of |
| - // false. Set |*defer| to true to defer the redirect. The redirect may be |
| - // followed later on via ResourceDispatcherHost::FollowDeferredRedirect. If |
| - // the handler returns false, then the request is cancelled. |
| - virtual bool OnRequestRedirected(const net::RedirectInfo& redirect_info, |
| - ResourceResponse* response, |
| - bool* defer) = 0; |
| - |
| - // Response headers and meta data are available. If the handler returns |
| - // false, then the request is cancelled. Set |*defer| to true to defer |
| - // processing of the response. Call ResourceDispatcherHostImpl:: |
| - // ResumeDeferredRequest to continue processing the response. |
| - virtual bool OnResponseStarted(ResourceResponse* response, bool* defer) = 0; |
| + // The request was redirected to a new URL. The request will not continue |
| + // until one of |controller|'s resume or cancellation methods is invoked, at |
| + // which point the request will be resumed synchronously. |
|
Randy Smith (Not in Mondays)
2016/12/16 21:37:27
nit: Implies Cancel() will resume the request, whi
|
| + virtual void OnRequestRedirected( |
| + const net::RedirectInfo& redirect_info, |
| + ResourceResponse* response, |
| + std::unique_ptr<ResourceController> controller) = 0; |
| + |
| + // Response headers and metadata are available. The request will not continue |
| + // until one of |controller|'s resume or cancellation methods is invoked, at |
| + // which point the request will be resumed synchronously. |
| + virtual void OnResponseStarted( |
| + ResourceResponse* response, |
| + std::unique_ptr<ResourceController> controller) = 0; |
| // Called before the net::URLRequest (whose url is |url|) is to be started. |
| - // If the handler returns false, then the request is cancelled. Otherwise if |
| - // the return value is true, the ResourceHandler can delay the request from |
| - // starting by setting |*defer = true|. A deferred request will not have |
| - // called net::URLRequest::Start(), and will not resume until someone calls |
| - // ResourceDispatcherHost::StartDeferredRequest(). |
| - virtual bool OnWillStart(const GURL& url, bool* defer) = 0; |
| + // The request will not continue until one of |controller|'s resume or |
| + // cancellation methods is invoked, at which point the request will be started |
| + // synchronously. |
| + virtual void OnWillStart(const GURL& url, |
| + std::unique_ptr<ResourceController> controller) = 0; |
| // Data will be read for the response. Upon success, this method places the |
| // size and address of the buffer where the data is to be written in its |
| @@ -78,22 +76,27 @@ class CONTENT_EXPORT ResourceHandler |
| // |
| // If the handler returns false, then the request is cancelled. Otherwise, |
| // once data is available, OnReadCompleted will be called. |
| + // TODO(mmenke): Make this method use a ResourceController, and allow it to |
| + // succeed asynchronously. |
| virtual bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
| int* buf_size, |
| int min_size) = 0; |
| // Data (*bytes_read bytes) was written into the buffer provided by |
| - // OnWillRead. A return value of false cancels the request, true continues |
| - // reading data. Set |*defer| to true to defer reading more response data. |
| - // Call controller()->Resume() to continue reading response data. A zero |
| - // |bytes_read| signals that no further data is available. |
| - virtual bool OnReadCompleted(int bytes_read, bool* defer) = 0; |
| - |
| - // The response is complete. The final response status is given. Set |
| - // |*defer| to true to defer destruction to a later time. Otherwise, the |
| - // request will be destroyed upon return. |
| - virtual void OnResponseCompleted(const net::URLRequestStatus& status, |
| - bool* defer) = 0; |
| + // OnWillRead. The request will not continue until one of |controller|'s |
| + // resume or cancellation methods is invoked, at which point the request will |
| + // be resumed synchronously. A zero |bytes_read| signals that no further data |
| + // is available. |
| + virtual void OnReadCompleted( |
| + int bytes_read, |
| + std::unique_ptr<ResourceController> controller) = 0; |
| + |
| + // The response is complete. The final response status is given. The request |
| + // will not be deleted until controller's Resume() method is invoked. It is |
| + // illegal to use its cancellation methods. |
| + virtual void OnResponseCompleted( |
| + const net::URLRequestStatus& status, |
| + std::unique_ptr<ResourceController> controller) = 0; |
| // This notification is synthesized by the RedirectToFileResourceHandler |
| // to indicate progress of 'download_to_file' requests. OnReadCompleted |
| @@ -102,9 +105,28 @@ class CONTENT_EXPORT ResourceHandler |
| virtual void OnDataDownloaded(int bytes_downloaded) = 0; |
| protected: |
| - ResourceHandler(net::URLRequest* request); |
| + explicit ResourceHandler(net::URLRequest* request); |
| + |
| + // Utility methods for managing a ResourceHandler's controller in the async |
| + // completion case. These ensure that the controller is nullptr after being |
| + // invoked, which allows for DCHECKing on it and better crashes on calling |
| + // into deleting objects. |
| + |
| + void set_controller(std::unique_ptr<ResourceController> controller) { |
| + controller_ = std::move(controller); |
| + } |
| + |
| + bool has_controller() const { return !!controller_; } |
| + |
| + std::unique_ptr<ResourceController> TakeController(); |
| + |
| + // These call the corresponding methods on the previously set |
| + // ResourceController, and then destroy the controller. |
| + void Resume(); |
| + void Cancel(); |
| + void CancelAndIgnore(); |
| + void CancelWithError(int error_code); |
| - ResourceController* controller() const { return controller_; } |
| net::URLRequest* request() const { return request_; } |
| // Convenience functions. |
| @@ -112,9 +134,13 @@ class CONTENT_EXPORT ResourceHandler |
| int GetRequestID() const; |
| ResourceMessageFilter* GetFilter() const; |
| + // Cancels the request when the class does not currently have ownership of the |
| + // ResourceController. |
| + void OutOfBandCancel(); |
| + |
| private: |
| - ResourceController* controller_; |
| net::URLRequest* request_; |
| + std::unique_ptr<ResourceController> controller_; |
| DISALLOW_COPY_AND_ASSIGN(ResourceHandler); |
| }; |