OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/host_dispatcher.h" | 5 #include "ppapi/proxy/host_dispatcher.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "ppapi/c/private/ppb_proxy_private.h" | 9 #include "ppapi/c/private/ppb_proxy_private.h" |
10 #include "ppapi/c/ppb_var.h" | 10 #include "ppapi/c/ppb_var.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 } | 54 } |
55 private: | 55 private: |
56 bool* var_; | 56 bool* var_; |
57 bool old_value_; | 57 bool old_value_; |
58 }; | 58 }; |
59 | 59 |
60 } // namespace | 60 } // namespace |
61 | 61 |
62 HostDispatcher::HostDispatcher(PP_Module module, | 62 HostDispatcher::HostDispatcher(PP_Module module, |
63 PP_GetInterface_Func local_get_interface, | 63 PP_GetInterface_Func local_get_interface, |
| 64 SyncMessageStatusReceiver* sync_status, |
64 const PpapiPermissions& permissions) | 65 const PpapiPermissions& permissions) |
65 : Dispatcher(local_get_interface, permissions), | 66 : Dispatcher(local_get_interface, permissions), |
| 67 sync_status_(sync_status), |
66 pp_module_(module), | 68 pp_module_(module), |
67 ppb_proxy_(NULL), | 69 ppb_proxy_(NULL), |
68 allow_plugin_reentrancy_(false) { | 70 allow_plugin_reentrancy_(false) { |
69 if (!g_module_to_dispatcher) | 71 if (!g_module_to_dispatcher) |
70 g_module_to_dispatcher = new ModuleToDispatcherMap; | 72 g_module_to_dispatcher = new ModuleToDispatcherMap; |
71 (*g_module_to_dispatcher)[pp_module_] = this; | 73 (*g_module_to_dispatcher)[pp_module_] = this; |
72 | 74 |
73 SetSerializationRules(new HostVarSerializationRules); | 75 SetSerializationRules(new HostVarSerializationRules); |
74 | 76 |
75 ppb_proxy_ = reinterpret_cast<const PPB_Proxy_Private*>( | 77 ppb_proxy_ = reinterpret_cast<const PPB_Proxy_Private*>( |
76 local_get_interface(PPB_PROXY_PRIVATE_INTERFACE)); | 78 local_get_interface(PPB_PROXY_PRIVATE_INTERFACE)); |
77 DCHECK(ppb_proxy_) << "The proxy interface should always be supported."; | 79 DCHECK(ppb_proxy_) << "The proxy interface should always be supported."; |
78 | 80 |
79 ppb_proxy_->SetReserveInstanceIDCallback(pp_module_, &ReserveInstanceID); | 81 ppb_proxy_->SetReserveInstanceIDCallback(pp_module_, &ReserveInstanceID); |
80 } | 82 } |
81 | 83 |
82 HostDispatcher::~HostDispatcher() { | 84 HostDispatcher::~HostDispatcher() { |
83 g_module_to_dispatcher->erase(pp_module_); | 85 g_module_to_dispatcher->erase(pp_module_); |
84 } | 86 } |
85 | 87 |
86 bool HostDispatcher::InitHostWithChannel( | 88 bool HostDispatcher::InitHostWithChannel( |
87 Delegate* delegate, | 89 Delegate* delegate, |
88 base::ProcessId peer_pid, | 90 base::ProcessId peer_pid, |
89 const IPC::ChannelHandle& channel_handle, | 91 const IPC::ChannelHandle& channel_handle, |
90 bool is_client, | 92 bool is_client, |
91 const ppapi::Preferences& preferences) { | 93 const ppapi::Preferences& preferences) { |
92 if (!Dispatcher::InitWithChannel(delegate, peer_pid, channel_handle, | 94 if (!Dispatcher::InitWithChannel(delegate, peer_pid, channel_handle, |
93 is_client)) | 95 is_client)) |
94 return false; | 96 return false; |
| 97 AddIOThreadMessageFilter(sync_status_.get()); |
| 98 |
95 Send(new PpapiMsg_SetPreferences(preferences)); | 99 Send(new PpapiMsg_SetPreferences(preferences)); |
96 return true; | 100 return true; |
97 } | 101 } |
98 | 102 |
99 // static | 103 // static |
100 HostDispatcher* HostDispatcher::GetForInstance(PP_Instance instance) { | 104 HostDispatcher* HostDispatcher::GetForInstance(PP_Instance instance) { |
101 if (!g_instance_to_dispatcher) | 105 if (!g_instance_to_dispatcher) |
102 return NULL; | 106 return NULL; |
103 InstanceToDispatcherMap::iterator found = g_instance_to_dispatcher->find( | 107 InstanceToDispatcherMap::iterator found = g_instance_to_dispatcher->find( |
104 instance); | 108 instance); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 // Don't allow sending sync messages during module shutdown. Seee the "else" | 150 // Don't allow sending sync messages during module shutdown. Seee the "else" |
147 // block below for why. | 151 // block below for why. |
148 CHECK(!PP_ToBool(ppb_proxy()->IsInModuleDestructor(pp_module()))); | 152 CHECK(!PP_ToBool(ppb_proxy()->IsInModuleDestructor(pp_module()))); |
149 | 153 |
150 // Prevent the dispatcher from going away during sync calls. Scenarios | 154 // Prevent the dispatcher from going away during sync calls. Scenarios |
151 // where this could happen include a Send for a sync message which while | 155 // where this could happen include a Send for a sync message which while |
152 // waiting for the reply, dispatches an incoming ExecuteScript call which | 156 // waiting for the reply, dispatches an incoming ExecuteScript call which |
153 // destroys the plugin module and in turn the dispatcher. | 157 // destroys the plugin module and in turn the dispatcher. |
154 ScopedModuleReference scoped_ref(this); | 158 ScopedModuleReference scoped_ref(this); |
155 | 159 |
156 FOR_EACH_OBSERVER(SyncMessageStatusObserver, sync_status_observer_list_, | 160 sync_status_->BeginBlockOnSyncMessage(); |
157 BeginBlockOnSyncMessage()); | |
158 bool result = Dispatcher::Send(msg); | 161 bool result = Dispatcher::Send(msg); |
159 FOR_EACH_OBSERVER(SyncMessageStatusObserver, sync_status_observer_list_, | 162 sync_status_->EndBlockOnSyncMessage(); |
160 EndBlockOnSyncMessage()); | |
161 | 163 |
162 return result; | 164 return result; |
163 } else { | 165 } else { |
164 // We don't want to have a scoped ref for async message cases since since | 166 // We don't want to have a scoped ref for async message cases since since |
165 // async messages are sent during module desruction. In this case, the | 167 // async messages are sent during module desruction. In this case, the |
166 // module will have a 0 refcount and addrefing and releasing it will | 168 // module will have a 0 refcount and addrefing and releasing it will |
167 // reenter the destructor and it will crash. | 169 // reenter the destructor and it will crash. |
168 return Dispatcher::Send(msg); | 170 return Dispatcher::Send(msg); |
169 } | 171 } |
170 } | 172 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 std::pair<PluginSupportedMap::iterator, bool> iter_success_pair; | 233 std::pair<PluginSupportedMap::iterator, bool> iter_success_pair; |
232 iter_success_pair = plugin_supported_.insert( | 234 iter_success_pair = plugin_supported_.insert( |
233 PluginSupportedMap::value_type(iface_name, supported)); | 235 PluginSupportedMap::value_type(iface_name, supported)); |
234 iter = iter_success_pair.first; | 236 iter = iter_success_pair.first; |
235 } | 237 } |
236 if (iter->second) | 238 if (iter->second) |
237 return proxied_interface; | 239 return proxied_interface; |
238 return NULL; | 240 return NULL; |
239 } | 241 } |
240 | 242 |
241 void HostDispatcher::AddSyncMessageStatusObserver( | |
242 SyncMessageStatusObserver* obs) { | |
243 sync_status_observer_list_.AddObserver(obs); | |
244 } | |
245 | |
246 void HostDispatcher::RemoveSyncMessageStatusObserver( | |
247 SyncMessageStatusObserver* obs) { | |
248 sync_status_observer_list_.RemoveObserver(obs); | |
249 } | |
250 | |
251 void HostDispatcher::AddFilter(IPC::Listener* listener) { | 243 void HostDispatcher::AddFilter(IPC::Listener* listener) { |
252 filters_.push_back(listener); | 244 filters_.push_back(listener); |
253 } | 245 } |
254 | 246 |
255 void HostDispatcher::OnInvalidMessageReceived() { | 247 void HostDispatcher::OnInvalidMessageReceived() { |
256 // TODO(brettw) bug 95345 kill the plugin when an invalid message is | 248 // TODO(brettw) bug 95345 kill the plugin when an invalid message is |
257 // received. | 249 // received. |
258 } | 250 } |
259 | 251 |
260 void HostDispatcher::OnHostMsgLogWithSource(PP_Instance instance, | 252 void HostDispatcher::OnHostMsgLogWithSource(PP_Instance instance, |
(...skipping 19 matching lines...) Expand all Loading... |
280 } | 272 } |
281 } | 273 } |
282 | 274 |
283 ScopedModuleReference::~ScopedModuleReference() { | 275 ScopedModuleReference::~ScopedModuleReference() { |
284 if (dispatcher_) | 276 if (dispatcher_) |
285 dispatcher_->ppb_proxy()->ReleaseModule(dispatcher_->pp_module()); | 277 dispatcher_->ppb_proxy()->ReleaseModule(dispatcher_->pp_module()); |
286 } | 278 } |
287 | 279 |
288 } // namespace proxy | 280 } // namespace proxy |
289 } // namespace ppapi | 281 } // namespace ppapi |
OLD | NEW |