Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/base/auto_thread.h" | 5 #include "remoting/base/auto_thread.h" |
| 6 | 6 |
| 7 #include <memory> | |
| 8 | |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 9 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 12 #include "base/logging.h" |
| 11 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 12 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
| 13 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 15 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 14 #include "base/threading/thread_local.h" | 16 #include "base/threading/thread_local.h" |
| 15 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
| 16 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 17 #include "remoting/base/auto_thread_task_runner.h" | 19 #include "remoting/base/auto_thread_task_runner.h" |
| 18 | 20 |
| 21 #if defined(OS_POSIX) && !defined(OS_NACL) | |
| 22 #include "base/files/file_descriptor_watcher_posix.h" | |
| 23 #endif | |
| 24 | |
| 19 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
| 20 #include "base/win/scoped_com_initializer.h" | 26 #include "base/win/scoped_com_initializer.h" |
| 21 #endif | 27 #endif |
| 22 | 28 |
| 23 namespace remoting { | 29 namespace remoting { |
| 24 | 30 |
| 25 namespace { | 31 namespace { |
| 26 | 32 |
| 27 #if defined(OS_WIN) | 33 #if defined(OS_WIN) |
| 28 std::unique_ptr<base::win::ScopedCOMInitializer> CreateComInitializer( | 34 std::unique_ptr<base::win::ScopedCOMInitializer> CreateComInitializer( |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 // no more references to it remain. | 201 // no more references to it remain. |
| 196 startup_data_->task_runner = new AutoThreadTaskRunner( | 202 startup_data_->task_runner = new AutoThreadTaskRunner( |
| 197 message_loop.task_runner(), | 203 message_loop.task_runner(), |
| 198 base::Bind(&AutoThread::QuitThread, base::Unretained(this), | 204 base::Bind(&AutoThread::QuitThread, base::Unretained(this), |
| 199 run_loop.QuitWhenIdleClosure())); | 205 run_loop.QuitWhenIdleClosure())); |
| 200 | 206 |
| 201 startup_data_->event.Signal(); | 207 startup_data_->event.Signal(); |
| 202 // startup_data_ can't be touched anymore since the starting thread is now | 208 // startup_data_ can't be touched anymore since the starting thread is now |
| 203 // unlocked. | 209 // unlocked. |
| 204 | 210 |
| 211 #if defined(OS_POSIX) && !defined(OS_NACL) | |
| 212 // Allow threads running a MessageLoopForIO to use FileDescriptorWatcher. | |
| 213 std::unique_ptr<base::FileDescriptorWatcher> file_descriptor_watcher; | |
| 214 if (startup_data_->loop_type == base::MessageLoop::TYPE_IO) { | |
|
Wez
2016/10/04 00:58:06
You shouldn't access startup_data_ here, since you
| |
| 215 DCHECK_EQ(&message_loop, base::MessageLoopForIO::current()); | |
| 216 file_descriptor_watcher.reset( | |
| 217 new base::FileDescriptorWatcher(base::MessageLoopForIO::current())); | |
| 218 } | |
| 219 #endif | |
| 220 | |
| 205 #if defined(OS_WIN) | 221 #if defined(OS_WIN) |
| 206 // Initialize COM on the thread, if requested. | 222 // Initialize COM on the thread, if requested. |
| 207 std::unique_ptr<base::win::ScopedCOMInitializer> com_initializer( | 223 std::unique_ptr<base::win::ScopedCOMInitializer> com_initializer( |
| 208 CreateComInitializer(com_init_type_)); | 224 CreateComInitializer(com_init_type_)); |
| 209 #endif | 225 #endif |
| 210 | 226 |
| 211 run_loop.Run(); | 227 run_loop.Run(); |
| 212 | 228 |
| 213 // Assert that MessageLoop::QuitWhenIdle was called by AutoThread::QuitThread. | 229 // Assert that MessageLoop::QuitWhenIdle was called by AutoThread::QuitThread. |
| 214 DCHECK(was_quit_properly_); | 230 DCHECK(was_quit_properly_); |
| 215 } | 231 } |
| 216 | 232 |
| 217 } // namespace base | 233 } // namespace base |
| OLD | NEW |