diff options
author | hidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-17 12:17:15 +0000 |
---|---|---|
committer | hidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-17 12:17:15 +0000 |
commit | bb86d4c372593987c16ab62d21456c4831946f1e (patch) | |
tree | 59cc18d98a0f2c112b8c2ae258599a7e50b97cb6 /ppapi | |
parent | 38f15fa3dd6e12e13d490c9630ca6ae25c9456a3 (diff) | |
download | chromium_src-bb86d4c372593987c16ab62d21456c4831946f1e.zip chromium_src-bb86d4c372593987c16ab62d21456c4831946f1e.tar.gz chromium_src-bb86d4c372593987c16ab62d21456c4831946f1e.tar.bz2 |
Add IPC Channel for new ManifestService.
This CL adds a new IPC Channel between NaCl plugin and the renderer process
with introducing ManifestService (in the plugin) and ManifestServiceChannel
(in the renderer) as its end points.
Currently, ManifestService is just an empty service. Its functions will be
added in following CLs. The service will be used only for non-SFI mode
as a first step. On other platforms, IPC Channel will not be created.
TEST=Ran trybots.
BUG=358431
Review URL: https://codereview.chromium.org/231793003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@264477 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/nacl_irt/irt_start.cc | 4 | ||||
-rw-r--r-- | ppapi/nacl_irt/manifest_service.cc | 29 | ||||
-rw-r--r-- | ppapi/nacl_irt/manifest_service.h | 41 | ||||
-rw-r--r-- | ppapi/nacl_irt/plugin_startup.cc | 48 | ||||
-rw-r--r-- | ppapi/nacl_irt/plugin_startup.h | 2 | ||||
-rw-r--r-- | ppapi/ppapi_proxy.gypi | 2 |
6 files changed, 122 insertions, 4 deletions
diff --git a/ppapi/nacl_irt/irt_start.cc b/ppapi/nacl_irt/irt_start.cc index a286737..a7c12e6 100644 --- a/ppapi/nacl_irt/irt_start.cc +++ b/ppapi/nacl_irt/irt_start.cc @@ -17,7 +17,9 @@ void nacl_irt_start(uint32_t* info) { // In SFI mode, the FDs of IPC channels are NACL_CHROME_DESC_BASE and its // successor, which is set in nacl_listener.cc. ppapi::SetIPCFileDescriptors( - NACL_CHROME_DESC_BASE, NACL_CHROME_DESC_BASE + 1); + NACL_CHROME_DESC_BASE, + NACL_CHROME_DESC_BASE + 1, + -1); // Currently manifest service is disabled on NaCl in SFI mode. ppapi::StartUpPlugin(); nacl_irt_enter_user_code(info, chrome_irt_query); diff --git a/ppapi/nacl_irt/manifest_service.cc b/ppapi/nacl_irt/manifest_service.cc new file mode 100644 index 0000000..1f2b714 --- /dev/null +++ b/ppapi/nacl_irt/manifest_service.cc @@ -0,0 +1,29 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/nacl_irt/manifest_service.h" + +#include "base/message_loop/message_loop_proxy.h" +#include "ipc/ipc_channel_handle.h" +#include "ipc/ipc_channel_proxy.h" +#include "ipc/ipc_sync_message_filter.h" + +namespace ppapi { + +ManifestService::ManifestService( + const IPC::ChannelHandle& handle, + scoped_refptr<base::MessageLoopProxy> io_message_loop, + base::WaitableEvent* shutdown_event) { + filter_ = new IPC::SyncMessageFilter(shutdown_event); + channel_.reset(new IPC::ChannelProxy(handle, + IPC::Channel::MODE_SERVER, + NULL, // Listener + io_message_loop)); + channel_->AddFilter(filter_.get()); +} + +ManifestService::~ManifestService() { +} + +} // namespace ppapi diff --git a/ppapi/nacl_irt/manifest_service.h b/ppapi/nacl_irt/manifest_service.h new file mode 100644 index 0000000..ce15add --- /dev/null +++ b/ppapi/nacl_irt/manifest_service.h @@ -0,0 +1,41 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_NACL_IRT_MANIFEST_SERVICE_H_ +#define PPAPI_NACL_IRT_MANIFEST_SERVICE_H_ + +#include "base/macros.h" +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" + +namespace base { +class MessageLoopProxy; +class WaitableEvent; +} // namespace base + +namespace IPC { +struct ChannelHandle; +class ChannelProxy; +class SyncMessageFilter; +} // namespace IPC + +namespace ppapi { + +class ManifestService { + public: + ManifestService(const IPC::ChannelHandle& handle, + scoped_refptr<base::MessageLoopProxy> io_message_loop, + base::WaitableEvent* shutdown_event); + ~ManifestService(); + + private: + scoped_ptr<IPC::ChannelProxy> channel_; + scoped_refptr<IPC::SyncMessageFilter> filter_; + + DISALLOW_COPY_AND_ASSIGN(ManifestService); +}; + +} // namespace ppapi + +#endif // PPAPI_NACL_IRT_MANIFEST_SERVICE_H_ diff --git a/ppapi/nacl_irt/plugin_startup.cc b/ppapi/nacl_irt/plugin_startup.cc index a3b5bc2..986fe32 100644 --- a/ppapi/nacl_irt/plugin_startup.cc +++ b/ppapi/nacl_irt/plugin_startup.cc @@ -2,28 +2,58 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "ppapi/nacl_irt/plugin_startup.h" + +#include "base/bind.h" +#include "base/file_descriptor_posix.h" #include "base/logging.h" #include "base/synchronization/waitable_event.h" #include "base/threading/thread.h" -#include "ppapi/nacl_irt/plugin_startup.h" +#include "ipc/ipc_channel_handle.h" +#include "ppapi/nacl_irt/manifest_service.h" namespace ppapi { namespace { int g_nacl_browser_ipc_fd = -1; int g_nacl_renderer_ipc_fd = -1; +int g_manifest_service_fd = -1; base::WaitableEvent* g_shutdown_event = NULL; base::Thread* g_io_thread = NULL; +ManifestService* g_manifest_service = NULL; + +// Creates the manifest service on IO thread so that its Listener's thread and +// IO thread are shared. Upon completion of the manifest service creation, +// event is signaled. +void StartUpManifestServiceOnIOThread(base::WaitableEvent* event) { + // The start up must be called only once. + DCHECK(!g_manifest_service); + // manifest_service_fd must be set. + DCHECK_NE(g_manifest_service_fd, -1); + // IOThread and shutdown event must be initialized in advance. + DCHECK(g_io_thread); + DCHECK(g_shutdown_event); + + g_manifest_service = new ManifestService( + IPC::ChannelHandle( + "NaCl IPC", base::FileDescriptor(g_manifest_service_fd, false)), + g_io_thread->message_loop_proxy(), + g_shutdown_event); + event->Signal(); +} } // namespace -void SetIPCFileDescriptors(int browser_ipc_fd, int renderer_ipc_fd) { +void SetIPCFileDescriptors( + int browser_ipc_fd, int renderer_ipc_fd, int manifest_service_fd) { // The initialization must be only once. DCHECK_EQ(g_nacl_browser_ipc_fd, -1); DCHECK_EQ(g_nacl_renderer_ipc_fd, -1); + DCHECK_EQ(g_manifest_service_fd, -1); g_nacl_browser_ipc_fd = browser_ipc_fd; g_nacl_renderer_ipc_fd = renderer_ipc_fd; + g_manifest_service_fd = manifest_service_fd; } void StartUpPlugin() { @@ -35,6 +65,20 @@ void StartUpPlugin() { g_io_thread = new base::Thread("Chrome_NaClIOThread"); g_io_thread->StartWithOptions( base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); + + if (g_manifest_service_fd != -1) { + // Manifest service must be created on IOThread so that the main message + // handling will be done on the thread, which has a message loop + // even before irt_ppapi_start invocation. + // TODO(hidehiko,dmichael): This works, but is probably not well designed + // usage. Once a better approach is made, replace this by that way. + // (crbug.com/364241). + base::WaitableEvent event(true, false); + g_io_thread->message_loop_proxy()->PostTask( + FROM_HERE, + base::Bind(StartUpManifestServiceOnIOThread, &event)); + event.Wait(); + } } int GetBrowserIPCFileDescriptor() { diff --git a/ppapi/nacl_irt/plugin_startup.h b/ppapi/nacl_irt/plugin_startup.h index 73c3495..15ca37e 100644 --- a/ppapi/nacl_irt/plugin_startup.h +++ b/ppapi/nacl_irt/plugin_startup.h @@ -18,7 +18,7 @@ namespace ppapi { // numbers. This will be used for non-SFI mode. Must be called before // PpapiPluginMain is called. PPAPI_PROXY_EXPORT void SetIPCFileDescriptors( - int browser_ipc_fd, int renderer_ipc_fd); + int browser_ipc_fd, int renderer_ipc_fd, int manifest_service_fd); // Runs start up procedure for the plugin. // Specifically, start background IO thread for IPC, and prepare diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi index 11eb697..f8605db6 100644 --- a/ppapi/ppapi_proxy.gypi +++ b/ppapi/ppapi_proxy.gypi @@ -247,6 +247,8 @@ 'nacl_irt/irt_ppapi.cc', 'nacl_irt/irt_ppapi.h', 'nacl_irt/irt_start.cc', + 'nacl_irt/manifest_service.cc', + 'nacl_irt/manifest_service.h', 'nacl_irt/plugin_main.cc', 'nacl_irt/plugin_main.h', 'nacl_irt/plugin_startup.cc', |