| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/nacl_irt/ppapi_dispatcher.h" | 5 #include "ppapi/nacl_irt/ppapi_dispatcher.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "ppapi/proxy/plugin_message_filter.h" | 27 #include "ppapi/proxy/plugin_message_filter.h" |
| 28 #include "ppapi/proxy/plugin_proxy_delegate.h" | 28 #include "ppapi/proxy/plugin_proxy_delegate.h" |
| 29 #include "ppapi/proxy/ppapi_messages.h" | 29 #include "ppapi/proxy/ppapi_messages.h" |
| 30 #include "ppapi/proxy/resource_reply_thread_registrar.h" | 30 #include "ppapi/proxy/resource_reply_thread_registrar.h" |
| 31 | 31 |
| 32 namespace ppapi { | 32 namespace ppapi { |
| 33 | 33 |
| 34 PpapiDispatcher::PpapiDispatcher( | 34 PpapiDispatcher::PpapiDispatcher( |
| 35 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 35 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| 36 base::WaitableEvent* shutdown_event, | 36 base::WaitableEvent* shutdown_event, |
| 37 int browser_ipc_fd, | 37 IPC::ChannelHandle browser_ipc_handle, |
| 38 int renderer_ipc_fd) | 38 IPC::ChannelHandle renderer_ipc_handle) |
| 39 : next_plugin_dispatcher_id_(0), | 39 : next_plugin_dispatcher_id_(0), |
| 40 task_runner_(io_task_runner), | 40 task_runner_(io_task_runner), |
| 41 shutdown_event_(shutdown_event), | 41 shutdown_event_(shutdown_event), |
| 42 renderer_ipc_fd_(renderer_ipc_fd) { | 42 renderer_ipc_handle_(renderer_ipc_handle) { |
| 43 IPC::ChannelHandle channel_handle( | |
| 44 "NaCl IPC", base::FileDescriptor(browser_ipc_fd, false)); | |
| 45 | |
| 46 proxy::PluginGlobals* globals = proxy::PluginGlobals::Get(); | 43 proxy::PluginGlobals* globals = proxy::PluginGlobals::Get(); |
| 47 // Delay initializing the SyncChannel until after we add filters. This | 44 // Delay initializing the SyncChannel until after we add filters. This |
| 48 // ensures that the filters won't miss any messages received by | 45 // ensures that the filters won't miss any messages received by |
| 49 // the channel. | 46 // the channel. |
| 50 channel_ = | 47 channel_ = |
| 51 IPC::SyncChannel::Create(this, GetIPCTaskRunner(), GetShutdownEvent()); | 48 IPC::SyncChannel::Create(this, GetIPCTaskRunner(), GetShutdownEvent()); |
| 52 scoped_refptr<ppapi::proxy::PluginMessageFilter> plugin_filter( | 49 scoped_refptr<ppapi::proxy::PluginMessageFilter> plugin_filter( |
| 53 new ppapi::proxy::PluginMessageFilter( | 50 new ppapi::proxy::PluginMessageFilter( |
| 54 NULL, globals->resource_reply_thread_registrar())); | 51 NULL, globals->resource_reply_thread_registrar())); |
| 55 channel_->AddFilter(plugin_filter.get()); | 52 channel_->AddFilter(plugin_filter.get()); |
| 56 globals->RegisterResourceMessageFilters(plugin_filter.get()); | 53 globals->RegisterResourceMessageFilters(plugin_filter.get()); |
| 57 | 54 |
| 58 channel_->AddFilter(new tracing::ChildTraceMessageFilter(task_runner_.get())); | 55 channel_->AddFilter(new tracing::ChildTraceMessageFilter(task_runner_.get())); |
| 59 channel_->Init(channel_handle, IPC::Channel::MODE_SERVER, true); | 56 channel_->Init(browser_ipc_handle, IPC::Channel::MODE_SERVER, true); |
| 60 } | 57 } |
| 61 | 58 |
| 62 base::SingleThreadTaskRunner* PpapiDispatcher::GetIPCTaskRunner() { | 59 base::SingleThreadTaskRunner* PpapiDispatcher::GetIPCTaskRunner() { |
| 63 return task_runner_.get(); | 60 return task_runner_.get(); |
| 64 } | 61 } |
| 65 | 62 |
| 66 base::WaitableEvent* PpapiDispatcher::GetShutdownEvent() { | 63 base::WaitableEvent* PpapiDispatcher::GetShutdownEvent() { |
| 67 return shutdown_event_; | 64 return shutdown_event_; |
| 68 } | 65 } |
| 69 | 66 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 174 |
| 178 int32_t error = ::PPP_InitializeModule( | 175 int32_t error = ::PPP_InitializeModule( |
| 179 0 /* module */, | 176 0 /* module */, |
| 180 &proxy::PluginDispatcher::GetBrowserInterface); | 177 &proxy::PluginDispatcher::GetBrowserInterface); |
| 181 if (error) | 178 if (error) |
| 182 ::exit(error); | 179 ::exit(error); |
| 183 | 180 |
| 184 proxy::PluginDispatcher* dispatcher = | 181 proxy::PluginDispatcher* dispatcher = |
| 185 new proxy::PluginDispatcher(::PPP_GetInterface, args.permissions, | 182 new proxy::PluginDispatcher(::PPP_GetInterface, args.permissions, |
| 186 args.off_the_record); | 183 args.off_the_record); |
| 187 IPC::ChannelHandle channel_handle( | |
| 188 "nacl", | |
| 189 base::FileDescriptor(renderer_ipc_fd_, false)); | |
| 190 if (!dispatcher->InitPluginWithChannel(this, base::kNullProcessId, | 184 if (!dispatcher->InitPluginWithChannel(this, base::kNullProcessId, |
| 191 channel_handle, false)) { | 185 renderer_ipc_handle_, false)) { |
| 192 delete dispatcher; | 186 delete dispatcher; |
| 193 return; | 187 return; |
| 194 } | 188 } |
| 195 // From here, the dispatcher will manage its own lifetime according to the | 189 // From here, the dispatcher will manage its own lifetime according to the |
| 196 // lifetime of the attached channel. | 190 // lifetime of the attached channel. |
| 197 | 191 |
| 198 // Notify the renderer process, if necessary. | 192 // Notify the renderer process, if necessary. |
| 199 ManifestService* manifest_service = GetManifestService(); | 193 ManifestService* manifest_service = GetManifestService(); |
| 200 if (manifest_service) | 194 if (manifest_service) |
| 201 manifest_service->StartupInitializationComplete(); | 195 manifest_service->StartupInitializationComplete(); |
| 202 } | 196 } |
| 203 | 197 |
| 204 void PpapiDispatcher::OnPluginDispatcherMessageReceived( | 198 void PpapiDispatcher::OnPluginDispatcherMessageReceived( |
| 205 const IPC::Message& msg) { | 199 const IPC::Message& msg) { |
| 206 // The first parameter should be a plugin dispatcher ID. | 200 // The first parameter should be a plugin dispatcher ID. |
| 207 base::PickleIterator iter(msg); | 201 base::PickleIterator iter(msg); |
| 208 uint32_t id = 0; | 202 uint32_t id = 0; |
| 209 if (!iter.ReadUInt32(&id)) { | 203 if (!iter.ReadUInt32(&id)) { |
| 210 NOTREACHED(); | 204 NOTREACHED(); |
| 211 return; | 205 return; |
| 212 } | 206 } |
| 213 std::map<uint32_t, proxy::PluginDispatcher*>::iterator dispatcher = | 207 std::map<uint32_t, proxy::PluginDispatcher*>::iterator dispatcher = |
| 214 plugin_dispatchers_.find(id); | 208 plugin_dispatchers_.find(id); |
| 215 if (dispatcher != plugin_dispatchers_.end()) | 209 if (dispatcher != plugin_dispatchers_.end()) |
| 216 dispatcher->second->OnMessageReceived(msg); | 210 dispatcher->second->OnMessageReceived(msg); |
| 217 } | 211 } |
| 218 | 212 |
| 219 } // namespace ppapi | 213 } // namespace ppapi |
| OLD | NEW |