Correctly reset theme color on NTP.
[chromium-blink-merge.git] / ppapi / nacl_irt / plugin_startup.cc
blob338f524608f767035087d3c207e8445fdc32d1da
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
3 // found in the LICENSE file.
5 #include "ppapi/nacl_irt/plugin_startup.h"
7 #include "base/bind.h"
8 #include "base/file_descriptor_posix.h"
9 #include "base/location.h"
10 #include "base/logging.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/synchronization/waitable_event.h"
13 #include "base/threading/thread.h"
14 #include "ipc/ipc_channel_handle.h"
15 #include "ppapi/nacl_irt/manifest_service.h"
16 #include "ppapi/shared_impl/ppb_audio_shared.h"
18 namespace ppapi {
19 namespace {
21 int g_nacl_browser_ipc_fd = -1;
22 int g_nacl_renderer_ipc_fd = -1;
23 int g_manifest_service_fd = -1;
25 base::WaitableEvent* g_shutdown_event = NULL;
26 base::Thread* g_io_thread = NULL;
27 ManifestService* g_manifest_service = NULL;
29 // Creates the manifest service on IO thread so that its Listener's thread and
30 // IO thread are shared. Upon completion of the manifest service creation,
31 // event is signaled.
32 void StartUpManifestServiceOnIOThread(base::WaitableEvent* event) {
33 // The start up must be called only once.
34 DCHECK(!g_manifest_service);
35 // manifest_service_fd must be set.
36 DCHECK_NE(g_manifest_service_fd, -1);
37 // IOThread and shutdown event must be initialized in advance.
38 DCHECK(g_io_thread);
39 DCHECK(g_shutdown_event);
41 g_manifest_service = new ManifestService(
42 IPC::ChannelHandle("NaCl IPC",
43 base::FileDescriptor(g_manifest_service_fd, false)),
44 g_io_thread->task_runner(), g_shutdown_event);
45 event->Signal();
48 } // namespace
50 void SetIPCFileDescriptors(
51 int browser_ipc_fd, int renderer_ipc_fd, int manifest_service_fd) {
52 // The initialization must be only once.
53 DCHECK_EQ(g_nacl_browser_ipc_fd, -1);
54 DCHECK_EQ(g_nacl_renderer_ipc_fd, -1);
55 DCHECK_EQ(g_manifest_service_fd, -1);
56 g_nacl_browser_ipc_fd = browser_ipc_fd;
57 g_nacl_renderer_ipc_fd = renderer_ipc_fd;
58 g_manifest_service_fd = manifest_service_fd;
61 void StartUpPlugin() {
62 // The start up must be called only once.
63 DCHECK(!g_shutdown_event);
64 DCHECK(!g_io_thread);
66 g_shutdown_event = new base::WaitableEvent(true, false);
67 g_io_thread = new base::Thread("Chrome_NaClIOThread");
68 g_io_thread->StartWithOptions(
69 base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
71 if (g_manifest_service_fd != -1) {
72 // Manifest service must be created on IOThread so that the main message
73 // handling will be done on the thread, which has a message loop
74 // even before irt_ppapi_start invocation.
75 // TODO(hidehiko,dmichael): This works, but is probably not well designed
76 // usage. Once a better approach is made, replace this by that way.
77 // (crbug.com/364241).
78 base::WaitableEvent event(true, false);
79 g_io_thread->task_runner()->PostTask(
80 FROM_HERE, base::Bind(StartUpManifestServiceOnIOThread, &event));
81 event.Wait();
84 PPB_Audio_Shared::SetNaClMode();
87 int GetBrowserIPCFileDescriptor() {
88 // The descriptor must be initialized in advance.
89 DCHECK_NE(g_nacl_browser_ipc_fd, -1);
90 return g_nacl_browser_ipc_fd;
93 int GetRendererIPCFileDescriptor() {
94 // The descriptor must be initialized in advance.
95 DCHECK_NE(g_nacl_renderer_ipc_fd, -1);
96 return g_nacl_renderer_ipc_fd;
99 base::WaitableEvent* GetShutdownEvent() {
100 // The shutdown event must be initialized in advance.
101 DCHECK(g_shutdown_event);
102 return g_shutdown_event;
105 base::Thread* GetIOThread() {
106 // The IOThread must be initialized in advance.
107 DCHECK(g_io_thread);
108 return g_io_thread;
111 ManifestService* GetManifestService() {
112 return g_manifest_service;
115 } // namespace ppapi