Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "remoting/protocol/channel_factory.h" |
| 11 #include "base/threading/non_thread_safe.h" | |
| 12 #include "remoting/protocol/buffered_socket_writer.h" | |
| 13 #include "remoting/protocol/errors.h" | 11 #include "remoting/protocol/errors.h" |
| 14 #include "remoting/protocol/session_config.h" | 12 #include "remoting/protocol/session_config.h" |
| 15 | 13 |
| 16 namespace net { | 14 namespace net { |
| 17 class IPEndPoint; | 15 class IPEndPoint; |
| 18 class Socket; | |
| 19 class StreamSocket; | |
| 20 } // namespace net | 16 } // namespace net |
| 21 | 17 |
| 22 namespace remoting { | 18 namespace remoting { |
| 23 namespace protocol { | 19 namespace protocol { |
| 24 | 20 |
| 25 struct TransportRoute; | 21 struct TransportRoute; |
| 26 | 22 |
| 27 // Generic interface for Chromotocol connection used by both client and host. | 23 // Generic interface for Chromotocol connection used by both client and host. |
| 28 // Provides access to the connection channels, but doesn't depend on the | 24 // Provides access to the connection channels, but doesn't depend on the |
| 29 // protocol used for each channel. | 25 // protocol used for each channel. |
| 30 class Session : public base::NonThreadSafe { | 26 class Session : public ChannelFactory { |
| 31 public: | 27 public: |
| 32 enum State { | 28 enum State { |
| 33 // Created, but not connecting yet. | 29 // Created, but not connecting yet. |
| 34 INITIALIZING, | 30 INITIALIZING, |
| 35 | 31 |
| 36 // Sent or received session-initiate, but haven't sent or received | 32 // Sent or received session-initiate, but haven't sent or received |
| 37 // session-accept. | 33 // session-accept. |
| 38 // TODO(sergeyu): Do we really need this state? | 34 // TODO(sergeyu): Do we really need this state? |
| 39 CONNECTING, | 35 CONNECTING, |
| 40 | 36 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 67 virtual void OnSessionRouteChange(const std::string& channel_name, | 63 virtual void OnSessionRouteChange(const std::string& channel_name, |
| 68 const TransportRoute& route) = 0; | 64 const TransportRoute& route) = 0; |
| 69 | 65 |
| 70 // Called when ready state on one of the channels changes. See | 66 // Called when ready state on one of the channels changes. See |
| 71 // comments in transport.h for explanation on what this state | 67 // comments in transport.h for explanation on what this state |
| 72 // means and how it can used. | 68 // means and how it can used. |
| 73 virtual void OnSessionChannelReady(const std::string& channel_name, | 69 virtual void OnSessionChannelReady(const std::string& channel_name, |
| 74 bool ready) {} | 70 bool ready) {} |
| 75 }; | 71 }; |
| 76 | 72 |
| 77 // TODO(sergeyu): Specify connection error code when channel | |
| 78 // connection fails. | |
| 79 typedef base::Callback<void(scoped_ptr<net::StreamSocket>)> | |
| 80 StreamChannelCallback; | |
| 81 typedef base::Callback<void(scoped_ptr<net::Socket>)> | |
| 82 DatagramChannelCallback; | |
| 83 | 73 |
| 84 Session() {} | 74 Session() {} |
| 85 virtual ~Session() {} | 75 virtual ~Session() {} |
| 86 | 76 |
| 87 // Set event handler for this session. |event_handler| must outlive | 77 // Set event handler for this session. |event_handler| must outlive |
| 88 // this object. | 78 // this object. |
| 89 virtual void SetEventHandler(EventHandler* event_handler) = 0; | 79 virtual void SetEventHandler(EventHandler* event_handler) = 0; |
| 90 | 80 |
| 91 // Returns error code for a failed session. | 81 // Returns error code for a failed session. |
| 92 virtual ErrorCode error() = 0; | 82 virtual ErrorCode error() = 0; |
| 93 | 83 |
| 94 // Creates new channels for this connection. The specified callback | |
| 95 // is called when then new channel is created and connected. The | |
| 96 // callback is called with NULL if connection failed for any reason. | |
| 97 // All channels must be destroyed before the session is | |
| 98 // destroyed. Can be called only when in CONNECTING, CONNECTED or | |
| 99 // AUTHENTICATED states. | |
| 100 virtual void CreateStreamChannel( | |
| 101 const std::string& name, const StreamChannelCallback& callback) = 0; | |
| 102 virtual void CreateDatagramChannel( | |
| 103 const std::string& name, const DatagramChannelCallback& callback) = 0; | |
| 104 | |
| 105 // Cancels a pending CreateStreamChannel() or CreateDatagramChannel() | 84 // Cancels a pending CreateStreamChannel() or CreateDatagramChannel() |
| 106 // operation for the named channel. If the channel creation already | 85 // operation for the named channel. If the channel creation already |
| 107 // completed then cancelling it has no effect. When shutting down | 86 // completed then cancelling it has no effect. When shutting down |
| 108 // this method must be called for each channel pending creation. | 87 // this method must be called for each channel pending creation. |
| 109 virtual void CancelChannelCreation(const std::string& name) = 0; | 88 virtual void CancelChannelCreation(const std::string& name) = 0; |
|
Wez
2012/08/06 23:14:07
Why does this not belong on ChannelFactory?
Sergey Ulanov
2012/08/07 20:12:22
Done.
| |
| 110 | 89 |
| 111 // JID of the other side. | 90 // JID of the other side. |
| 112 virtual const std::string& jid() = 0; | 91 virtual const std::string& jid() = 0; |
| 113 | 92 |
| 114 // Configuration of the protocol that was sent or received in the | 93 // Configuration of the protocol that was sent or received in the |
| 115 // session-initiate jingle message. Returned pointer is valid until | 94 // session-initiate jingle message. Returned pointer is valid until |
| 116 // connection is closed. | 95 // connection is closed. |
| 117 virtual const CandidateSessionConfig* candidate_config() = 0; | 96 virtual const CandidateSessionConfig* candidate_config() = 0; |
| 118 | 97 |
| 119 // Protocol configuration. Can be called only after session has been accepted. | 98 // Protocol configuration. Can be called only after session has been accepted. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 131 virtual void Close() = 0; | 110 virtual void Close() = 0; |
| 132 | 111 |
| 133 private: | 112 private: |
| 134 DISALLOW_COPY_AND_ASSIGN(Session); | 113 DISALLOW_COPY_AND_ASSIGN(Session); |
| 135 }; | 114 }; |
| 136 | 115 |
| 137 } // namespace protocol | 116 } // namespace protocol |
| 138 } // namespace remoting | 117 } // namespace remoting |
| 139 | 118 |
| 140 #endif // REMOTING_PROTOCOL_SESSION_H_ | 119 #endif // REMOTING_PROTOCOL_SESSION_H_ |
| OLD | NEW |