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/memory/weak_ptr.h" |
8 #include "remoting/proto/mux.pb.h" | 9 #include "remoting/proto/mux.pb.h" |
9 #include "remoting/protocol/buffered_socket_writer.h" | 10 #include "remoting/protocol/buffered_socket_writer.h" |
10 #include "remoting/protocol/channel_factory.h" | 11 #include "remoting/protocol/channel_factory.h" |
11 #include "remoting/protocol/message_reader.h" | 12 #include "remoting/protocol/message_reader.h" |
12 | 13 |
13 namespace remoting { | 14 namespace remoting { |
14 namespace protocol { | 15 namespace protocol { |
15 | 16 |
16 class ChannelMultiplexer : public ChannelFactory { | 17 class ChannelMultiplexer : public ChannelFactory { |
17 public: | 18 public: |
(...skipping 15 matching lines...) Expand all Loading... |
33 | 34 |
34 private: | 35 private: |
35 struct PendingChannel; | 36 struct PendingChannel; |
36 class MuxChannel; | 37 class MuxChannel; |
37 class MuxSocket; | 38 class MuxSocket; |
38 friend class MuxChannel; | 39 friend class MuxChannel; |
39 | 40 |
40 // Callback for |base_channel_| creation. | 41 // Callback for |base_channel_| creation. |
41 void OnBaseChannelReady(scoped_ptr<net::StreamSocket> socket); | 42 void OnBaseChannelReady(scoped_ptr<net::StreamSocket> socket); |
42 | 43 |
| 44 // Helper to create channels asynchronously. |
| 45 void DoCreatePendingChannels(); |
| 46 |
43 // Helper method used to create channels. | 47 // Helper method used to create channels. |
44 MuxChannel* GetOrCreateChannel(const std::string& name); | 48 MuxChannel* GetOrCreateChannel(const std::string& name); |
45 | 49 |
46 // Callbacks for |writer_| and |reader_|. | 50 // Error handling callback for |writer_|. |
47 void OnWriteFailed(int error); | 51 void OnWriteFailed(int error); |
| 52 |
| 53 // Failed write notifier, queued asynchronously by OnWriteFailed(). |
| 54 void NotifyWriteFailed(const std::string& name); |
| 55 |
| 56 // Callback for |reader_; |
48 void OnIncomingPacket(scoped_ptr<MultiplexPacket> packet, | 57 void OnIncomingPacket(scoped_ptr<MultiplexPacket> packet, |
49 const base::Closure& done_task); | 58 const base::Closure& done_task); |
50 | 59 |
51 // Called by MuxChannel. | 60 // Called by MuxChannel. |
52 bool DoWrite(scoped_ptr<MultiplexPacket> packet, | 61 bool DoWrite(scoped_ptr<MultiplexPacket> packet, |
53 const base::Closure& done_task); | 62 const base::Closure& done_task); |
54 | 63 |
55 // Factory used to create |base_channel_|. Set to NULL once creation is | 64 // Factory used to create |base_channel_|. Set to NULL once creation is |
56 // finished or failed. | 65 // finished or failed. |
57 ChannelFactory* base_channel_factory_; | 66 ChannelFactory* base_channel_factory_; |
(...skipping 10 matching lines...) Expand all Loading... |
68 int next_channel_id_; | 77 int next_channel_id_; |
69 std::map<std::string, MuxChannel*> channels_; | 78 std::map<std::string, MuxChannel*> channels_; |
70 | 79 |
71 // Channels are added to |channels_by_receive_id_| only after we receive | 80 // Channels are added to |channels_by_receive_id_| only after we receive |
72 // receive_id from the remote peer. | 81 // receive_id from the remote peer. |
73 std::map<int, MuxChannel*> channels_by_receive_id_; | 82 std::map<int, MuxChannel*> channels_by_receive_id_; |
74 | 83 |
75 BufferedSocketWriter writer_; | 84 BufferedSocketWriter writer_; |
76 ProtobufMessageReader<MultiplexPacket> reader_; | 85 ProtobufMessageReader<MultiplexPacket> reader_; |
77 | 86 |
78 // Flag used by OnWriteFailed() to detect when the multiplexer is destroyed. | 87 base::WeakPtrFactory<ChannelMultiplexer> weak_factory_; |
79 bool* destroyed_flag_; | |
80 | 88 |
81 DISALLOW_COPY_AND_ASSIGN(ChannelMultiplexer); | 89 DISALLOW_COPY_AND_ASSIGN(ChannelMultiplexer); |
82 }; | 90 }; |
83 | 91 |
84 } // namespace protocol | 92 } // namespace protocol |
85 } // namespace remoting | 93 } // namespace remoting |
86 | 94 |
87 | 95 |
88 #endif // REMOTING_PROTOCOL_CHANNEL_MULTIPLEXER_H_ | 96 #endif // REMOTING_PROTOCOL_CHANNEL_MULTIPLEXER_H_ |
OLD | NEW |