| Index: net/base/test_completion_callback.h
|
| diff --git a/net/base/test_completion_callback.h b/net/base/test_completion_callback.h
|
| index 1519e10e573cfc67e381da4396fd3e44556f6672..25c96766b1775d2a3feb9e0b2820ad3365495809 100644
|
| --- a/net/base/test_completion_callback.h
|
| +++ b/net/base/test_completion_callback.h
|
| @@ -9,6 +9,7 @@
|
| #include "base/compiler_specific.h"
|
| #include "base/tuple.h"
|
| #include "net/base/completion_callback.h"
|
| +#include "net/base/net_errors.h"
|
|
|
| //-----------------------------------------------------------------------------
|
| // completion callback helper
|
| @@ -22,26 +23,62 @@
|
| // reason, this class is probably not ideal for a general application.
|
| //
|
|
|
| -// Base class overridden by custom implementations of TestCompletionCallback.
|
| -class TestCompletionCallbackBase {
|
| +namespace net {
|
| +
|
| +namespace internal {
|
| +
|
| +class TestCompletionCallbackBaseInternal {
|
| public:
|
| - void SetResult(int result);
|
| - int WaitForResult();
|
| - int GetResult(int result);
|
| bool have_result() const { return have_result_; }
|
|
|
| protected:
|
| - TestCompletionCallbackBase();
|
| + TestCompletionCallbackBaseInternal();
|
| + void DidSetResult();
|
| + void WaitForResult();
|
|
|
| - int result_;
|
| bool have_result_;
|
| bool waiting_for_result_;
|
|
|
| private:
|
| - DISALLOW_COPY_AND_ASSIGN(TestCompletionCallbackBase);
|
| + DISALLOW_COPY_AND_ASSIGN(TestCompletionCallbackBaseInternal);
|
| };
|
|
|
| -namespace net {
|
| +template <typename R>
|
| +class TestCompletionCallbackTemplate
|
| + : public TestCompletionCallbackBaseInternal {
|
| + public:
|
| + void SetResult(R result) {
|
| + result_ = result;
|
| + DidSetResult();
|
| + }
|
| +
|
| + R WaitForResult() {
|
| + TestCompletionCallbackBaseInternal::WaitForResult();
|
| + return result_;
|
| + }
|
| +
|
| + R GetResult(R result) {
|
| + if (net::ERR_IO_PENDING != result)
|
| + return result;
|
| + return WaitForResult();
|
| + }
|
| +
|
| + protected:
|
| + TestCompletionCallbackTemplate() : result_(R()) {}
|
| + R result_;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(TestCompletionCallbackTemplate);
|
| +};
|
| +
|
| +} // namespace internal
|
| +
|
| +// Base class overridden by custom implementations of TestCompletionCallback.
|
| +typedef internal::TestCompletionCallbackTemplate<int>
|
| + TestCompletionCallbackBase;
|
| +
|
| +typedef internal::TestCompletionCallbackTemplate<int64>
|
| + TestInt64CompletionCallbackBase;
|
|
|
| class TestCompletionCallback : public TestCompletionCallbackBase {
|
| public:
|
| @@ -56,6 +93,19 @@ class TestCompletionCallback : public TestCompletionCallbackBase {
|
| DISALLOW_COPY_AND_ASSIGN(TestCompletionCallback);
|
| };
|
|
|
| +class TestInt64CompletionCallback : public TestInt64CompletionCallbackBase {
|
| + public:
|
| + TestInt64CompletionCallback();
|
| + ~TestInt64CompletionCallback();
|
| +
|
| + const Int64CompletionCallback& callback() const { return callback_; }
|
| +
|
| + private:
|
| + const Int64CompletionCallback callback_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TestInt64CompletionCallback);
|
| +};
|
| +
|
| } // namespace net
|
|
|
| #endif // NET_BASE_TEST_COMPLETION_CALLBACK_H_
|
|
|