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 #ifndef REMOTING_JINGLE_GLUE_JINGLE_CLIENT_H_ | 5 #ifndef REMOTING_JINGLE_GLUE_JINGLE_CLIENT_H_ |
6 #define REMOTING_JINGLE_GLUE_JINGLE_CLIENT_H_ | 6 #define REMOTING_JINGLE_GLUE_JINGLE_CLIENT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
| 10 #include "base/waitable_event.h" |
10 #include "remoting/jingle_glue/jingle_channel.h" | 11 #include "remoting/jingle_glue/jingle_channel.h" |
11 #include "third_party/libjingle/source/talk/xmpp/xmppclient.h" | 12 #include "third_party/libjingle/source/talk/xmpp/xmppclient.h" |
12 | 13 |
13 class MessageLoop; | 14 class MessageLoop; |
14 | 15 |
15 namespace talk_base { | 16 namespace talk_base { |
16 class NetworkManager; | 17 class NetworkManager; |
17 } // namespace talk_base | 18 } // namespace talk_base |
18 | 19 |
19 namespace buzz { | 20 namespace buzz { |
20 class PreXmppAuth; | 21 class PreXmppAuth; |
21 } // namespace buzz | 22 } // namespace buzz |
22 | 23 |
23 namespace cricket { | 24 namespace cricket { |
24 class BasicPortAllocator; | 25 class BasicPortAllocator; |
25 class SessionManager; | 26 class SessionManager; |
26 class TunnelSessionClient; | 27 class TunnelSessionClient; |
27 class SessionManagerTask; | 28 class SessionManagerTask; |
28 class Session; | 29 class Session; |
29 } // namespace cricket | 30 } // namespace cricket |
30 | 31 |
31 namespace remoting { | 32 namespace remoting { |
32 | 33 |
33 class IqRequest; | 34 class IqRequest; |
34 | 35 |
35 class JingleClient : public base::RefCountedThreadSafe<JingleClient>, | 36 class JingleClient : public base::RefCountedThreadSafe<JingleClient>, |
36 public sigslot::has_slots<> { | 37 public sigslot::has_slots<> { |
37 public: | 38 public: |
38 enum State { | 39 enum State { |
39 CREATED, // Initial state. | 40 START, // Initial state. |
40 INITIALIZED, | |
41 CONNECTING, | 41 CONNECTING, |
42 CONNECTED, | 42 CONNECTED, |
43 CLOSED, | 43 CLOSED, |
44 }; | 44 }; |
45 | 45 |
46 class Callback { | 46 class Callback { |
47 public: | 47 public: |
48 virtual ~Callback() {} | 48 virtual ~Callback() {} |
49 | 49 |
50 // Called when state of the connection is changed. | 50 // Called when state of the connection is changed. |
(...skipping 26 matching lines...) Expand all Loading... |
77 | 77 |
78 // Creates new JingleChannel connected to the host with the specified jid. | 78 // Creates new JingleChannel connected to the host with the specified jid. |
79 // The result is returned immediately but the channel fails if the host | 79 // The result is returned immediately but the channel fails if the host |
80 // rejects connection. |host_jid| must be a full jid (includes resource ID). | 80 // rejects connection. |host_jid| must be a full jid (includes resource ID). |
81 // Ownership of the result is transfered to the caller. The channel must | 81 // Ownership of the result is transfered to the caller. The channel must |
82 // be closed/destroyed before JingleClient is destroyed. | 82 // be closed/destroyed before JingleClient is destroyed. |
83 JingleChannel* Connect(const std::string& host_jid, | 83 JingleChannel* Connect(const std::string& host_jid, |
84 JingleChannel::Callback* callback); | 84 JingleChannel::Callback* callback); |
85 | 85 |
86 // Closes XMPP connection and stops the thread. Must be called before the | 86 // Closes XMPP connection and stops the thread. Must be called before the |
87 // object is destroyed. | 87 // object is destroyed. If specified, |closed_task| is executed after the |
| 88 // connection is successfully closed. |
88 void Close(); | 89 void Close(); |
| 90 void Close(Task* closed_task); |
89 | 91 |
90 // Returns JID with resource ID. Empty string is returned if full JID is not | 92 // Returns JID with resource ID. Empty string is returned if full JID is not |
91 // known yet, i.e. authentication hasn't finished. | 93 // known yet, i.e. authentication hasn't finished. |
92 std::string GetFullJid(); | 94 std::string GetFullJid(); |
93 | 95 |
94 // Creates new IqRequest for this client. Ownership for of the created object | 96 // Creates new IqRequest for this client. Ownership for of the created object |
95 // is transfered to the caller. | 97 // is transfered to the caller. |
96 virtual IqRequest* CreateIqRequest(); | 98 virtual IqRequest* CreateIqRequest(); |
97 | 99 |
98 // Current state of the client. | 100 // Current connection state of the client. |
99 State state() { return state_; } | 101 State state() { return state_; } |
100 | 102 |
101 // Returns XmppClient object for the xmpp connection or NULL if not connected. | 103 // Returns XmppClient object for the xmpp connection or NULL if not connected. |
102 buzz::XmppClient* xmpp_client() { return client_; } | 104 buzz::XmppClient* xmpp_client() { return client_; } |
103 | 105 |
104 // Message loop used by this object to execute tasks. | 106 // Message loop used by this object to execute tasks. |
105 MessageLoop* message_loop(); | 107 MessageLoop* message_loop(); |
106 | 108 |
107 private: | 109 private: |
108 friend class HeartbeatSenderTest; | 110 friend class HeartbeatSenderTest; |
| 111 friend class JingleClientTest; |
109 | 112 |
110 void OnConnectionStateChanged(buzz::XmppEngine::State state); | 113 void OnConnectionStateChanged(buzz::XmppEngine::State state); |
111 | 114 |
112 void OnIncomingTunnel(cricket::TunnelSessionClient* client, buzz::Jid jid, | 115 void OnIncomingTunnel(cricket::TunnelSessionClient* client, buzz::Jid jid, |
113 std::string description, cricket::Session* session); | 116 std::string description, cricket::Session* session); |
114 | 117 |
115 void DoInitialize(const std::string& username, | 118 void DoInitialize(const std::string& username, |
116 const std::string& auth_token, | 119 const std::string& auth_token, |
117 const std::string& auth_token_service); | 120 const std::string& auth_token_service); |
118 | 121 |
119 // Used by Connect(). | 122 // Used by Connect(). |
120 void DoConnect(scoped_refptr<JingleChannel> channel, | 123 void DoConnect(scoped_refptr<JingleChannel> channel, |
121 const std::string& host_jid, | 124 const std::string& host_jid, |
122 JingleChannel::Callback* callback); | 125 JingleChannel::Callback* callback); |
123 | 126 |
124 // Used by Close(). | 127 // Used by Close(). |
125 void DoClose(); | 128 void DoClose(); |
126 | 129 |
127 // Updates current state of the connection. Must be called only in | 130 // Updates current state of the connection. Must be called only in |
128 // the jingle thread. | 131 // the jingle thread. |
129 void UpdateState(State new_state); | 132 void UpdateState(State new_state); |
130 | 133 |
131 buzz::PreXmppAuth* CreatePreXmppAuth( | 134 buzz::PreXmppAuth* CreatePreXmppAuth( |
132 const buzz::XmppClientSettings& settings); | 135 const buzz::XmppClientSettings& settings); |
133 | 136 |
134 buzz::XmppClient* client_; | 137 // JingleThread used for the connection. Set in the constructor. |
135 JingleThread* thread_; | 138 JingleThread* thread_; |
136 State state_; | 139 |
| 140 // Callback for this object. Callback must not be called if closed_ == true. |
137 Callback* callback_; | 141 Callback* callback_; |
138 | 142 |
| 143 // The XmppClient and its state and jid. |
| 144 buzz::XmppClient* client_; |
| 145 State state_; |
139 Lock full_jid_lock_; | 146 Lock full_jid_lock_; |
140 std::string full_jid_; | 147 std::string full_jid_; |
141 | 148 |
| 149 // Current state of the object. |
| 150 Lock state_lock_; // Must be locked when accessing initialized_ or closed_. |
| 151 bool initialized_; |
| 152 bool closed_; |
| 153 scoped_ptr<Task> closed_task_; |
| 154 |
142 scoped_ptr<talk_base::NetworkManager> network_manager_; | 155 scoped_ptr<talk_base::NetworkManager> network_manager_; |
143 scoped_ptr<cricket::BasicPortAllocator> port_allocator_; | 156 scoped_ptr<cricket::BasicPortAllocator> port_allocator_; |
144 scoped_ptr<cricket::SessionManager> session_manager_; | 157 scoped_ptr<cricket::SessionManager> session_manager_; |
145 scoped_ptr<cricket::TunnelSessionClient> tunnel_session_client_; | 158 scoped_ptr<cricket::TunnelSessionClient> tunnel_session_client_; |
146 | 159 |
147 DISALLOW_COPY_AND_ASSIGN(JingleClient); | 160 DISALLOW_COPY_AND_ASSIGN(JingleClient); |
148 }; | 161 }; |
149 | 162 |
150 } // namespace remoting | 163 } // namespace remoting |
151 | 164 |
152 #endif // REMOTING_JINGLE_GLUE_JINGLE_CLIENT_H_ | 165 #endif // REMOTING_JINGLE_GLUE_JINGLE_CLIENT_H_ |
OLD | NEW |