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.
4
5#include "components/nacl/loader/nacl_trusted_listener.h"
6
7#include "base/single_thread_task_runner.h"
8
9NaClTrustedListener::NaClTrustedListener(
10    const IPC::ChannelHandle& handle,
11    base::SingleThreadTaskRunner* ipc_task_runner,
12    base::WaitableEvent* shutdown_event)
13    : channel_handle_(handle) {
14  channel_ = IPC::SyncChannel::Create(handle,
15                                      IPC::Channel::MODE_SERVER,
16                                      this,
17                                      ipc_task_runner,
18                                      true,  /* create_channel_now */
19                                      shutdown_event).Pass();
20}
21
22NaClTrustedListener::~NaClTrustedListener() {
23}
24
25IPC::ChannelHandle NaClTrustedListener::TakeClientChannelHandle() {
26  IPC::ChannelHandle handle = channel_handle_;
27#if defined(OS_POSIX)
28  handle.socket =
29      base::FileDescriptor(channel_->TakeClientFileDescriptor(), true);
30#endif
31  return handle;
32}
33
34bool NaClTrustedListener::OnMessageReceived(const IPC::Message& msg) {
35  return false;
36}
37
38void NaClTrustedListener::OnChannelError() {
39  channel_->Close();
40}
41
42bool NaClTrustedListener::Send(IPC::Message* msg) {
43  return channel_->Send(msg);
44}
45