Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: chromeos/arc/libarcbridge/arc_bridge.cc

Issue 1424503002: arc-bridge: Add IPC message definitions (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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"
6
7 #include <stdint.h>
8
9 #include <base/bind_helpers.h>
10 #include <base/files/file_util.h>
11 #include <ipc/ipc_channel.h>
12
13 #include "arc_host_messages.h"
14 #include "arc_instance_messages.h"
15
16 namespace arc {
17
18 BridgeEndpoint::BridgeEndpoint() : io_thread_("ARC bridge listener") {
19 io_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 io_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 char* 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) {
satorux1 2015/10/23 05:16:43 should this function run on the io_thread_? Then y
Luis Héctor Chávez 2015/10/23 17:09:24 No, this is supposed to be processed in the origin
satorux1 2015/10/26 01:58:52 I see. In that case, how about adding ThreadChecke
satorux1 2015/10/27 07:10:16 maybe missed this comment?
lhc(google) 2015/10/27 08:00:23 Forgot to reply, but I did add the DCHECKs that th
satorux1 2015/10/28 04:57:26 oops. I didn't noticed about the DCHECKs. thank yo
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 char* socket_path) {
70 base::FilePath path(socket_path);
satorux1 2015/10/23 05:16:43 Please use base::FilePath::FromUTF8Unsafe() for co
Luis Héctor Chávez 2015/10/23 17:09:24 Done.
71 if (!base::CreateDirectory(path.DirName()))
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
78 // user the instance will run as.
79 if (chmod(socket_path, 0777) != 0)
satorux1 2015/10/23 05:16:43 HANDLE_EINTR?
Luis Héctor Chávez 2015/10/23 17:09:24 Done.
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698