OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_COMMON_RESOURCE_DISPATCHER_H_ | 7 #ifndef CONTENT_COMMON_RESOURCE_DISPATCHER_H_ |
8 #define CONTENT_COMMON_RESOURCE_DISPATCHER_H_ | 8 #define CONTENT_COMMON_RESOURCE_DISPATCHER_H_ |
9 #pragma once | 9 #pragma once |
10 | 10 |
11 #include <deque> | 11 #include <deque> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/hash_tables.h" | 14 #include "base/hash_tables.h" |
15 #include "base/memory/linked_ptr.h" | 15 #include "base/memory/linked_ptr.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "base/shared_memory.h" | 17 #include "base/shared_memory.h" |
18 #include "base/time.h" | 18 #include "base/time.h" |
19 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
20 #include "ipc/ipc_channel.h" | 20 #include "ipc/ipc_listener.h" |
| 21 #include "ipc/ipc_sender.h" |
21 #include "webkit/glue/resource_loader_bridge.h" | 22 #include "webkit/glue/resource_loader_bridge.h" |
22 | 23 |
23 namespace content { | 24 namespace content { |
24 class ResourceDispatcherDelegate; | 25 class ResourceDispatcherDelegate; |
25 struct ResourceResponseHead; | 26 struct ResourceResponseHead; |
26 } | 27 } |
27 | 28 |
28 // This class serves as a communication interface between the | 29 // This class serves as a communication interface between the |
29 // ResourceDispatcherHost in the browser process and the ResourceLoaderBridge in | 30 // ResourceDispatcherHost in the browser process and the ResourceLoaderBridge in |
30 // the child process. It can be used from any child process. | 31 // the child process. It can be used from any child process. |
31 class CONTENT_EXPORT ResourceDispatcher : public IPC::Channel::Listener { | 32 class CONTENT_EXPORT ResourceDispatcher : public IPC::Listener { |
32 public: | 33 public: |
33 explicit ResourceDispatcher(IPC::Message::Sender* sender); | 34 explicit ResourceDispatcher(IPC::Sender* sender); |
34 virtual ~ResourceDispatcher(); | 35 virtual ~ResourceDispatcher(); |
35 | 36 |
36 // IPC::Channel::Listener implementation. | 37 // IPC::Listener implementation. |
37 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 38 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
38 | 39 |
39 // Creates a ResourceLoaderBridge for this type of dispatcher, this is so | 40 // Creates a ResourceLoaderBridge for this type of dispatcher, this is so |
40 // this can be tested regardless of the ResourceLoaderBridge::Create | 41 // this can be tested regardless of the ResourceLoaderBridge::Create |
41 // implementation. | 42 // implementation. |
42 webkit_glue::ResourceLoaderBridge* CreateBridge( | 43 webkit_glue::ResourceLoaderBridge* CreateBridge( |
43 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info); | 44 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info); |
44 | 45 |
45 // Adds a request from the pending_requests_ list, returning the new | 46 // Adds a request from the pending_requests_ list, returning the new |
46 // requests' ID | 47 // requests' ID |
47 int AddPendingRequest(webkit_glue::ResourceLoaderBridge::Peer* callback, | 48 int AddPendingRequest(webkit_glue::ResourceLoaderBridge::Peer* callback, |
48 ResourceType::Type resource_type, | 49 ResourceType::Type resource_type, |
49 const GURL& request_url); | 50 const GURL& request_url); |
50 | 51 |
51 // Removes a request from the pending_requests_ list, returning true if the | 52 // Removes a request from the pending_requests_ list, returning true if the |
52 // request was found and removed. | 53 // request was found and removed. |
53 bool RemovePendingRequest(int request_id); | 54 bool RemovePendingRequest(int request_id); |
54 | 55 |
55 // Cancels a request in the pending_requests_ list. | 56 // Cancels a request in the pending_requests_ list. |
56 void CancelPendingRequest(int routing_id, int request_id); | 57 void CancelPendingRequest(int routing_id, int request_id); |
57 | 58 |
58 IPC::Message::Sender* message_sender() const { | 59 IPC::Sender* message_sender() const { |
59 return message_sender_; | 60 return message_sender_; |
60 } | 61 } |
61 | 62 |
62 // Toggles the is_deferred attribute for the specified request. | 63 // Toggles the is_deferred attribute for the specified request. |
63 void SetDefersLoading(int request_id, bool value); | 64 void SetDefersLoading(int request_id, bool value); |
64 | 65 |
65 // This does not take ownership of the delegate. It is expected that the | 66 // This does not take ownership of the delegate. It is expected that the |
66 // delegate have a longer lifetime than the ResourceDispatcher. | 67 // delegate have a longer lifetime than the ResourceDispatcher. |
67 void set_delegate(content::ResourceDispatcherDelegate* delegate) { | 68 void set_delegate(content::ResourceDispatcherDelegate* delegate) { |
68 delegate_ = delegate; | 69 delegate_ = delegate; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 // handle in it that we should cleanup it up nicely. This method accepts any | 156 // handle in it that we should cleanup it up nicely. This method accepts any |
156 // message and determine whether the message is | 157 // message and determine whether the message is |
157 // ViewHostMsg_Resource_DataReceived and clean up the shared memory handle. | 158 // ViewHostMsg_Resource_DataReceived and clean up the shared memory handle. |
158 static void ReleaseResourcesInDataMessage(const IPC::Message& message); | 159 static void ReleaseResourcesInDataMessage(const IPC::Message& message); |
159 | 160 |
160 // Iterate through a message queue and clean up the messages by calling | 161 // Iterate through a message queue and clean up the messages by calling |
161 // ReleaseResourcesInDataMessage and removing them from the queue. Intended | 162 // ReleaseResourcesInDataMessage and removing them from the queue. Intended |
162 // for use on deferred message queues that are no longer needed. | 163 // for use on deferred message queues that are no longer needed. |
163 static void ReleaseResourcesInMessageQueue(MessageQueue* queue); | 164 static void ReleaseResourcesInMessageQueue(MessageQueue* queue); |
164 | 165 |
165 IPC::Message::Sender* message_sender_; | 166 IPC::Sender* message_sender_; |
166 | 167 |
167 // All pending requests issued to the host | 168 // All pending requests issued to the host |
168 PendingRequestList pending_requests_; | 169 PendingRequestList pending_requests_; |
169 | 170 |
170 base::WeakPtrFactory<ResourceDispatcher> weak_factory_; | 171 base::WeakPtrFactory<ResourceDispatcher> weak_factory_; |
171 | 172 |
172 content::ResourceDispatcherDelegate* delegate_; | 173 content::ResourceDispatcherDelegate* delegate_; |
173 | 174 |
174 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcher); | 175 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcher); |
175 }; | 176 }; |
176 | 177 |
177 #endif // CONTENT_COMMON_RESOURCE_DISPATCHER_H_ | 178 #endif // CONTENT_COMMON_RESOURCE_DISPATCHER_H_ |
OLD | NEW |