c/b/download: Replace usage of GetActiveEntry by GetLastCommittedEntry.
[chromium-blink-merge.git] / remoting / protocol / session.h
blob6fcd2c61993cb3efdb591b71e4880993f531ed49
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 #ifndef REMOTING_PROTOCOL_SESSION_H_
6 #define REMOTING_PROTOCOL_SESSION_H_
8 #include <string>
10 #include "remoting/protocol/errors.h"
11 #include "remoting/protocol/session_config.h"
13 namespace net {
14 class IPEndPoint;
15 } // namespace net
17 namespace remoting {
18 namespace protocol {
20 class StreamChannelFactory;
21 struct TransportRoute;
23 // Generic interface for Chromotocol connection used by both client and host.
24 // Provides access to the connection channels, but doesn't depend on the
25 // protocol used for each channel.
26 class Session {
27 public:
28 enum State {
29 // Created, but not connecting yet.
30 INITIALIZING,
32 // Sent session-initiate, but haven't received session-accept.
33 CONNECTING,
35 // Received session-initiate, but haven't sent session-accept.
36 ACCEPTING,
38 // Session has been accepted and is pending authentication.
39 CONNECTED,
41 // Session has started authenticating.
42 AUTHENTICATING,
44 // Session has been connected and authenticated.
45 AUTHENTICATED,
47 // Session has been closed.
48 CLOSED,
50 // Connection has failed.
51 FAILED,
54 class EventHandler {
55 public:
56 EventHandler() {}
57 virtual ~EventHandler() {}
59 // Called after session state has changed. It is safe to destroy
60 // the session from within the handler if |state| is AUTHENTICATING
61 // or CLOSED or FAILED.
62 virtual void OnSessionStateChange(State state) = 0;
64 // Called whenever route for the channel specified with
65 // |channel_name| changes. Session must not be destroyed by the
66 // handler of this event.
67 virtual void OnSessionRouteChange(const std::string& channel_name,
68 const TransportRoute& route) = 0;
71 Session() {}
72 virtual ~Session() {}
74 // Set event handler for this session. |event_handler| must outlive
75 // this object.
76 virtual void SetEventHandler(EventHandler* event_handler) = 0;
78 // Returns error code for a failed session.
79 virtual ErrorCode error() = 0;
81 // JID of the other side.
82 virtual const std::string& jid() = 0;
84 // Protocol configuration. Can be called only after session has been accepted.
85 // Returned pointer is valid until connection is closed.
86 virtual const SessionConfig& config() = 0;
88 // GetTransportChannelFactory() returns a factory that creates a new transport
89 // channel for each logical channel. GetMultiplexedChannelFactory() channels
90 // share a single underlying transport channel
91 virtual StreamChannelFactory* GetTransportChannelFactory() = 0;
92 virtual StreamChannelFactory* GetMultiplexedChannelFactory() = 0;
93 virtual StreamChannelFactory* GetQuicChannelFactory() = 0;
95 // Closes connection. Callbacks are guaranteed not to be called
96 // after this method returns. Must be called before the object is
97 // destroyed, unless the state is set to FAILED or CLOSED.
98 virtual void Close() = 0;
100 private:
101 DISALLOW_COPY_AND_ASSIGN(Session);
104 } // namespace protocol
105 } // namespace remoting
107 #endif // REMOTING_PROTOCOL_SESSION_H_