OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 "remoting/host/daemon_process.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" |
| 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/threading/thread.h" |
| 11 |
| 12 namespace { |
| 13 |
| 14 const char kIpcThreadName[] = "Daemon process IPC"; |
| 15 |
| 16 } // namespace |
| 17 |
| 18 namespace remoting { |
| 19 |
| 20 DaemonProcess::~DaemonProcess() { |
| 21 } |
| 22 |
| 23 bool DaemonProcess::OnMessageReceived(const IPC::Message& message) { |
| 24 return true; |
| 25 } |
| 26 |
| 27 DaemonProcess::DaemonProcess( |
| 28 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 29 const Shutdownable::Callback& callback) |
| 30 : Shutdownable(main_task_runner, callback), |
| 31 main_task_runner_(main_task_runner) { |
| 32 // Initialize on the same thread that will be used for shutting down. |
| 33 main_task_runner_->PostTask( |
| 34 FROM_HERE, |
| 35 base::Bind(&DaemonProcess::Init, base::Unretained(this))); |
| 36 } |
| 37 |
| 38 void DaemonProcess::Init() { |
| 39 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 40 |
| 41 // Launch the IPC thread. |
| 42 ipc_thread_.reset(new base::Thread(kIpcThreadName)); |
| 43 base::Thread::Options io_thread_options(MessageLoop::TYPE_IO, 0); |
| 44 if (!ipc_thread_->StartWithOptions(io_thread_options)) { |
| 45 LOG(ERROR) << "Failed to start the Daemon process IPC thread."; |
| 46 Shutdown(); |
| 47 return; |
| 48 } |
| 49 |
| 50 if (!LaunchNetworkProcess()) { |
| 51 LOG(ERROR) << "Failed to launch the networking process."; |
| 52 Shutdown(); |
| 53 return; |
| 54 } |
| 55 } |
| 56 |
| 57 void DaemonProcess::DoShutdown() { |
| 58 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 59 |
| 60 if (ipc_thread_.get()) { |
| 61 ipc_thread_->Stop(); |
| 62 } |
| 63 |
| 64 CompleteShutdown(); |
| 65 } |
| 66 |
| 67 } // namespace remoting |
OLD | NEW |