Chromium Code Reviews| 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..cd3e9693d9143f2486a1481360e6d7e50e3ca79c 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,25 +23,62 @@ | 
| // reason, this class is probably not ideal for a general application. | 
| // | 
| -// Base class overridden by custom implementations of TestCompletionCallback. | 
| -class TestCompletionCallbackBase { | 
| +namespace internal { | 
| 
 
willchan no longer on Chromium
2012/04/09 12:33:57
This should be nested within the net namespace. Th
 
kinuko
2012/04/09 17:04:36
Done.
 
 | 
| + | 
| +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); | 
| +}; | 
| + | 
| +template <typename R> | 
| +class TestCompletionCallbackTemplate | 
| + : public TestCompletionCallbackBaseInternal { | 
| + public: | 
| + void SetResult(R result) { | 
| + result_ = result; | 
| + DidSetResult(); | 
| + } | 
| + | 
| + R WaitForResult() { | 
| + TestCompletionCallbackBaseInternal::WaitForResult(); | 
| + have_result_ = false; // Auto-reset for next callback. | 
| 
 
willchan no longer on Chromium
2012/04/09 12:33:57
Why did this move out to the template? Why isn't t
 
kinuko
2012/04/09 17:04:36
Fixed.
 
 | 
| + 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; | 
| + | 
| namespace net { | 
| class TestCompletionCallback : public TestCompletionCallbackBase { | 
| @@ -56,6 +94,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_ |