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_CHANNEL_MULTIPLEXER_H_ | 5 #ifndef REMOTING_PROTOCOL_CHANNEL_MULTIPLEXER_H_ |
6 #define REMOTING_PROTOCOL_CHANNEL_MULTIPLEXER_H_ | 6 #define REMOTING_PROTOCOL_CHANNEL_MULTIPLEXER_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "remoting/base/buffered_socket_writer.h" | 10 #include "remoting/base/buffered_socket_writer.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 const ChannelCreatedCallback& callback) override; | 29 const ChannelCreatedCallback& callback) override; |
30 void CancelChannelCreation(const std::string& name) override; | 30 void CancelChannelCreation(const std::string& name) override; |
31 | 31 |
32 private: | 32 private: |
33 struct PendingChannel; | 33 struct PendingChannel; |
34 class MuxChannel; | 34 class MuxChannel; |
35 class MuxSocket; | 35 class MuxSocket; |
36 friend class MuxChannel; | 36 friend class MuxChannel; |
37 | 37 |
38 // Callback for |base_channel_| creation. | 38 // Callback for |base_channel_| creation. |
39 void OnBaseChannelReady(scoped_ptr<P2PStreamSocket> socket); | 39 void OnBaseChannelReady(std::unique_ptr<P2PStreamSocket> socket); |
40 | 40 |
41 // Helper to create channels asynchronously. | 41 // Helper to create channels asynchronously. |
42 void DoCreatePendingChannels(); | 42 void DoCreatePendingChannels(); |
43 | 43 |
44 // Helper method used to create channels. | 44 // Helper method used to create channels. |
45 MuxChannel* GetOrCreateChannel(const std::string& name); | 45 MuxChannel* GetOrCreateChannel(const std::string& name); |
46 | 46 |
47 // Error handling callback for |reader_| and |writer_|. | 47 // Error handling callback for |reader_| and |writer_|. |
48 void OnBaseChannelError(int error); | 48 void OnBaseChannelError(int error); |
49 | 49 |
50 // Propagates base channel error to channel |name|, queued asynchronously by | 50 // Propagates base channel error to channel |name|, queued asynchronously by |
51 // OnBaseChannelError(). | 51 // OnBaseChannelError(). |
52 void NotifyBaseChannelError(const std::string& name, int error); | 52 void NotifyBaseChannelError(const std::string& name, int error); |
53 | 53 |
54 // Callback for |reader_; | 54 // Callback for |reader_; |
55 void OnIncomingPacket(scoped_ptr<CompoundBuffer> buffer); | 55 void OnIncomingPacket(std::unique_ptr<CompoundBuffer> buffer); |
56 | 56 |
57 // Called by MuxChannel. | 57 // Called by MuxChannel. |
58 void DoWrite(scoped_ptr<MultiplexPacket> packet, | 58 void DoWrite(std::unique_ptr<MultiplexPacket> packet, |
59 const base::Closure& done_task); | 59 const base::Closure& done_task); |
60 | 60 |
61 // Factory used to create |base_channel_|. Set to nullptr once creation is | 61 // Factory used to create |base_channel_|. Set to nullptr once creation is |
62 // finished or failed. | 62 // finished or failed. |
63 StreamChannelFactory* base_channel_factory_; | 63 StreamChannelFactory* base_channel_factory_; |
64 | 64 |
65 // Name of the underlying channel. | 65 // Name of the underlying channel. |
66 std::string base_channel_name_; | 66 std::string base_channel_name_; |
67 | 67 |
68 // The channel over which to multiplex. | 68 // The channel over which to multiplex. |
69 scoped_ptr<P2PStreamSocket> base_channel_; | 69 std::unique_ptr<P2PStreamSocket> base_channel_; |
70 | 70 |
71 // List of requested channels while we are waiting for |base_channel_|. | 71 // List of requested channels while we are waiting for |base_channel_|. |
72 std::list<PendingChannel> pending_channels_; | 72 std::list<PendingChannel> pending_channels_; |
73 | 73 |
74 int next_channel_id_; | 74 int next_channel_id_; |
75 std::map<std::string, MuxChannel*> channels_; | 75 std::map<std::string, MuxChannel*> channels_; |
76 | 76 |
77 // Channels are added to |channels_by_receive_id_| only after we receive | 77 // Channels are added to |channels_by_receive_id_| only after we receive |
78 // receive_id from the remote peer. | 78 // receive_id from the remote peer. |
79 std::map<int, MuxChannel*> channels_by_receive_id_; | 79 std::map<int, MuxChannel*> channels_by_receive_id_; |
80 | 80 |
81 BufferedSocketWriter writer_; | 81 BufferedSocketWriter writer_; |
82 MessageReader reader_; | 82 MessageReader reader_; |
83 | 83 |
84 base::WeakPtrFactory<ChannelMultiplexer> weak_factory_; | 84 base::WeakPtrFactory<ChannelMultiplexer> weak_factory_; |
85 | 85 |
86 DISALLOW_COPY_AND_ASSIGN(ChannelMultiplexer); | 86 DISALLOW_COPY_AND_ASSIGN(ChannelMultiplexer); |
87 }; | 87 }; |
88 | 88 |
89 } // namespace protocol | 89 } // namespace protocol |
90 } // namespace remoting | 90 } // namespace remoting |
91 | 91 |
92 | 92 |
93 #endif // REMOTING_PROTOCOL_CHANNEL_MULTIPLEXER_H_ | 93 #endif // REMOTING_PROTOCOL_CHANNEL_MULTIPLEXER_H_ |
OLD | NEW |