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

Unified Diff: chromeos/binder/ipc_thread.cc

Issue 1575313002: Add CommandBroker::OnTransaction to handle incoming transactions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add comment Created 4 years, 11 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
« no previous file with comments | « chromeos/binder/ipc_thread.h ('k') | chromeos/binder/test_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/binder/ipc_thread.cc
diff --git a/chromeos/binder/ipc_thread.cc b/chromeos/binder/ipc_thread.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7fe92c8503742215becec1d0f7f841092eb74993
--- /dev/null
+++ b/chromeos/binder/ipc_thread.cc
@@ -0,0 +1,71 @@
+// 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 "chromeos/binder/ipc_thread.h"
+
+#include "chromeos/binder/command_broker.h"
+#include "chromeos/binder/driver.h"
+
+namespace binder {
+
+IpcThread::IpcThread()
+ : base::Thread("BinderThread"),
+ driver_(new Driver()),
+ watcher_(new base::MessageLoopForIO::FileDescriptorWatcher()) {}
+
+IpcThread::~IpcThread() {
+ Stop();
+}
+
+bool IpcThread::Start() {
+ DCHECK(!initialized_);
+ base::Thread::Options options;
+ options.message_loop_type = base::MessageLoop::TYPE_IO;
+ return StartWithOptions(options);
+}
+
+void IpcThread::OnFileCanReadWithoutBlocking(int fd) {
+ DCHECK(initialized_);
+ bool success = command_broker_->PollCommands();
+ LOG_IF(ERROR, !success) << "PollCommands() failed.";
+}
+
+void IpcThread::OnFileCanWriteWithoutBlocking(int fd) {
+ NOTREACHED();
+}
+
+void IpcThread::Init() {
+ DCHECK(!initialized_);
+ if (!driver_->Initialize()) {
+ LOG(ERROR) << "Failed to initialize driver.";
+ return;
+ }
+ command_broker_.reset(new CommandBroker(driver_.get()));
+ if (!command_broker_->EnterLooper()) {
+ LOG(ERROR) << "Failed to enter looper.";
+ return;
+ }
+ if (!base::MessageLoopForIO::current()->WatchFileDescriptor(
+ driver_->GetFD(), true, base::MessageLoopForIO::WATCH_READ,
+ watcher_.get(), this)) {
+ LOG(ERROR) << "Failed to initialize watcher.";
+ return;
+ }
+ initialized_ = true;
+}
+
+void IpcThread::CleanUp() {
+ DCHECK(initialized_);
+ if (!command_broker_->ExitLooper()) {
+ LOG(ERROR) << "Failed to exit looper.";
+ }
+ if (!driver_->NotifyCurrentThreadExiting()) {
+ LOG(ERROR) << "Failed to send thread exit.";
+ }
+ watcher_.reset();
+ command_broker_.reset();
+ driver_.reset();
+}
+
+} // namespace binder
« no previous file with comments | « chromeos/binder/ipc_thread.h ('k') | chromeos/binder/test_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698