| 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 "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
| 19 #include "ipc/ipc_channel.h" | 20 #include "ipc/ipc_channel.h" |
| 20 #include "webkit/glue/resource_loader_bridge.h" | 21 #include "webkit/glue/resource_loader_bridge.h" |
| 21 | 22 |
| 22 namespace content { | 23 namespace content { |
| 23 class ResourceDispatcherDelegate; | 24 class ResourceDispatcherDelegate; |
| 24 struct ResourceResponseHead; | 25 struct ResourceResponseHead; |
| 25 } | 26 } |
| 26 | 27 |
| 27 // This class serves as a communication interface between the | 28 // This class serves as a communication interface between the |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 73 |
| 73 typedef std::deque<IPC::Message*> MessageQueue; | 74 typedef std::deque<IPC::Message*> MessageQueue; |
| 74 struct PendingRequestInfo { | 75 struct PendingRequestInfo { |
| 75 PendingRequestInfo() { } | 76 PendingRequestInfo() { } |
| 76 PendingRequestInfo(webkit_glue::ResourceLoaderBridge::Peer* peer, | 77 PendingRequestInfo(webkit_glue::ResourceLoaderBridge::Peer* peer, |
| 77 ResourceType::Type resource_type, | 78 ResourceType::Type resource_type, |
| 78 const GURL& request_url) | 79 const GURL& request_url) |
| 79 : peer(peer), | 80 : peer(peer), |
| 80 resource_type(resource_type), | 81 resource_type(resource_type), |
| 81 is_deferred(false), | 82 is_deferred(false), |
| 82 url(request_url) { | 83 url(request_url), |
| 84 request_start(base::TimeTicks::Now()) { |
| 83 } | 85 } |
| 84 ~PendingRequestInfo() { } | 86 ~PendingRequestInfo() { } |
| 85 webkit_glue::ResourceLoaderBridge::Peer* peer; | 87 webkit_glue::ResourceLoaderBridge::Peer* peer; |
| 86 ResourceType::Type resource_type; | 88 ResourceType::Type resource_type; |
| 87 MessageQueue deferred_message_queue; | 89 MessageQueue deferred_message_queue; |
| 88 bool is_deferred; | 90 bool is_deferred; |
| 89 GURL url; | 91 GURL url; |
| 90 linked_ptr<IPC::Message> pending_redirect_message; | 92 linked_ptr<IPC::Message> pending_redirect_message; |
| 93 base::TimeTicks request_start; |
| 94 base::TimeTicks response_start; |
| 95 base::TimeTicks completion_time; |
| 91 }; | 96 }; |
| 92 typedef base::hash_map<int, PendingRequestInfo> PendingRequestList; | 97 typedef base::hash_map<int, PendingRequestInfo> PendingRequestList; |
| 93 | 98 |
| 94 // Helper to lookup the info based on the request_id. | 99 // Helper to lookup the info based on the request_id. |
| 95 // May return NULL if the request as been canceled from the client side. | 100 // May return NULL if the request as been canceled from the client side. |
| 96 PendingRequestInfo* GetPendingRequestInfo(int request_id); | 101 PendingRequestInfo* GetPendingRequestInfo(int request_id); |
| 97 | 102 |
| 98 // Follows redirect, if any, for the given request. | 103 // Follows redirect, if any, for the given request. |
| 99 void FollowPendingRedirect(int request_id, PendingRequestInfo& request_info); | 104 void FollowPendingRedirect(int request_id, PendingRequestInfo& request_info); |
| 100 | 105 |
| 101 // Message response handlers, called by the message handler for this process. | 106 // Message response handlers, called by the message handler for this process. |
| 102 void OnUploadProgress( | 107 void OnUploadProgress( |
| 103 const IPC::Message& message, | 108 const IPC::Message& message, |
| 104 int request_id, | 109 int request_id, |
| 105 int64 position, | 110 int64 position, |
| 106 int64 size); | 111 int64 size); |
| 107 void OnReceivedResponse(int request_id, const content::ResourceResponseHead&); | 112 void OnReceivedResponse(int request_id, const content::ResourceResponseHead&); |
| 108 void OnReceivedCachedMetadata(int request_id, const std::vector<char>& data); | 113 void OnReceivedCachedMetadata(int request_id, const std::vector<char>& data); |
| 109 void OnReceivedRedirect( | 114 void OnReceivedRedirect( |
| 110 const IPC::Message& message, | 115 const IPC::Message& message, |
| 111 int request_id, | 116 int request_id, |
| 112 const GURL& new_url, | 117 const GURL& new_url, |
| 113 const webkit_glue::ResourceResponseInfo& info); | 118 const content::ResourceResponseHead& response_head); |
| 114 void OnReceivedData( | 119 void OnReceivedData( |
| 115 const IPC::Message& message, | 120 const IPC::Message& message, |
| 116 int request_id, | 121 int request_id, |
| 117 base::SharedMemoryHandle data, | 122 base::SharedMemoryHandle data, |
| 118 int data_len, | 123 int data_len, |
| 119 int encoded_data_length); | 124 int encoded_data_length); |
| 120 void OnDownloadedData( | 125 void OnDownloadedData( |
| 121 const IPC::Message& message, | 126 const IPC::Message& message, |
| 122 int request_id, | 127 int request_id, |
| 123 int data_len); | 128 int data_len); |
| 124 void OnRequestComplete( | 129 void OnRequestComplete( |
| 125 int request_id, | 130 int request_id, |
| 126 const net::URLRequestStatus& status, | 131 const net::URLRequestStatus& status, |
| 127 const std::string& security_info, | 132 const std::string& security_info, |
| 128 const base::Time& completion_time); | 133 const base::TimeTicks& completion_time); |
| 129 | 134 |
| 130 // Dispatch the message to one of the message response handlers. | 135 // Dispatch the message to one of the message response handlers. |
| 131 void DispatchMessage(const IPC::Message& message); | 136 void DispatchMessage(const IPC::Message& message); |
| 132 | 137 |
| 133 // Dispatch any deferred messages for the given request, provided it is not | 138 // Dispatch any deferred messages for the given request, provided it is not |
| 134 // again in the deferred state. | 139 // again in the deferred state. |
| 135 void FlushDeferredMessages(int request_id); | 140 void FlushDeferredMessages(int request_id); |
| 136 | 141 |
| 142 void ToResourceResponseInfo( |
| 143 const PendingRequestInfo& request_info, |
| 144 const content::ResourceResponseHead& browser_info, |
| 145 webkit_glue::ResourceResponseInfo* renderer_info) const; |
| 146 |
| 147 base::TimeTicks ToRendererCompletionTime( |
| 148 const PendingRequestInfo& request_info, |
| 149 const base::TimeTicks& browser_completion_time) const; |
| 150 |
| 137 // Returns true if the message passed in is a resource related message. | 151 // Returns true if the message passed in is a resource related message. |
| 138 static bool IsResourceDispatcherMessage(const IPC::Message& message); | 152 static bool IsResourceDispatcherMessage(const IPC::Message& message); |
| 139 | 153 |
| 140 // ViewHostMsg_Resource_DataReceived is not POD, it has a shared memory | 154 // ViewHostMsg_Resource_DataReceived is not POD, it has a shared memory |
| 141 // handle in it that we should cleanup it up nicely. This method accepts any | 155 // handle in it that we should cleanup it up nicely. This method accepts any |
| 142 // message and determine whether the message is | 156 // message and determine whether the message is |
| 143 // ViewHostMsg_Resource_DataReceived and clean up the shared memory handle. | 157 // ViewHostMsg_Resource_DataReceived and clean up the shared memory handle. |
| 144 static void ReleaseResourcesInDataMessage(const IPC::Message& message); | 158 static void ReleaseResourcesInDataMessage(const IPC::Message& message); |
| 145 | 159 |
| 146 // Iterate through a message queue and clean up the messages by calling | 160 // Iterate through a message queue and clean up the messages by calling |
| 147 // ReleaseResourcesInDataMessage and removing them from the queue. Intended | 161 // ReleaseResourcesInDataMessage and removing them from the queue. Intended |
| 148 // for use on deferred message queues that are no longer needed. | 162 // for use on deferred message queues that are no longer needed. |
| 149 static void ReleaseResourcesInMessageQueue(MessageQueue* queue); | 163 static void ReleaseResourcesInMessageQueue(MessageQueue* queue); |
| 150 | 164 |
| 151 IPC::Message::Sender* message_sender_; | 165 IPC::Message::Sender* message_sender_; |
| 152 | 166 |
| 153 // All pending requests issued to the host | 167 // All pending requests issued to the host |
| 154 PendingRequestList pending_requests_; | 168 PendingRequestList pending_requests_; |
| 155 | 169 |
| 156 base::WeakPtrFactory<ResourceDispatcher> weak_factory_; | 170 base::WeakPtrFactory<ResourceDispatcher> weak_factory_; |
| 157 | 171 |
| 158 content::ResourceDispatcherDelegate* delegate_; | 172 content::ResourceDispatcherDelegate* delegate_; |
| 159 | 173 |
| 160 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcher); | 174 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcher); |
| 161 }; | 175 }; |
| 162 | 176 |
| 163 #endif // CONTENT_COMMON_RESOURCE_DISPATCHER_H_ | 177 #endif // CONTENT_COMMON_RESOURCE_DISPATCHER_H_ |
| OLD | NEW |