diff options
Diffstat (limited to 'remoting/jingle_glue')
-rw-r--r-- | remoting/jingle_glue/iq_request.h | 5 | ||||
-rw-r--r-- | remoting/jingle_glue/jingle_channel.cc | 3 | ||||
-rw-r--r-- | remoting/jingle_glue/jingle_client.cc | 21 | ||||
-rw-r--r-- | remoting/jingle_glue/jingle_client.h | 11 | ||||
-rw-r--r-- | remoting/jingle_glue/jingle_thread.h | 2 |
5 files changed, 27 insertions, 15 deletions
diff --git a/remoting/jingle_glue/iq_request.h b/remoting/jingle_glue/iq_request.h index 9d6dcad..6933b17 100644 --- a/remoting/jingle_glue/iq_request.h +++ b/remoting/jingle_glue/iq_request.h @@ -21,7 +21,6 @@ class JingleClient; // set_callback(). If multiple IQ stanzas are send with SendIq() then only reply // to the last one will be received. // The class must be used on the jingle thread only. -// TODO(sergeyu): Implement unittests for this class. class IqRequest : private buzz::XmppIqHandler { public: typedef Callback1<const buzz::XmlElement*>::Type ReplyCallback; @@ -32,8 +31,8 @@ class IqRequest : private buzz::XmppIqHandler { // Sends stanza of type |type| to |addressee|. |iq_body| contains body of // the stanza. Ownership of |iq_body| is transfered to IqRequest. Must // be called on the jingle thread. - void SendIq(const std::string& type, const std::string& addressee, - buzz::XmlElement* iq_body); + virtual void SendIq(const std::string& type, const std::string& addressee, + buzz::XmlElement* iq_body); // Sets callback that is called when reply stanza is received. Callback // is called on the jingle thread. diff --git a/remoting/jingle_glue/jingle_channel.cc b/remoting/jingle_glue/jingle_channel.cc index 77fcd1b..0ff634c 100644 --- a/remoting/jingle_glue/jingle_channel.cc +++ b/remoting/jingle_glue/jingle_channel.cc @@ -45,6 +45,7 @@ void JingleChannel::Init(JingleThread* thread, thread_ = thread; stream_.reset(stream); stream_->SignalEvent.connect(&event_handler_, &EventHandler::OnStreamEvent); + jid_ = jid; // Initialize |state_|. switch (stream->GetState()) { @@ -63,8 +64,6 @@ void JingleChannel::Init(JingleThread* thread, default: NOTREACHED(); } - - jid_ = jid; } void JingleChannel::Write(scoped_refptr<DataBuffer> data) { diff --git a/remoting/jingle_glue/jingle_client.cc b/remoting/jingle_glue/jingle_client.cc index 5287d77..a50ba71 100644 --- a/remoting/jingle_glue/jingle_client.cc +++ b/remoting/jingle_glue/jingle_client.cc @@ -2,10 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// TODO(ajwong): Check the initialization sentinels. Can we base it off of -// state_ instead of a member variable? Also, we assign and read from a few of -// the member variables on two threads. We need to audit this for thread -// safety. +// TODO(ajwong): We assign and read from a few of the member variables on +// two threads. We need to audit this for thread safety. #include "remoting/jingle_glue/jingle_client.h" @@ -13,6 +11,7 @@ #include "base/waitable_event.h" #include "base/message_loop.h" #include "remoting/jingle_glue/gaia_token_pre_xmpp_auth.h" +#include "remoting/jingle_glue/iq_request.h" #include "remoting/jingle_glue/jingle_thread.h" #include "remoting/jingle_glue/relay_port_allocator.h" #include "remoting/jingle_glue/xmpp_socket_adapter.h" @@ -32,13 +31,13 @@ namespace remoting { JingleClient::JingleClient(JingleThread* thread) : client_(NULL), thread_(thread), - state_(START), + state_(CREATED), callback_(NULL) { } JingleClient::~JingleClient() { // JingleClient can be destroyed only after it's closed. - DCHECK(state_ == CLOSED); + DCHECK(state_ == CLOSED || state_ == CREATED); } void JingleClient::Init( @@ -46,13 +45,13 @@ void JingleClient::Init( const std::string& auth_token_service, Callback* callback) { DCHECK_NE(username, ""); DCHECK(callback != NULL); - DCHECK(callback_ == NULL); // Init() can be called only once. + DCHECK(state_ == CREATED); callback_ = callback; - message_loop()->PostTask( FROM_HERE, NewRunnableMethod(this, &JingleClient::DoInitialize, username, auth_token, auth_token_service)); + state_ = INITIALIZED; } JingleChannel* JingleClient::Connect(const std::string& host_jid, @@ -160,6 +159,10 @@ std::string JingleClient::GetFullJid() { return full_jid_; } +IqRequest* JingleClient::CreateIqRequest() { + return new IqRequest(this); +} + MessageLoop* JingleClient::message_loop() { return thread_->message_loop(); } @@ -167,7 +170,7 @@ MessageLoop* JingleClient::message_loop() { void JingleClient::OnConnectionStateChanged(buzz::XmppEngine::State state) { switch (state) { case buzz::XmppEngine::STATE_START: - UpdateState(START); + UpdateState(INITIALIZED); break; case buzz::XmppEngine::STATE_OPENING: UpdateState(CONNECTING); diff --git a/remoting/jingle_glue/jingle_client.h b/remoting/jingle_glue/jingle_client.h index aa94a00..bac15d8 100644 --- a/remoting/jingle_glue/jingle_client.h +++ b/remoting/jingle_glue/jingle_client.h @@ -30,11 +30,14 @@ class Session; namespace remoting { +class IqRequest; + class JingleClient : public base::RefCountedThreadSafe<JingleClient>, public sigslot::has_slots<> { public: enum State { - START, // Initial state. + CREATED, // Initial state. + INITIALIZED, CONNECTING, CONNECTED, CLOSED, @@ -88,6 +91,10 @@ class JingleClient : public base::RefCountedThreadSafe<JingleClient>, // known yet, i.e. authentication hasn't finished. std::string GetFullJid(); + // Creates new IqRequest for this client. Ownership for of the created object + // is transfered to the caller. + virtual IqRequest* CreateIqRequest(); + // Current state of the client. State state() { return state_; } @@ -98,6 +105,8 @@ class JingleClient : public base::RefCountedThreadSafe<JingleClient>, MessageLoop* message_loop(); private: + friend class HeartbeatSenderTest; + void OnConnectionStateChanged(buzz::XmppEngine::State state); void OnIncomingTunnel(cricket::TunnelSessionClient* client, buzz::Jid jid, diff --git a/remoting/jingle_glue/jingle_thread.h b/remoting/jingle_glue/jingle_thread.h index b30d07f..2aa23f3 100644 --- a/remoting/jingle_glue/jingle_thread.h +++ b/remoting/jingle_glue/jingle_thread.h @@ -54,6 +54,8 @@ class JingleThread : public talk_base::Thread, TaskPump* task_pump() { return task_pump_; } private: + friend class HeartbeatSenderTest; + virtual void OnMessage(talk_base::Message* msg); void PumpAuxiliaryLoops(); |