Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/client/client_context.h" | 5 #include "remoting/client/client_context.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | |
| 8 #include "base/synchronization/waitable_event.h" | |
| 9 | |
| 7 namespace remoting { | 10 namespace remoting { |
| 8 | 11 |
| 12 namespace { | |
| 13 void InitializeMessageLoopProxy( | |
| 14 scoped_refptr<base::MessageLoopProxy>* proxy, | |
| 15 base::WaitableEvent* done) { | |
| 16 *proxy = base::MessageLoopProxy::CreateForCurrentThread(); | |
| 17 done->Signal(); | |
| 18 } | |
| 19 | |
| 20 } // namespace | |
| 21 | |
| 9 ClientContext::ClientContext() | 22 ClientContext::ClientContext() |
| 10 : main_thread_("ChromotingClientMainThread"), | 23 : main_thread_("ChromotingClientMainThread"), |
| 11 decode_thread_("ChromotingClientDecodeThread"), | 24 decode_thread_("ChromotingClientDecodeThread"), |
| 12 network_thread_("ChromotingClientNetworkThread") { | 25 network_thread_("ChromotingClientNetworkThread") { |
| 13 } | 26 } |
| 14 | 27 |
| 15 ClientContext::~ClientContext() { | 28 ClientContext::~ClientContext() { |
| 16 } | 29 } |
| 17 | 30 |
| 18 void ClientContext::Start() { | 31 void ClientContext::Start() { |
| 19 // Start all the threads. | 32 // Start all the threads. |
| 20 main_thread_.Start(); | 33 main_thread_.Start(); |
| 21 decode_thread_.Start(); | 34 decode_thread_.Start(); |
| 22 network_thread_.StartWithOptions( | 35 network_thread_.StartWithOptions( |
| 23 base::Thread::Options(MessageLoop::TYPE_IO, 0)); | 36 base::Thread::Options(MessageLoop::TYPE_IO, 0)); |
| 37 | |
| 38 // Initialize |network_message_loop_| on the network thread. | |
| 39 base::WaitableEvent proxy_event(true, false); | |
| 40 network_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | |
| 41 &InitializeMessageLoopProxy, &network_message_loop_, &proxy_event)); | |
|
Wez
2011/08/12 21:11:20
Is there a reason we can't just call message_loop_
Sergey Ulanov
2011/08/12 21:24:18
I didn't know about Thread::message_loop_proxy().
| |
| 42 proxy_event.Wait(); | |
| 24 } | 43 } |
| 25 | 44 |
| 26 void ClientContext::Stop() { | 45 void ClientContext::Stop() { |
| 27 // Stop all the threads. | 46 // Stop all the threads. |
| 28 network_thread_.Stop(); | 47 network_thread_.Stop(); |
| 29 decode_thread_.Stop(); | 48 decode_thread_.Stop(); |
| 30 main_thread_.Stop(); | 49 main_thread_.Stop(); |
| 31 } | 50 } |
| 32 | 51 |
| 33 MessageLoop* ClientContext::main_message_loop() { | 52 MessageLoop* ClientContext::main_message_loop() { |
| 34 return main_thread_.message_loop(); | 53 return main_thread_.message_loop(); |
| 35 } | 54 } |
| 36 | 55 |
| 37 MessageLoop* ClientContext::decode_message_loop() { | 56 MessageLoop* ClientContext::decode_message_loop() { |
| 38 return decode_thread_.message_loop(); | 57 return decode_thread_.message_loop(); |
| 39 } | 58 } |
| 40 | 59 |
| 41 MessageLoop* ClientContext::network_message_loop() { | 60 base::MessageLoopProxy* ClientContext::network_message_loop() { |
| 42 return network_thread_.message_loop(); | 61 return network_message_loop_; |
| 43 } | 62 } |
| 44 | 63 |
| 45 } // namespace remoting | 64 } // namespace remoting |
| OLD | NEW |