| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/host/chromoting_host_context.h" | 5 #include "remoting/host/chromoting_host_context.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| 11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 12 #include "remoting/jingle_glue/jingle_thread.h" | 12 #include "remoting/jingle_glue/jingle_thread.h" |
| 13 | 13 |
| 14 namespace remoting { | 14 namespace remoting { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 void InitializeMessageLoopProxy( | 17 void InitializeMessageLoopProxy( |
| 18 scoped_refptr<base::MessageLoopProxy>* proxy, | 18 scoped_refptr<base::MessageLoopProxy>* proxy, |
| 19 base::WaitableEvent* done) { | 19 base::WaitableEvent* done) { |
| 20 *proxy = base::MessageLoopProxy::CreateForCurrentThread(); | 20 *proxy = base::MessageLoopProxy::CreateForCurrentThread(); |
| 21 done->Signal(); | 21 done->Signal(); |
| 22 } | 22 } |
| 23 } // namespace | 23 } // namespace |
| 24 | 24 |
| 25 ChromotingHostContext::ChromotingHostContext() | 25 ChromotingHostContext::ChromotingHostContext( |
| 26 base::MessageLoopProxy* ui_message_loop) |
| 26 : main_thread_("ChromotingMainThread"), | 27 : main_thread_("ChromotingMainThread"), |
| 27 encode_thread_("ChromotingEncodeThread"), | 28 encode_thread_("ChromotingEncodeThread"), |
| 28 desktop_thread_("ChromotingDesktopThread") { | 29 desktop_thread_("ChromotingDesktopThread"), |
| 30 ui_message_loop_(ui_message_loop) { |
| 29 } | 31 } |
| 30 | 32 |
| 31 ChromotingHostContext::~ChromotingHostContext() { | 33 ChromotingHostContext::~ChromotingHostContext() { |
| 32 } | 34 } |
| 33 | 35 |
| 34 void ChromotingHostContext::Start() { | 36 void ChromotingHostContext::Start() { |
| 35 // Start all the threads. | 37 // Start all the threads. |
| 36 main_thread_.Start(); | 38 main_thread_.Start(); |
| 37 encode_thread_.Start(); | 39 encode_thread_.Start(); |
| 38 jingle_thread_.Start(); | 40 jingle_thread_.Start(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 50 jingle_thread_.Stop(); | 52 jingle_thread_.Stop(); |
| 51 encode_thread_.Stop(); | 53 encode_thread_.Stop(); |
| 52 main_thread_.Stop(); | 54 main_thread_.Stop(); |
| 53 desktop_thread_.Stop(); | 55 desktop_thread_.Stop(); |
| 54 } | 56 } |
| 55 | 57 |
| 56 JingleThread* ChromotingHostContext::jingle_thread() { | 58 JingleThread* ChromotingHostContext::jingle_thread() { |
| 57 return &jingle_thread_; | 59 return &jingle_thread_; |
| 58 } | 60 } |
| 59 | 61 |
| 62 base::MessageLoopProxy* ChromotingHostContext::ui_message_loop() { |
| 63 return ui_message_loop_; |
| 64 } |
| 65 |
| 60 MessageLoop* ChromotingHostContext::main_message_loop() { | 66 MessageLoop* ChromotingHostContext::main_message_loop() { |
| 61 return main_thread_.message_loop(); | 67 return main_thread_.message_loop(); |
| 62 } | 68 } |
| 63 | 69 |
| 64 MessageLoop* ChromotingHostContext::encode_message_loop() { | 70 MessageLoop* ChromotingHostContext::encode_message_loop() { |
| 65 return encode_thread_.message_loop(); | 71 return encode_thread_.message_loop(); |
| 66 } | 72 } |
| 67 | 73 |
| 68 base::MessageLoopProxy* ChromotingHostContext::network_message_loop() { | 74 base::MessageLoopProxy* ChromotingHostContext::network_message_loop() { |
| 69 return network_message_loop_; | 75 return network_message_loop_; |
| 70 } | 76 } |
| 71 | 77 |
| 72 MessageLoop* ChromotingHostContext::desktop_message_loop() { | 78 MessageLoop* ChromotingHostContext::desktop_message_loop() { |
| 73 return desktop_thread_.message_loop(); | 79 return desktop_thread_.message_loop(); |
| 74 } | 80 } |
| 75 | 81 |
| 76 void ChromotingHostContext::SetUITaskPostFunction( | |
| 77 const UIThreadPostTaskFunction& poster) { | |
| 78 ui_poster_ = poster; | |
| 79 ui_main_thread_id_ = base::PlatformThread::CurrentId(); | |
| 80 } | |
| 81 | |
| 82 void ChromotingHostContext::PostTaskToUIThread( | |
| 83 const tracked_objects::Location& from_here, const base::Closure& task) { | |
| 84 ui_poster_.Run(from_here, task); | |
| 85 } | |
| 86 | |
| 87 void ChromotingHostContext::PostDelayedTaskToUIThread( | |
| 88 const tracked_objects::Location& from_here, | |
| 89 const base::Closure& task, | |
| 90 int delay_ms) { | |
| 91 // Post delayed task on the main thread that will post task on UI | |
| 92 // thread. It is safe to use base::Unretained() here because | |
| 93 // ChromotingHostContext owns |main_thread_|. | |
| 94 main_message_loop()->PostDelayedTask(from_here, base::Bind( | |
| 95 &ChromotingHostContext::PostTaskToUIThread, base::Unretained(this), | |
| 96 from_here, task), delay_ms); | |
| 97 } | |
| 98 | |
| 99 bool ChromotingHostContext::IsUIThread() const { | |
| 100 return ui_main_thread_id_ == base::PlatformThread::CurrentId(); | |
| 101 } | |
| 102 | |
| 103 } // namespace remoting | 82 } // namespace remoting |
| OLD | NEW |