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

Side by Side Diff: net/curvecp/client_packetizer.cc

Issue 8801004: base::Bind: Convert StreamSocket::Connect. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes 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/curvecp/client_packetizer.h ('k') | net/curvecp/curvecp_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/curvecp/client_packetizer.h" 5 #include "net/curvecp/client_packetizer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "net/base/io_buffer.h" 8 #include "net/base/io_buffer.h"
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "net/base/sys_addrinfo.h" 10 #include "net/base/sys_addrinfo.h"
(...skipping 15 matching lines...) Expand all
26 }; 26 };
27 27
28 } // namespace 28 } // namespace
29 29
30 namespace net { 30 namespace net {
31 31
32 ClientPacketizer::ClientPacketizer() 32 ClientPacketizer::ClientPacketizer()
33 : Packetizer(), 33 : Packetizer(),
34 next_state_(NONE), 34 next_state_(NONE),
35 listener_(NULL), 35 listener_(NULL),
36 user_callback_(NULL), 36 old_user_callback_(NULL),
37 current_address_(NULL), 37 current_address_(NULL),
38 hello_attempts_(0), 38 hello_attempts_(0),
39 initiate_sent_(false), 39 initiate_sent_(false),
40 ALLOW_THIS_IN_INITIALIZER_LIST( 40 ALLOW_THIS_IN_INITIALIZER_LIST(
41 io_callback_(this, &ClientPacketizer::OnIOComplete)), 41 io_callback_(this, &ClientPacketizer::OnIOComplete)),
42 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 42 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
43 // TODO(mbelshe): Initialize our keys and such properly. 43 // TODO(mbelshe): Initialize our keys and such properly.
44 // for now we use random values to keep them unique. 44 // for now we use random values to keep them unique.
45 for (int i = 0; i < 32; ++i) 45 for (int i = 0; i < 32; ++i)
46 shortterm_public_key_[i] = rand() % 26 + 'a'; 46 shortterm_public_key_[i] = rand() % 26 + 'a';
47 } 47 }
48 48
49 ClientPacketizer::~ClientPacketizer() { 49 ClientPacketizer::~ClientPacketizer() {
50 } 50 }
51 51
52 int ClientPacketizer::Connect(const AddressList& server, 52 int ClientPacketizer::Connect(const AddressList& server,
53 Packetizer::Listener* listener, 53 Packetizer::Listener* listener,
54 OldCompletionCallback* callback) { 54 OldCompletionCallback* callback) {
55 DCHECK(!user_callback_); 55 DCHECK(!old_user_callback_);
56 DCHECK(!socket_.get()); 56 DCHECK(!socket_.get());
57 DCHECK(!listener_); 57 DCHECK(!listener_);
58 58
59 listener_ = listener;
60
61 addresses_ = server;
62
63 old_user_callback_ = callback;
64 next_state_ = LOOKUP_COOKIE;
65
66 return DoLoop(OK);
67 }
68 int ClientPacketizer::Connect(const AddressList& server,
69 Packetizer::Listener* listener,
70 const net::CompletionCallback& callback) {
71 DCHECK(user_callback_.is_null());
72 DCHECK(!socket_.get());
73 DCHECK(!listener_);
74
59 listener_ = listener; 75 listener_ = listener;
60 76
61 addresses_ = server; 77 addresses_ = server;
62 78
63 user_callback_ = callback; 79 user_callback_ = callback;
64 next_state_ = LOOKUP_COOKIE; 80 next_state_ = LOOKUP_COOKIE;
65 81
66 return DoLoop(OK); 82 return DoLoop(OK);
67 } 83 }
68 84
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 288
273 int ClientPacketizer::DoConnected(int rv) { 289 int ClientPacketizer::DoConnected(int rv) {
274 DCHECK(next_state_ == CONNECTED); 290 DCHECK(next_state_ == CONNECTED);
275 if (rv > 0) 291 if (rv > 0)
276 ProcessRead(rv); 292 ProcessRead(rv);
277 return ReadPackets(); 293 return ReadPackets();
278 } 294 }
279 295
280 void ClientPacketizer::DoCallback(int result) { 296 void ClientPacketizer::DoCallback(int result) {
281 DCHECK_NE(result, ERR_IO_PENDING); 297 DCHECK_NE(result, ERR_IO_PENDING);
282 DCHECK(user_callback_); 298 DCHECK(old_user_callback_ || !user_callback_.is_null());
283 299
284 OldCompletionCallback* callback = user_callback_; 300 if (old_user_callback_) {
285 user_callback_ = NULL; 301 OldCompletionCallback* callback = old_user_callback_;
286 callback->Run(result); 302 old_user_callback_ = NULL;
303 callback->Run(result);
304 } else {
305 CompletionCallback callback = user_callback_;
306 user_callback_.Reset();
307 callback.Run(result);
308 }
287 } 309 }
288 310
289 int ClientPacketizer::ConnectNextAddress() { 311 int ClientPacketizer::ConnectNextAddress() {
290 // TODO(mbelshe): plumb Netlog information 312 // TODO(mbelshe): plumb Netlog information
291 313
292 DCHECK(addresses_.head()); 314 DCHECK(addresses_.head());
293 315
294 socket_.reset(new UDPClientSocket(DatagramSocket::DEFAULT_BIND, 316 socket_.reset(new UDPClientSocket(DatagramSocket::DEFAULT_BIND,
295 RandIntCallback(), 317 RandIntCallback(),
296 NULL, 318 NULL,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 return rv; 402 return rv;
381 } 403 }
382 404
383 void ClientPacketizer::OnIOComplete(int result) { 405 void ClientPacketizer::OnIOComplete(int result) {
384 int rv = DoLoop(result); 406 int rv = DoLoop(result);
385 if (rv != ERR_IO_PENDING) 407 if (rv != ERR_IO_PENDING)
386 DoCallback(rv); 408 DoCallback(rv);
387 } 409 }
388 410
389 } // namespace net 411 } // namespace net
OLDNEW
« no previous file with comments | « net/curvecp/client_packetizer.h ('k') | net/curvecp/curvecp_client_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698