Chromium Code Reviews| 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" |
| 29 #include "url/gurl.h" | 30 #include "url/gurl.h" |
| 30 | 31 |
| 31 namespace net { | 32 namespace net { |
| 32 struct RedirectInfo; | 33 struct RedirectInfo; |
| 33 } | 34 } |
| 34 | 35 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 61 | 62 |
| 62 // Call this method to load the resource synchronously (i.e., in one shot). | 63 // 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 | 64 // 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 | 65 // 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 | 66 // 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 | 67 // 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 | 68 // interrupt this method. Errors are reported via the status field of the |
| 68 // response parameter. | 69 // response parameter. |
| 69 void StartSync(const RequestInfo& request_info, | 70 void StartSync(const RequestInfo& request_info, |
| 70 ResourceRequestBody* request_body, | 71 ResourceRequestBody* request_body, |
| 71 SyncLoadResponse* response); | 72 SyncLoadResponse* response, |
| 73 mojom::URLLoaderPtr url_loader); | |
| 72 | 74 |
| 73 // Call this method to initiate the request. If this method succeeds, then | 75 // 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. | 76 // the peer's methods will be called asynchronously to report various events. |
| 75 // Returns the request id. | 77 // Returns the request id. |
| 76 virtual int StartAsync(const RequestInfo& request_info, | 78 virtual int StartAsync(const RequestInfo& request_info, |
| 77 ResourceRequestBody* request_body, | 79 ResourceRequestBody* request_body, |
| 78 std::unique_ptr<RequestPeer> peer); | 80 std::unique_ptr<RequestPeer> peer, |
| 81 mojom::URLLoaderPtr url_loader); | |
| 79 | 82 |
| 80 // Removes a request from the |pending_requests_| list, returning true if the | 83 // Removes a request from the |pending_requests_| list, returning true if the |
| 81 // request was found and removed. | 84 // request was found and removed. |
| 82 bool RemovePendingRequest(int request_id); | 85 bool RemovePendingRequest(int request_id); |
| 83 | 86 |
| 84 // Cancels a request in the |pending_requests_| list. The request will be | 87 // Cancels a request in the |pending_requests_| list. The request will be |
| 85 // removed from the dispatcher as well. | 88 // removed from the dispatcher as well. |
| 86 virtual void Cancel(int request_id); | 89 virtual void Cancel(int request_id); |
| 87 | 90 |
| 88 // Toggles the is_deferred attribute for the specified request. | 91 // Toggles the is_deferred attribute for the specified request. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 112 | 115 |
| 113 void SetMainThreadTaskRunner( | 116 void SetMainThreadTaskRunner( |
| 114 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) { | 117 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) { |
| 115 main_thread_task_runner_ = main_thread_task_runner; | 118 main_thread_task_runner_ = main_thread_task_runner; |
| 116 } | 119 } |
| 117 | 120 |
| 118 void SetResourceSchedulingFilter( | 121 void SetResourceSchedulingFilter( |
| 119 scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter); | 122 scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter); |
| 120 | 123 |
| 121 private: | 124 private: |
| 125 friend class URLResponseBodyConsumer; | |
| 122 friend class ResourceDispatcherTest; | 126 friend class ResourceDispatcherTest; |
| 123 | 127 |
| 124 typedef std::deque<IPC::Message*> MessageQueue; | 128 typedef std::deque<IPC::Message*> MessageQueue; |
| 125 struct PendingRequestInfo { | 129 struct PendingRequestInfo { |
| 126 PendingRequestInfo(std::unique_ptr<RequestPeer> peer, | 130 PendingRequestInfo(std::unique_ptr<RequestPeer> peer, |
| 127 ResourceType resource_type, | 131 ResourceType resource_type, |
| 128 int origin_pid, | 132 int origin_pid, |
| 129 const GURL& frame_origin, | 133 const GURL& frame_origin, |
| 130 const GURL& request_url, | 134 const GURL& request_url, |
| 131 bool download_to_file); | 135 bool download_to_file); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 147 // The url of the latest response even in case of redirection. | 151 // The url of the latest response even in case of redirection. |
| 148 GURL response_url; | 152 GURL response_url; |
| 149 bool download_to_file; | 153 bool download_to_file; |
| 150 std::unique_ptr<IPC::Message> pending_redirect_message; | 154 std::unique_ptr<IPC::Message> pending_redirect_message; |
| 151 base::TimeTicks request_start; | 155 base::TimeTicks request_start; |
| 152 base::TimeTicks response_start; | 156 base::TimeTicks response_start; |
| 153 base::TimeTicks completion_time; | 157 base::TimeTicks completion_time; |
| 154 linked_ptr<base::SharedMemory> buffer; | 158 linked_ptr<base::SharedMemory> buffer; |
| 155 scoped_refptr<SharedMemoryReceivedDataFactory> received_data_factory; | 159 scoped_refptr<SharedMemoryReceivedDataFactory> received_data_factory; |
| 156 std::unique_ptr<SiteIsolationResponseMetaData> site_isolation_metadata; | 160 std::unique_ptr<SiteIsolationResponseMetaData> site_isolation_metadata; |
| 161 mojom::URLLoaderPtr url_loader; | |
| 162 std::unique_ptr<mojom::URLLoaderClient> url_loader_client; | |
|
kinuko
2016/05/20 09:38:51
nit: can we move these at the very end of the stru
yhirano
2016/05/20 11:32:54
Done.
| |
| 157 int buffer_size; | 163 int buffer_size; |
| 158 }; | 164 }; |
| 159 using PendingRequestMap = std::map<int, std::unique_ptr<PendingRequestInfo>>; | 165 using PendingRequestMap = std::map<int, std::unique_ptr<PendingRequestInfo>>; |
| 160 | 166 |
| 161 // Helper to lookup the info based on the request_id. | 167 // Helper to lookup the info based on the request_id. |
| 162 // May return NULL if the request as been canceled from the client side. | 168 // May return NULL if the request as been canceled from the client side. |
| 163 PendingRequestInfo* GetPendingRequestInfo(int request_id); | 169 PendingRequestInfo* GetPendingRequestInfo(int request_id); |
| 164 | 170 |
| 165 // Follows redirect, if any, for the given request. | 171 // Follows redirect, if any, for the given request. |
| 166 void FollowPendingRedirect(int request_id, PendingRequestInfo* request_info); | 172 void FollowPendingRedirect(int request_id, PendingRequestInfo* request_info); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter_; | 247 scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter_; |
| 242 | 248 |
| 243 base::WeakPtrFactory<ResourceDispatcher> weak_factory_; | 249 base::WeakPtrFactory<ResourceDispatcher> weak_factory_; |
| 244 | 250 |
| 245 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcher); | 251 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcher); |
| 246 }; | 252 }; |
| 247 | 253 |
| 248 } // namespace content | 254 } // namespace content |
| 249 | 255 |
| 250 #endif // CONTENT_CHILD_RESOURCE_DISPATCHER_H_ | 256 #endif // CONTENT_CHILD_RESOURCE_DISPATCHER_H_ |
| OLD | NEW |