| 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/plugin_startup.h" | 5 #include "ppapi/nacl_irt/plugin_startup.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_descriptor_posix.h" | 8 #include "base/file_descriptor_posix.h" |
| 9 #include "base/location.h" |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/single_thread_task_runner.h" |
| 10 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
| 11 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 12 #include "ipc/ipc_channel_handle.h" | 14 #include "ipc/ipc_channel_handle.h" |
| 13 #include "ppapi/nacl_irt/manifest_service.h" | 15 #include "ppapi/nacl_irt/manifest_service.h" |
| 14 #include "ppapi/shared_impl/ppb_audio_shared.h" | 16 #include "ppapi/shared_impl/ppb_audio_shared.h" |
| 15 | 17 |
| 16 namespace ppapi { | 18 namespace ppapi { |
| 17 namespace { | 19 namespace { |
| 18 | 20 |
| 19 int g_nacl_browser_ipc_fd = -1; | 21 int g_nacl_browser_ipc_fd = -1; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 30 void StartUpManifestServiceOnIOThread(base::WaitableEvent* event) { | 32 void StartUpManifestServiceOnIOThread(base::WaitableEvent* event) { |
| 31 // The start up must be called only once. | 33 // The start up must be called only once. |
| 32 DCHECK(!g_manifest_service); | 34 DCHECK(!g_manifest_service); |
| 33 // manifest_service_fd must be set. | 35 // manifest_service_fd must be set. |
| 34 DCHECK_NE(g_manifest_service_fd, -1); | 36 DCHECK_NE(g_manifest_service_fd, -1); |
| 35 // IOThread and shutdown event must be initialized in advance. | 37 // IOThread and shutdown event must be initialized in advance. |
| 36 DCHECK(g_io_thread); | 38 DCHECK(g_io_thread); |
| 37 DCHECK(g_shutdown_event); | 39 DCHECK(g_shutdown_event); |
| 38 | 40 |
| 39 g_manifest_service = new ManifestService( | 41 g_manifest_service = new ManifestService( |
| 40 IPC::ChannelHandle( | 42 IPC::ChannelHandle("NaCl IPC", |
| 41 "NaCl IPC", base::FileDescriptor(g_manifest_service_fd, false)), | 43 base::FileDescriptor(g_manifest_service_fd, false)), |
| 42 g_io_thread->message_loop_proxy(), | 44 g_io_thread->task_runner(), g_shutdown_event); |
| 43 g_shutdown_event); | |
| 44 event->Signal(); | 45 event->Signal(); |
| 45 } | 46 } |
| 46 | 47 |
| 47 } // namespace | 48 } // namespace |
| 48 | 49 |
| 49 void SetIPCFileDescriptors( | 50 void SetIPCFileDescriptors( |
| 50 int browser_ipc_fd, int renderer_ipc_fd, int manifest_service_fd) { | 51 int browser_ipc_fd, int renderer_ipc_fd, int manifest_service_fd) { |
| 51 // The initialization must be only once. | 52 // The initialization must be only once. |
| 52 DCHECK_EQ(g_nacl_browser_ipc_fd, -1); | 53 DCHECK_EQ(g_nacl_browser_ipc_fd, -1); |
| 53 DCHECK_EQ(g_nacl_renderer_ipc_fd, -1); | 54 DCHECK_EQ(g_nacl_renderer_ipc_fd, -1); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 68 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 69 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
| 69 | 70 |
| 70 if (g_manifest_service_fd != -1) { | 71 if (g_manifest_service_fd != -1) { |
| 71 // Manifest service must be created on IOThread so that the main message | 72 // Manifest service must be created on IOThread so that the main message |
| 72 // handling will be done on the thread, which has a message loop | 73 // handling will be done on the thread, which has a message loop |
| 73 // even before irt_ppapi_start invocation. | 74 // even before irt_ppapi_start invocation. |
| 74 // TODO(hidehiko,dmichael): This works, but is probably not well designed | 75 // TODO(hidehiko,dmichael): This works, but is probably not well designed |
| 75 // usage. Once a better approach is made, replace this by that way. | 76 // usage. Once a better approach is made, replace this by that way. |
| 76 // (crbug.com/364241). | 77 // (crbug.com/364241). |
| 77 base::WaitableEvent event(true, false); | 78 base::WaitableEvent event(true, false); |
| 78 g_io_thread->message_loop_proxy()->PostTask( | 79 g_io_thread->task_runner()->PostTask( |
| 79 FROM_HERE, | 80 FROM_HERE, base::Bind(StartUpManifestServiceOnIOThread, &event)); |
| 80 base::Bind(StartUpManifestServiceOnIOThread, &event)); | |
| 81 event.Wait(); | 81 event.Wait(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 PPB_Audio_Shared::SetNaClMode(); | 84 PPB_Audio_Shared::SetNaClMode(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 int GetBrowserIPCFileDescriptor() { | 87 int GetBrowserIPCFileDescriptor() { |
| 88 // The descriptor must be initialized in advance. | 88 // The descriptor must be initialized in advance. |
| 89 DCHECK_NE(g_nacl_browser_ipc_fd, -1); | 89 DCHECK_NE(g_nacl_browser_ipc_fd, -1); |
| 90 return g_nacl_browser_ipc_fd; | 90 return g_nacl_browser_ipc_fd; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 106 // The IOThread must be initialized in advance. | 106 // The IOThread must be initialized in advance. |
| 107 DCHECK(g_io_thread); | 107 DCHECK(g_io_thread); |
| 108 return g_io_thread; | 108 return g_io_thread; |
| 109 } | 109 } |
| 110 | 110 |
| 111 ManifestService* GetManifestService() { | 111 ManifestService* GetManifestService() { |
| 112 return g_manifest_service; | 112 return g_manifest_service; |
| 113 } | 113 } |
| 114 | 114 |
| 115 } // namespace ppapi | 115 } // namespace ppapi |
| OLD | NEW |