OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef REMOTING_PROTOCOL_SESSION_H_ | 5 #ifndef REMOTING_PROTOCOL_SESSION_H_ |
6 #define REMOTING_PROTOCOL_SESSION_H_ | 6 #define REMOTING_PROTOCOL_SESSION_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 // with a clean stack, i.e. not from event handlers, when sigslot may | 29 // with a clean stack, i.e. not from event handlers, when sigslot may |
30 // be present in the stack. | 30 // be present in the stack. |
31 class Session : public base::NonThreadSafe { | 31 class Session : public base::NonThreadSafe { |
32 public: | 32 public: |
33 enum State { | 33 enum State { |
34 // Created, but not connecting yet. | 34 // Created, but not connecting yet. |
35 INITIALIZING, | 35 INITIALIZING, |
36 | 36 |
37 // Sent or received session-initiate, but haven't sent or received | 37 // Sent or received session-initiate, but haven't sent or received |
38 // session-accept. | 38 // session-accept. |
| 39 // TODO(sergeyu): Do we really need this state? |
39 CONNECTING, | 40 CONNECTING, |
40 | 41 |
41 // Session has been accepted. | 42 // Session has been accepted and is pending authentication. |
42 CONNECTED, | 43 CONNECTED, |
43 | 44 |
| 45 // Session has been connected and authenticated. |
| 46 AUTHENTICATED, |
| 47 |
44 // Session has been closed. | 48 // Session has been closed. |
45 CLOSED, | 49 CLOSED, |
46 | 50 |
47 // Connection has failed. | 51 // Connection has failed. |
48 FAILED, | 52 FAILED, |
49 }; | 53 }; |
50 | 54 |
51 // TODO(sergeyu): Move error codes to a separate file. | 55 // TODO(sergeyu): Move error codes to a separate file. |
52 enum Error { | 56 enum Error { |
53 OK = 0, | 57 OK = 0, |
54 PEER_IS_OFFLINE, | 58 PEER_IS_OFFLINE, |
55 SESSION_REJECTED, | 59 SESSION_REJECTED, |
56 INCOMPATIBLE_PROTOCOL, | 60 INCOMPATIBLE_PROTOCOL, |
57 AUTHENTICATION_FAILED, | 61 AUTHENTICATION_FAILED, |
58 CHANNEL_CONNECTION_ERROR, | 62 CHANNEL_CONNECTION_ERROR, |
59 }; | 63 }; |
60 | 64 |
61 typedef base::Callback<void(State)> StateChangeCallback; | 65 // State change callbacks are called after session state has |
| 66 // changed. It is not safe to destroy the session from within the |
| 67 // handler unless |state| is CLOSED or FAILED. |
| 68 typedef base::Callback<void(State state)> StateChangeCallback; |
62 | 69 |
63 // TODO(sergeyu): Specify connection error code when channel | 70 // TODO(sergeyu): Specify connection error code when channel |
64 // connection fails. | 71 // connection fails. |
65 typedef base::Callback<void(net::StreamSocket*)> StreamChannelCallback; | 72 typedef base::Callback<void(net::StreamSocket*)> StreamChannelCallback; |
66 typedef base::Callback<void(net::Socket*)> DatagramChannelCallback; | 73 typedef base::Callback<void(net::Socket*)> DatagramChannelCallback; |
67 | 74 |
68 Session() { } | 75 Session() { } |
69 virtual ~Session() { } | 76 virtual ~Session() { } |
70 | 77 |
71 // Set callback that is called when state of the connection is changed. | 78 // Set callback that is called when state of the connection is changed. |
72 // Must be called on the jingle thread only. | 79 // Must be called on the jingle thread only. |
73 virtual void SetStateChangeCallback(const StateChangeCallback& callback) = 0; | 80 virtual void SetStateChangeCallback(const StateChangeCallback& callback) = 0; |
74 | 81 |
75 // Returns error code for a failed session. | 82 // Returns error code for a failed session. |
76 virtual Error error() = 0; | 83 virtual Error error() = 0; |
77 | 84 |
78 // Creates new channels for this connection. The specified callback | 85 // Creates new channels for this connection. The specified callback |
79 // is called when then new channel is created and connected. The | 86 // is called when then new channel is created and connected. The |
80 // callback is called with NULL if connection failed for any reason. | 87 // callback is called with NULL if connection failed for any reason. |
81 // Ownership of the channel socket is given to the caller when the | 88 // Ownership of the channel socket is given to the caller when the |
82 // callback is called. All channels must be destroyed before the | 89 // callback is called. All channels must be destroyed before the |
83 // session is destroyed. Can be called only when in CONNECTING or | 90 // session is destroyed. Can be called only when in CONNECTING, |
84 // CONNECTED state. | 91 // CONNECTED or AUTHENTICATED states. |
85 virtual void CreateStreamChannel( | 92 virtual void CreateStreamChannel( |
86 const std::string& name, const StreamChannelCallback& callback) = 0; | 93 const std::string& name, const StreamChannelCallback& callback) = 0; |
87 virtual void CreateDatagramChannel( | 94 virtual void CreateDatagramChannel( |
88 const std::string& name, const DatagramChannelCallback& callback) = 0; | 95 const std::string& name, const DatagramChannelCallback& callback) = 0; |
89 | 96 |
90 // Cancels a pending CreateStreamChannel() or CreateDatagramChannel() | 97 // Cancels a pending CreateStreamChannel() or CreateDatagramChannel() |
91 // operation for the named channel. If the channel creation already | 98 // operation for the named channel. If the channel creation already |
92 // completed then cancelling it has no effect. When shutting down | 99 // completed then cancelling it has no effect. When shutting down |
93 // this method must be called for each channel pending creation. | 100 // this method must be called for each channel pending creation. |
94 virtual void CancelChannelCreation(const std::string& name) = 0; | 101 virtual void CancelChannelCreation(const std::string& name) = 0; |
(...skipping 21 matching lines...) Expand all Loading... |
116 virtual void Close() = 0; | 123 virtual void Close() = 0; |
117 | 124 |
118 private: | 125 private: |
119 DISALLOW_COPY_AND_ASSIGN(Session); | 126 DISALLOW_COPY_AND_ASSIGN(Session); |
120 }; | 127 }; |
121 | 128 |
122 } // namespace protocol | 129 } // namespace protocol |
123 } // namespace remoting | 130 } // namespace remoting |
124 | 131 |
125 #endif // REMOTING_PROTOCOL_SESSION_H_ | 132 #endif // REMOTING_PROTOCOL_SESSION_H_ |
OLD | NEW |