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