Chromium Code Reviews| 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 #include "components/nacl/common/nacl_messages.h" | |
| 9 | |
| 10 namespace { | |
| 11 | |
| 12 NaClTrustedListener* g_trusted_listener; | |
| 13 | |
| 14 } // namespace | |
| 8 | 15 |
| 9 NaClTrustedListener::NaClTrustedListener( | 16 NaClTrustedListener::NaClTrustedListener( |
| 10 const IPC::ChannelHandle& handle, | 17 const IPC::ChannelHandle& handle, |
| 11 base::SingleThreadTaskRunner* ipc_task_runner) { | 18 base::SingleThreadTaskRunner* ipc_task_runner) |
| 19 : ipc_task_runner_(ipc_task_runner), | |
| 20 waitable_event_(true, false), | |
| 21 send_fatal_crash_log_called_(false) { | |
| 12 channel_proxy_ = IPC::ChannelProxy::Create( | 22 channel_proxy_ = IPC::ChannelProxy::Create( |
| 13 handle, | 23 handle, |
| 14 IPC::Channel::MODE_SERVER, | 24 IPC::Channel::MODE_SERVER, |
| 15 this, | 25 this, |
| 16 ipc_task_runner).Pass(); | 26 ipc_task_runner).Pass(); |
| 27 g_trusted_listener = this; | |
| 17 } | 28 } |
| 18 | 29 |
| 19 NaClTrustedListener::~NaClTrustedListener() { | 30 NaClTrustedListener::~NaClTrustedListener() { |
| 31 g_trusted_listener = NULL; | |
| 20 } | 32 } |
| 21 | 33 |
| 22 #if defined(OS_POSIX) | 34 #if defined(OS_POSIX) |
| 23 int NaClTrustedListener::TakeClientFileDescriptor() { | 35 int NaClTrustedListener::TakeClientFileDescriptor() { |
| 24 return channel_proxy_->TakeClientFileDescriptor(); | 36 return channel_proxy_->TakeClientFileDescriptor(); |
| 25 } | 37 } |
| 26 #endif | 38 #endif |
| 27 | 39 |
| 28 bool NaClTrustedListener::OnMessageReceived(const IPC::Message& msg) { | 40 bool NaClTrustedListener::OnMessageReceived(const IPC::Message& msg) { |
| 29 return false; | 41 return false; |
| 30 } | 42 } |
| 31 | 43 |
| 32 void NaClTrustedListener::OnChannelError() { | 44 void NaClTrustedListener::OnChannelError() { |
| 33 channel_proxy_->Close(); | 45 channel_proxy_->Close(); |
| 34 } | 46 } |
| 35 | 47 |
| 36 bool NaClTrustedListener::Send(IPC::Message* msg) { | 48 bool NaClTrustedListener::Send(IPC::Message* msg) { |
| 49 DCHECK(msg->type() != NaClProcessHostMsg_FatalLogReceived::ID); | |
| 50 | |
| 37 return channel_proxy_->Send(msg); | 51 return channel_proxy_->Send(msg); |
| 38 } | 52 } |
| 53 | |
| 54 bool NaClTrustedListener::SendFatalCrashLog(const std::string& log) { | |
| 55 DCHECK(!send_fatal_crash_log_called_); | |
| 56 send_fatal_crash_log_called_ = true; | |
| 57 | |
| 58 Send(new NaClProcessHostMsg_FatalLogReceived(log)); | |
| 59 ipc_task_runner_->PostTask( | |
|
Mark Seaborn
2014/07/30 22:23:26
So ipc_task_runner is io_thread_.message_loop_prox
| |
| 60 FROM_HERE, | |
| 61 base::Bind(&NaClTrustedListener::SignalIpcTaskRunnerFlushed, this)); | |
| 62 // Give the IPC task runner 50ms to try to send the fatal log message. | |
| 63 return waitable_event_.TimedWait(base::TimeDelta::FromMilliseconds(50)); | |
|
dmichael (off chromium)
2014/07/30 21:17:48
nit: Might make sense to name waitable_event_ more
| |
| 64 } | |
| 65 | |
| 66 void NaClTrustedListener::SignalIpcTaskRunnerFlushed() { | |
| 67 waitable_event_.Signal(); | |
| 68 } | |
| 69 | |
| 70 NaClTrustedListener* NaClTrustedListener::Get() { | |
| 71 return g_trusted_listener; | |
| 72 } | |
| OLD | NEW |