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