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

Side by Side Diff: net/socket/web_socket_server_socket_unittest.cc

Issue 8889036: Revert 113699 - base::Bind: Convert Socket::Write. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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
« no previous file with comments | « net/socket/web_socket_server_socket.cc ('k') | net/spdy/spdy_proxy_client_socket.h » ('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 (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 #include "net/socket/web_socket_server_socket.h" 5 #include "net/socket/web_socket_server_socket.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <algorithm> 8 #include <algorithm>
9 9
10 #include "base/callback_old.h" 10 #include "base/callback_old.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 int lot = std::min(remaining, buf_len); 150 int lot = std::min(remaining, buf_len);
151 if (GetRand(0, 1)) 151 if (GetRand(0, 1))
152 lot = GetRand(1, lot); 152 lot = GetRand(1, lot);
153 std::copy(buf->data(), buf->data() + lot, answer_->data()); 153 std::copy(buf->data(), buf->data() + lot, answer_->data());
154 answer_->DidConsume(lot); 154 answer_->DidConsume(lot);
155 if (GetRand(0, 1)) { 155 if (GetRand(0, 1)) {
156 return lot; 156 return lot;
157 } 157 }
158 MessageLoop::current()->PostTask(FROM_HERE, 158 MessageLoop::current()->PostTask(FROM_HERE,
159 method_factory_.NewRunnableMethod( 159 method_factory_.NewRunnableMethod(
160 &TestingTransportSocket::DoOldWriteCallback, callback, lot));
161 return net::ERR_IO_PENDING;
162 }
163 virtual int Write(net::IOBuffer* buf, int buf_len,
164 const net::CompletionCallback& callback) {
165 CHECK_GT(buf_len, 0);
166 int remaining = answer_->BytesRemaining();
167 CHECK_GE(remaining, buf_len);
168 int lot = std::min(remaining, buf_len);
169 if (GetRand(0, 1))
170 lot = GetRand(1, lot);
171 std::copy(buf->data(), buf->data() + lot, answer_->data());
172 answer_->DidConsume(lot);
173 if (GetRand(0, 1)) {
174 return lot;
175 }
176 MessageLoop::current()->PostTask(FROM_HERE,
177 method_factory_.NewRunnableMethod(
178 &TestingTransportSocket::DoWriteCallback, callback, lot)); 160 &TestingTransportSocket::DoWriteCallback, callback, lot));
179 return net::ERR_IO_PENDING; 161 return net::ERR_IO_PENDING;
180 } 162 }
181 163
182 virtual bool SetReceiveBufferSize(int32 size) { 164 virtual bool SetReceiveBufferSize(int32 size) {
183 return true; 165 return true;
184 } 166 }
185 167
186 virtual bool SetSendBufferSize(int32 size) { 168 virtual bool SetSendBufferSize(int32 size) {
187 return true; 169 return true;
(...skipping 15 matching lines...) Expand all
203 if (result == 0 && !is_closed_) { 185 if (result == 0 && !is_closed_) {
204 MessageLoop::current()->PostTask(FROM_HERE, 186 MessageLoop::current()->PostTask(FROM_HERE,
205 method_factory_.NewRunnableMethod( 187 method_factory_.NewRunnableMethod(
206 &TestingTransportSocket::DoReadCallback, callback, 0)); 188 &TestingTransportSocket::DoReadCallback, callback, 0));
207 } else { 189 } else {
208 if (!callback.is_null()) 190 if (!callback.is_null())
209 callback.Run(result); 191 callback.Run(result);
210 } 192 }
211 } 193 }
212 194
213 void DoOldWriteCallback(net::OldCompletionCallback* callback, int result) { 195 void DoWriteCallback(net::OldCompletionCallback* callback, int result) {
214 if (callback) 196 if (callback)
215 callback->Run(result); 197 callback->Run(result);
216 } 198 }
217 void DoWriteCallback(const net::CompletionCallback& callback, int result) {
218 if (!callback.is_null())
219 callback.Run(result);
220 }
221 199
222 bool is_closed_; 200 bool is_closed_;
223 201
224 // Data to return for Read requests. 202 // Data to return for Read requests.
225 scoped_refptr<net::DrainableIOBuffer> sample_; 203 scoped_refptr<net::DrainableIOBuffer> sample_;
226 204
227 // Data pushed to us by server socket (using Write calls). 205 // Data pushed to us by server socket (using Write calls).
228 scoped_refptr<net::DrainableIOBuffer> answer_; 206 scoped_refptr<net::DrainableIOBuffer> answer_;
229 207
230 // Final read callback to report zero (zero stands for EOF). 208 // Final read callback to report zero (zero stands for EOF).
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 MessageLoop::current()->RunAllPending(); 625 MessageLoop::current()->RunAllPending();
648 626
649 for (size_t i = kill_list.size(); i--;) 627 for (size_t i = kill_list.size(); i--;)
650 delete kill_list[i]; 628 delete kill_list[i];
651 for (size_t i = tracker_list.size(); i--;) 629 for (size_t i = tracker_list.size(); i--;)
652 delete tracker_list[i]; 630 delete tracker_list[i];
653 MessageLoop::current()->RunAllPending(); 631 MessageLoop::current()->RunAllPending();
654 } 632 }
655 633
656 } // namespace net 634 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/web_socket_server_socket.cc ('k') | net/spdy/spdy_proxy_client_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698