| 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/shared_memory.h" | 16 #include "base/shared_memory.h" |
| 17 #include "base/task.h" | 17 #include "base/task.h" |
| 18 #include "ipc/ipc_channel.h" | 18 #include "ipc/ipc_channel.h" |
| 19 #include "webkit/glue/resource_loader_bridge.h" | 19 #include "webkit/glue/resource_loader_bridge.h" |
| 20 | 20 |
| 21 class ResourceDispatcherDelegate; |
| 21 struct ResourceResponseHead; | 22 struct ResourceResponseHead; |
| 22 | 23 |
| 23 // This class serves as a communication interface between the | 24 // This class serves as a communication interface between the |
| 24 // ResourceDispatcherHost in the browser process and the ResourceLoaderBridge in | 25 // ResourceDispatcherHost in the browser process and the ResourceLoaderBridge in |
| 25 // the child process. It can be used from any child process. | 26 // the child process. It can be used from any child process. |
| 26 class ResourceDispatcher : public IPC::Channel::Listener { | 27 class ResourceDispatcher : public IPC::Channel::Listener { |
| 27 public: | 28 public: |
| 28 // Interface that allows observing request events and optionally replacing the | |
| 29 // peer. | |
| 30 class Observer { | |
| 31 public: | |
| 32 Observer(); | |
| 33 virtual ~Observer(); | |
| 34 | |
| 35 virtual webkit_glue::ResourceLoaderBridge::Peer* OnRequestComplete( | |
| 36 webkit_glue::ResourceLoaderBridge::Peer* current_peer, | |
| 37 ResourceType::Type resource_type, | |
| 38 const net::URLRequestStatus& status) = 0; | |
| 39 | |
| 40 virtual webkit_glue::ResourceLoaderBridge::Peer* OnReceivedResponse( | |
| 41 webkit_glue::ResourceLoaderBridge::Peer* current_peer, | |
| 42 const std::string& mime_type, | |
| 43 const GURL& url) = 0; | |
| 44 }; | |
| 45 | |
| 46 explicit ResourceDispatcher(IPC::Message::Sender* sender); | 29 explicit ResourceDispatcher(IPC::Message::Sender* sender); |
| 47 virtual ~ResourceDispatcher(); | 30 virtual ~ResourceDispatcher(); |
| 48 | 31 |
| 49 // IPC::Channel::Listener implementation. | 32 // IPC::Channel::Listener implementation. |
| 50 virtual bool OnMessageReceived(const IPC::Message& message); | 33 virtual bool OnMessageReceived(const IPC::Message& message); |
| 51 | 34 |
| 52 // Creates a ResourceLoaderBridge for this type of dispatcher, this is so | 35 // Creates a ResourceLoaderBridge for this type of dispatcher, this is so |
| 53 // this can be tested regardless of the ResourceLoaderBridge::Create | 36 // this can be tested regardless of the ResourceLoaderBridge::Create |
| 54 // implementation. | 37 // implementation. |
| 55 webkit_glue::ResourceLoaderBridge* CreateBridge( | 38 webkit_glue::ResourceLoaderBridge* CreateBridge( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 68 // Cancels a request in the pending_requests_ list. | 51 // Cancels a request in the pending_requests_ list. |
| 69 void CancelPendingRequest(int routing_id, int request_id); | 52 void CancelPendingRequest(int routing_id, int request_id); |
| 70 | 53 |
| 71 IPC::Message::Sender* message_sender() const { | 54 IPC::Message::Sender* message_sender() const { |
| 72 return message_sender_; | 55 return message_sender_; |
| 73 } | 56 } |
| 74 | 57 |
| 75 // Toggles the is_deferred attribute for the specified request. | 58 // Toggles the is_deferred attribute for the specified request. |
| 76 void SetDefersLoading(int request_id, bool value); | 59 void SetDefersLoading(int request_id, bool value); |
| 77 | 60 |
| 78 // Takes ownership of the object. | 61 // This does not take ownership of the delegate. It is expected that the |
| 79 void set_observer(Observer* observer) { observer_.reset(observer); } | 62 // delegate have a longer lifetime than the ResourceDispatcher. |
| 63 void set_delegate(ResourceDispatcherDelegate* delegate) { |
| 64 delegate_ = delegate; |
| 65 } |
| 80 | 66 |
| 81 private: | 67 private: |
| 82 friend class ResourceDispatcherTest; | 68 friend class ResourceDispatcherTest; |
| 83 | 69 |
| 84 typedef std::deque<IPC::Message*> MessageQueue; | 70 typedef std::deque<IPC::Message*> MessageQueue; |
| 85 struct PendingRequestInfo { | 71 struct PendingRequestInfo { |
| 86 PendingRequestInfo() { } | 72 PendingRequestInfo() { } |
| 87 PendingRequestInfo(webkit_glue::ResourceLoaderBridge::Peer* peer, | 73 PendingRequestInfo(webkit_glue::ResourceLoaderBridge::Peer* peer, |
| 88 ResourceType::Type resource_type, | 74 ResourceType::Type resource_type, |
| 89 const GURL& request_url) | 75 const GURL& request_url) |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 // for use on deferred message queues that are no longer needed. | 145 // for use on deferred message queues that are no longer needed. |
| 160 static void ReleaseResourcesInMessageQueue(MessageQueue* queue); | 146 static void ReleaseResourcesInMessageQueue(MessageQueue* queue); |
| 161 | 147 |
| 162 IPC::Message::Sender* message_sender_; | 148 IPC::Message::Sender* message_sender_; |
| 163 | 149 |
| 164 // All pending requests issued to the host | 150 // All pending requests issued to the host |
| 165 PendingRequestList pending_requests_; | 151 PendingRequestList pending_requests_; |
| 166 | 152 |
| 167 ScopedRunnableMethodFactory<ResourceDispatcher> method_factory_; | 153 ScopedRunnableMethodFactory<ResourceDispatcher> method_factory_; |
| 168 | 154 |
| 169 scoped_ptr<Observer> observer_; | 155 ResourceDispatcherDelegate* delegate_; |
| 170 | 156 |
| 171 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcher); | 157 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcher); |
| 172 }; | 158 }; |
| 173 | 159 |
| 174 #endif // CONTENT_COMMON_RESOURCE_DISPATCHER_H_ | 160 #endif // CONTENT_COMMON_RESOURCE_DISPATCHER_H_ |
| OLD | NEW |