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/jingle_glue/jingle_client.h" | 5 #include "remoting/jingle_glue/jingle_client.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/waitable_event.h" | 8 #include "base/waitable_event.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "chrome/common/net/notifier/communicator/gaia_token_pre_xmpp_auth.h" |
10 #include "chrome/common/net/notifier/communicator/xmpp_socket_adapter.h" | 11 #include "chrome/common/net/notifier/communicator/xmpp_socket_adapter.h" |
11 #include "remoting/jingle_glue/jingle_thread.h" | 12 #include "remoting/jingle_glue/jingle_thread.h" |
12 #include "remoting/jingle_glue/relay_port_allocator.h" | 13 #include "remoting/jingle_glue/relay_port_allocator.h" |
13 #include "talk/base/asyncsocket.h" | 14 #include "talk/base/asyncsocket.h" |
14 #include "talk/base/ssladapter.h" | 15 #include "talk/base/ssladapter.h" |
15 #include "talk/p2p/base/sessionmanager.h" | 16 #include "talk/p2p/base/sessionmanager.h" |
16 #include "talk/p2p/client/sessionmanagertask.h" | 17 #include "talk/p2p/client/sessionmanagertask.h" |
17 #ifdef USE_SSL_TUNNEL | 18 #ifdef USE_SSL_TUNNEL |
18 #include "talk/session/tunnel/securetunnelsessionclient.h" | 19 #include "talk/session/tunnel/securetunnelsessionclient.h" |
19 #endif | 20 #endif |
20 #include "talk/session/tunnel/tunnelsessionclient.h" | 21 #include "talk/session/tunnel/tunnelsessionclient.h" |
| 22 #include "talk/xmpp/prexmppauth.h" |
| 23 #include "talk/xmpp/saslcookiemechanism.h" |
21 | 24 |
22 namespace remoting { | 25 namespace remoting { |
23 | 26 |
24 JingleClient::JingleClient() | 27 JingleClient::JingleClient() |
25 : callback_(NULL), | 28 : callback_(NULL), |
26 state_(START) { } | 29 state_(START) { } |
27 | 30 |
28 JingleClient::~JingleClient() { | 31 JingleClient::~JingleClient() { |
29 // JingleClient can be destroyed only after it's closed. | 32 // JingleClient can be destroyed only after it's closed. |
30 DCHECK(state_ == CLOSED); | 33 DCHECK(state_ == CLOSED); |
31 } | 34 } |
32 | 35 |
33 void JingleClient::Init(const std::string& username, | 36 void JingleClient::Init( |
34 const std::string& password, | 37 const std::string& username, const std::string& auth_token, |
35 Callback* callback) { | 38 const std::string& auth_token_service, Callback* callback) { |
36 DCHECK(username != ""); | 39 DCHECK(username != ""); |
37 DCHECK(callback != NULL); | 40 DCHECK(callback != NULL); |
38 DCHECK(thread_ == NULL); // Init() can be called only once. | 41 DCHECK(thread_ == NULL); // Init() can be called only once. |
39 | 42 |
40 callback_ = callback; | 43 callback_ = callback; |
41 | 44 |
42 username_ = username; | |
43 password_ = password; | |
44 | |
45 thread_.reset(new JingleThread()); | 45 thread_.reset(new JingleThread()); |
46 thread_->Start(); | 46 thread_->Start(); |
47 thread_->message_loop()->PostTask( | 47 thread_->message_loop()->PostTask( |
48 FROM_HERE, NewRunnableMethod(this, &JingleClient::DoInitialize)); | 48 FROM_HERE, NewRunnableMethod(this, &JingleClient::DoInitialize, |
| 49 username, auth_token, auth_token_service)); |
49 } | 50 } |
50 | 51 |
51 class JingleClient::ConnectRequest { | 52 class JingleClient::ConnectRequest { |
52 public: | 53 public: |
53 ConnectRequest() | 54 ConnectRequest() |
54 : completed_event_(true, false) { } | 55 : completed_event_(true, false) { } |
55 | 56 |
56 JingleChannel* Wait() { | 57 JingleChannel* Wait() { |
57 completed_event_.Wait(); | 58 completed_event_.Wait(); |
58 return channel_; | 59 return channel_; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 client_->Disconnect(); | 102 client_->Disconnect(); |
102 // Client is deleted by TaskRunner. | 103 // Client is deleted by TaskRunner. |
103 client_ = NULL; | 104 client_ = NULL; |
104 tunnel_session_client_.reset(); | 105 tunnel_session_client_.reset(); |
105 port_allocator_.reset(); | 106 port_allocator_.reset(); |
106 session_manager_.reset(); | 107 session_manager_.reset(); |
107 network_manager_.reset(); | 108 network_manager_.reset(); |
108 UpdateState(CLOSED); | 109 UpdateState(CLOSED); |
109 } | 110 } |
110 | 111 |
111 void JingleClient::DoInitialize() { | 112 void JingleClient::DoInitialize(const std::string& username, |
112 buzz::Jid login_jid(username_); | 113 const std::string& auth_token, |
113 talk_base::InsecureCryptStringImpl password; | 114 const std::string& auth_token_service) { |
114 password.password() = password_; | 115 buzz::Jid login_jid(username); |
115 | 116 |
116 buzz::XmppClientSettings xcs; | 117 buzz::XmppClientSettings settings; |
117 xcs.set_user(login_jid.node()); | 118 settings.set_user(login_jid.node()); |
118 xcs.set_host(login_jid.domain()); | 119 settings.set_host(login_jid.domain()); |
119 xcs.set_resource("chromoting"); | 120 settings.set_resource("chromoting"); |
120 xcs.set_use_tls(true); | 121 settings.set_use_tls(true); |
121 xcs.set_pass(talk_base::CryptString(password)); | 122 settings.set_token_service(auth_token_service); |
122 xcs.set_server(talk_base::SocketAddress("talk.google.com", 5222)); | 123 settings.set_auth_cookie(auth_token); |
| 124 settings.set_server(talk_base::SocketAddress("talk.google.com", 5222)); |
123 | 125 |
124 client_ = new buzz::XmppClient(thread_->task_pump()); | 126 client_ = new buzz::XmppClient(thread_->task_pump()); |
125 client_->SignalStateChange.connect( | 127 client_->SignalStateChange.connect( |
126 this, &JingleClient::OnConnectionStateChanged); | 128 this, &JingleClient::OnConnectionStateChanged); |
127 | 129 |
128 buzz::AsyncSocket* socket = | 130 buzz::AsyncSocket* socket = |
129 new notifier::XmppSocketAdapter(xcs, false); | 131 new notifier::XmppSocketAdapter(settings, false); |
130 | 132 |
131 client_->Connect(xcs, "", socket, NULL); | 133 client_->Connect(settings, "", socket, CreatePreXmppAuth(settings)); |
132 client_->Start(); | 134 client_->Start(); |
133 | 135 |
134 network_manager_.reset(new talk_base::NetworkManager()); | 136 network_manager_.reset(new talk_base::NetworkManager()); |
135 | 137 |
136 RelayPortAllocator* port_allocator = | 138 RelayPortAllocator* port_allocator = |
137 new RelayPortAllocator(network_manager_.get(), "transp2"); | 139 new RelayPortAllocator(network_manager_.get(), "transp2"); |
138 port_allocator_.reset(port_allocator); | 140 port_allocator_.reset(port_allocator); |
139 port_allocator->SetJingleInfo(client_); | 141 port_allocator->SetJingleInfo(client_); |
140 | 142 |
141 session_manager_.reset(new cricket::SessionManager(port_allocator_.get())); | 143 session_manager_.reset(new cricket::SessionManager(port_allocator_.get())); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 } | 219 } |
218 | 220 |
219 void JingleClient::UpdateState(State new_state) { | 221 void JingleClient::UpdateState(State new_state) { |
220 if (new_state != state_) { | 222 if (new_state != state_) { |
221 state_ = new_state; | 223 state_ = new_state; |
222 if (callback_) | 224 if (callback_) |
223 callback_->OnStateChange(this, new_state); | 225 callback_->OnStateChange(this, new_state); |
224 } | 226 } |
225 } | 227 } |
226 | 228 |
| 229 buzz::PreXmppAuth* JingleClient::CreatePreXmppAuth( |
| 230 const buzz::XmppClientSettings& settings) { |
| 231 buzz::Jid jid(settings.user(), settings.host(), buzz::STR_EMPTY); |
| 232 return new notifier::GaiaTokenPreXmppAuth(jid.Str(), settings.auth_cookie(), |
| 233 settings.token_service()); |
| 234 } |
| 235 |
227 } // namespace remoting | 236 } // namespace remoting |
OLD | NEW |