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

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

Issue 1197853003: Add P2PDatagramSocket and P2PStreamSocket interfaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « remoting/protocol/fake_datagram_socket.cc ('k') | remoting/protocol/fake_stream_socket.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "net/base/completion_callback.h" 13 #include "net/base/completion_callback.h"
14 #include "net/socket/stream_socket.h" 14 #include "remoting/protocol/p2p_stream_socket.h"
15 #include "remoting/protocol/stream_channel_factory.h" 15 #include "remoting/protocol/stream_channel_factory.h"
16 16
17 namespace base { 17 namespace base {
18 class SingleThreadTaskRunner; 18 class SingleThreadTaskRunner;
19 } 19 }
20 20
21 namespace remoting { 21 namespace remoting {
22 namespace protocol { 22 namespace protocol {
23 23
24 // FakeStreamSocket implement net::StreamSocket interface. All data written to 24 // FakeStreamSocket implement P2PStreamSocket interface. All data written to
25 // FakeStreamSocket is stored in a buffer returned by written_data(). Read() 25 // FakeStreamSocket is stored in a buffer returned by written_data(). Read()
26 // reads data from another buffer that can be set with AppendInputData(). 26 // reads data from another buffer that can be set with AppendInputData().
27 // Pending reads are supported, so if there is a pending read AppendInputData() 27 // Pending reads are supported, so if there is a pending read AppendInputData()
28 // calls the read callback. 28 // calls the read callback.
29 // 29 //
30 // Two fake sockets can be connected to each other using the 30 // Two fake sockets can be connected to each other using the
31 // PairWith() method, e.g.: a->PairWith(b). After this all data 31 // PairWith() method, e.g.: a->PairWith(b). After this all data
32 // written to |a| can be read from |b| and vice versa. Two connected 32 // written to |a| can be read from |b| and vice versa. Two connected
33 // sockets |a| and |b| must be created and used on the same thread. 33 // sockets |a| and |b| must be created and used on the same thread.
34 class FakeStreamSocket : public net::StreamSocket { 34 class FakeStreamSocket : public P2PStreamSocket {
35 public: 35 public:
36 FakeStreamSocket(); 36 FakeStreamSocket();
37 ~FakeStreamSocket() override; 37 ~FakeStreamSocket() override;
38 38
39 // Returns all data written to the socket. 39 // Returns all data written to the socket.
40 const std::string& written_data() const { return written_data_; } 40 const std::string& written_data() const { return written_data_; }
41 41
42 // Sets maximum number of bytes written by each Write() call. 42 // Sets maximum number of bytes written by each Write() call.
43 void set_write_limit(int write_limit) { write_limit_ = write_limit; } 43 void set_write_limit(int write_limit) { write_limit_ = write_limit; }
44 44
(...skipping 16 matching lines...) Expand all
61 void PairWith(FakeStreamSocket* peer_socket); 61 void PairWith(FakeStreamSocket* peer_socket);
62 62
63 // Current input position in bytes. 63 // Current input position in bytes.
64 int input_pos() const { return input_pos_; } 64 int input_pos() const { return input_pos_; }
65 65
66 // True if a Read() call is currently pending. 66 // True if a Read() call is currently pending.
67 bool read_pending() const { return !read_callback_.is_null(); } 67 bool read_pending() const { return !read_callback_.is_null(); }
68 68
69 base::WeakPtr<FakeStreamSocket> GetWeakPtr(); 69 base::WeakPtr<FakeStreamSocket> GetWeakPtr();
70 70
71 // net::Socket implementation. 71 // P2PStreamSocket interface.
72 int Read(net::IOBuffer* buf, 72 int Read(const scoped_refptr<net::IOBuffer>& buf, int buf_len,
73 int buf_len,
74 const net::CompletionCallback& callback) override; 73 const net::CompletionCallback& callback) override;
75 int Write(net::IOBuffer* buf, 74 int Write(const scoped_refptr<net::IOBuffer>& buf, int buf_len,
76 int buf_len,
77 const net::CompletionCallback& callback) override; 75 const net::CompletionCallback& callback) override;
78 int SetReceiveBufferSize(int32 size) override;
79 int SetSendBufferSize(int32 size) override;
80
81 // net::StreamSocket interface.
82 int Connect(const net::CompletionCallback& callback) override;
83 void Disconnect() override;
84 bool IsConnected() const override;
85 bool IsConnectedAndIdle() const override;
86 int GetPeerAddress(net::IPEndPoint* address) const override;
87 int GetLocalAddress(net::IPEndPoint* address) const override;
88 const net::BoundNetLog& NetLog() const override;
89 void SetSubresourceSpeculation() override;
90 void SetOmniboxSpeculation() override;
91 bool WasEverUsed() const override;
92 bool UsingTCPFastOpen() const override;
93 bool WasNpnNegotiated() const override;
94 net::NextProto GetNegotiatedProtocol() const override;
95 bool GetSSLInfo(net::SSLInfo* ssl_info) override;
96 void GetConnectionAttempts(net::ConnectionAttempts* out) const override;
97 void ClearConnectionAttempts() override {}
98 void AddConnectionAttempts(const net::ConnectionAttempts& attempts) override {
99 }
100 76
101 private: 77 private:
102 void DoAsyncWrite(scoped_refptr<net::IOBuffer> buf, int buf_len, 78 void DoAsyncWrite(const scoped_refptr<net::IOBuffer>& buf, int buf_len,
103 const net::CompletionCallback& callback); 79 const net::CompletionCallback& callback);
104 void DoWrite(net::IOBuffer* buf, int buf_len); 80 void DoWrite(const scoped_refptr<net::IOBuffer>& buf, int buf_len);
105 81
106 bool async_write_; 82 bool async_write_;
107 bool write_pending_; 83 bool write_pending_;
108 int write_limit_; 84 int write_limit_;
109 int next_write_error_; 85 int next_write_error_;
110 86
111 int next_read_error_; 87 int next_read_error_;
112 scoped_refptr<net::IOBuffer> read_buffer_; 88 scoped_refptr<net::IOBuffer> read_buffer_;
113 int read_buffer_size_; 89 int read_buffer_size_;
114 net::CompletionCallback read_callback_; 90 net::CompletionCallback read_callback_;
115 base::WeakPtr<FakeStreamSocket> peer_socket_; 91 base::WeakPtr<FakeStreamSocket> peer_socket_;
116 92
117 std::string written_data_; 93 std::string written_data_;
118 std::string input_data_; 94 std::string input_data_;
119 int input_pos_; 95 int input_pos_;
120 96
121 net::BoundNetLog net_log_;
122
123 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 97 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
124 base::WeakPtrFactory<FakeStreamSocket> weak_factory_; 98 base::WeakPtrFactory<FakeStreamSocket> weak_factory_;
125 99
126 DISALLOW_COPY_AND_ASSIGN(FakeStreamSocket); 100 DISALLOW_COPY_AND_ASSIGN(FakeStreamSocket);
127 }; 101 };
128 102
129 // StreamChannelFactory that creates FakeStreamSocket. 103 // StreamChannelFactory that creates FakeStreamSocket.
130 class FakeStreamChannelFactory : public StreamChannelFactory { 104 class FakeStreamChannelFactory : public StreamChannelFactory {
131 public: 105 public:
132 FakeStreamChannelFactory(); 106 FakeStreamChannelFactory();
(...skipping 25 matching lines...) Expand all
158 132
159 base::WeakPtrFactory<FakeStreamChannelFactory> weak_factory_; 133 base::WeakPtrFactory<FakeStreamChannelFactory> weak_factory_;
160 134
161 DISALLOW_COPY_AND_ASSIGN(FakeStreamChannelFactory); 135 DISALLOW_COPY_AND_ASSIGN(FakeStreamChannelFactory);
162 }; 136 };
163 137
164 } // namespace protocol 138 } // namespace protocol
165 } // namespace remoting 139 } // namespace remoting
166 140
167 #endif // REMOTING_PROTOCOL_FAKE_STREAM_SOCKET_H_ 141 #endif // REMOTING_PROTOCOL_FAKE_STREAM_SOCKET_H_
OLDNEW
« no previous file with comments | « remoting/protocol/fake_datagram_socket.cc ('k') | remoting/protocol/fake_stream_socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698