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

Side by Side Diff: content/browser/renderer_host/p2p/socket_host_test_utils.h

Issue 8824006: Migrate net/socket/socket.h, net/socket/stream_socket.h to base::Bind(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TEST_UTILS_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TEST_UTILS_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TEST_UTILS_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TEST_UTILS_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "content/common/p2p_messages.h" 10 #include "content/common/p2p_messages.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 virtual ~FakeSocket(); 50 virtual ~FakeSocket();
51 51
52 void AppendInputData(const char* data, int data_size); 52 void AppendInputData(const char* data, int data_size);
53 int input_pos() const { return input_pos_; } 53 int input_pos() const { return input_pos_; }
54 bool read_pending() const { return read_pending_; } 54 bool read_pending() const { return read_pending_; }
55 void SetPeerAddress(const net::IPEndPoint& peer_address); 55 void SetPeerAddress(const net::IPEndPoint& peer_address);
56 void SetLocalAddress(const net::IPEndPoint& local_address); 56 void SetLocalAddress(const net::IPEndPoint& local_address);
57 57
58 // net::Socket implementation. 58 // net::Socket implementation.
59 virtual int Read(net::IOBuffer* buf, int buf_len, 59 virtual int Read(net::IOBuffer* buf, int buf_len,
60 net::OldCompletionCallback* callback) OVERRIDE;
61 virtual int Read(net::IOBuffer* buf, int buf_len,
62 const net::CompletionCallback& callback) OVERRIDE; 60 const net::CompletionCallback& callback) OVERRIDE;
63 virtual int Write(net::IOBuffer* buf, int buf_len, 61 virtual int Write(net::IOBuffer* buf, int buf_len,
64 net::OldCompletionCallback* callback) OVERRIDE; 62 const net::CompletionCallback& callback) OVERRIDE;
65 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; 63 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE;
66 virtual bool SetSendBufferSize(int32 size) OVERRIDE; 64 virtual bool SetSendBufferSize(int32 size) OVERRIDE;
67 virtual int Connect(net::OldCompletionCallback* callback) OVERRIDE;
68 virtual int Connect(const net::CompletionCallback& callback) OVERRIDE; 65 virtual int Connect(const net::CompletionCallback& callback) OVERRIDE;
69 virtual void Disconnect() OVERRIDE; 66 virtual void Disconnect() OVERRIDE;
70 virtual bool IsConnected() const OVERRIDE; 67 virtual bool IsConnected() const OVERRIDE;
71 virtual bool IsConnectedAndIdle() const OVERRIDE; 68 virtual bool IsConnectedAndIdle() const OVERRIDE;
72 virtual int GetPeerAddress(net::AddressList* address) const OVERRIDE; 69 virtual int GetPeerAddress(net::AddressList* address) const OVERRIDE;
73 virtual int GetLocalAddress(net::IPEndPoint* address) const OVERRIDE; 70 virtual int GetLocalAddress(net::IPEndPoint* address) const OVERRIDE;
74 virtual const net::BoundNetLog& NetLog() const OVERRIDE; 71 virtual const net::BoundNetLog& NetLog() const OVERRIDE;
75 virtual void SetSubresourceSpeculation() OVERRIDE; 72 virtual void SetSubresourceSpeculation() OVERRIDE;
76 virtual void SetOmniboxSpeculation() OVERRIDE; 73 virtual void SetOmniboxSpeculation() OVERRIDE;
77 virtual bool WasEverUsed() const OVERRIDE; 74 virtual bool WasEverUsed() const OVERRIDE;
78 virtual bool UsingTCPFastOpen() const OVERRIDE; 75 virtual bool UsingTCPFastOpen() const OVERRIDE;
79 virtual int64 NumBytesRead() const OVERRIDE; 76 virtual int64 NumBytesRead() const OVERRIDE;
80 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE; 77 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
81 78
82 private: 79 private:
83 bool read_pending_; 80 bool read_pending_;
84 scoped_refptr<net::IOBuffer> read_buffer_; 81 scoped_refptr<net::IOBuffer> read_buffer_;
85 int read_buffer_size_; 82 int read_buffer_size_;
86 net::OldCompletionCallback* old_read_callback_;
87 net::CompletionCallback read_callback_; 83 net::CompletionCallback read_callback_;
88 84
89 std::string* written_data_; 85 std::string* written_data_;
90 std::string input_data_; 86 std::string input_data_;
91 int input_pos_; 87 int input_pos_;
92 88
93 net::IPEndPoint peer_address_; 89 net::IPEndPoint peer_address_;
94 net::IPEndPoint local_address_; 90 net::IPEndPoint local_address_;
95 91
96 net::BoundNetLog net_log_; 92 net::BoundNetLog net_log_;
(...skipping 11 matching lines...) Expand all
108 input_data_.insert(input_data_.end(), data, data + data_size); 104 input_data_.insert(input_data_.end(), data, data + data_size);
109 // Complete pending read if any. 105 // Complete pending read if any.
110 if (read_pending_) { 106 if (read_pending_) {
111 read_pending_ = false; 107 read_pending_ = false;
112 int result = std::min(read_buffer_size_, 108 int result = std::min(read_buffer_size_,
113 static_cast<int>(input_data_.size() - input_pos_)); 109 static_cast<int>(input_data_.size() - input_pos_));
114 CHECK(result > 0); 110 CHECK(result > 0);
115 memcpy(read_buffer_->data(), &input_data_[0] + input_pos_, result); 111 memcpy(read_buffer_->data(), &input_data_[0] + input_pos_, result);
116 input_pos_ += result; 112 input_pos_ += result;
117 read_buffer_ = NULL; 113 read_buffer_ = NULL;
118 if (old_read_callback_) { 114 net::CompletionCallback cb = read_callback_;
119 net::OldCompletionCallback* cb = old_read_callback_; 115 read_callback_.Reset();
120 old_read_callback_ = NULL; 116 cb.Run(result);
121 cb->Run(result);
122 } else {
123 net::CompletionCallback cb = read_callback_;
124 read_callback_.Reset();
125 cb.Run(result);
126 }
127 } 117 }
128 } 118 }
129 119
130 void FakeSocket::SetPeerAddress(const net::IPEndPoint& peer_address) { 120 void FakeSocket::SetPeerAddress(const net::IPEndPoint& peer_address) {
131 peer_address_ = peer_address; 121 peer_address_ = peer_address;
132 } 122 }
133 123
134 void FakeSocket::SetLocalAddress(const net::IPEndPoint& local_address) { 124 void FakeSocket::SetLocalAddress(const net::IPEndPoint& local_address) {
135 local_address_ = local_address; 125 local_address_ = local_address;
136 } 126 }
137 127
138 int FakeSocket::Read(net::IOBuffer* buf, int buf_len, 128 int FakeSocket::Read(net::IOBuffer* buf, int buf_len,
139 net::OldCompletionCallback* callback) {
140 DCHECK(buf);
141 if (input_pos_ < static_cast<int>(input_data_.size())){
142 int result = std::min(buf_len,
143 static_cast<int>(input_data_.size()) - input_pos_);
144 memcpy(buf->data(), &(*input_data_.begin()) + input_pos_, result);
145 input_pos_ += result;
146 return result;
147 } else {
148 read_pending_ = true;
149 read_buffer_ = buf;
150 read_buffer_size_ = buf_len;
151 old_read_callback_ = callback;
152 return net::ERR_IO_PENDING;
153 }
154 }
155 int FakeSocket::Read(net::IOBuffer* buf, int buf_len,
156 const net::CompletionCallback& callback) { 129 const net::CompletionCallback& callback) {
157 DCHECK(buf); 130 DCHECK(buf);
158 if (input_pos_ < static_cast<int>(input_data_.size())){ 131 if (input_pos_ < static_cast<int>(input_data_.size())){
159 int result = std::min(buf_len, 132 int result = std::min(buf_len,
160 static_cast<int>(input_data_.size()) - input_pos_); 133 static_cast<int>(input_data_.size()) - input_pos_);
161 memcpy(buf->data(), &(*input_data_.begin()) + input_pos_, result); 134 memcpy(buf->data(), &(*input_data_.begin()) + input_pos_, result);
162 input_pos_ += result; 135 input_pos_ += result;
163 return result; 136 return result;
164 } else { 137 } else {
165 read_pending_ = true; 138 read_pending_ = true;
166 read_buffer_ = buf; 139 read_buffer_ = buf;
167 read_buffer_size_ = buf_len; 140 read_buffer_size_ = buf_len;
168 read_callback_ = callback; 141 read_callback_ = callback;
169 return net::ERR_IO_PENDING; 142 return net::ERR_IO_PENDING;
170 } 143 }
171 } 144 }
172 145
173 int FakeSocket::Write(net::IOBuffer* buf, int buf_len, 146 int FakeSocket::Write(net::IOBuffer* buf, int buf_len,
174 net::OldCompletionCallback* callback) { 147 const net::CompletionCallback& callback) {
175 DCHECK(buf); 148 DCHECK(buf);
176 if (written_data_) { 149 if (written_data_) {
177 written_data_->insert(written_data_->end(), 150 written_data_->insert(written_data_->end(),
178 buf->data(), buf->data() + buf_len); 151 buf->data(), buf->data() + buf_len);
179 } 152 }
180 return buf_len; 153 return buf_len;
181 } 154 }
182 155
183 156
184 bool FakeSocket::SetReceiveBufferSize(int32 size) { 157 bool FakeSocket::SetReceiveBufferSize(int32 size) {
185 NOTIMPLEMENTED(); 158 NOTIMPLEMENTED();
186 return false; 159 return false;
187 } 160 }
188 bool FakeSocket::SetSendBufferSize(int32 size) { 161 bool FakeSocket::SetSendBufferSize(int32 size) {
189 NOTIMPLEMENTED(); 162 NOTIMPLEMENTED();
190 return false; 163 return false;
191 } 164 }
192 165
193 int FakeSocket::Connect(net::OldCompletionCallback* callback) {
194 return 0;
195 }
196
197 int FakeSocket::Connect(const net::CompletionCallback& callback) { 166 int FakeSocket::Connect(const net::CompletionCallback& callback) {
198 return 0; 167 return 0;
199 } 168 }
200 169
201 void FakeSocket::Disconnect() { 170 void FakeSocket::Disconnect() {
202 NOTREACHED(); 171 NOTREACHED();
203 } 172 }
204 173
205 bool FakeSocket::IsConnected() const { 174 bool FakeSocket::IsConnected() const {
206 return true; 175 return true;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 return false; 273 return false;
305 P2PMsg_OnIncomingTcpConnection::Param params; 274 P2PMsg_OnIncomingTcpConnection::Param params;
306 P2PMsg_OnIncomingTcpConnection::Read( 275 P2PMsg_OnIncomingTcpConnection::Read(
307 arg, &params); 276 arg, &params);
308 return params.b == address; 277 return params.b == address;
309 } 278 }
310 279
311 } // namespace 280 } // namespace
312 281
313 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TEST_UTILS_H_ 282 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TEST_UTILS_H_
OLDNEW
« no previous file with comments | « content/browser/renderer_host/p2p/socket_host_tcp.cc ('k') | content/browser/renderer_host/p2p/socket_host_udp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698