diff options
Diffstat (limited to 'net/base/test_completion_callback.cc')
-rw-r--r-- | net/base/test_completion_callback.cc | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/net/base/test_completion_callback.cc b/net/base/test_completion_callback.cc index 6851a7c..aa04d22 100644 --- a/net/base/test_completion_callback.cc +++ b/net/base/test_completion_callback.cc @@ -5,54 +5,57 @@ #include "net/base/test_completion_callback.h" #include "base/bind.h" +#include "base/bind_helpers.h" #include "base/compiler_specific.h" #include "base/message_loop.h" #include "net/base/net_errors.h" -TestOldCompletionCallback::TestOldCompletionCallback() - : result_(0), - have_result_(false), - waiting_for_result_(false) { +void TestCompletionCallbackBase::SetResult(int result) { + result_ = result; + have_result_ = true; + if (waiting_for_result_) + MessageLoop::current()->Quit(); } -TestOldCompletionCallback::~TestOldCompletionCallback() {} - -int TestOldCompletionCallback::WaitForResult() { +int TestCompletionCallbackBase::WaitForResult() { DCHECK(!waiting_for_result_); + while (!have_result_) { waiting_for_result_ = true; MessageLoop::current()->Run(); waiting_for_result_ = false; } - have_result_ = false; // auto-reset for next callback + + have_result_ = false; // Auto-reset for next callback. return result_; } -int TestOldCompletionCallback::GetResult(int result) { +int TestCompletionCallbackBase::GetResult(int result) { if (net::ERR_IO_PENDING != result) return result; + return WaitForResult(); } +TestCompletionCallbackBase::TestCompletionCallbackBase() + : result_(0), + have_result_(false), + waiting_for_result_(false) { +} + void TestOldCompletionCallback::RunWithParams(const Tuple1<int>& params) { - result_ = params.a; - have_result_ = true; - if (waiting_for_result_) - MessageLoop::current()->Quit(); + SetResult(params.a); } namespace net { TestCompletionCallback::TestCompletionCallback() : ALLOW_THIS_IN_INITIALIZER_LIST(callback_( - base::Bind(&TestCompletionCallback::OnComplete, + base::Bind(&TestCompletionCallback::SetResult, base::Unretained(this)))) { } TestCompletionCallback::~TestCompletionCallback() {} -void TestCompletionCallback::OnComplete(int result) { - old_callback_impl_.RunWithParams(Tuple1<int>(result)); -} } // namespace net |