Send activityLogPrivate to stable
[chromium-blink-merge.git] / remoting / jingle_glue / xmpp_signal_strategy.h
blobecb13cc5f6bd551bf30acfb8d23222c51f93c813
1 // Copyright (c) 2012 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_JINGLE_GLUE_XMPP_SIGNAL_STRATEGY_H_
11 #define REMOTING_JINGLE_GLUE_XMPP_SIGNAL_STRATEGY_H_
13 #include "remoting/jingle_glue/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/libjingle/source/talk/base/sigslot.h"
22 #include "third_party/libjingle/source/talk/xmpp/xmppclient.h"
24 namespace jingle_glue {
25 class ResolvingClientSocketFactory;
26 } // namespace jingle_glue
28 namespace talk_base {
29 class TaskRunner;
30 } // namespace talk_base
32 namespace remoting {
34 class JingleThread;
36 class XmppSignalStrategy : public base::NonThreadSafe,
37 public SignalStrategy,
38 public buzz::XmppStanzaHandler,
39 public sigslot::has_slots<> {
40 public:
41 // XMPP Server configuration for XmppSignalStrategy.
42 struct XmppServerConfig {
43 XmppServerConfig();
44 ~XmppServerConfig();
46 std::string host;
47 int port;
48 bool use_tls;
50 std::string username;
51 std::string auth_token;
52 std::string auth_service;
55 XmppSignalStrategy(
56 scoped_ptr<jingle_glue::ResolvingClientSocketFactory> socket_factory,
57 const XmppServerConfig& xmpp_server_config);
58 virtual ~XmppSignalStrategy();
60 // SignalStrategy interface.
61 virtual void Connect() OVERRIDE;
62 virtual void Disconnect() OVERRIDE;
63 virtual State GetState() const OVERRIDE;
64 virtual Error GetError() const OVERRIDE;
65 virtual std::string GetLocalJid() const OVERRIDE;
66 virtual void AddListener(Listener* listener) OVERRIDE;
67 virtual void RemoveListener(Listener* listener) OVERRIDE;
68 virtual bool SendStanza(scoped_ptr<buzz::XmlElement> stanza) OVERRIDE;
69 virtual std::string GetNextId() OVERRIDE;
71 // buzz::XmppStanzaHandler interface.
72 virtual bool HandleStanza(const buzz::XmlElement* stanza) OVERRIDE;
74 // This method is used to update the auth info (for example when the OAuth
75 // access token is renewed). It is OK to call this even when we are in the
76 // CONNECTED state. It will be used on the next Connect() call.
77 void SetAuthInfo(const std::string& username,
78 const std::string& auth_token,
79 const std::string& auth_service);
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 scoped_ptr<jingle_glue::ResolvingClientSocketFactory> socket_factory_;
95 std::string resource_name_;
96 scoped_ptr<talk_base::TaskRunner> task_runner_;
97 buzz::XmppClient* xmpp_client_;
98 XmppServerConfig xmpp_server_config_;
100 State state_;
101 Error error_;
103 ObserverList<Listener, true> listeners_;
105 base::RepeatingTimer<XmppSignalStrategy> keep_alive_timer_;
107 DISALLOW_COPY_AND_ASSIGN(XmppSignalStrategy);
110 } // namespace remoting
112 #endif // REMOTING_JINGLE_GLUE_XMPP_SIGNAL_STRATEGY_H_