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.
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"
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"
25 class ClientSocketFactory
;
26 class URLRequestContextGetter
;
37 class XmppSignalStrategy
: public base::NonThreadSafe
,
38 public SignalStrategy
,
39 public buzz::XmppStanzaHandler
,
40 public sigslot::has_slots
<> {
42 // XMPP Server configuration for XmppSignalStrategy.
43 struct XmppServerConfig
{
52 std::string auth_token
;
53 std::string auth_service
;
57 net::ClientSocketFactory
* socket_factory
,
58 const scoped_refptr
<net::URLRequestContextGetter
>& request_context_getter
,
59 const XmppServerConfig
& xmpp_server_config
);
60 ~XmppSignalStrategy() override
;
62 // SignalStrategy interface.
63 void Connect() override
;
64 void Disconnect() override
;
65 State
GetState() const override
;
66 Error
GetError() const override
;
67 std::string
GetLocalJid() const override
;
68 void AddListener(Listener
* listener
) override
;
69 void RemoveListener(Listener
* listener
) override
;
70 bool SendStanza(scoped_ptr
<buzz::XmlElement
> stanza
) override
;
71 std::string
GetNextId() override
;
73 // buzz::XmppStanzaHandler interface.
74 bool HandleStanza(const buzz::XmlElement
* stanza
) override
;
76 // This method is used to update the auth info (for example when the OAuth
77 // access token is renewed). It is OK to call this even when we are in the
78 // CONNECTED state. It will be used on the next Connect() call.
79 void SetAuthInfo(const std::string
& username
,
80 const std::string
& auth_token
,
81 const std::string
& auth_service
);
83 // Use this method to override the default resource name used (optional).
84 // This will be used on the next Connect() call.
85 void SetResourceName(const std::string
& resource_name
);
88 static buzz::PreXmppAuth
* CreatePreXmppAuth(
89 const buzz::XmppClientSettings
& settings
);
91 void OnConnectionStateChanged(buzz::XmppEngine::State state
);
92 void SetState(State new_state
);
96 net::ClientSocketFactory
* socket_factory_
;
97 scoped_refptr
<net::URLRequestContextGetter
> request_context_getter_
;
98 std::string resource_name_
;
99 scoped_ptr
<rtc::TaskRunner
> task_runner_
;
100 buzz::XmppClient
* xmpp_client_
;
101 XmppServerConfig xmpp_server_config_
;
106 ObserverList
<Listener
, true> listeners_
;
108 base::RepeatingTimer
<XmppSignalStrategy
> keep_alive_timer_
;
110 DISALLOW_COPY_AND_ASSIGN(XmppSignalStrategy
);
113 } // namespace remoting
115 #endif // REMOTING_SIGNALING_XMPP_SIGNAL_STRATEGY_H_