OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // This is the browser side of the resource dispatcher, it receives requests | |
6 // from the RenderProcessHosts, and dispatches them to URLRequests. It then | |
7 // fowards the messages from the URLRequests back to the correct process for | |
8 // handling. | |
9 // | |
10 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading | |
11 | |
12 #ifndef CONTENT_BROWSER_RENDERER_HOST_RESOURCE_HANDLER_H_ | |
13 #define CONTENT_BROWSER_RENDERER_HOST_RESOURCE_HANDLER_H_ | |
14 | |
15 #include <string> | |
16 | |
17 #include "base/sequenced_task_runner_helpers.h" | |
18 #include "base/threading/non_thread_safe.h" | |
19 #include "content/common/content_export.h" | |
20 #include "content/public/browser/browser_thread.h" | |
21 | |
22 class GURL; | |
23 | |
24 namespace net { | |
25 class IOBuffer; | |
26 class URLRequestStatus; | |
27 } // namespace net | |
28 | |
29 namespace content { | |
30 class ResourceController; | |
31 struct ResourceResponse; | |
32 | |
33 // The resource dispatcher host uses this interface to process network events | |
34 // for an URLRequest instance. A ResourceHandler's lifetime is bound to its | |
35 // associated URLRequest. | |
36 class CONTENT_EXPORT ResourceHandler | |
37 : public NON_EXPORTED_BASE(base::NonThreadSafe) { | |
38 public: | |
39 virtual ~ResourceHandler() {} | |
40 | |
41 // Sets the controller for this handler. | |
42 virtual void SetController(ResourceController* controller); | |
43 | |
44 // Called as upload progress is made. The return value is ignored. | |
45 virtual bool OnUploadProgress(int request_id, | |
46 uint64 position, | |
47 uint64 size) = 0; | |
48 | |
49 // The request was redirected to a new URL. |*defer| has an initial value of | |
50 // false. Set |*defer| to true to defer the redirect. The redirect may be | |
51 // followed later on via ResourceDispatcherHost::FollowDeferredRedirect. If | |
52 // the handler returns false, then the request is cancelled. | |
53 virtual bool OnRequestRedirected(int request_id, const GURL& url, | |
54 ResourceResponse* response, | |
55 bool* defer) = 0; | |
56 | |
57 // Response headers and meta data are available. If the handler returns | |
58 // false, then the request is cancelled. Set |*defer| to true to defer | |
59 // processing of the response. Call ResourceDispatcherHostImpl:: | |
60 // ResumeDeferredRequest to continue processing the response. | |
61 virtual bool OnResponseStarted(int request_id, | |
62 ResourceResponse* response, | |
63 bool* defer) = 0; | |
64 | |
65 // Called before the net::URLRequest for |request_id| (whose url is |url|) is | |
66 // to be started. If the handler returns false, then the request is | |
67 // cancelled. Otherwise if the return value is true, the ResourceHandler can | |
68 // delay the request from starting by setting |*defer = true|. A deferred | |
69 // request will not have called net::URLRequest::Start(), and will not resume | |
70 // until someone calls ResourceDispatcherHost::StartDeferredRequest(). | |
71 virtual bool OnWillStart(int request_id, const GURL& url, bool* defer) = 0; | |
72 | |
73 // Data will be read for the response. Upon success, this method places the | |
74 // size and address of the buffer where the data is to be written in its | |
75 // out-params. This call will be followed by either OnReadCompleted or | |
76 // OnResponseCompleted, at which point the buffer may be recycled. | |
77 // | |
78 // If the handler returns false, then the request is cancelled. Otherwise, | |
79 // once data is available, OnReadCompleted will be called. | |
80 virtual bool OnWillRead(int request_id, | |
81 net::IOBuffer** buf, | |
82 int* buf_size, | |
83 int min_size) = 0; | |
84 | |
85 // Data (*bytes_read bytes) was written into the buffer provided by | |
86 // OnWillRead. A return value of false cancels the request, true continues | |
87 // reading data. Set |*defer| to true to defer reading more response data. | |
88 // Call ResourceDispatcherHostImpl::ResumeDeferredRequest to continue reading | |
89 // response data. | |
90 virtual bool OnReadCompleted(int request_id, int bytes_read, | |
91 bool* defer) = 0; | |
92 | |
93 // The response is complete. The final response status is given. Returns | |
94 // false if the handler is deferring the call to a later time. Otherwise, | |
95 // the request will be destroyed upon return. | |
96 virtual bool OnResponseCompleted(int request_id, | |
97 const net::URLRequestStatus& status, | |
98 const std::string& security_info) = 0; | |
99 | |
100 // This notification is synthesized by the RedirectToFileResourceHandler | |
101 // to indicate progress of 'download_to_file' requests. OnReadCompleted | |
102 // calls are consumed by the RedirectToFileResourceHandler and replaced | |
103 // with OnDataDownloaded calls. | |
104 virtual void OnDataDownloaded(int request_id, int bytes_downloaded) {} | |
105 | |
106 protected: | |
107 ResourceHandler() : controller_(NULL) {} | |
108 ResourceController* controller() { return controller_; } | |
109 | |
110 private: | |
111 ResourceController* controller_; | |
112 }; | |
113 | |
114 } // namespace content | |
115 | |
116 #endif // CONTENT_BROWSER_RENDERER_HOST_RESOURCE_HANDLER_H_ | |
OLD | NEW |