| 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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading | 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading |
| 6 | 6 |
| 7 #ifndef CONTENT_CHILD_RESOURCE_DISPATCHER_H_ | 7 #ifndef CONTENT_CHILD_RESOURCE_DISPATCHER_H_ |
| 8 #define CONTENT_CHILD_RESOURCE_DISPATCHER_H_ | 8 #define CONTENT_CHILD_RESOURCE_DISPATCHER_H_ |
| 9 | 9 |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| 11 | 11 |
| 12 #include <deque> | 12 #include <deque> |
| 13 #include <map> | 13 #include <map> |
| 14 #include <memory> | 14 #include <memory> |
| 15 #include <string> | 15 #include <string> |
| 16 | 16 |
| 17 #include "base/containers/hash_tables.h" | 17 #include "base/containers/hash_tables.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/memory/linked_ptr.h" | 19 #include "base/memory/linked_ptr.h" |
| 20 #include "base/memory/shared_memory.h" | 20 #include "base/memory/shared_memory.h" |
| 21 #include "base/memory/weak_ptr.h" | 21 #include "base/memory/weak_ptr.h" |
| 22 #include "base/single_thread_task_runner.h" | 22 #include "base/single_thread_task_runner.h" |
| 23 #include "base/time/time.h" | 23 #include "base/time/time.h" |
| 24 #include "content/common/content_export.h" | 24 #include "content/common/content_export.h" |
| 25 #include "content/common/url_loader.mojom.h" |
| 25 #include "content/public/common/resource_type.h" | 26 #include "content/public/common/resource_type.h" |
| 26 #include "ipc/ipc_listener.h" | 27 #include "ipc/ipc_listener.h" |
| 27 #include "ipc/ipc_sender.h" | 28 #include "ipc/ipc_sender.h" |
| 28 #include "net/base/request_priority.h" | 29 #include "net/base/request_priority.h" |
| 30 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 29 #include "url/gurl.h" | 31 #include "url/gurl.h" |
| 30 | 32 |
| 31 namespace net { | 33 namespace net { |
| 32 struct RedirectInfo; | 34 struct RedirectInfo; |
| 33 } | 35 } |
| 34 | 36 |
| 35 namespace content { | 37 namespace content { |
| 36 class RequestPeer; | 38 class RequestPeer; |
| 37 class ResourceDispatcherDelegate; | 39 class ResourceDispatcherDelegate; |
| 38 class ResourceRequestBodyImpl; | 40 class ResourceRequestBodyImpl; |
| 39 class ResourceSchedulingFilter; | 41 class ResourceSchedulingFilter; |
| 40 struct ResourceResponseInfo; | 42 struct ResourceResponseInfo; |
| 41 struct RequestInfo; | 43 struct RequestInfo; |
| 42 struct ResourceRequest; | 44 struct ResourceRequest; |
| 43 struct ResourceRequestCompletionStatus; | 45 struct ResourceRequestCompletionStatus; |
| 44 struct ResourceResponseHead; | 46 struct ResourceResponseHead; |
| 45 class SharedMemoryReceivedDataFactory; | 47 class SharedMemoryReceivedDataFactory; |
| 46 struct SiteIsolationResponseMetaData; | 48 struct SiteIsolationResponseMetaData; |
| 47 struct SyncLoadResponse; | 49 struct SyncLoadResponse; |
| 48 | 50 |
| 51 namespace mojom { |
| 52 class URLLoaderFactory; |
| 53 } // namespace mojom |
| 54 |
| 49 // This class serves as a communication interface to the ResourceDispatcherHost | 55 // This class serves as a communication interface to the ResourceDispatcherHost |
| 50 // in the browser process. It can be used from any child process. | 56 // in the browser process. It can be used from any child process. |
| 51 // Virtual methods are for tests. | 57 // Virtual methods are for tests. |
| 52 class CONTENT_EXPORT ResourceDispatcher : public IPC::Listener { | 58 class CONTENT_EXPORT ResourceDispatcher : public IPC::Listener { |
| 53 public: | 59 public: |
| 54 ResourceDispatcher( | 60 ResourceDispatcher( |
| 55 IPC::Sender* sender, | 61 IPC::Sender* sender, |
| 56 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner); | 62 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner); |
| 57 ~ResourceDispatcher() override; | 63 ~ResourceDispatcher() override; |
| 58 | 64 |
| 59 // IPC::Listener implementation. | 65 // IPC::Listener implementation. |
| 60 bool OnMessageReceived(const IPC::Message& message) override; | 66 bool OnMessageReceived(const IPC::Message& message) override; |
| 61 | 67 |
| 62 // Call this method to load the resource synchronously (i.e., in one shot). | 68 // Call this method to load the resource synchronously (i.e., in one shot). |
| 63 // This is an alternative to the StartAsync method. Be warned that this method | 69 // This is an alternative to the StartAsync method. Be warned that this method |
| 64 // will block the calling thread until the resource is fully downloaded or an | 70 // will block the calling thread until the resource is fully downloaded or an |
| 65 // error occurs. It could block the calling thread for a long time, so only | 71 // error occurs. It could block the calling thread for a long time, so only |
| 66 // use this if you really need it! There is also no way for the caller to | 72 // use this if you really need it! There is also no way for the caller to |
| 67 // interrupt this method. Errors are reported via the status field of the | 73 // interrupt this method. Errors are reported via the status field of the |
| 68 // response parameter. | 74 // response parameter. |
| 69 virtual void StartSync(const RequestInfo& request_info, | 75 virtual void StartSync(const RequestInfo& request_info, |
| 70 ResourceRequestBodyImpl* request_body, | 76 ResourceRequestBodyImpl* request_body, |
| 71 SyncLoadResponse* response); | 77 SyncLoadResponse* response, |
| 78 blink::WebURLRequest::LoadingIPCType ipc_type, |
| 79 mojom::URLLoaderFactory* url_loader_factory); |
| 72 | 80 |
| 73 // Call this method to initiate the request. If this method succeeds, then | 81 // Call this method to initiate the request. If this method succeeds, then |
| 74 // the peer's methods will be called asynchronously to report various events. | 82 // the peer's methods will be called asynchronously to report various events. |
| 75 // Returns the request id. | 83 // Returns the request id. |url_loader_factory| must be non-null if and only |
| 84 // if |ipc_type| is LoadingIPCType::Mojo. |
| 76 virtual int StartAsync(const RequestInfo& request_info, | 85 virtual int StartAsync(const RequestInfo& request_info, |
| 77 ResourceRequestBodyImpl* request_body, | 86 ResourceRequestBodyImpl* request_body, |
| 78 std::unique_ptr<RequestPeer> peer); | 87 std::unique_ptr<RequestPeer> peer, |
| 88 blink::WebURLRequest::LoadingIPCType ipc_type, |
| 89 mojom::URLLoaderFactory* url_loader_factory); |
| 79 | 90 |
| 80 // Removes a request from the |pending_requests_| list, returning true if the | 91 // Removes a request from the |pending_requests_| list, returning true if the |
| 81 // request was found and removed. | 92 // request was found and removed. |
| 82 bool RemovePendingRequest(int request_id); | 93 bool RemovePendingRequest(int request_id); |
| 83 | 94 |
| 84 // Cancels a request in the |pending_requests_| list. The request will be | 95 // Cancels a request in the |pending_requests_| list. The request will be |
| 85 // removed from the dispatcher as well. | 96 // removed from the dispatcher as well. |
| 86 virtual void Cancel(int request_id); | 97 virtual void Cancel(int request_id); |
| 87 | 98 |
| 88 // Toggles the is_deferred attribute for the specified request. | 99 // Toggles the is_deferred attribute for the specified request. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 112 | 123 |
| 113 void SetMainThreadTaskRunner( | 124 void SetMainThreadTaskRunner( |
| 114 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) { | 125 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) { |
| 115 main_thread_task_runner_ = main_thread_task_runner; | 126 main_thread_task_runner_ = main_thread_task_runner; |
| 116 } | 127 } |
| 117 | 128 |
| 118 void SetResourceSchedulingFilter( | 129 void SetResourceSchedulingFilter( |
| 119 scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter); | 130 scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter); |
| 120 | 131 |
| 121 private: | 132 private: |
| 133 friend class URLResponseBodyConsumer; |
| 122 friend class ResourceDispatcherTest; | 134 friend class ResourceDispatcherTest; |
| 123 | 135 |
| 124 typedef std::deque<IPC::Message*> MessageQueue; | 136 typedef std::deque<IPC::Message*> MessageQueue; |
| 125 struct PendingRequestInfo { | 137 struct PendingRequestInfo { |
| 126 PendingRequestInfo(std::unique_ptr<RequestPeer> peer, | 138 PendingRequestInfo(std::unique_ptr<RequestPeer> peer, |
| 127 ResourceType resource_type, | 139 ResourceType resource_type, |
| 128 int origin_pid, | 140 int origin_pid, |
| 129 const GURL& frame_origin, | 141 const GURL& frame_origin, |
| 130 const GURL& request_url, | 142 const GURL& request_url, |
| 131 bool download_to_file); | 143 bool download_to_file); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 148 GURL response_url; | 160 GURL response_url; |
| 149 bool download_to_file; | 161 bool download_to_file; |
| 150 std::unique_ptr<IPC::Message> pending_redirect_message; | 162 std::unique_ptr<IPC::Message> pending_redirect_message; |
| 151 base::TimeTicks request_start; | 163 base::TimeTicks request_start; |
| 152 base::TimeTicks response_start; | 164 base::TimeTicks response_start; |
| 153 base::TimeTicks completion_time; | 165 base::TimeTicks completion_time; |
| 154 linked_ptr<base::SharedMemory> buffer; | 166 linked_ptr<base::SharedMemory> buffer; |
| 155 scoped_refptr<SharedMemoryReceivedDataFactory> received_data_factory; | 167 scoped_refptr<SharedMemoryReceivedDataFactory> received_data_factory; |
| 156 std::unique_ptr<SiteIsolationResponseMetaData> site_isolation_metadata; | 168 std::unique_ptr<SiteIsolationResponseMetaData> site_isolation_metadata; |
| 157 int buffer_size; | 169 int buffer_size; |
| 170 |
| 171 // For mojo loading. |
| 172 mojom::URLLoaderPtr url_loader; |
| 173 std::unique_ptr<mojom::URLLoaderClient> url_loader_client; |
| 158 }; | 174 }; |
| 159 using PendingRequestMap = std::map<int, std::unique_ptr<PendingRequestInfo>>; | 175 using PendingRequestMap = std::map<int, std::unique_ptr<PendingRequestInfo>>; |
| 160 | 176 |
| 161 // Helper to lookup the info based on the request_id. | 177 // Helper to lookup the info based on the request_id. |
| 162 // May return NULL if the request as been canceled from the client side. | 178 // May return NULL if the request as been canceled from the client side. |
| 163 PendingRequestInfo* GetPendingRequestInfo(int request_id); | 179 PendingRequestInfo* GetPendingRequestInfo(int request_id); |
| 164 | 180 |
| 165 // Follows redirect, if any, for the given request. | 181 // Follows redirect, if any, for the given request. |
| 166 void FollowPendingRedirect(int request_id, PendingRequestInfo* request_info); | 182 void FollowPendingRedirect(int request_id, PendingRequestInfo* request_info); |
| 167 | 183 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter_; | 259 scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter_; |
| 244 | 260 |
| 245 base::WeakPtrFactory<ResourceDispatcher> weak_factory_; | 261 base::WeakPtrFactory<ResourceDispatcher> weak_factory_; |
| 246 | 262 |
| 247 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcher); | 263 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcher); |
| 248 }; | 264 }; |
| 249 | 265 |
| 250 } // namespace content | 266 } // namespace content |
| 251 | 267 |
| 252 #endif // CONTENT_CHILD_RESOURCE_DISPATCHER_H_ | 268 #endif // CONTENT_CHILD_RESOURCE_DISPATCHER_H_ |
| OLD | NEW |