Roll src/third_party/WebKit 3a0ba1e:fcd7003 (svn 191141:191149)
[chromium-blink-merge.git] / remoting / signaling / xmpp_signal_strategy.h
blob2d8268b786134ecfc36883a054cb90458a40e719
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // The XmppSignalStrategy encapsulates all the logic to perform the signaling
6 // STUN/ICE for jingle via a direct XMPP connection.
7 //
8 // This class is not threadsafe.
10 #ifndef REMOTING_SIGNALING_XMPP_SIGNAL_STRATEGY_H_
11 #define REMOTING_SIGNALING_XMPP_SIGNAL_STRATEGY_H_
13 #include "remoting/signaling/signal_strategy.h"
15 #include <vector>
17 #include "base/compiler_specific.h"
18 #include "base/observer_list.h"
19 #include "base/threading/non_thread_safe.h"
20 #include "base/timer/timer.h"
21 #include "third_party/webrtc/base/sigslot.h"
22 #include "third_party/webrtc/libjingle/xmpp/xmppclient.h"
24 namespace net {
25 class ClientSocketFactory;
26 class URLRequestContextGetter;
27 } // namespace net
29 namespace rtc {
30 class TaskRunner;
31 } // namespace rtc
33 namespace remoting {
35 class JingleThread;
37 class XmppSignalStrategy : public base::NonThreadSafe,
38 public SignalStrategy,
39 public buzz::XmppStanzaHandler,
40 public sigslot::has_slots<> {
41 public:
42 // XMPP Server configuration for XmppSignalStrategy.
43 struct XmppServerConfig {
44 XmppServerConfig();
45 ~XmppServerConfig();
47 std::string host;
48 int port;
49 bool use_tls;
51 std::string username;
52 std::string auth_token;
55 XmppSignalStrategy(
56 net::ClientSocketFactory* socket_factory,
57 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
58 const XmppServerConfig& xmpp_server_config);
59 ~XmppSignalStrategy() override;
61 // SignalStrategy interface.
62 void Connect() override;
63 void Disconnect() override;
64 State GetState() const override;
65 Error GetError() const override;
66 std::string GetLocalJid() const override;
67 void AddListener(Listener* listener) override;
68 void RemoveListener(Listener* listener) override;
69 bool SendStanza(scoped_ptr<buzz::XmlElement> stanza) override;
70 std::string GetNextId() override;
72 // buzz::XmppStanzaHandler interface.
73 bool HandleStanza(const buzz::XmlElement* stanza) override;
75 // This method is used to update the auth info (for example when the OAuth
76 // access token is renewed). It is OK to call this even when we are in the
77 // CONNECTED state. It will be used on the next Connect() call.
78 void SetAuthInfo(const std::string& username,
79 const std::string& auth_token);
81 // Use this method to override the default resource name used (optional).
82 // This will be used on the next Connect() call.
83 void SetResourceName(const std::string& resource_name);
85 private:
86 static buzz::PreXmppAuth* CreatePreXmppAuth(
87 const buzz::XmppClientSettings& settings);
89 void OnConnectionStateChanged(buzz::XmppEngine::State state);
90 void SetState(State new_state);
92 void SendKeepAlive();
94 net::ClientSocketFactory* socket_factory_;
95 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
96 std::string resource_name_;
97 scoped_ptr<rtc::TaskRunner> task_runner_;
98 buzz::XmppClient* xmpp_client_;
99 XmppServerConfig xmpp_server_config_;
101 State state_;
102 Error error_;
104 ObserverList<Listener, true> listeners_;
106 base::RepeatingTimer<XmppSignalStrategy> keep_alive_timer_;
108 DISALLOW_COPY_AND_ASSIGN(XmppSignalStrategy);
111 } // namespace remoting
113 #endif // REMOTING_SIGNALING_XMPP_SIGNAL_STRATEGY_H_