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 #include "ppapi/proxy/ppb_flash_file_proxy.h" | 5 #include "ppapi/proxy/ppb_flash_file_proxy.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop_proxy.h" |
13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
14 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
16 #include "ipc/ipc_channel_proxy.h" | 16 #include "ipc/ipc_channel_proxy.h" |
17 #include "ipc/ipc_message.h" | 17 #include "ipc/ipc_message.h" |
18 #include "ipc/ipc_sync_message.h" | 18 #include "ipc/ipc_sync_message.h" |
19 #include "ppapi/c/dev/pp_file_info_dev.h" | 19 #include "ppapi/c/dev/pp_file_info_dev.h" |
20 #include "ppapi/c/pp_errors.h" | 20 #include "ppapi/c/pp_errors.h" |
21 #include "ppapi/c/private/ppb_flash_file.h" | 21 #include "ppapi/c/private/ppb_flash_file.h" |
22 #include "ppapi/proxy/plugin_dispatcher.h" | 22 #include "ppapi/proxy/plugin_dispatcher.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 }; | 104 }; |
105 | 105 |
106 virtual void SendFromIOThread(Dispatcher* dispatcher, IPC::Message* msg); | 106 virtual void SendFromIOThread(Dispatcher* dispatcher, IPC::Message* msg); |
107 | 107 |
108 // Internal version of OnModuleLocalMessageFailed which assumes the lock | 108 // Internal version of OnModuleLocalMessageFailed which assumes the lock |
109 // is already held. | 109 // is already held. |
110 void OnModuleLocalMessageFailedLocked(int message_id); | 110 void OnModuleLocalMessageFailedLocked(int message_id); |
111 | 111 |
112 base::Lock lock_; | 112 base::Lock lock_; |
113 | 113 |
114 MessageLoop* main_thread_; | 114 scoped_refptr<base::MessageLoopProxy> main_thread_; |
115 | 115 |
116 // Will be NULL before an instance routing is added. | 116 // Will be NULL before an instance routing is added. |
117 MessageLoop* io_thread_; | 117 scoped_refptr<base::MessageLoopProxy> io_thread_; |
118 | 118 |
119 typedef std::map<PP_Instance, Dispatcher*> InstanceToDispatcher; | 119 typedef std::map<PP_Instance, Dispatcher*> InstanceToDispatcher; |
120 InstanceToDispatcher instance_to_dispatcher_; | 120 InstanceToDispatcher instance_to_dispatcher_; |
121 | 121 |
122 // The filters are owned by the channel. | 122 // The filters are owned by the channel. |
123 typedef std::map<Dispatcher*, Filter*> DispatcherToFilter; | 123 typedef std::map<Dispatcher*, Filter*> DispatcherToFilter; |
124 DispatcherToFilter dispatcher_to_filter_; | 124 DispatcherToFilter dispatcher_to_filter_; |
125 | 125 |
126 // Tracks all messages with currently waiting threads. This does not own | 126 // Tracks all messages with currently waiting threads. This does not own |
127 // the pointer, the pointer lifetime is managed by Send(). | 127 // the pointer, the pointer lifetime is managed by Send(). |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 if (g_module_local_thread_adapter->OnModuleLocalMessageReceived(message)) { | 181 if (g_module_local_thread_adapter->OnModuleLocalMessageReceived(message)) { |
182 // The message was consumed, this means we can remove the message ID from | 182 // The message was consumed, this means we can remove the message ID from |
183 // the list of messages this channel is waiting on. | 183 // the list of messages this channel is waiting on. |
184 pending_requests_for_filter_.erase(IPC::SyncMessage::GetMessageId(message)); | 184 pending_requests_for_filter_.erase(IPC::SyncMessage::GetMessageId(message)); |
185 return true; | 185 return true; |
186 } | 186 } |
187 return false; | 187 return false; |
188 } | 188 } |
189 | 189 |
190 ModuleLocalThreadAdapter::ModuleLocalThreadAdapter() | 190 ModuleLocalThreadAdapter::ModuleLocalThreadAdapter() |
191 : main_thread_(MessageLoop::current()), | 191 : main_thread_(base::MessageLoopProxy::CreateForCurrentThread()) { |
192 io_thread_(NULL) { | |
193 } | 192 } |
194 | 193 |
195 void ModuleLocalThreadAdapter::AddInstanceRouting(PP_Instance instance, | 194 void ModuleLocalThreadAdapter::AddInstanceRouting(PP_Instance instance, |
196 Dispatcher* dispatcher) { | 195 Dispatcher* dispatcher) { |
197 base::AutoLock lock(lock_); | 196 base::AutoLock lock(lock_); |
198 | 197 |
199 // Now that we've had contact with a dispatcher, we can set up the IO thread. | 198 // Now that we've had contact with a dispatcher, we can set up the IO thread. |
200 DCHECK(MessageLoop::current() == main_thread_); | 199 DCHECK(main_thread_->BelongsToCurrentThread()); |
201 if (!io_thread_) | 200 if (!io_thread_.get()) |
202 io_thread_ = dispatcher->GetIPCMessageLoop(); | 201 io_thread_ = dispatcher->GetIPCMessageLoop(); |
203 | 202 |
204 // Set up the instance -> dispatcher routing. | 203 // Set up the instance -> dispatcher routing. |
205 DCHECK(instance_to_dispatcher_.find(instance) == | 204 DCHECK(instance_to_dispatcher_.find(instance) == |
206 instance_to_dispatcher_.end()); | 205 instance_to_dispatcher_.end()); |
207 instance_to_dispatcher_[instance] = dispatcher; | 206 instance_to_dispatcher_[instance] = dispatcher; |
208 | 207 |
209 DispatcherToFilter::iterator found_filter = | 208 DispatcherToFilter::iterator found_filter = |
210 dispatcher_to_filter_.find(dispatcher); | 209 dispatcher_to_filter_.find(dispatcher); |
211 if (found_filter == dispatcher_to_filter_.end()) { | 210 if (found_filter == dispatcher_to_filter_.end()) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 InstanceToDispatcher::iterator found = | 267 InstanceToDispatcher::iterator found = |
269 instance_to_dispatcher_.find(instance); | 268 instance_to_dispatcher_.find(instance); |
270 if (found == instance_to_dispatcher_.end()) { | 269 if (found == instance_to_dispatcher_.end()) { |
271 NOTREACHED(); | 270 NOTREACHED(); |
272 delete msg; | 271 delete msg; |
273 return false; | 272 return false; |
274 } | 273 } |
275 dispatcher = found->second; | 274 dispatcher = found->second; |
276 } | 275 } |
277 | 276 |
278 if (MessageLoop::current() == main_thread_) { | 277 if (main_thread_->BelongsToCurrentThread()) { |
279 // Easy case: We're on the same thread as the dispatcher, so we don't need | 278 // Easy case: We're on the same thread as the dispatcher, so we don't need |
280 // a lock to access it, and we can just use the normal sync channel stuff | 279 // a lock to access it, and we can just use the normal sync channel stuff |
281 // to handle the message. Actually, we MUST use the normal sync channel | 280 // to handle the message. Actually, we MUST use the normal sync channel |
282 // stuff since there may be incoming sync messages that need processing. | 281 // stuff since there may be incoming sync messages that need processing. |
283 // The code below doesn't handle any nested message loops. | 282 // The code below doesn't handle any nested message loops. |
284 return dispatcher->Send(msg); | 283 return dispatcher->Send(msg); |
285 } | 284 } |
286 | 285 |
287 // Background thread case | 286 // Background thread case |
288 // ---------------------- | 287 // ---------------------- |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 void PPB_Flash_File_FileRef_Proxy::OnMsgQueryFile( | 723 void PPB_Flash_File_FileRef_Proxy::OnMsgQueryFile( |
725 const HostResource& host_resource, | 724 const HostResource& host_resource, |
726 PP_FileInfo_Dev* info, | 725 PP_FileInfo_Dev* info, |
727 int32_t* result) { | 726 int32_t* result) { |
728 *result = ppb_flash_file_module_local_target()-> | 727 *result = ppb_flash_file_module_local_target()-> |
729 QueryFile(host_resource.host_resource(), info); | 728 QueryFile(host_resource.host_resource(), info); |
730 } | 729 } |
731 | 730 |
732 } // namespace proxy | 731 } // namespace proxy |
733 } // namespace pp | 732 } // namespace pp |
OLD | NEW |