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

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

Issue 8734017: base::Bind: More random cleanups. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Mac build fix 2. 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') | no next file » | 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 "net/base/io_buffer.h" 8 #include "net/base/io_buffer.h"
8 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
9 #include "net/base/sys_addrinfo.h" 10 #include "net/base/sys_addrinfo.h"
10 #include "net/curvecp/protocol.h" 11 #include "net/curvecp/protocol.h"
11 #include "net/udp/udp_client_socket.h" 12 #include "net/udp/udp_client_socket.h"
12 13
13 namespace { 14 namespace {
14 15
15 const int kMaxHelloAttempts = 8; 16 const int kMaxHelloAttempts = 8;
16 const int kHelloTimeoutMs[kMaxHelloAttempts] = { 17 const int kHelloTimeoutMs[kMaxHelloAttempts] = {
(...skipping 14 matching lines...) Expand all
31 ClientPacketizer::ClientPacketizer() 32 ClientPacketizer::ClientPacketizer()
32 : Packetizer(), 33 : Packetizer(),
33 next_state_(NONE), 34 next_state_(NONE),
34 listener_(NULL), 35 listener_(NULL),
35 user_callback_(NULL), 36 user_callback_(NULL),
36 current_address_(NULL), 37 current_address_(NULL),
37 hello_attempts_(0), 38 hello_attempts_(0),
38 initiate_sent_(false), 39 initiate_sent_(false),
39 ALLOW_THIS_IN_INITIALIZER_LIST( 40 ALLOW_THIS_IN_INITIALIZER_LIST(
40 io_callback_(this, &ClientPacketizer::OnIOComplete)), 41 io_callback_(this, &ClientPacketizer::OnIOComplete)),
41 ALLOW_THIS_IN_INITIALIZER_LIST(timers_factory_(this)) { 42 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
42 // TODO(mbelshe): Initialize our keys and such properly. 43 // TODO(mbelshe): Initialize our keys and such properly.
43 // for now we use random values to keep them unique. 44 // for now we use random values to keep them unique.
44 for (int i = 0; i < 32; ++i) 45 for (int i = 0; i < 32; ++i)
45 shortterm_public_key_[i] = rand() % 26 + 'a'; 46 shortterm_public_key_[i] = rand() % 26 + 'a';
46 } 47 }
47 48
48 ClientPacketizer::~ClientPacketizer() { 49 ClientPacketizer::~ClientPacketizer() {
49 } 50 }
50 51
51 int ClientPacketizer::Connect(const AddressList& server, 52 int ClientPacketizer::Connect(const AddressList& server,
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 309
309 int rv = socket_->Connect(endpoint); 310 int rv = socket_->Connect(endpoint);
310 DCHECK_NE(ERR_IO_PENDING, rv); 311 DCHECK_NE(ERR_IO_PENDING, rv);
311 312
312 return rv; 313 return rv;
313 } 314 }
314 315
315 void ClientPacketizer::StartHelloTimer(int milliseconds) { 316 void ClientPacketizer::StartHelloTimer(int milliseconds) {
316 MessageLoop::current()->PostDelayedTask( 317 MessageLoop::current()->PostDelayedTask(
317 FROM_HERE, 318 FROM_HERE,
318 timers_factory_.NewRunnableMethod(&ClientPacketizer::OnHelloTimeout), 319 base::Bind(&ClientPacketizer::OnHelloTimeout, weak_factory_.GetWeakPtr()),
319 milliseconds); 320 milliseconds);
320 } 321 }
321 322
322 void ClientPacketizer::RevokeHelloTimer() { 323 void ClientPacketizer::RevokeHelloTimer() {
323 timers_factory_.RevokeAll(); 324 weak_factory_.InvalidateWeakPtrs();
324 } 325 }
325 326
326 void ClientPacketizer::OnHelloTimeout() { 327 void ClientPacketizer::OnHelloTimeout() {
327 DCHECK_EQ(WAITING_COOKIE_COMPLETE, next_state_); 328 DCHECK_EQ(WAITING_COOKIE_COMPLETE, next_state_);
328 next_state_ = SENDING_HELLO; 329 next_state_ = SENDING_HELLO;
329 DLOG(INFO) << "HelloTimeout #" << hello_attempts_; 330 DLOG(INFO) << "HelloTimeout #" << hello_attempts_;
330 int rv = DoLoop(OK); 331 int rv = DoLoop(OK);
331 if (rv != ERR_IO_PENDING) 332 if (rv != ERR_IO_PENDING)
332 DoCallback(rv); 333 DoCallback(rv);
333 } 334 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 return rv; 380 return rv;
380 } 381 }
381 382
382 void ClientPacketizer::OnIOComplete(int result) { 383 void ClientPacketizer::OnIOComplete(int result) {
383 int rv = DoLoop(result); 384 int rv = DoLoop(result);
384 if (rv != ERR_IO_PENDING) 385 if (rv != ERR_IO_PENDING)
385 DoCallback(rv); 386 DoCallback(rv);
386 } 387 }
387 388
388 } // namespace net 389 } // namespace net
OLDNEW
« no previous file with comments | « net/curvecp/client_packetizer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698