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

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

Issue 580243003: Cleanup Fake* classes in remoting/protocol (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sctp
Patch Set: Created 6 years, 3 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef REMOTING_PROTOCOL_FAKE_STREAM_SOCKET_H_
6 #define REMOTING_PROTOCOL_FAKE_STREAM_SOCKET_H_
7
8 #include <map>
9 #include <string>
10
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "net/base/completion_callback.h"
14 #include "net/socket/stream_socket.h"
15 #include "remoting/protocol/stream_channel_factory.h"
16
17 namespace base {
18 class SingleThreadTaskRunner;
19 }
20
21 namespace remoting {
22 namespace protocol {
23
24 // FakeStreamSocket implement net::StreamSocket interface. All data written to
Wez 2014/09/20 00:25:10 Is there really nothing in net/ that performs this
Sergey Ulanov 2014/09/22 19:22:12 No.
25 // FakeStreamSocket is stored in a buffer returned by written_data(). Read()
26 // reads data from another buffer that can be set with AppendInputData().
Wez 2014/09/20 00:25:10 Similar comments re naming of "input data" apply a
Sergey Ulanov 2014/09/22 19:22:12 This is not new code, so I'd prefer to keep Append
27 // Pending reads are supported, so if there is a pending read AppendInputData()
28 // calls the read callback.
29 //
30 // Two fake sockets can be connected to each other using the
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
33 // sockets |a| and |b| must be created and used on the same thread.
34 class FakeStreamSocket : public net::StreamSocket {
35 public:
36 FakeStreamSocket();
37 virtual ~FakeStreamSocket();
38
39 const std::string& written_data() const { return written_data_; }
Wez 2014/09/20 00:25:10 I assume that this returns a single string w/ all
Sergey Ulanov 2014/09/22 19:22:12 Done.
40
41 void set_write_limit(int write_limit) { write_limit_ = write_limit; }
42 void set_async_write(bool async_write) { async_write_ = async_write; }
43 void set_next_write_error(int error) { next_write_error_ = error; }
44 void set_next_read_error(int error) { next_read_error_ = error; }
45 void AppendInputData(const std::string& data);
46 void PairWith(FakeStreamSocket* peer_socket);
47 int input_pos() const { return input_pos_; }
48 bool read_pending() const { return read_pending_; }
Wez 2014/09/20 00:25:10 Document each of these, e.g. specify units of writ
Sergey Ulanov 2014/09/22 19:22:12 Done.
49
50 // net::Socket implementation.
51 virtual int Read(net::IOBuffer* buf, int buf_len,
52 const net::CompletionCallback& callback) OVERRIDE;
53 virtual int Write(net::IOBuffer* buf, int buf_len,
54 const net::CompletionCallback& callback) OVERRIDE;
55
56 virtual int SetReceiveBufferSize(int32 size) OVERRIDE;
57 virtual int SetSendBufferSize(int32 size) OVERRIDE;
58
59 // net::StreamSocket interface.
60 virtual int Connect(const net::CompletionCallback& callback) OVERRIDE;
61 virtual void Disconnect() OVERRIDE;
62 virtual bool IsConnected() const OVERRIDE;
63 virtual bool IsConnectedAndIdle() const OVERRIDE;
64 virtual int GetPeerAddress(net::IPEndPoint* address) const OVERRIDE;
65 virtual int GetLocalAddress(net::IPEndPoint* address) const OVERRIDE;
66 virtual const net::BoundNetLog& NetLog() const OVERRIDE;
67 virtual void SetSubresourceSpeculation() OVERRIDE;
68 virtual void SetOmniboxSpeculation() OVERRIDE;
69 virtual bool WasEverUsed() const OVERRIDE;
70 virtual bool UsingTCPFastOpen() const OVERRIDE;
71 virtual bool WasNpnNegotiated() const OVERRIDE;
72 virtual net::NextProto GetNegotiatedProtocol() const OVERRIDE;
73 virtual bool GetSSLInfo(net::SSLInfo* ssl_info) OVERRIDE;
74
75 private:
76 void DoAsyncWrite(scoped_refptr<net::IOBuffer> buf, int buf_len,
77 const net::CompletionCallback& callback);
78 void DoWrite(net::IOBuffer* buf, int buf_len);
79
80 bool async_write_;
81 bool write_pending_;
82 int write_limit_;
83 int next_write_error_;
84
85 int next_read_error_;
86 bool read_pending_;
Wez 2014/09/20 00:25:10 is_read_pending_ or read_is_pending_
Sergey Ulanov 2014/09/22 19:22:12 read_pending_ is used in many other places. remove
87 scoped_refptr<net::IOBuffer> read_buffer_;
88 int read_buffer_size_;
89 net::CompletionCallback read_callback_;
90 base::WeakPtr<FakeStreamSocket> peer_socket_;
91
92 std::string written_data_;
93 std::string input_data_;
94 int input_pos_;
95
96 net::BoundNetLog net_log_;
97
98 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
99 base::WeakPtrFactory<FakeStreamSocket> weak_factory_;
100
101 DISALLOW_COPY_AND_ASSIGN(FakeStreamSocket);
102 };
103
104 // StreamChannelFactory that creates FakeStreamSocket.
105 class FakeStreamChannelFactory : public StreamChannelFactory {
106 public:
107 FakeStreamChannelFactory();
108 virtual ~FakeStreamChannelFactory();
109
110 void set_async_creation(bool async_creation) {
111 async_creation_ = async_creation;
112 }
113
114 void set_fail(bool fail) { fail_ = fail; }
115
116 FakeStreamSocket* GetChannel(const std::string& name);
117
118 // ChannelFactory interface.
119 virtual void CreateChannel(const std::string& name,
120 const ChannelCreatedCallback& callback) OVERRIDE;
121 virtual void CancelChannelCreation(const std::string& name) OVERRIDE;
122
123 private:
124 void NotifyChannelCreated(const std::string& name,
125 const ChannelCreatedCallback& callback);
126
127 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
128 bool async_creation_;
129 std::map<std::string, FakeStreamSocket*> channels_;
130
131 bool fail_;
132
133 base::WeakPtrFactory<FakeStreamChannelFactory> weak_factory_;
134
135 DISALLOW_COPY_AND_ASSIGN(FakeStreamChannelFactory);
136 };
137
138 } // namespace protocol
139 } // namespace remoting
140
141 #endif // REMOTING_PROTOCOL_FAKE_STREAM_SOCKET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698