1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/base/test_completion_callback.h"
8 #include "base/bind_helpers.h"
9 #include "base/compiler_specific.h"
10 #include "base/message_loop.h"
11 #include "net/base/io_buffer.h"
17 void TestCompletionCallbackBaseInternal::DidSetResult() {
19 if (waiting_for_result_
)
20 MessageLoop::current()->Quit();
23 void TestCompletionCallbackBaseInternal::WaitForResult() {
24 DCHECK(!waiting_for_result_
);
25 while (!have_result_
) {
26 waiting_for_result_
= true;
27 MessageLoop::current()->Run();
28 waiting_for_result_
= false;
30 have_result_
= false; // Auto-reset for next callback.
33 TestCompletionCallbackBaseInternal::TestCompletionCallbackBaseInternal()
34 : have_result_(false),
35 waiting_for_result_(false) {
38 } // namespace internal
40 TestCompletionCallback::TestCompletionCallback()
41 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
42 base::Bind(&TestCompletionCallback::SetResult
,
43 base::Unretained(this)))) {
46 TestCompletionCallback::~TestCompletionCallback() {
49 TestInt64CompletionCallback::TestInt64CompletionCallback()
50 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
51 base::Bind(&TestInt64CompletionCallback::SetResult
,
52 base::Unretained(this)))) {
55 TestInt64CompletionCallback::~TestInt64CompletionCallback() {
58 ReleaseBufferCompletionCallback::ReleaseBufferCompletionCallback(
59 IOBuffer
* buffer
) : buffer_(buffer
) {
62 ReleaseBufferCompletionCallback::~ReleaseBufferCompletionCallback() {
65 void ReleaseBufferCompletionCallback::SetResult(int result
) {
66 if (!buffer_
->HasOneRef())
67 result
= net::ERR_FAILED
;
68 TestCompletionCallback::SetResult(result
);