| 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 |
| 11 | 11 |
| 12 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_HANDLER_H_ | 12 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_HANDLER_H_ |
| 13 #define CONTENT_BROWSER_LOADER_RESOURCE_HANDLER_H_ | 13 #define CONTENT_BROWSER_LOADER_RESOURCE_HANDLER_H_ |
| 14 | 14 |
| 15 #include <string> | 15 #include <string> |
| 16 | 16 |
| 17 #include "base/memory/ref_counted.h" | |
| 18 #include "base/sequenced_task_runner_helpers.h" | 17 #include "base/sequenced_task_runner_helpers.h" |
| 19 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
| 20 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
| 21 | 20 |
| 22 class GURL; | 21 class GURL; |
| 23 | 22 |
| 24 namespace net { | 23 namespace net { |
| 25 class IOBuffer; | 24 class IOBuffer; |
| 26 class URLRequest; | |
| 27 class URLRequestStatus; | 25 class URLRequestStatus; |
| 28 } // namespace net | 26 } // namespace net |
| 29 | 27 |
| 30 namespace content { | 28 namespace content { |
| 31 class ResourceController; | 29 class ResourceController; |
| 32 class ResourceMessageFilter; | |
| 33 class ResourceRequestInfoImpl; | |
| 34 struct ResourceResponse; | 30 struct ResourceResponse; |
| 35 | 31 |
| 36 // The resource dispatcher host uses this interface to process network events | 32 // The resource dispatcher host uses this interface to process network events |
| 37 // for an URLRequest instance. A ResourceHandler's lifetime is bound to its | 33 // for an URLRequest instance. A ResourceHandler's lifetime is bound to its |
| 38 // associated URLRequest. | 34 // associated URLRequest. |
| 39 class CONTENT_EXPORT ResourceHandler | 35 class CONTENT_EXPORT ResourceHandler |
| 40 : public NON_EXPORTED_BASE(base::NonThreadSafe) { | 36 : public NON_EXPORTED_BASE(base::NonThreadSafe) { |
| 41 public: | 37 public: |
| 42 virtual ~ResourceHandler() {} | 38 virtual ~ResourceHandler() {} |
| 43 | 39 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 74 virtual bool OnWillStart(int request_id, const GURL& url, bool* defer) = 0; | 70 virtual bool OnWillStart(int request_id, const GURL& url, bool* defer) = 0; |
| 75 | 71 |
| 76 // Data will be read for the response. Upon success, this method places the | 72 // Data will be read for the response. Upon success, this method places the |
| 77 // size and address of the buffer where the data is to be written in its | 73 // size and address of the buffer where the data is to be written in its |
| 78 // out-params. This call will be followed by either OnReadCompleted or | 74 // out-params. This call will be followed by either OnReadCompleted or |
| 79 // OnResponseCompleted, at which point the buffer may be recycled. | 75 // OnResponseCompleted, at which point the buffer may be recycled. |
| 80 // | 76 // |
| 81 // If the handler returns false, then the request is cancelled. Otherwise, | 77 // If the handler returns false, then the request is cancelled. Otherwise, |
| 82 // once data is available, OnReadCompleted will be called. | 78 // once data is available, OnReadCompleted will be called. |
| 83 virtual bool OnWillRead(int request_id, | 79 virtual bool OnWillRead(int request_id, |
| 84 scoped_refptr<net::IOBuffer>* buf, | 80 net::IOBuffer** buf, |
| 85 int* buf_size, | 81 int* buf_size, |
| 86 int min_size) = 0; | 82 int min_size) = 0; |
| 87 | 83 |
| 88 // Data (*bytes_read bytes) was written into the buffer provided by | 84 // Data (*bytes_read bytes) was written into the buffer provided by |
| 89 // OnWillRead. A return value of false cancels the request, true continues | 85 // OnWillRead. A return value of false cancels the request, true continues |
| 90 // reading data. Set |*defer| to true to defer reading more response data. | 86 // reading data. Set |*defer| to true to defer reading more response data. |
| 91 // Call controller()->Resume() to continue reading response data. | 87 // Call controller()->Resume() to continue reading response data. |
| 92 virtual bool OnReadCompleted(int request_id, int bytes_read, | 88 virtual bool OnReadCompleted(int request_id, int bytes_read, |
| 93 bool* defer) = 0; | 89 bool* defer) = 0; |
| 94 | 90 |
| 95 // The response is complete. The final response status is given. Returns | 91 // The response is complete. The final response status is given. Returns |
| 96 // false if the handler is deferring the call to a later time. Otherwise, | 92 // false if the handler is deferring the call to a later time. Otherwise, |
| 97 // the request will be destroyed upon return. | 93 // the request will be destroyed upon return. |
| 98 virtual bool OnResponseCompleted(int request_id, | 94 virtual bool OnResponseCompleted(int request_id, |
| 99 const net::URLRequestStatus& status, | 95 const net::URLRequestStatus& status, |
| 100 const std::string& security_info) = 0; | 96 const std::string& security_info) = 0; |
| 101 | 97 |
| 102 // This notification is synthesized by the RedirectToFileResourceHandler | 98 // This notification is synthesized by the RedirectToFileResourceHandler |
| 103 // to indicate progress of 'download_to_file' requests. OnReadCompleted | 99 // to indicate progress of 'download_to_file' requests. OnReadCompleted |
| 104 // calls are consumed by the RedirectToFileResourceHandler and replaced | 100 // calls are consumed by the RedirectToFileResourceHandler and replaced |
| 105 // with OnDataDownloaded calls. | 101 // with OnDataDownloaded calls. |
| 106 virtual void OnDataDownloaded(int request_id, int bytes_downloaded) = 0; | 102 virtual void OnDataDownloaded(int request_id, int bytes_downloaded) = 0; |
| 107 | 103 |
| 108 protected: | 104 protected: |
| 109 ResourceHandler(net::URLRequest* request); | 105 ResourceHandler() : controller_(NULL) {} |
| 110 | 106 ResourceController* controller() { return controller_; } |
| 111 ResourceController* controller() const { return controller_; } | |
| 112 net::URLRequest* request() const { return request_; } | |
| 113 | |
| 114 // Convenience functions. | |
| 115 ResourceRequestInfoImpl* GetRequestInfo() const; | |
| 116 int GetRequestID() const; | |
| 117 ResourceMessageFilter* GetFilter() const; | |
| 118 | 107 |
| 119 private: | 108 private: |
| 120 ResourceController* controller_; | 109 ResourceController* controller_; |
| 121 net::URLRequest* request_; | |
| 122 }; | 110 }; |
| 123 | 111 |
| 124 } // namespace content | 112 } // namespace content |
| 125 | 113 |
| 126 #endif // CONTENT_BROWSER_LOADER_RESOURCE_HANDLER_H_ | 114 #endif // CONTENT_BROWSER_LOADER_RESOURCE_HANDLER_H_ |
| OLD | NEW |