| Index: net/base/test_completion_callback.h
|
| diff --git a/net/base/test_completion_callback.h b/net/base/test_completion_callback.h
|
| index 3762783a8c079ff5b0589925425abb368f5dbf4a..883180c5baa8c059a00f4c4cc129e20b13267695 100644
|
| --- a/net/base/test_completion_callback.h
|
| +++ b/net/base/test_completion_callback.h
|
| @@ -7,6 +7,7 @@
|
|
|
| #include "base/callback.h"
|
| #include "base/compiler_specific.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| #include "net/base/completion_callback.h"
|
| #include "net/base/net_errors.h"
|
|
|
| @@ -15,12 +16,17 @@
|
|
|
| // A helper class for completion callbacks, designed to make it easy to run
|
| // tests involving asynchronous operations. Just call WaitForResult to wait
|
| -// for the asynchronous operation to complete.
|
| +// for the asynchronous operation to complete. Uses a RunLoop to spin the
|
| +// current MessageLoop while waiting. The callback must be invoked on the same
|
| +// thread WaitForResult is called on.
|
| //
|
| // NOTE: Since this runs a message loop to wait for the completion callback,
|
| // there could be other side-effects resulting from WaitForResult. For this
|
| // reason, this class is probably not ideal for a general application.
|
| //
|
| +namespace base {
|
| +class RunLoop;
|
| +}
|
|
|
| namespace net {
|
|
|
| @@ -39,10 +45,12 @@ class TestCompletionCallbackBaseInternal {
|
| void DidSetResult();
|
| void WaitForResult();
|
|
|
| + private:
|
| + // RunLoop. Only non-NULL during the call to WaitForResult, so the class is
|
| + // reusable.
|
| + scoped_ptr<base::RunLoop> run_loop_;
|
| bool have_result_;
|
| - bool waiting_for_result_;
|
|
|
| - private:
|
| DISALLOW_COPY_AND_ASSIGN(TestCompletionCallbackBaseInternal);
|
| };
|
|
|
| @@ -64,23 +72,23 @@ class TestCompletionCallbackTemplate
|
| }
|
|
|
| protected:
|
| + TestCompletionCallbackTemplate() : result_(R()) {}
|
| +
|
| // Override this method to gain control as the callback is running.
|
| virtual void SetResult(R result) {
|
| result_ = result;
|
| DidSetResult();
|
| }
|
|
|
| - TestCompletionCallbackTemplate() : result_(R()) {}
|
| + private:
|
| R result_;
|
|
|
| - private:
|
| DISALLOW_COPY_AND_ASSIGN(TestCompletionCallbackTemplate);
|
| };
|
|
|
| } // namespace internal
|
|
|
| -class TestClosure
|
| - : public internal::TestCompletionCallbackBaseInternal {
|
| +class TestClosure : public internal::TestCompletionCallbackBaseInternal {
|
| public:
|
| using internal::TestCompletionCallbackBaseInternal::WaitForResult;
|
|
|
|
|