| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This is the browser side of the resource dispatcher, it receives requests | 5 // This is the browser side of the resource dispatcher, it receives requests |
| 6 // from the RenderProcessHosts, and dispatches them to URLRequests. It then | 6 // from the RenderProcessHosts, and dispatches them to URLRequests. It then |
| 7 // fowards the messages from the URLRequests back to the correct process for | 7 // fowards the messages from the URLRequests back to the correct process for |
| 8 // handling. | 8 // handling. |
| 9 // | 9 // |
| 10 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading | 10 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 namespace content { | 32 namespace content { |
| 33 class ResourceController; | 33 class ResourceController; |
| 34 class ResourceMessageFilter; | 34 class ResourceMessageFilter; |
| 35 class ResourceRequestInfoImpl; | 35 class ResourceRequestInfoImpl; |
| 36 struct ResourceResponse; | 36 struct ResourceResponse; |
| 37 | 37 |
| 38 // The resource dispatcher host uses this interface to process network events | 38 // The resource dispatcher host uses this interface to process network events |
| 39 // for an URLRequest instance. A ResourceHandler's lifetime is bound to its | 39 // for an URLRequest instance. A ResourceHandler's lifetime is bound to its |
| 40 // associated URLRequest. | 40 // associated URLRequest. |
| 41 // |
| 42 // For all methods that take a bool |defer_or_cancel| pointer, the pointer has |
| 43 // an initial value of false. It should be set to true if the request should be |
| 44 // deferred until a later point in time, at which point the ResourceContoller's |
| 45 // Resume() method may be called to continue the request, or its Cancel() method |
| 46 // to cancel the request. It must also be set to true if the |
| 47 // ResourceController's method to cancel the request are called synchronously. |
| 41 class CONTENT_EXPORT ResourceHandler | 48 class CONTENT_EXPORT ResourceHandler |
| 42 : public NON_EXPORTED_BASE(base::NonThreadSafe) { | 49 : public NON_EXPORTED_BASE(base::NonThreadSafe) { |
| 43 public: | 50 public: |
| 44 virtual ~ResourceHandler(); | 51 virtual ~ResourceHandler(); |
| 45 | 52 |
| 46 // Sets the controller for this handler. | 53 // Sets the controller for this handler. The controller can be used to resume |
| 54 // the request after deferring it, or to cancel the request. |
| 55 // |
| 56 // On cancel, teardown will start asynchronously. |
| 47 virtual void SetController(ResourceController* controller); | 57 virtual void SetController(ResourceController* controller); |
| 48 | 58 |
| 49 // The request was redirected to a new URL. |*defer| has an initial value of | 59 // The request was redirected to a new URL. |
| 50 // false. Set |*defer| to true to defer the redirect. The redirect may be | 60 virtual void OnRequestRedirected(const net::RedirectInfo& redirect_info, |
| 51 // followed later on via ResourceDispatcherHost::FollowDeferredRedirect. If | |
| 52 // the handler returns false, then the request is cancelled. | |
| 53 virtual bool OnRequestRedirected(const net::RedirectInfo& redirect_info, | |
| 54 ResourceResponse* response, | 61 ResourceResponse* response, |
| 55 bool* defer) = 0; | 62 bool* defer_or_cancel) = 0; |
| 56 | 63 |
| 57 // Response headers and meta data are available. If the handler returns | 64 // Response headers and meta data are available. |
| 58 // false, then the request is cancelled. Set |*defer| to true to defer | 65 virtual void OnResponseStarted(ResourceResponse* response, |
| 59 // processing of the response. Call ResourceDispatcherHostImpl:: | 66 bool* defer_or_cancel) = 0; |
| 60 // ResumeDeferredRequest to continue processing the response. | |
| 61 virtual bool OnResponseStarted(ResourceResponse* response, bool* defer) = 0; | |
| 62 | 67 |
| 63 // Called before the net::URLRequest (whose url is |url|) is to be started. | 68 // Called before the net::URLRequest (whose url is |url|) is to be started. |
| 64 // If the handler returns false, then the request is cancelled. Otherwise if | 69 virtual void OnWillStart(const GURL& url, bool* defer_or_cancel) = 0; |
| 65 // the return value is true, the ResourceHandler can delay the request from | |
| 66 // starting by setting |*defer = true|. A deferred request will not have | |
| 67 // called net::URLRequest::Start(), and will not resume until someone calls | |
| 68 // ResourceDispatcherHost::StartDeferredRequest(). | |
| 69 virtual bool OnWillStart(const GURL& url, bool* defer) = 0; | |
| 70 | 70 |
| 71 // Data will be read for the response. Upon success, this method places the | 71 // Data will be read for the response. Upon success, this method places the |
| 72 // size and address of the buffer where the data is to be written in its | 72 // size and address of the buffer where the data is to be written in its |
| 73 // out-params. This call will be followed by either OnReadCompleted (on | 73 // out-params. This call will be followed by either OnReadCompleted (on |
| 74 // successful read or EOF) or OnResponseCompleted (on error). If | 74 // successful read or EOF) or OnResponseCompleted (on error). If |
| 75 // OnReadCompleted is called, the buffer may be recycled. Otherwise, it may | 75 // OnReadCompleted is called, the buffer may be recycled. Otherwise, it may |
| 76 // not be recycled and may potentially outlive the handler. If |min_size| is | 76 // not be recycled and may potentially outlive the handler. If |min_size| is |
| 77 // not -1, it is the minimum size of the returned buffer. | 77 // not -1, it is the minimum size of the returned buffer. |
| 78 // | 78 // |
| 79 // If the handler returns false, then the request is cancelled. Otherwise, | 79 // If the handler returns false, then the request is cancelled. Otherwise, |
| 80 // once data is available, OnReadCompleted will be called. | 80 // once data is available, OnReadCompleted will be called. The request must |
| 81 // not be cancelled via the ResourceController during this call. |
| 82 // |
| 83 // TODO(mmenke): Make this work like other methods (Sync/async completion, |
| 84 // cancel through the ResourceController). |
| 81 virtual bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, | 85 virtual bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
| 82 int* buf_size, | 86 int* buf_size, |
| 83 int min_size) = 0; | 87 int min_size) = 0; |
| 84 | 88 |
| 85 // Data (*bytes_read bytes) was written into the buffer provided by | 89 // Data (*bytes_read bytes) was written into the buffer provided by |
| 86 // OnWillRead. A return value of false cancels the request, true continues | 90 // OnWillRead. A zero |bytes_read| signals that no further data is available. |
| 87 // reading data. Set |*defer| to true to defer reading more response data. | 91 virtual void OnReadCompleted(int bytes_read, bool* defer_or_cancel) = 0; |
| 88 // Call controller()->Resume() to continue reading response data. A zero | |
| 89 // |bytes_read| signals that no further data is available. | |
| 90 virtual bool OnReadCompleted(int bytes_read, bool* defer) = 0; | |
| 91 | 92 |
| 92 // The response is complete. The final response status is given. Set | 93 // The response is complete. The final response status is given. Set |
| 93 // |*defer| to true to defer destruction to a later time. Otherwise, the | 94 // |*defer| to true to defer destruction to a later time. It will be |
| 94 // request will be destroyed upon return. | 95 // completed by calling ResourceController::Resume(). |
| 96 // TODO(mmenke): Make cancellation do something reasonble during this call, |
| 97 // and document it here. |
| 95 virtual void OnResponseCompleted(const net::URLRequestStatus& status, | 98 virtual void OnResponseCompleted(const net::URLRequestStatus& status, |
| 96 bool* defer) = 0; | 99 bool* defer) = 0; |
| 97 | 100 |
| 98 // This notification is synthesized by the RedirectToFileResourceHandler | 101 // This notification is synthesized by the RedirectToFileResourceHandler |
| 99 // to indicate progress of 'download_to_file' requests. OnReadCompleted | 102 // to indicate progress of 'download_to_file' requests. OnReadCompleted |
| 100 // calls are consumed by the RedirectToFileResourceHandler and replaced | 103 // calls are consumed by the RedirectToFileResourceHandler and replaced |
| 101 // with OnDataDownloaded calls. | 104 // with OnDataDownloaded calls. |
| 102 virtual void OnDataDownloaded(int bytes_downloaded) = 0; | 105 virtual void OnDataDownloaded(int bytes_downloaded) = 0; |
| 103 | 106 |
| 104 protected: | 107 protected: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 115 private: | 118 private: |
| 116 ResourceController* controller_; | 119 ResourceController* controller_; |
| 117 net::URLRequest* request_; | 120 net::URLRequest* request_; |
| 118 | 121 |
| 119 DISALLOW_COPY_AND_ASSIGN(ResourceHandler); | 122 DISALLOW_COPY_AND_ASSIGN(ResourceHandler); |
| 120 }; | 123 }; |
| 121 | 124 |
| 122 } // namespace content | 125 } // namespace content |
| 123 | 126 |
| 124 #endif // CONTENT_BROWSER_LOADER_RESOURCE_HANDLER_H_ | 127 #endif // CONTENT_BROWSER_LOADER_RESOURCE_HANDLER_H_ |
| OLD | NEW |