Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1717)

Unified Diff: content/browser/loader/resource_handler.h

Issue 2476163003: Refactor ResourceHandler API. (Closed)
Patch Set: Minor cleanups, one real fix Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..e075c56d38d15ef3bb4dbb3de06abb7d65598ad1 100644
--- a/content/browser/loader/resource_handler.h
+++ b/content/browser/loader/resource_handler.h
@@ -38,35 +38,35 @@ struct ResourceResponse;
// 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.
+//
+// For all methods that take a bool |defer_or_cancel| pointer, the pointer has
+// an initial value of false. It should be set to true if the request should be
+// deferred until a later point in time, at which point the ResourceContoller's
+// Resume() method may be called to continue the request, or its Cancel() method
+// to cancel the request. It must also be set to true if the
+// ResourceController's method to cancel the request are called synchronously.
class CONTENT_EXPORT ResourceHandler
: public NON_EXPORTED_BASE(base::NonThreadSafe) {
public:
virtual ~ResourceHandler();
- // Sets the controller for this handler.
+ // Sets the controller for this handler. The controller can be used to resume
+ // the request after deferring it, or to cancel the request.
+ //
+ // On cancel, teardown will start asynchronously.
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,
+ // The request was redirected to a new URL.
+ virtual void OnRequestRedirected(const net::RedirectInfo& redirect_info,
ResourceResponse* response,
- bool* defer) = 0;
+ bool* defer_or_cancel) = 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;
+ // Response headers and meta data are available.
+ virtual void OnResponseStarted(ResourceResponse* response,
+ bool* defer_or_cancel) = 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;
+ virtual void OnWillStart(const GURL& url, bool* defer_or_cancel) = 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
@@ -77,21 +77,24 @@ class CONTENT_EXPORT ResourceHandler
// not -1, it is the minimum size of the returned buffer.
//
// If the handler returns false, then the request is cancelled. Otherwise,
- // once data is available, OnReadCompleted will be called.
+ // once data is available, OnReadCompleted will be called. The request must
+ // not be cancelled via the ResourceController during this call.
+ //
+ // TODO(mmenke): Make this work like other methods (Sync/async completion,
+ // cancel through the ResourceController).
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;
+ // OnWillRead. A zero |bytes_read| signals that no further data is available.
+ virtual void OnReadCompleted(int bytes_read, bool* defer_or_cancel) = 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.
+ // |*defer| to true to defer destruction to a later time. It will be
+ // completed by calling ResourceController::Resume().
+ // TODO(mmenke): Make cancellation do something reasonble during this call,
+ // and document it here.
virtual void OnResponseCompleted(const net::URLRequestStatus& status,
bool* defer) = 0;
« no previous file with comments | « content/browser/loader/redirect_to_file_resource_handler.cc ('k') | content/browser/loader/resource_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698