| 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/common/url_loader.mojom.h" | 
|  | 26 #include "content/public/child/url_loader_throttle.h" | 
| 26 #include "content/public/common/resource_type.h" | 27 #include "content/public/common/resource_type.h" | 
| 27 #include "ipc/ipc_listener.h" | 28 #include "ipc/ipc_listener.h" | 
| 28 #include "ipc/ipc_sender.h" | 29 #include "ipc/ipc_sender.h" | 
| 29 #include "mojo/public/cpp/system/data_pipe.h" | 30 #include "mojo/public/cpp/system/data_pipe.h" | 
| 30 #include "net/base/request_priority.h" | 31 #include "net/base/request_priority.h" | 
| 31 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 32 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 
| 32 #include "url/gurl.h" | 33 #include "url/gurl.h" | 
| 33 #include "url/origin.h" | 34 #include "url/origin.h" | 
| 34 | 35 | 
| 35 namespace net { | 36 namespace net { | 
| 36 struct RedirectInfo; | 37 struct RedirectInfo; | 
| 37 } | 38 } | 
| 38 | 39 | 
| 39 namespace content { | 40 namespace content { | 
| 40 class RequestPeer; | 41 class RequestPeer; | 
| 41 class ResourceDispatcherDelegate; | 42 class ResourceDispatcherDelegate; | 
| 42 class ResourceSchedulingFilter; | 43 class ResourceSchedulingFilter; | 
| 43 struct ResourceResponseInfo; | 44 struct ResourceResponseInfo; | 
| 44 struct ResourceRequest; | 45 struct ResourceRequest; | 
| 45 struct ResourceRequestCompletionStatus; | 46 struct ResourceRequestCompletionStatus; | 
| 46 struct ResourceResponseHead; | 47 struct ResourceResponseHead; | 
| 47 class SharedMemoryReceivedDataFactory; | 48 class SharedMemoryReceivedDataFactory; | 
| 48 struct SiteIsolationResponseMetaData; | 49 struct SiteIsolationResponseMetaData; | 
| 49 struct SyncLoadResponse; | 50 struct SyncLoadResponse; | 
|  | 51 class ThrottlingURLLoader; | 
| 50 class URLLoaderClientImpl; | 52 class URLLoaderClientImpl; | 
| 51 | 53 | 
| 52 namespace mojom { | 54 namespace mojom { | 
| 53 class URLLoaderFactory; | 55 class URLLoaderFactory; | 
| 54 }  // namespace mojom | 56 }  // namespace mojom | 
| 55 | 57 | 
| 56 // This class serves as a communication interface to the ResourceDispatcherHost | 58 // This class serves as a communication interface to the ResourceDispatcherHost | 
| 57 // in the browser process. It can be used from any child process. | 59 // in the browser process. It can be used from any child process. | 
| 58 // Virtual methods are for tests. | 60 // Virtual methods are for tests. | 
| 59 class CONTENT_EXPORT ResourceDispatcher : public IPC::Listener { | 61 class CONTENT_EXPORT ResourceDispatcher : public IPC::Listener { | 
| 60  public: | 62  public: | 
| 61   ResourceDispatcher( | 63   ResourceDispatcher( | 
| 62       IPC::Sender* sender, | 64       IPC::Sender* sender, | 
| 63       scoped_refptr<base::SingleThreadTaskRunner> thread_task_runner); | 65       scoped_refptr<base::SingleThreadTaskRunner> thread_task_runner); | 
| 64   ~ResourceDispatcher() override; | 66   ~ResourceDispatcher() override; | 
| 65 | 67 | 
| 66   // IPC::Listener implementation. | 68   // IPC::Listener implementation. | 
| 67   bool OnMessageReceived(const IPC::Message& message) override; | 69   bool OnMessageReceived(const IPC::Message& message) override; | 
| 68 | 70 | 
| 69   // Call this method to load the resource synchronously (i.e., in one shot). | 71   // Call this method to load the resource synchronously (i.e., in one shot). | 
| 70   // This is an alternative to the StartAsync method. Be warned that this method | 72   // This is an alternative to the StartAsync method. Be warned that this method | 
| 71   // will block the calling thread until the resource is fully downloaded or an | 73   // will block the calling thread until the resource is fully downloaded or an | 
| 72   // error occurs. It could block the calling thread for a long time, so only | 74   // error occurs. It could block the calling thread for a long time, so only | 
| 73   // use this if you really need it!  There is also no way for the caller to | 75   // use this if you really need it!  There is also no way for the caller to | 
| 74   // interrupt this method. Errors are reported via the status field of the | 76   // interrupt this method. Errors are reported via the status field of the | 
| 75   // response parameter. | 77   // response parameter. | 
| 76   // | 78   // | 
| 77   // |routing_id| is used to associated the bridge with a frame's network | 79   // |routing_id| is used to associated the bridge with a frame's network | 
| 78   // context. | 80   // context. | 
| 79   virtual void StartSync(std::unique_ptr<ResourceRequest> request, | 81   virtual void StartSync( | 
| 80                          int routing_id, | 82       std::unique_ptr<ResourceRequest> request, | 
| 81                          SyncLoadResponse* response, | 83       int routing_id, | 
| 82                          blink::WebURLRequest::LoadingIPCType ipc_type, | 84       SyncLoadResponse* response, | 
| 83                          mojom::URLLoaderFactory* url_loader_factory); | 85       blink::WebURLRequest::LoadingIPCType ipc_type, | 
|  | 86       mojom::URLLoaderFactory* url_loader_factory, | 
|  | 87       std::vector<std::unique_ptr<URLLoaderThrottle>> throttles); | 
| 84 | 88 | 
| 85   // Call this method to initiate the request. If this method succeeds, then | 89   // Call this method to initiate the request. If this method succeeds, then | 
| 86   // the peer's methods will be called asynchronously to report various events. | 90   // the peer's methods will be called asynchronously to report various events. | 
| 87   // Returns the request id. |url_loader_factory| must be non-null if and only | 91   // Returns the request id. |url_loader_factory| must be non-null if and only | 
| 88   // if |ipc_type| is LoadingIPCType::Mojo. | 92   // if |ipc_type| is LoadingIPCType::Mojo. | 
| 89   // | 93   // | 
| 90   // |routing_id| is used to associated the bridge with a frame's network | 94   // |routing_id| is used to associated the bridge with a frame's network | 
| 91   // context. | 95   // context. | 
| 92   // | 96   // | 
| 93   // You can pass an optional argument |loading_task_runner| to specify task | 97   // You can pass an optional argument |loading_task_runner| to specify task | 
| 94   // queue to execute loading tasks on. | 98   // queue to execute loading tasks on. | 
| 95   virtual int StartAsync( | 99   virtual int StartAsync( | 
| 96       std::unique_ptr<ResourceRequest> request, | 100       std::unique_ptr<ResourceRequest> request, | 
| 97       int routing_id, | 101       int routing_id, | 
| 98       scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner, | 102       scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner, | 
| 99       const url::Origin& frame_origin, | 103       const url::Origin& frame_origin, | 
| 100       std::unique_ptr<RequestPeer> peer, | 104       std::unique_ptr<RequestPeer> peer, | 
| 101       blink::WebURLRequest::LoadingIPCType ipc_type, | 105       blink::WebURLRequest::LoadingIPCType ipc_type, | 
| 102       mojom::URLLoaderFactory* url_loader_factory, | 106       mojom::URLLoaderFactory* url_loader_factory, | 
|  | 107       std::vector<std::unique_ptr<URLLoaderThrottle>> throttles, | 
| 103       mojo::ScopedDataPipeConsumerHandle consumer_handle); | 108       mojo::ScopedDataPipeConsumerHandle consumer_handle); | 
| 104 | 109 | 
| 105   // Removes a request from the |pending_requests_| list, returning true if the | 110   // Removes a request from the |pending_requests_| list, returning true if the | 
| 106   // request was found and removed. | 111   // request was found and removed. | 
| 107   bool RemovePendingRequest(int request_id); | 112   bool RemovePendingRequest(int request_id); | 
| 108 | 113 | 
| 109   // Cancels a request in the |pending_requests_| list.  The request will be | 114   // Cancels a request in the |pending_requests_| list.  The request will be | 
| 110   // removed from the dispatcher as well. | 115   // removed from the dispatcher as well. | 
| 111   virtual void Cancel(int request_id); | 116   virtual void Cancel(int request_id); | 
| 112 | 117 | 
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 183     std::unique_ptr<IPC::Message> pending_redirect_message; | 188     std::unique_ptr<IPC::Message> pending_redirect_message; | 
| 184     base::TimeTicks request_start; | 189     base::TimeTicks request_start; | 
| 185     base::TimeTicks response_start; | 190     base::TimeTicks response_start; | 
| 186     base::TimeTicks completion_time; | 191     base::TimeTicks completion_time; | 
| 187     linked_ptr<base::SharedMemory> buffer; | 192     linked_ptr<base::SharedMemory> buffer; | 
| 188     scoped_refptr<SharedMemoryReceivedDataFactory> received_data_factory; | 193     scoped_refptr<SharedMemoryReceivedDataFactory> received_data_factory; | 
| 189     std::unique_ptr<SiteIsolationResponseMetaData> site_isolation_metadata; | 194     std::unique_ptr<SiteIsolationResponseMetaData> site_isolation_metadata; | 
| 190     int buffer_size; | 195     int buffer_size; | 
| 191 | 196 | 
| 192     // For mojo loading. | 197     // For mojo loading. | 
| 193     mojom::URLLoaderPtr url_loader; | 198     std::unique_ptr<ThrottlingURLLoader> url_loader; | 
| 194     std::unique_ptr<URLLoaderClientImpl> url_loader_client; | 199     std::unique_ptr<URLLoaderClientImpl> url_loader_client; | 
| 195   }; | 200   }; | 
| 196   using PendingRequestMap = std::map<int, std::unique_ptr<PendingRequestInfo>>; | 201   using PendingRequestMap = std::map<int, std::unique_ptr<PendingRequestInfo>>; | 
| 197 | 202 | 
| 198   // Helper to lookup the info based on the request_id. | 203   // Helper to lookup the info based on the request_id. | 
| 199   // May return NULL if the request as been canceled from the client side. | 204   // May return NULL if the request as been canceled from the client side. | 
| 200   PendingRequestInfo* GetPendingRequestInfo(int request_id); | 205   PendingRequestInfo* GetPendingRequestInfo(int request_id); | 
| 201 | 206 | 
| 202   // Follows redirect, if any, for the given request. | 207   // Follows redirect, if any, for the given request. | 
| 203   void FollowPendingRedirect(int request_id, PendingRequestInfo* request_info); | 208   void FollowPendingRedirect(int request_id, PendingRequestInfo* request_info); | 
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 275   scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter_; | 280   scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter_; | 
| 276 | 281 | 
| 277   base::WeakPtrFactory<ResourceDispatcher> weak_factory_; | 282   base::WeakPtrFactory<ResourceDispatcher> weak_factory_; | 
| 278 | 283 | 
| 279   DISALLOW_COPY_AND_ASSIGN(ResourceDispatcher); | 284   DISALLOW_COPY_AND_ASSIGN(ResourceDispatcher); | 
| 280 }; | 285 }; | 
| 281 | 286 | 
| 282 }  // namespace content | 287 }  // namespace content | 
| 283 | 288 | 
| 284 #endif  // CONTENT_CHILD_RESOURCE_DISPATCHER_H_ | 289 #endif  // CONTENT_CHILD_RESOURCE_DISPATCHER_H_ | 
| OLD | NEW | 
|---|