Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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 "arc_bridge.h" | |
|
hidehiko
2015/10/26 09:15:00
nit: IIUC, probably we should use
#include "chrome
Luis Héctor Chávez
2015/10/26 21:03:27
This code should be able to be built from within A
satorux1
2015/10/27 07:10:16
The relative paths look worrisome to me. tools/git
Shuhei Takahashi
2015/10/27 07:14:25
Maybe this is another reason to avoid having ArcBr
lhc(google)
2015/10/27 08:00:23
Yes, it would be very difficult to compile this co
| |
| 6 | |
| 7 #include <stdint.h> | |
| 8 | |
| 9 #include <base/bind_helpers.h> | |
|
hidehiko
2015/10/26 09:15:00
nit: #include "base/bind_helpers.h"
Ditto for belo
Luis Héctor Chávez
2015/10/26 21:03:27
Done.
| |
| 10 #include <base/files/file_util.h> | |
| 11 #include <ipc/ipc_channel.h> | |
| 12 | |
| 13 #include "arc_host_messages.h" | |
|
hidehiko
2015/10/26 09:15:00
ditto. And sort in lexicographical order (with mix
Luis Héctor Chávez
2015/10/26 21:03:27
Since we can't use the full path, I'm a bit wary o
| |
| 14 #include "arc_instance_messages.h" | |
| 15 | |
| 16 namespace arc { | |
| 17 | |
| 18 BridgeEndpoint::BridgeEndpoint() : ipc_thread_("ARC bridge listener") { | |
| 19 ipc_thread_.StartWithOptions( | |
| 20 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | |
| 21 } | |
| 22 | |
| 23 BridgeEndpoint::~BridgeEndpoint() {} | |
| 24 | |
| 25 bool BridgeEndpoint::Connect(const IPC::ChannelHandle& handle, | |
| 26 IPC::Channel::Mode mode) { | |
| 27 channel_ = IPC::ChannelProxy::Create(handle, mode, this, | |
| 28 ipc_thread_.task_runner().get()); | |
| 29 if (!channel_) | |
| 30 return false; | |
| 31 | |
| 32 return true; | |
| 33 } | |
| 34 | |
| 35 BridgeInstanceEndpoint::BridgeInstanceEndpoint() : BridgeEndpoint() {} | |
| 36 | |
| 37 BridgeInstanceEndpoint::~BridgeInstanceEndpoint() {} | |
| 38 | |
| 39 bool BridgeInstanceEndpoint::SocketConnect(const std::string& socket_path) { | |
| 40 return BridgeEndpoint::Connect(IPC::ChannelHandle(socket_path), | |
| 41 IPC::Channel::MODE_NAMED_CLIENT); | |
| 42 } | |
| 43 | |
| 44 bool BridgeInstanceEndpoint::InstanceReady() { | |
| 45 return channel_->Send(new ArcHostMsg_InstanceReady()); | |
| 46 } | |
| 47 | |
| 48 bool BridgeInstanceEndpoint::OnMessageReceived(const IPC::Message& message) { | |
| 49 bool handled = true; | |
| 50 | |
| 51 IPC_BEGIN_MESSAGE_MAP(BridgeInstanceEndpoint, message) | |
| 52 IPC_MESSAGE_HANDLER(ArcInstanceMsg_Ping, OnPing) | |
| 53 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 54 IPC_END_MESSAGE_MAP() | |
| 55 | |
| 56 if (!handled) | |
| 57 LOG(ERROR) << "Invalid message with type = " << message.type(); | |
| 58 return handled; | |
| 59 } | |
| 60 | |
| 61 void BridgeInstanceEndpoint::OnPing() { | |
| 62 channel_->Send(new ArcHostMsg_Pong()); | |
| 63 } | |
| 64 | |
| 65 BridgeHostEndpoint::BridgeHostEndpoint() : BridgeEndpoint() {} | |
| 66 | |
| 67 BridgeHostEndpoint::~BridgeHostEndpoint() {} | |
| 68 | |
| 69 bool BridgeHostEndpoint::SocketConnect(const std::string& socket_path) { | |
| 70 base::FilePath path = base::FilePath::FromUTF8Unsafe(socket_path); | |
| 71 if (!base::CreateDirectory(path.DirName())) | |
|
hidehiko
2015/10/26 09:15:00
Clarification: Which thread will this be invoked o
Shuhei Takahashi
2015/10/26 11:13:40
And one more question: Is this really needed for o
Luis Héctor Chávez
2015/10/26 21:03:27
This is run on the browser main thread. I'll add a
| |
| 72 return false; | |
| 73 | |
| 74 if (!BridgeEndpoint::Connect(IPC::ChannelHandle(path.value()), | |
| 75 IPC::Channel::MODE_OPEN_NAMED_SERVER)) | |
| 76 return false; | |
| 77 // TODO(lhchavez): Tighten the security around the socket by tying it to the | |
|
Shuhei Takahashi
2015/10/26 11:13:40
Maybe better to file a bug so we don't remember to
| |
| 78 // user the instance will run as. | |
| 79 if (HANDLE_EINTR(chmod(socket_path.c_str(), 0777)) != 0) | |
| 80 return false; | |
| 81 return true; | |
| 82 } | |
| 83 | |
| 84 bool BridgeHostEndpoint::Ping() { | |
| 85 return channel_->Send(new ArcInstanceMsg_Ping()); | |
| 86 } | |
| 87 | |
| 88 bool BridgeHostEndpoint::OnMessageReceived(const IPC::Message& message) { | |
| 89 bool handled = true; | |
| 90 | |
| 91 IPC_BEGIN_MESSAGE_MAP(BridgeHostEndpoint, message) | |
| 92 IPC_MESSAGE_HANDLER(ArcHostMsg_Pong, OnPong) | |
| 93 IPC_MESSAGE_HANDLER(ArcHostMsg_InstanceReady, OnInstanceReady) | |
| 94 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 95 IPC_END_MESSAGE_MAP() | |
| 96 | |
| 97 if (!handled) | |
| 98 LOG(ERROR) << "Invalid message with type = " << message.type(); | |
| 99 return handled; | |
| 100 } | |
| 101 | |
| 102 } // namespace arc | |
| OLD | NEW |