Rename GDataSystemService to DriveSystemService
[chromium-blink-merge.git] / ppapi / proxy / proxy_channel.cc
blobf5743e832ec9d0db462482c66cbaf7a65303fb87
1 // Copyright (c) 2012 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/proxy/proxy_channel.h"
7 #include "ipc/ipc_platform_file.h"
8 #include "ipc/ipc_test_sink.h"
10 namespace ppapi {
11 namespace proxy {
13 ProxyChannel::ProxyChannel()
14 : delegate_(NULL),
15 test_sink_(NULL) {
18 ProxyChannel::~ProxyChannel() {
19 DVLOG(1) << "ProxyChannel::~ProxyChannel()";
22 bool ProxyChannel::InitWithChannel(Delegate* delegate,
23 const IPC::ChannelHandle& channel_handle,
24 bool is_client) {
25 delegate_ = delegate;
26 IPC::Channel::Mode mode = is_client ? IPC::Channel::MODE_CLIENT
27 : IPC::Channel::MODE_SERVER;
28 channel_.reset(new IPC::SyncChannel(channel_handle, mode, this,
29 delegate->GetIPCMessageLoop(), true,
30 delegate->GetShutdownEvent()));
31 return true;
34 void ProxyChannel::InitWithTestSink(IPC::TestSink* test_sink) {
35 DCHECK(!test_sink_);
36 test_sink_ = test_sink;
39 void ProxyChannel::OnChannelError() {
40 channel_.reset();
43 #if defined(OS_POSIX) && !defined(OS_NACL)
44 int ProxyChannel::TakeRendererFD() {
45 DCHECK(channel());
46 return channel()->TakeClientFileDescriptor();
48 #endif
50 IPC::PlatformFileForTransit ProxyChannel::ShareHandleWithRemote(
51 base::PlatformFile handle,
52 bool should_close_source) {
53 return delegate_->ShareHandleWithRemote(handle, *channel_,
54 should_close_source);
57 bool ProxyChannel::Send(IPC::Message* msg) {
58 if (test_sink_)
59 return test_sink_->Send(msg);
60 if (channel_.get())
61 return channel_->Send(msg);
63 // Remote side crashed, drop this message.
64 delete msg;
65 return false;
68 } // namespace proxy
69 } // namespace ppapi