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