OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_FAKE_STREAM_SOCKET_H_ | 5 #ifndef REMOTING_PROTOCOL_FAKE_STREAM_SOCKET_H_ |
6 #define REMOTING_PROTOCOL_FAKE_STREAM_SOCKET_H_ | 6 #define REMOTING_PROTOCOL_FAKE_STREAM_SOCKET_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 int Read(const scoped_refptr<net::IOBuffer>& buf, int buf_len, | 72 int Read(const scoped_refptr<net::IOBuffer>& buf, int buf_len, |
73 const net::CompletionCallback& callback) override; | 73 const net::CompletionCallback& callback) override; |
74 int Write(const scoped_refptr<net::IOBuffer>& buf, int buf_len, | 74 int Write(const scoped_refptr<net::IOBuffer>& buf, int buf_len, |
75 const net::CompletionCallback& callback) override; | 75 const net::CompletionCallback& callback) override; |
76 | 76 |
77 private: | 77 private: |
78 void DoAsyncWrite(const scoped_refptr<net::IOBuffer>& buf, int buf_len, | 78 void DoAsyncWrite(const scoped_refptr<net::IOBuffer>& buf, int buf_len, |
79 const net::CompletionCallback& callback); | 79 const net::CompletionCallback& callback); |
80 void DoWrite(const scoped_refptr<net::IOBuffer>& buf, int buf_len); | 80 void DoWrite(const scoped_refptr<net::IOBuffer>& buf, int buf_len); |
81 | 81 |
82 bool async_write_; | 82 bool async_write_ = false; |
83 bool write_pending_; | 83 bool write_pending_ = false; |
84 int write_limit_; | 84 int write_limit_ = 0; |
85 int next_write_error_; | 85 int next_write_error_ = 0; |
86 | 86 |
87 int next_read_error_; | 87 int next_read_error_ = 0; |
88 scoped_refptr<net::IOBuffer> read_buffer_; | 88 scoped_refptr<net::IOBuffer> read_buffer_; |
89 int read_buffer_size_; | 89 int read_buffer_size_ = 0; |
90 net::CompletionCallback read_callback_; | 90 net::CompletionCallback read_callback_; |
91 base::WeakPtr<FakeStreamSocket> peer_socket_; | 91 base::WeakPtr<FakeStreamSocket> peer_socket_; |
92 | 92 |
93 std::string written_data_; | 93 std::string written_data_; |
94 std::string input_data_; | 94 std::string input_data_; |
95 int input_pos_; | 95 int input_pos_ = 0; |
96 | 96 |
97 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 97 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
98 base::WeakPtrFactory<FakeStreamSocket> weak_factory_; | 98 base::WeakPtrFactory<FakeStreamSocket> weak_factory_; |
99 | 99 |
100 DISALLOW_COPY_AND_ASSIGN(FakeStreamSocket); | 100 DISALLOW_COPY_AND_ASSIGN(FakeStreamSocket); |
101 }; | 101 }; |
102 | 102 |
103 // StreamChannelFactory that creates FakeStreamSocket. | 103 // StreamChannelFactory that creates FakeStreamSocket. |
104 class FakeStreamChannelFactory : public StreamChannelFactory { | 104 class FakeStreamChannelFactory : public StreamChannelFactory { |
105 public: | 105 public: |
106 FakeStreamChannelFactory(); | 106 FakeStreamChannelFactory(); |
107 ~FakeStreamChannelFactory() override; | 107 ~FakeStreamChannelFactory() override; |
108 | 108 |
109 void set_asynchronous_create(bool asynchronous_create) { | 109 void set_asynchronous_create(bool asynchronous_create) { |
110 asynchronous_create_ = asynchronous_create; | 110 asynchronous_create_ = asynchronous_create; |
111 } | 111 } |
112 | 112 |
113 void set_fail_create(bool fail_create) { fail_create_ = fail_create; } | 113 void set_fail_create(bool fail_create) { fail_create_ = fail_create; } |
114 | 114 |
| 115 // Enables asynchronous Write() on created channels. |
| 116 void set_async_write(bool async_write) { async_write_ = async_write; } |
| 117 |
115 FakeStreamSocket* GetFakeChannel(const std::string& name); | 118 FakeStreamSocket* GetFakeChannel(const std::string& name); |
116 | 119 |
117 // Pairs the socket with |peer_socket|. Deleting either of the paired sockets | 120 // Pairs the socket with |peer_socket|. Deleting either of the paired sockets |
118 // unpairs them. | 121 // unpairs them. |
119 void PairWith(FakeStreamChannelFactory* peer_factory); | 122 void PairWith(FakeStreamChannelFactory* peer_factory); |
120 | 123 |
121 // ChannelFactory interface. | 124 // ChannelFactory interface. |
122 void CreateChannel(const std::string& name, | 125 void CreateChannel(const std::string& name, |
123 const ChannelCreatedCallback& callback) override; | 126 const ChannelCreatedCallback& callback) override; |
124 void CancelChannelCreation(const std::string& name) override; | 127 void CancelChannelCreation(const std::string& name) override; |
125 | 128 |
126 private: | 129 private: |
127 void NotifyChannelCreated(scoped_ptr<FakeStreamSocket> owned_channel, | 130 void NotifyChannelCreated(scoped_ptr<FakeStreamSocket> owned_channel, |
128 const std::string& name, | 131 const std::string& name, |
129 const ChannelCreatedCallback& callback); | 132 const ChannelCreatedCallback& callback); |
130 | 133 |
131 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 134 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
132 bool asynchronous_create_; | 135 bool asynchronous_create_ = false; |
133 std::map<std::string, base::WeakPtr<FakeStreamSocket> > channels_; | 136 std::map<std::string, base::WeakPtr<FakeStreamSocket>> channels_; |
134 | 137 |
135 bool fail_create_; | 138 bool fail_create_ = false; |
| 139 |
| 140 bool async_write_ = false; |
136 | 141 |
137 base::WeakPtr<FakeStreamChannelFactory> peer_factory_; | 142 base::WeakPtr<FakeStreamChannelFactory> peer_factory_; |
138 base::WeakPtrFactory<FakeStreamChannelFactory> weak_factory_; | 143 base::WeakPtrFactory<FakeStreamChannelFactory> weak_factory_; |
139 | 144 |
140 DISALLOW_COPY_AND_ASSIGN(FakeStreamChannelFactory); | 145 DISALLOW_COPY_AND_ASSIGN(FakeStreamChannelFactory); |
141 }; | 146 }; |
142 | 147 |
143 } // namespace protocol | 148 } // namespace protocol |
144 } // namespace remoting | 149 } // namespace remoting |
145 | 150 |
146 #endif // REMOTING_PROTOCOL_FAKE_STREAM_SOCKET_H_ | 151 #endif // REMOTING_PROTOCOL_FAKE_STREAM_SOCKET_H_ |
OLD | NEW |