blob: e18019e1c23244746847fbce0bf97b143fd167a7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// The XmppSignalStrategy encapsulates all the logic to perform the signaling
// STUN/ICE for jingle via a direct XMPP connection.
//
// This class is not threadsafe.
#ifndef REMOTING_JINGLE_GLUE_XMPP_SIGNAL_STRATEGY_H_
#define REMOTING_JINGLE_GLUE_XMPP_SIGNAL_STRATEGY_H_
#include "remoting/jingle_glue/signal_strategy.h"
#include <vector>
#include "base/compiler_specific.h"
#include "base/observer_list.h"
#include "base/timer.h"
#include "base/threading/non_thread_safe.h"
#include "third_party/libjingle/source/talk/base/sigslot.h"
#include "third_party/libjingle/source/talk/xmpp/xmppclient.h"
namespace net {
class URLRequestContextGetter;
} // namespace net
namespace talk_base {
class TaskRunner;
} // namespace talk_base
namespace remoting {
class JingleThread;
class XmppSignalStrategy : public base::NonThreadSafe,
public SignalStrategy,
public buzz::XmppStanzaHandler,
public sigslot::has_slots<> {
public:
XmppSignalStrategy(
scoped_refptr<net::URLRequestContextGetter> request_context_getter,
const std::string& username,
const std::string& auth_token,
const std::string& auth_token_service);
virtual ~XmppSignalStrategy();
// SignalStrategy interface.
virtual void Connect() OVERRIDE;
virtual void Disconnect() OVERRIDE;
virtual State GetState() const OVERRIDE;
virtual Error GetError() const OVERRIDE;
virtual std::string GetLocalJid() const OVERRIDE;
virtual void AddListener(Listener* listener) OVERRIDE;
virtual void RemoveListener(Listener* listener) OVERRIDE;
virtual bool SendStanza(scoped_ptr<buzz::XmlElement> stanza) OVERRIDE;
virtual std::string GetNextId() OVERRIDE;
// buzz::XmppStanzaHandler interface.
virtual bool HandleStanza(const buzz::XmlElement* stanza) OVERRIDE;
// This method is used to update the auth info (for example when the OAuth
// access token is renewed). It is OK to call this even when we are in the
// CONNECTED state. It will be used on the next Connect() call.
void SetAuthInfo(const std::string& username,
const std::string& auth_token,
const std::string& auth_token_service);
// Use this method to override the default resource name used (optional).
// This will be used on the next Connect() call.
void SetResourceName(const std::string& resource_name);
private:
static buzz::PreXmppAuth* CreatePreXmppAuth(
const buzz::XmppClientSettings& settings);
void OnConnectionStateChanged(buzz::XmppEngine::State state);
void SetState(State new_state);
void SendKeepAlive();
scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
std::string username_;
std::string auth_token_;
std::string auth_token_service_;
std::string resource_name_;
scoped_ptr<talk_base::TaskRunner> task_runner_;
buzz::XmppClient* xmpp_client_;
State state_;
Error error_;
ObserverList<Listener, true> listeners_;
base::RepeatingTimer<XmppSignalStrategy> keep_alive_timer_;
DISALLOW_COPY_AND_ASSIGN(XmppSignalStrategy);
};
} // namespace remoting
#endif // REMOTING_JINGLE_GLUE_XMPP_SIGNAL_STRATEGY_H_
|