Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Side by Side Diff: remoting/protocol/transport.h

Issue 9325036: Add abstract interfaces for the transport layer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix crash Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/protocol/pepper_transport_factory.cc ('k') | remoting/remoting.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
10 // datagram connection. The Transport interface itself doesn't provide
11 // methods to send/receive data. Instead it creates an instance of
12 // net::Socket or net::SocketStream which provides access to the data
13 // channel. After a new transport is Initialize()'ed the Connect()
14 // method must be called. Connect() starts asynchronous creation and
15 // initialization of the connection socket that can be used later to
16 // send and receive data. The socket is passed to the callback
17 // specified in the Connect() call. The Transport object must exist
18 // during the whole lifetime of the connection socket. Later deletion
19 // of the connection socket causes teardown of the corresponding
20 // 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 parameters.
68 // |authenticator| is used to secure and authenticate the connection.
69 virtual void Initialize(const std::string& name,
70 const TransportConfig& config,
71 Transport::EventHandler* event_handler,
72 scoped_ptr<ChannelAuthenticator> authenticator) = 0;
73
74 // Adds |candidate| received from the peer.
75 virtual void AddRemoteCandidate(const cricket::Candidate& candidate) = 0;
76
77 // Name of the channel. It is used to identify the channel and
78 // disambiguate candidates it generates from candidates generated by
79 // parallel connections.
80 virtual const std::string& name() const = 0;
81
82 // Returns true if the channel is already connected.
83 virtual bool is_connected() const = 0;
84
85 private:
86 DISALLOW_COPY_AND_ASSIGN(Transport);
87 };
88
89 class StreamTransport : public Transport {
90 public:
91 typedef base::Callback<void(scoped_ptr<net::StreamSocket>)> ConnectedCallback;
92
93 StreamTransport() { }
94 virtual ~StreamTransport() { }
95
96 virtual void Connect(const ConnectedCallback& callback) = 0;
97
98 private:
99 DISALLOW_COPY_AND_ASSIGN(StreamTransport);
100 };
101
102 class DatagramTransport : public Transport {
103 public:
104 typedef base::Callback<void(scoped_ptr<net::Socket>)> ConnectedCallback;
105
106 DatagramTransport() { }
107 virtual ~DatagramTransport() { }
108
109 virtual void Connect(const ConnectedCallback& callback) = 0;
110
111 private:
112 DISALLOW_COPY_AND_ASSIGN(DatagramTransport);
113 };
114
115 class TransportFactory {
116 public:
117 TransportFactory() { }
118 virtual ~TransportFactory() { }
119
120 virtual scoped_ptr<StreamTransport> CreateStreamTransport() = 0;
121 virtual scoped_ptr<DatagramTransport> CreateDatagramTransport() = 0;
122
123 private:
124 DISALLOW_COPY_AND_ASSIGN(TransportFactory);
125 };
126
127 } // namespace protocol
128 } // namespace remoting
129
130 #endif // REMOTING_PROTOCOL_TRANSPORT_H_
OLDNEW
« no previous file with comments | « remoting/protocol/pepper_transport_factory.cc ('k') | remoting/remoting.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698