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

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

Issue 8832006: Reverts a commit that caused ASAN failures, and 2 dependent commits. (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/base/test_completion_callback.h ('k') | net/disk_cache/backend_impl.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/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/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
11 11
12 void TestCompletionCallbackBase::SetResult(int result) { 12 TestOldCompletionCallback::TestOldCompletionCallback()
13 result_ = result;
14 have_result_ = true;
15 if (waiting_for_result_)
16 MessageLoop::current()->Quit();
17 }
18
19 int TestCompletionCallbackBase::WaitForResult() {
20 DCHECK(!waiting_for_result_);
21
22 while (!have_result_) {
23 printf("waiting\n");
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()
41 : result_(0), 13 : result_(0),
42 have_result_(false), 14 have_result_(false),
43 waiting_for_result_(false) { 15 waiting_for_result_(false) {
44 } 16 }
45 17
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
46 void TestOldCompletionCallback::RunWithParams(const Tuple1<int>& params) { 37 void TestOldCompletionCallback::RunWithParams(const Tuple1<int>& params) {
47 SetResult(params.a); 38 result_ = params.a;
39 have_result_ = true;
40 if (waiting_for_result_)
41 MessageLoop::current()->Quit();
48 } 42 }
49 43
50 namespace net { 44 namespace net {
51 45
52 TestCompletionCallback::TestCompletionCallback() 46 TestCompletionCallback::TestCompletionCallback()
53 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_( 47 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
54 base::Bind(&TestCompletionCallback::SetResult, 48 base::Bind(&TestCompletionCallback::OnComplete,
55 base::Unretained(this)))) { 49 base::Unretained(this)))) {
56 } 50 }
57 51
58 TestCompletionCallback::~TestCompletionCallback() {} 52 TestCompletionCallback::~TestCompletionCallback() {}
59 53
54 void TestCompletionCallback::OnComplete(int result) {
55 old_callback_impl_.RunWithParams(Tuple1<int>(result));
56 }
60 57
61 } // namespace net 58 } // namespace net
OLDNEW
« no previous file with comments | « net/base/test_completion_callback.h ('k') | net/disk_cache/backend_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698