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

Side by Side Diff: net/base/test_completion_callback.cc

Issue 8898036: base::Bind: Convert proxy_resolving_client_socket.[cc,h] and deps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Possible test fix. 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/base/test_completion_callback.h ('k') | net/http/http_network_transaction_unittest.cc » ('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/base/test_completion_callback.h" 5 #include "net/base/test_completion_callback.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
8 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
9 #include "base/message_loop.h" 10 #include "base/message_loop.h"
10 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
11 12
12 TestOldCompletionCallback::TestOldCompletionCallback() 13 void TestCompletionCallbackBase::SetResult(int result) {
14 result_ = result;
15 have_result_ = true;
16 if (waiting_for_result_)
17 MessageLoop::current()->Quit();
18 }
19
20 int TestCompletionCallbackBase::WaitForResult() {
21 DCHECK(!waiting_for_result_);
22
23 while (!have_result_) {
24 waiting_for_result_ = true;
25 MessageLoop::current()->Run();
26 waiting_for_result_ = false;
27 }
28
29 have_result_ = false; // Auto-reset for next callback.
30 return result_;
31 }
32
33 int TestCompletionCallbackBase::GetResult(int result) {
34 if (net::ERR_IO_PENDING != result)
35 return result;
36
37 return WaitForResult();
38 }
39
40 TestCompletionCallbackBase::TestCompletionCallbackBase()
13 : result_(0), 41 : result_(0),
14 have_result_(false), 42 have_result_(false),
15 waiting_for_result_(false) { 43 waiting_for_result_(false) {
16 } 44 }
17 45
18 TestOldCompletionCallback::~TestOldCompletionCallback() {}
19
20 int TestOldCompletionCallback::WaitForResult() {
21 DCHECK(!waiting_for_result_);
22 while (!have_result_) {
23 waiting_for_result_ = true;
24 MessageLoop::current()->Run();
25 waiting_for_result_ = false;
26 }
27 have_result_ = false; // auto-reset for next callback
28 return result_;
29 }
30
31 int TestOldCompletionCallback::GetResult(int result) {
32 if (net::ERR_IO_PENDING != result)
33 return result;
34 return WaitForResult();
35 }
36
37 void TestOldCompletionCallback::RunWithParams(const Tuple1<int>& params) { 46 void TestOldCompletionCallback::RunWithParams(const Tuple1<int>& params) {
38 result_ = params.a; 47 SetResult(params.a);
39 have_result_ = true;
40 if (waiting_for_result_)
41 MessageLoop::current()->Quit();
42 } 48 }
43 49
44 namespace net { 50 namespace net {
45 51
46 TestCompletionCallback::TestCompletionCallback() 52 TestCompletionCallback::TestCompletionCallback()
47 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_( 53 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
48 base::Bind(&TestCompletionCallback::OnComplete, 54 base::Bind(&TestCompletionCallback::SetResult,
49 base::Unretained(this)))) { 55 base::Unretained(this)))) {
50 } 56 }
51 57
52 TestCompletionCallback::~TestCompletionCallback() {} 58 TestCompletionCallback::~TestCompletionCallback() {}
53 59
54 void TestCompletionCallback::OnComplete(int result) {
55 old_callback_impl_.RunWithParams(Tuple1<int>(result));
56 }
57 60
58 } // namespace net 61 } // namespace net
OLDNEW
« no previous file with comments | « net/base/test_completion_callback.h ('k') | net/http/http_network_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698