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

Side by Side 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: Address comments 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 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 "chromeos/binder/ipc_thread.h"
6
7 #include "chromeos/binder/command_broker.h"
8 #include "chromeos/binder/driver.h"
9
10 namespace binder {
11
12 IpcThread::IpcThread()
13 : base::Thread("BinderThread"),
14 driver_(new Driver()),
15 watcher_(new base::MessageLoopForIO::FileDescriptorWatcher()) {}
16
17 IpcThread::~IpcThread() {
18 Stop();
19 }
20
21 bool IpcThread::Start() {
22 DCHECK(!initialized_);
23 base::Thread::Options options;
24 options.message_loop_type = base::MessageLoop::TYPE_IO;
25 return StartWithOptions(options);
26 }
27
28 void IpcThread::OnFileCanReadWithoutBlocking(int fd) {
29 DCHECK(initialized_);
30 bool success = command_broker_->PollCommands();
31 LOG_IF(ERROR, !success) << "PollCommands() failed.";
32 }
33
34 void IpcThread::OnFileCanWriteWithoutBlocking(int fd) {
35 NOTREACHED();
36 }
37
38 void IpcThread::Init() {
39 DCHECK(!initialized_);
40 if (!driver_->Initialize()) {
41 LOG(ERROR) << "Failed to initialize driver.";
42 return;
43 }
44 command_broker_.reset(new CommandBroker(driver_.get()));
45 if (!command_broker_->EnterLooper()) {
46 LOG(ERROR) << "Failed to enter looper.";
47 return;
48 }
49 if (!base::MessageLoopForIO::current()->WatchFileDescriptor(
50 driver_->GetFD(), true, base::MessageLoopForIO::WATCH_READ,
51 watcher_.get(), this)) {
52 LOG(ERROR) << "Failed to initialize watcher.";
53 return;
54 }
55 initialized_ = true;
56 }
57
58 void IpcThread::CleanUp() {
59 DCHECK(initialized_);
60 if (!command_broker_->ExitLooper()) {
61 LOG(ERROR) << "Failed to exit looper.";
62 }
63 if (!driver_->NotifyCurrentThreadExiting()) {
64 LOG(ERROR) << "Failed to send thread exit.";
65 }
66 watcher_.reset();
67 command_broker_.reset();
68 driver_.reset();
69 }
70
71 } // namespace binder
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698