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 "components/nacl/loader/nacl_trusted_listener.h" | 5 #include "components/nacl/loader/nacl_trusted_listener.h" |
6 | 6 |
7 #include "base/single_thread_task_runner.h" | 7 #include "base/single_thread_task_runner.h" |
8 | 8 |
9 namespace { | |
10 | |
11 NaClTrustedListener* g_trusted_listener; | |
12 | |
13 } // namespace | |
14 | |
9 NaClTrustedListener::NaClTrustedListener( | 15 NaClTrustedListener::NaClTrustedListener( |
10 const IPC::ChannelHandle& handle, | 16 const IPC::ChannelHandle& handle, |
11 base::SingleThreadTaskRunner* ipc_task_runner) { | 17 base::SingleThreadTaskRunner* ipc_task_runner) |
18 : ipc_task_runner_(ipc_task_runner), | |
19 waitable_event_(true, false) { | |
12 channel_proxy_ = IPC::ChannelProxy::Create( | 20 channel_proxy_ = IPC::ChannelProxy::Create( |
13 handle, | 21 handle, |
14 IPC::Channel::MODE_SERVER, | 22 IPC::Channel::MODE_SERVER, |
15 this, | 23 this, |
16 ipc_task_runner).Pass(); | 24 ipc_task_runner).Pass(); |
25 g_trusted_listener = this; | |
17 } | 26 } |
18 | 27 |
19 NaClTrustedListener::~NaClTrustedListener() { | 28 NaClTrustedListener::~NaClTrustedListener() { |
29 g_trusted_listener = NULL; | |
20 } | 30 } |
21 | 31 |
22 #if defined(OS_POSIX) | 32 #if defined(OS_POSIX) |
23 int NaClTrustedListener::TakeClientFileDescriptor() { | 33 int NaClTrustedListener::TakeClientFileDescriptor() { |
24 return channel_proxy_->TakeClientFileDescriptor(); | 34 return channel_proxy_->TakeClientFileDescriptor(); |
25 } | 35 } |
26 #endif | 36 #endif |
27 | 37 |
28 bool NaClTrustedListener::OnMessageReceived(const IPC::Message& msg) { | 38 bool NaClTrustedListener::OnMessageReceived(const IPC::Message& msg) { |
29 return false; | 39 return false; |
30 } | 40 } |
31 | 41 |
32 void NaClTrustedListener::OnChannelError() { | 42 void NaClTrustedListener::OnChannelError() { |
33 channel_proxy_->Close(); | 43 channel_proxy_->Close(); |
34 } | 44 } |
35 | 45 |
36 bool NaClTrustedListener::Send(IPC::Message* msg) { | 46 bool NaClTrustedListener::Send(IPC::Message* msg) { |
37 return channel_proxy_->Send(msg); | 47 return channel_proxy_->Send(msg); |
38 } | 48 } |
49 | |
50 bool NaClTrustedListener::FlushIpcTaskRunner(const base::TimeDelta& time) { | |
51 waitable_event_.Reset(); | |
dmichael (off chromium)
2014/07/30 20:18:52
Note, if there's ever a second caller to this meth
| |
52 ipc_task_runner_->PostTask( | |
53 FROM_HERE, | |
54 base::Bind(&NaClTrustedListener::SignalIpcTaskRunnerFlushed, this)); | |
55 return waitable_event_.TimedWait(time); | |
56 } | |
57 | |
58 void NaClTrustedListener::SignalIpcTaskRunnerFlushed() { | |
59 waitable_event_.Signal(); | |
60 } | |
61 | |
62 NaClTrustedListener* NaClTrustedListener::Get() { | |
63 return g_trusted_listener; | |
64 } | |
OLD | NEW |