Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 // This file defines the interface for peer-to-peer transport. There | |
| 6 // are two types of transport: StreamTransport and DatagramTransport. | |
| 7 // They must both be created using TransportFactory instances and they | |
| 8 // provide the same interface, except that one should be used for | |
| 9 // reliable stream connection and the other one - for unreliable | |
|
simonmorris
2012/02/08 19:45:16
Remove "- ".
Sergey Ulanov
2012/02/08 20:20:30
Done.
| |
| 10 // datagram connection. Transport interface itself doesn't provide | |
|
simonmorris
2012/02/08 19:45:16
"The transport interface..."
Sergey Ulanov
2012/02/08 20:20:30
Done.
| |
| 11 // methods to send/receive data. Instead it creates an instance of | |
| 12 // net::Socket or net::SocketStream interface which provides access to | |
|
simonmorris
2012/02/08 19:45:16
Remove "interface", or add "the" before "net::Sock
Sergey Ulanov
2012/02/08 20:20:30
Done.
| |
| 13 // the data channel. After a new transport is Initialize()'ed the | |
| 14 // Connect() method must be called. Connect() starts asynchronous | |
| 15 // creation and initializations of connection socket that can be used | |
|
simonmorris
2012/02/08 19:45:16
"initialization"?
"of the connection socket".
Sergey Ulanov
2012/02/08 20:20:30
Done.
| |
| 16 // later to send and receive data. The socket is passed to the | |
| 17 // callback specified in the Connect() call. Transport object must | |
|
simonmorris
2012/02/08 19:45:16
"The Transport object".
Sergey Ulanov
2012/02/08 20:20:30
Done.
| |
| 18 // exist during whole lifetime of the connection socket. Later | |
|
simonmorris
2012/02/08 19:45:16
"during the whole"
Sergey Ulanov
2012/02/08 20:20:30
Done.
| |
| 19 // deletion of the transport socket causes teardown of the | |
|
simonmorris
2012/02/08 19:45:16
This is the first mention of a transport socket. I
Sergey Ulanov
2012/02/08 20:20:30
Done.
| |
| 20 // corresponding Transport object. | |
| 21 | |
| 22 #ifndef REMOTING_PROTOCOL_TRANSPORT_H_ | |
| 23 #define REMOTING_PROTOCOL_TRANSPORT_H_ | |
| 24 | |
| 25 #include <string> | |
| 26 | |
| 27 #include "base/basictypes.h" | |
| 28 #include "base/callback_forward.h" | |
| 29 #include "base/memory/scoped_ptr.h" | |
| 30 #include "base/threading/non_thread_safe.h" | |
| 31 | |
| 32 namespace cricket { | |
| 33 class Candidate; | |
| 34 } // namespace cricket | |
| 35 | |
| 36 namespace net { | |
| 37 class Socket; | |
| 38 class StreamSocket; | |
| 39 } // namespace net | |
| 40 | |
| 41 namespace remoting { | |
| 42 namespace protocol { | |
| 43 | |
| 44 class ChannelAuthenticator; | |
| 45 struct TransportConfig; | |
| 46 | |
| 47 class Transport : public base::NonThreadSafe { | |
| 48 public: | |
| 49 class EventHandler { | |
| 50 public: | |
| 51 EventHandler() {}; | |
| 52 virtual ~EventHandler() {}; | |
| 53 | |
| 54 // Called when the transport generates a new candidate that needs | |
| 55 // to be passed to the AddRemoteCandidate() method on the remote | |
| 56 // end of the connection. | |
| 57 virtual void OnTransportCandidate(Transport* transport, | |
| 58 const cricket::Candidate& candidate) = 0; | |
| 59 | |
| 60 // Called when the transport is about to be deleted. | |
| 61 virtual void OnTransportDeleted(Transport* transport) = 0; | |
| 62 }; | |
| 63 | |
| 64 Transport() {} | |
| 65 virtual ~Transport() {} | |
| 66 | |
| 67 // Intialize the transport with the specified | |
| 68 // paramters. |authenticator| is used to secure and authenticate the | |
|
simonmorris
2012/02/08 19:45:16
"parameters".
Sergey Ulanov
2012/02/08 20:20:30
Done.
| |
| 69 // connection. | |
| 70 virtual void Initialize(const std::string& name, | |
| 71 const TransportConfig& config, | |
| 72 Transport::EventHandler* event_handler, | |
| 73 scoped_ptr<ChannelAuthenticator> authenticator) = 0; | |
| 74 | |
| 75 // Adds |candidate| received from the peer. | |
| 76 virtual void AddRemoteCandidate(const cricket::Candidate& candidate) = 0; | |
| 77 | |
| 78 // Name of the channel. It is used to identify the channel and | |
| 79 // disambiguate candidates it generates from candidates generated by | |
| 80 // parallel connections. | |
| 81 virtual const std::string& name() const = 0; | |
| 82 | |
| 83 // Returns true if the channel is already connected. | |
| 84 virtual bool is_connected() const = 0; | |
| 85 | |
| 86 private: | |
| 87 DISALLOW_COPY_AND_ASSIGN(Transport); | |
| 88 }; | |
| 89 | |
| 90 class StreamTransport : public Transport { | |
| 91 public: | |
| 92 typedef base::Callback<void(scoped_ptr<net::StreamSocket>)> ConnectedCallback; | |
| 93 | |
| 94 StreamTransport() { } | |
| 95 ~StreamTransport() { } | |
| 96 | |
| 97 virtual void Connect(const ConnectedCallback& callback) = 0; | |
| 98 | |
| 99 private: | |
| 100 DISALLOW_COPY_AND_ASSIGN(StreamTransport); | |
| 101 }; | |
| 102 | |
| 103 class DatagramTransport : public Transport { | |
| 104 public: | |
| 105 typedef base::Callback<void(scoped_ptr<net::Socket>)> ConnectedCallback; | |
| 106 | |
| 107 DatagramTransport() { } | |
| 108 ~DatagramTransport() { } | |
| 109 | |
| 110 virtual void Connect(const ConnectedCallback& callback) = 0; | |
| 111 | |
| 112 private: | |
| 113 DISALLOW_COPY_AND_ASSIGN(DatagramTransport); | |
| 114 }; | |
| 115 | |
| 116 class TransportFactory { | |
| 117 public: | |
| 118 TransportFactory() { } | |
| 119 virtual ~TransportFactory() { } | |
| 120 | |
| 121 virtual scoped_ptr<StreamTransport> CreateStreamTransport() = 0; | |
| 122 virtual scoped_ptr<DatagramTransport> CreateDatagramTransport() = 0; | |
| 123 | |
| 124 private: | |
| 125 DISALLOW_COPY_AND_ASSIGN(TransportFactory); | |
| 126 }; | |
| 127 | |
| 128 } // namespace protocol | |
| 129 } // namespace remoting | |
| 130 | |
| 131 #endif // REMOTING_PROTOCOL_TRANSPORT_H_ | |
| OLD | NEW |