| 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 // TODO(ajwong): Check the initialization sentinels. Can we base it off of | 5 // TODO(ajwong): We assign and read from a few of the member variables on |
| 6 // state_ instead of a member variable? Also, we assign and read from a few of | 6 // two threads. We need to audit this for thread safety. |
| 7 // the member variables on two threads. We need to audit this for thread | |
| 8 // safety. | |
| 9 | 7 |
| 10 #include "remoting/jingle_glue/jingle_client.h" | 8 #include "remoting/jingle_glue/jingle_client.h" |
| 11 | 9 |
| 12 #include "base/logging.h" | 10 #include "base/logging.h" |
| 13 #include "base/waitable_event.h" | 11 #include "base/waitable_event.h" |
| 14 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 15 #include "remoting/jingle_glue/gaia_token_pre_xmpp_auth.h" | 13 #include "remoting/jingle_glue/gaia_token_pre_xmpp_auth.h" |
| 14 #include "remoting/jingle_glue/iq_request.h" |
| 16 #include "remoting/jingle_glue/jingle_thread.h" | 15 #include "remoting/jingle_glue/jingle_thread.h" |
| 17 #include "remoting/jingle_glue/relay_port_allocator.h" | 16 #include "remoting/jingle_glue/relay_port_allocator.h" |
| 18 #include "remoting/jingle_glue/xmpp_socket_adapter.h" | 17 #include "remoting/jingle_glue/xmpp_socket_adapter.h" |
| 19 #include "third_party/libjingle/source/talk/base/asyncsocket.h" | 18 #include "third_party/libjingle/source/talk/base/asyncsocket.h" |
| 20 #include "third_party/libjingle/source/talk/base/ssladapter.h" | 19 #include "third_party/libjingle/source/talk/base/ssladapter.h" |
| 21 #include "third_party/libjingle/source/talk/p2p/base/sessionmanager.h" | 20 #include "third_party/libjingle/source/talk/p2p/base/sessionmanager.h" |
| 22 #include "third_party/libjingle/source/talk/p2p/client/sessionmanagertask.h" | 21 #include "third_party/libjingle/source/talk/p2p/client/sessionmanagertask.h" |
| 23 #ifdef USE_SSL_TUNNEL | 22 #ifdef USE_SSL_TUNNEL |
| 24 #include "third_party/libjingle/source/talk/session/tunnel/securetunnelsessioncl
ient.h" | 23 #include "third_party/libjingle/source/talk/session/tunnel/securetunnelsessioncl
ient.h" |
| 25 #endif | 24 #endif |
| 26 #include "third_party/libjingle/source/talk/session/tunnel/tunnelsessionclient.h
" | 25 #include "third_party/libjingle/source/talk/session/tunnel/tunnelsessionclient.h
" |
| 27 #include "third_party/libjingle/source/talk/xmpp/prexmppauth.h" | 26 #include "third_party/libjingle/source/talk/xmpp/prexmppauth.h" |
| 28 #include "third_party/libjingle/source/talk/xmpp/saslcookiemechanism.h" | 27 #include "third_party/libjingle/source/talk/xmpp/saslcookiemechanism.h" |
| 29 | 28 |
| 30 namespace remoting { | 29 namespace remoting { |
| 31 | 30 |
| 32 JingleClient::JingleClient(JingleThread* thread) | 31 JingleClient::JingleClient(JingleThread* thread) |
| 33 : client_(NULL), | 32 : client_(NULL), |
| 34 thread_(thread), | 33 thread_(thread), |
| 35 state_(START), | 34 state_(CREATED), |
| 36 callback_(NULL) { | 35 callback_(NULL) { |
| 37 } | 36 } |
| 38 | 37 |
| 39 JingleClient::~JingleClient() { | 38 JingleClient::~JingleClient() { |
| 40 // JingleClient can be destroyed only after it's closed. | 39 // JingleClient can be destroyed only after it's closed. |
| 41 DCHECK(state_ == CLOSED); | 40 DCHECK(state_ == CLOSED || state_ == CREATED); |
| 42 } | 41 } |
| 43 | 42 |
| 44 void JingleClient::Init( | 43 void JingleClient::Init( |
| 45 const std::string& username, const std::string& auth_token, | 44 const std::string& username, const std::string& auth_token, |
| 46 const std::string& auth_token_service, Callback* callback) { | 45 const std::string& auth_token_service, Callback* callback) { |
| 47 DCHECK_NE(username, ""); | 46 DCHECK_NE(username, ""); |
| 48 DCHECK(callback != NULL); | 47 DCHECK(callback != NULL); |
| 49 DCHECK(callback_ == NULL); // Init() can be called only once. | 48 DCHECK(state_ == CREATED); |
| 50 | 49 |
| 51 callback_ = callback; | 50 callback_ = callback; |
| 52 | |
| 53 message_loop()->PostTask( | 51 message_loop()->PostTask( |
| 54 FROM_HERE, NewRunnableMethod(this, &JingleClient::DoInitialize, | 52 FROM_HERE, NewRunnableMethod(this, &JingleClient::DoInitialize, |
| 55 username, auth_token, auth_token_service)); | 53 username, auth_token, auth_token_service)); |
| 54 state_ = START; |
| 56 } | 55 } |
| 57 | 56 |
| 58 JingleChannel* JingleClient::Connect(const std::string& host_jid, | 57 JingleChannel* JingleClient::Connect(const std::string& host_jid, |
| 59 JingleChannel::Callback* callback) { | 58 JingleChannel::Callback* callback) { |
| 60 // Ownership if channel is given to DoConnect. | 59 // Ownership if channel is given to DoConnect. |
| 61 scoped_refptr<JingleChannel> channel = new JingleChannel(callback); | 60 scoped_refptr<JingleChannel> channel = new JingleChannel(callback); |
| 62 message_loop()->PostTask( | 61 message_loop()->PostTask( |
| 63 FROM_HERE, NewRunnableMethod(this, &JingleClient::DoConnect, | 62 FROM_HERE, NewRunnableMethod(this, &JingleClient::DoConnect, |
| 64 channel, host_jid, callback)); | 63 channel, host_jid, callback)); |
| 65 return channel; | 64 return channel; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 152 |
| 154 tunnel_session_client_->SignalIncomingTunnel.connect( | 153 tunnel_session_client_->SignalIncomingTunnel.connect( |
| 155 this, &JingleClient::OnIncomingTunnel); | 154 this, &JingleClient::OnIncomingTunnel); |
| 156 } | 155 } |
| 157 | 156 |
| 158 std::string JingleClient::GetFullJid() { | 157 std::string JingleClient::GetFullJid() { |
| 159 AutoLock auto_lock(full_jid_lock_); | 158 AutoLock auto_lock(full_jid_lock_); |
| 160 return full_jid_; | 159 return full_jid_; |
| 161 } | 160 } |
| 162 | 161 |
| 162 IqRequest* JingleClient::CreateIqRequest() { |
| 163 return new IqRequest(this); |
| 164 } |
| 165 |
| 163 MessageLoop* JingleClient::message_loop() { | 166 MessageLoop* JingleClient::message_loop() { |
| 164 return thread_->message_loop(); | 167 return thread_->message_loop(); |
| 165 } | 168 } |
| 166 | 169 |
| 167 void JingleClient::OnConnectionStateChanged(buzz::XmppEngine::State state) { | 170 void JingleClient::OnConnectionStateChanged(buzz::XmppEngine::State state) { |
| 168 switch (state) { | 171 switch (state) { |
| 169 case buzz::XmppEngine::STATE_START: | 172 case buzz::XmppEngine::STATE_START: |
| 170 UpdateState(START); | 173 UpdateState(START); |
| 171 break; | 174 break; |
| 172 case buzz::XmppEngine::STATE_OPENING: | 175 case buzz::XmppEngine::STATE_OPENING: |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 } | 221 } |
| 219 | 222 |
| 220 buzz::PreXmppAuth* JingleClient::CreatePreXmppAuth( | 223 buzz::PreXmppAuth* JingleClient::CreatePreXmppAuth( |
| 221 const buzz::XmppClientSettings& settings) { | 224 const buzz::XmppClientSettings& settings) { |
| 222 buzz::Jid jid(settings.user(), settings.host(), buzz::STR_EMPTY); | 225 buzz::Jid jid(settings.user(), settings.host(), buzz::STR_EMPTY); |
| 223 return new GaiaTokenPreXmppAuth(jid.Str(), settings.auth_cookie(), | 226 return new GaiaTokenPreXmppAuth(jid.Str(), settings.auth_cookie(), |
| 224 settings.token_service()); | 227 settings.token_service()); |
| 225 } | 228 } |
| 226 | 229 |
| 227 } // namespace remoting | 230 } // namespace remoting |
| OLD | NEW |