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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if !defined(OS_WIN) | 7 #if !defined(OS_WIN) |
8 extern "C" { | 8 extern "C" { |
9 #include <unistd.h> | 9 #include <unistd.h> |
10 } | 10 } |
11 #endif // !defined(OS_WIN) | 11 #endif // !defined(OS_WIN) |
12 | 12 |
13 #include <iostream> | 13 #include <iostream> |
14 #include <list> | 14 #include <list> |
15 | 15 |
16 #include "base/at_exit.h" | 16 #include "base/at_exit.h" |
17 #include "base/bind.h" | 17 #include "base/bind.h" |
18 #include "base/command_line.h" | 18 #include "base/command_line.h" |
19 #include "base/message_loop_proxy.h" | 19 #include "base/message_loop_proxy.h" |
| 20 #include "base/synchronization/waitable_event.h" |
20 #include "base/test/mock_chrome_application_mac.h" | 21 #include "base/test/mock_chrome_application_mac.h" |
21 #include "base/time.h" | 22 #include "base/time.h" |
22 #include "crypto/nss_util.h" | 23 #include "crypto/nss_util.h" |
23 #include "net/base/completion_callback.h" | 24 #include "net/base/completion_callback.h" |
24 #include "net/base/io_buffer.h" | 25 #include "net/base/io_buffer.h" |
25 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
26 #include "net/socket/socket.h" | 27 #include "net/socket/socket.h" |
27 #include "remoting/base/constants.h" | 28 #include "remoting/base/constants.h" |
28 #include "remoting/jingle_glue/jingle_thread.h" | 29 #include "remoting/jingle_glue/jingle_thread.h" |
29 #include "remoting/jingle_glue/xmpp_signal_strategy.h" | 30 #include "remoting/jingle_glue/xmpp_signal_strategy.h" |
30 #include "remoting/protocol/jingle_session_manager.h" | 31 #include "remoting/protocol/jingle_session_manager.h" |
31 | 32 |
32 namespace remoting { | 33 namespace remoting { |
33 namespace protocol { | 34 namespace protocol { |
34 | 35 |
35 namespace { | 36 namespace { |
| 37 |
36 const int kBufferSize = 4096; | 38 const int kBufferSize = 4096; |
37 const char kDummyAuthToken[] = ""; | 39 const char kDummyAuthToken[] = ""; |
| 40 |
| 41 void InitializeMessageLoopProxy( |
| 42 scoped_refptr<base::MessageLoopProxy>* proxy, |
| 43 base::WaitableEvent* done) { |
| 44 *proxy = base::MessageLoopProxy::CreateForCurrentThread(); |
| 45 done->Signal(); |
| 46 } |
| 47 |
38 } // namespace | 48 } // namespace |
39 | 49 |
40 class ProtocolTestClient; | 50 class ProtocolTestClient; |
41 | 51 |
42 class ProtocolTestConnection | 52 class ProtocolTestConnection |
43 : public base::RefCountedThreadSafe<ProtocolTestConnection> { | 53 : public base::RefCountedThreadSafe<ProtocolTestConnection> { |
44 public: | 54 public: |
45 ProtocolTestConnection(ProtocolTestClient* client) | 55 ProtocolTestConnection(ProtocolTestClient* client) |
46 : client_(client), | 56 : client_(client), |
47 message_loop_(MessageLoop::current()), | 57 message_loop_(MessageLoop::current()), |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 } | 222 } |
213 } | 223 } |
214 | 224 |
215 void ProtocolTestClient::Run(const std::string& username, | 225 void ProtocolTestClient::Run(const std::string& username, |
216 const std::string& auth_token, | 226 const std::string& auth_token, |
217 const std::string& auth_service, | 227 const std::string& auth_service, |
218 const std::string& host_jid) { | 228 const std::string& host_jid) { |
219 remoting::JingleThread jingle_thread; | 229 remoting::JingleThread jingle_thread; |
220 jingle_thread.Start(); | 230 jingle_thread.Start(); |
221 | 231 |
| 232 scoped_refptr<base::MessageLoopProxy> network_message_loop; |
| 233 base::WaitableEvent proxy_event(true, false); |
| 234 jingle_thread.message_loop()->PostTask(FROM_HERE, base::Bind( |
| 235 &InitializeMessageLoopProxy, &network_message_loop, &proxy_event)); |
| 236 proxy_event.Wait(); |
| 237 |
222 signal_strategy_.reset( | 238 signal_strategy_.reset( |
223 new XmppSignalStrategy(&jingle_thread, username, auth_token, | 239 new XmppSignalStrategy(&jingle_thread, username, auth_token, |
224 auth_service)); | 240 auth_service)); |
225 signal_strategy_->Init(this); | 241 signal_strategy_->Init(this); |
226 session_manager_.reset(JingleSessionManager::CreateNotSandboxed( | 242 session_manager_.reset( |
227 jingle_thread.message_loop_proxy())); | 243 JingleSessionManager::CreateNotSandboxed(network_message_loop)); |
228 | 244 |
229 host_jid_ = host_jid; | 245 host_jid_ = host_jid; |
230 | 246 |
231 while (true) { | 247 while (true) { |
232 std::string line; | 248 std::string line; |
233 std::getline(std::cin, line); | 249 std::getline(std::cin, line); |
234 | 250 |
235 { | 251 { |
236 base::AutoLock auto_lock(connections_lock_); | 252 base::AutoLock auto_lock(connections_lock_); |
237 | 253 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 std::string auth_service("oauth2"); | 375 std::string auth_service("oauth2"); |
360 if (cmd_line->HasSwitch("auth_service")) | 376 if (cmd_line->HasSwitch("auth_service")) |
361 auth_service = cmd_line->GetSwitchValueASCII("auth_service"); | 377 auth_service = cmd_line->GetSwitchValueASCII("auth_service"); |
362 | 378 |
363 scoped_refptr<ProtocolTestClient> client(new ProtocolTestClient()); | 379 scoped_refptr<ProtocolTestClient> client(new ProtocolTestClient()); |
364 | 380 |
365 client->Run(username, auth_token, host_jid, auth_service); | 381 client->Run(username, auth_token, host_jid, auth_service); |
366 | 382 |
367 return 0; | 383 return 0; |
368 } | 384 } |
OLD | NEW |