| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 CHROME_COMMON_RESOURCE_DISPATCHER_H__ | 7 #ifndef CHROME_COMMON_RESOURCE_DISPATCHER_H__ |
| 8 #define CHROME_COMMON_RESOURCE_DISPATCHER_H__ | 8 #define CHROME_COMMON_RESOURCE_DISPATCHER_H__ |
| 9 | 9 |
| 10 #include <deque> |
| 10 #include <queue> | 11 #include <queue> |
| 12 #include <string> |
| 11 | 13 |
| 12 #include "base/hash_tables.h" | 14 #include "base/hash_tables.h" |
| 13 #include "base/shared_memory.h" | 15 #include "base/shared_memory.h" |
| 14 #include "base/task.h" | 16 #include "base/task.h" |
| 15 #include "chrome/common/filter_policy.h" | 17 #include "chrome/common/filter_policy.h" |
| 16 #include "chrome/common/ipc_channel.h" | 18 #include "chrome/common/ipc_channel.h" |
| 17 #include "webkit/glue/resource_loader_bridge.h" | 19 #include "webkit/glue/resource_loader_bridge.h" |
| 18 | 20 |
| 19 struct ResourceResponseHead; | 21 struct ResourceResponseHead; |
| 20 struct ViewMsg_Resource_ResponseHead; | |
| 21 | 22 |
| 22 // Uncomment this to disable loading resources via the parent process. This | 23 // Uncomment this to disable loading resources via the parent process. This |
| 23 // may be useful for debugging purposes. | 24 // may be useful for debugging purposes. |
| 24 //#define USING_SIMPLE_RESOURCE_LOADER_BRIDGE | 25 //#define USING_SIMPLE_RESOURCE_LOADER_BRIDGE |
| 25 | 26 |
| 26 // This class serves as a communication interface between the | 27 // This class serves as a communication interface between the |
| 27 // ResourceDispatcherHost in the browser process and the ResourceLoaderBridge in | 28 // ResourceDispatcherHost in the browser process and the ResourceLoaderBridge in |
| 28 // the child process. It can be used from either the renderer or plugin | 29 // the child process. It can be used from either the renderer or plugin |
| 29 // processes. | 30 // processes. |
| 30 class ResourceDispatcher : public base::RefCounted<ResourceDispatcher> { | 31 class ResourceDispatcher : public base::RefCounted<ResourceDispatcher> { |
| 31 public: | 32 public: |
| 32 ResourceDispatcher(IPC::Message::Sender* sender); | 33 explicit ResourceDispatcher(IPC::Message::Sender* sender); |
| 33 ~ResourceDispatcher(); | 34 ~ResourceDispatcher(); |
| 34 | 35 |
| 35 // Called to possibly handle the incoming IPC message. Returns true if | 36 // Called to possibly handle the incoming IPC message. Returns true if |
| 36 // handled, else false. | 37 // handled, else false. |
| 37 bool OnMessageReceived(const IPC::Message& message); | 38 bool OnMessageReceived(const IPC::Message& message); |
| 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(const std::string& method, | 43 webkit_glue::ResourceLoaderBridge* CreateBridge(const std::string& method, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 is_deferred(false) { | 93 is_deferred(false) { |
| 93 } | 94 } |
| 94 ~PendingRequestInfo() { } | 95 ~PendingRequestInfo() { } |
| 95 webkit_glue::ResourceLoaderBridge::Peer* peer; | 96 webkit_glue::ResourceLoaderBridge::Peer* peer; |
| 96 ResourceType::Type resource_type; | 97 ResourceType::Type resource_type; |
| 97 FilterPolicy::Type filter_policy; | 98 FilterPolicy::Type filter_policy; |
| 98 MessageQueue deferred_message_queue; | 99 MessageQueue deferred_message_queue; |
| 99 bool mixed_content; | 100 bool mixed_content; |
| 100 bool is_deferred; | 101 bool is_deferred; |
| 101 }; | 102 }; |
| 102 typedef base::hash_map<int,PendingRequestInfo> PendingRequestList; | 103 typedef base::hash_map<int, PendingRequestInfo> PendingRequestList; |
| 103 | 104 |
| 104 // Message response handlers, called by the message handler for this process. | 105 // Message response handlers, called by the message handler for this process. |
| 105 void OnUploadProgress(int request_id, int64 position, int64 size); | 106 void OnUploadProgress(int request_id, int64 position, int64 size); |
| 106 void OnReceivedResponse(int request_id, const ResourceResponseHead&); | 107 void OnReceivedResponse(int request_id, const ResourceResponseHead&); |
| 107 void OnReceivedRedirect(int request_id, const GURL& new_url); | 108 void OnReceivedRedirect(int request_id, const GURL& new_url); |
| 108 void OnReceivedData(int request_id, base::SharedMemoryHandle data, | 109 void OnReceivedData(int request_id, base::SharedMemoryHandle data, |
| 109 int data_len); | 110 int data_len); |
| 110 void OnRequestComplete(int request_id, const URLRequestStatus& status); | 111 void OnRequestComplete(int request_id, const URLRequestStatus& status); |
| 111 | 112 |
| 112 // Dispatch the message to one of the message response handlers. | 113 // Dispatch the message to one of the message response handlers. |
| 113 void DispatchMessage(const IPC::Message& message); | 114 void DispatchMessage(const IPC::Message& message); |
| 114 | 115 |
| 115 // Dispatch any deferred messages for the given request, provided it is not | 116 // Dispatch any deferred messages for the given request, provided it is not |
| 116 // again in the deferred state. | 117 // again in the deferred state. |
| 117 void FlushDeferredMessages(int request_id); | 118 void FlushDeferredMessages(int request_id); |
| 118 | 119 |
| 119 IPC::Message::Sender* message_sender_; | 120 IPC::Message::Sender* message_sender_; |
| 120 | 121 |
| 121 // All pending requests issued to the host | 122 // All pending requests issued to the host |
| 122 PendingRequestList pending_requests_; | 123 PendingRequestList pending_requests_; |
| 123 | 124 |
| 124 ScopedRunnableMethodFactory<ResourceDispatcher> method_factory_; | 125 ScopedRunnableMethodFactory<ResourceDispatcher> method_factory_; |
| 125 | 126 |
| 126 DISALLOW_EVIL_CONSTRUCTORS(ResourceDispatcher); | 127 DISALLOW_EVIL_CONSTRUCTORS(ResourceDispatcher); |
| 127 }; | 128 }; |
| 128 | 129 |
| 129 #endif // CHROME_COMMON_RESOURCE_DISPATCHER_H__ | 130 #endif // CHROME_COMMON_RESOURCE_DISPATCHER_H__ |
| OLD | NEW |