- add sources.
[platform/framework/web/crosswalk.git] / src / remoting / protocol / jingle_session_manager.h
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.
4
5 #ifndef REMOTING_PROTOCOL_JINGLE_SESSION_MANAGER_H_
6 #define REMOTING_PROTOCOL_JINGLE_SESSION_MANAGER_H_
7
8 #include <list>
9 #include <map>
10 #include <string>
11
12 #include "base/memory/ref_counted.h"
13 #include "net/cert/x509_certificate.h"
14 #include "remoting/jingle_glue/signal_strategy.h"
15 #include "remoting/protocol/jingle_messages.h"
16 #include "remoting/protocol/session_manager.h"
17
18 namespace pp {
19 class Instance;
20 }  // namespace pp
21
22 namespace buzz {
23 class XmlElement;
24 }  // namespace buzz
25
26 namespace talk_base {
27 class SocketAddress;
28 }  // namespace talk_base
29
30 namespace remoting {
31
32 class IqSender;
33 class JingleInfoRequest;
34
35 namespace protocol {
36
37 class JingleSession;
38 class TransportFactory;
39
40 // JingleSessionManager and JingleSession implement the subset of the
41 // Jingle protocol used in Chromoting. JingleSessionManager provides
42 // the protocol::SessionManager interface for accepting incoming and
43 // creating outgoing sessions.
44 class JingleSessionManager : public SessionManager,
45                              public SignalStrategy::Listener {
46  public:
47   // When |fetch_stun_relay_config| is set to true then
48   // JingleSessionManager will also try to query configuration of STUN
49   // and Relay servers from the signaling server.
50   //
51   // TODO(sergeyu): Move NAT-traversal config fetching to a separate
52   // class.
53   explicit JingleSessionManager(
54       scoped_ptr<TransportFactory> transport_factory,
55       bool fetch_stun_relay_config);
56   virtual ~JingleSessionManager();
57
58   // SessionManager interface.
59   virtual void Init(SignalStrategy* signal_strategy,
60                     SessionManager::Listener* listener) OVERRIDE;
61   virtual scoped_ptr<Session> Connect(
62       const std::string& host_jid,
63       scoped_ptr<Authenticator> authenticator,
64       scoped_ptr<CandidateSessionConfig> config) OVERRIDE;
65   virtual void Close() OVERRIDE;
66   virtual void set_authenticator_factory(
67       scoped_ptr<AuthenticatorFactory> authenticator_factory) OVERRIDE;
68
69   // SignalStrategy::Listener interface.
70   virtual void OnSignalStrategyStateChange(
71       SignalStrategy::State state) OVERRIDE;
72   virtual bool OnSignalStrategyIncomingStanza(
73       const buzz::XmlElement* stanza) OVERRIDE;
74
75  private:
76   friend class JingleSession;
77
78   typedef std::map<std::string, JingleSession*> SessionsMap;
79
80   void OnJingleInfo(
81       const std::string& relay_token,
82       const std::vector<std::string>& relay_hosts,
83       const std::vector<talk_base::SocketAddress>& stun_hosts);
84
85   IqSender* iq_sender() { return iq_sender_.get(); }
86   void SendReply(const buzz::XmlElement* original_stanza,
87                  JingleMessageReply::ErrorType error);
88
89   // Called by JingleSession when it is being destroyed.
90   void SessionDestroyed(JingleSession* session);
91
92   scoped_ptr<TransportFactory> transport_factory_;
93   bool fetch_stun_relay_config_;
94
95   SignalStrategy* signal_strategy_;
96   scoped_ptr<AuthenticatorFactory> authenticator_factory_;
97   scoped_ptr<IqSender> iq_sender_;
98   SessionManager::Listener* listener_;
99
100   bool ready_;
101
102   scoped_ptr<JingleInfoRequest> jingle_info_request_;
103
104   SessionsMap sessions_;
105
106   DISALLOW_COPY_AND_ASSIGN(JingleSessionManager);
107 };
108
109 }  // namespace protocol
110 }  // namespace remoting
111
112 #endif  // REMOTING_PROTOCOL_JINGLE_SESSION_MANAGER_H_