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

Unified Diff: chromeos/arc/bridge/common/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: Renamed libarcbridge=>bridge/common and addressed feedback Created 5 years, 2 months 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 side-by-side diff with in-line comments
Download patch
Index: chromeos/arc/bridge/common/arc_bridge.cc
diff --git a/chromeos/arc/bridge/common/arc_bridge.cc b/chromeos/arc/bridge/common/arc_bridge.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9c405ad844a44b9278f8a8a766d84750969cd776
--- /dev/null
+++ b/chromeos/arc/bridge/common/arc_bridge.cc
@@ -0,0 +1,102 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#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
+
+#include <stdint.h>
+
+#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.
+#include <base/files/file_util.h>
+#include <ipc/ipc_channel.h>
+
+#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
+#include "arc_instance_messages.h"
+
+namespace arc {
+
+BridgeEndpoint::BridgeEndpoint() : ipc_thread_("ARC bridge listener") {
+ ipc_thread_.StartWithOptions(
+ base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
+}
+
+BridgeEndpoint::~BridgeEndpoint() {}
+
+bool BridgeEndpoint::Connect(const IPC::ChannelHandle& handle,
+ IPC::Channel::Mode mode) {
+ channel_ = IPC::ChannelProxy::Create(handle, mode, this,
+ ipc_thread_.task_runner().get());
+ if (!channel_)
+ return false;
+
+ return true;
+}
+
+BridgeInstanceEndpoint::BridgeInstanceEndpoint() : BridgeEndpoint() {}
+
+BridgeInstanceEndpoint::~BridgeInstanceEndpoint() {}
+
+bool BridgeInstanceEndpoint::SocketConnect(const std::string& socket_path) {
+ return BridgeEndpoint::Connect(IPC::ChannelHandle(socket_path),
+ IPC::Channel::MODE_NAMED_CLIENT);
+}
+
+bool BridgeInstanceEndpoint::InstanceReady() {
+ return channel_->Send(new ArcHostMsg_InstanceReady());
+}
+
+bool BridgeInstanceEndpoint::OnMessageReceived(const IPC::Message& message) {
+ bool handled = true;
+
+ IPC_BEGIN_MESSAGE_MAP(BridgeInstanceEndpoint, message)
+ IPC_MESSAGE_HANDLER(ArcInstanceMsg_Ping, OnPing)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+
+ if (!handled)
+ LOG(ERROR) << "Invalid message with type = " << message.type();
+ return handled;
+}
+
+void BridgeInstanceEndpoint::OnPing() {
+ channel_->Send(new ArcHostMsg_Pong());
+}
+
+BridgeHostEndpoint::BridgeHostEndpoint() : BridgeEndpoint() {}
+
+BridgeHostEndpoint::~BridgeHostEndpoint() {}
+
+bool BridgeHostEndpoint::SocketConnect(const std::string& socket_path) {
+ base::FilePath path = base::FilePath::FromUTF8Unsafe(socket_path);
+ 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
+ return false;
+
+ if (!BridgeEndpoint::Connect(IPC::ChannelHandle(path.value()),
+ IPC::Channel::MODE_OPEN_NAMED_SERVER))
+ return false;
+ // 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
+ // user the instance will run as.
+ if (HANDLE_EINTR(chmod(socket_path.c_str(), 0777)) != 0)
+ return false;
+ return true;
+}
+
+bool BridgeHostEndpoint::Ping() {
+ return channel_->Send(new ArcInstanceMsg_Ping());
+}
+
+bool BridgeHostEndpoint::OnMessageReceived(const IPC::Message& message) {
+ bool handled = true;
+
+ IPC_BEGIN_MESSAGE_MAP(BridgeHostEndpoint, message)
+ IPC_MESSAGE_HANDLER(ArcHostMsg_Pong, OnPong)
+ IPC_MESSAGE_HANDLER(ArcHostMsg_InstanceReady, OnInstanceReady)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+
+ if (!handled)
+ LOG(ERROR) << "Invalid message with type = " << message.type();
+ return handled;
+}
+
+} // namespace arc

Powered by Google App Engine
This is Rietveld 408576698