Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(473)

Side by Side Diff: ppapi/nacl_irt/plugin_startup.cc

Issue 231793003: Add IPC Channel for new ManifestService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
6
7 #include "base/bind.h"
8 #include "base/file_descriptor_posix.h"
5 #include "base/logging.h" 9 #include "base/logging.h"
6 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
7 #include "base/threading/thread.h" 11 #include "base/threading/thread.h"
8 #include "ppapi/nacl_irt/plugin_startup.h" 12 #include "ipc/ipc_channel_handle.h"
13 #include "ppapi/nacl_irt/embedder_service.h"
9 14
10 namespace ppapi { 15 namespace ppapi {
11 namespace { 16 namespace {
12 17
13 int g_nacl_browser_ipc_fd = -1; 18 int g_nacl_browser_ipc_fd = -1;
14 int g_nacl_renderer_ipc_fd = -1; 19 int g_nacl_renderer_ipc_fd = -1;
20 int g_embedder_service_fd = -1;
15 21
16 base::WaitableEvent* g_shutdown_event = NULL; 22 base::WaitableEvent* g_shutdown_event = NULL;
17 base::Thread* g_io_thread = NULL; 23 base::Thread* g_io_thread = NULL;
24 EmbedderService* g_embedder_service = NULL;
25
26 void StartUpEmbedderServiceOnIOThread(base::WaitableEvent* event) {
27 // The start up must be called only once.
28 DCHECK(!g_embedder_service);
29 // embedder_service_fd must be set.
30 DCHECK_NE(g_embedder_service_fd, -1);
31 // IOThread and shutdown event must be initialized in advance.
32 DCHECK(g_io_thread);
33 DCHECK(g_shutdown_event);
34
35 g_embedder_service = new EmbedderService(
36 IPC::ChannelHandle(
37 "NaCl IPC", base::FileDescriptor(g_embedder_service_fd, false)),
38 g_io_thread->message_loop_proxy(),
39 g_shutdown_event);
40 event->Signal();
41 }
18 42
19 } // namespace 43 } // namespace
20 44
21 void SetIPCFileDescriptors(int browser_ipc_fd, int renderer_ipc_fd) { 45 void SetIPCFileDescriptors(
46 int browser_ipc_fd, int renderer_ipc_fd, int embedder_service_fd) {
22 // The initialization must be only once. 47 // The initialization must be only once.
23 DCHECK_EQ(g_nacl_browser_ipc_fd, -1); 48 DCHECK_EQ(g_nacl_browser_ipc_fd, -1);
24 DCHECK_EQ(g_nacl_renderer_ipc_fd, -1); 49 DCHECK_EQ(g_nacl_renderer_ipc_fd, -1);
50 DCHECK_EQ(g_embedder_service_fd, -1);
25 g_nacl_browser_ipc_fd = browser_ipc_fd; 51 g_nacl_browser_ipc_fd = browser_ipc_fd;
26 g_nacl_renderer_ipc_fd = renderer_ipc_fd; 52 g_nacl_renderer_ipc_fd = renderer_ipc_fd;
53 g_embedder_service_fd = embedder_service_fd;
27 } 54 }
28 55
29 void StartUpPlugin() { 56 void StartUpPlugin() {
30 // The start up must be called only once. 57 // The start up must be called only once.
31 DCHECK(!g_shutdown_event); 58 DCHECK(!g_shutdown_event);
32 DCHECK(!g_io_thread); 59 DCHECK(!g_io_thread);
33 60
34 g_shutdown_event = new base::WaitableEvent(true, false); 61 g_shutdown_event = new base::WaitableEvent(true, false);
35 g_io_thread = new base::Thread("Chrome_NaClIOThread"); 62 g_io_thread = new base::Thread("Chrome_NaClIOThread");
36 g_io_thread->StartWithOptions( 63 g_io_thread->StartWithOptions(
37 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); 64 base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
65
66 if (g_embedder_service_fd != -1) {
67 // EmbedderService must be created on IOThread so that the main message
68 // handling will be done on the thread, which has a message loop
69 // even before irt_ppapi_start invocation.
70 base::WaitableEvent event(true, false);
71 g_io_thread->message_loop_proxy()->PostTask(
72 FROM_HERE,
73 base::Bind(StartUpEmbedderServiceOnIOThread, &event));
74 event.Wait();
75 }
38 } 76 }
39 77
40 int GetBrowserIPCFileDescriptor() { 78 int GetBrowserIPCFileDescriptor() {
41 // The descriptor must be initialized in advance. 79 // The descriptor must be initialized in advance.
42 DCHECK_NE(g_nacl_browser_ipc_fd, -1); 80 DCHECK_NE(g_nacl_browser_ipc_fd, -1);
43 return g_nacl_browser_ipc_fd; 81 return g_nacl_browser_ipc_fd;
44 } 82 }
45 83
46 int GetRendererIPCFileDescriptor() { 84 int GetRendererIPCFileDescriptor() {
47 // The descriptor must be initialized in advance. 85 // The descriptor must be initialized in advance.
48 DCHECK_NE(g_nacl_renderer_ipc_fd, -1); 86 DCHECK_NE(g_nacl_renderer_ipc_fd, -1);
49 return g_nacl_renderer_ipc_fd; 87 return g_nacl_renderer_ipc_fd;
50 } 88 }
51 89
52 base::WaitableEvent* GetShutdownEvent() { 90 base::WaitableEvent* GetShutdownEvent() {
53 // The shutdown event must be initialized in advance. 91 // The shutdown event must be initialized in advance.
54 DCHECK(g_shutdown_event); 92 DCHECK(g_shutdown_event);
55 return g_shutdown_event; 93 return g_shutdown_event;
56 } 94 }
57 95
58 base::Thread* GetIOThread() { 96 base::Thread* GetIOThread() {
59 // The IOThread must be initialized in advance. 97 // The IOThread must be initialized in advance.
60 DCHECK(g_io_thread); 98 DCHECK(g_io_thread);
61 return g_io_thread; 99 return g_io_thread;
62 } 100 }
63 101
64 } // namespace ppapi 102 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698