Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Unified Diff: net/base/test_completion_callback.h

Issue 1142843002: net: Make TestCompletionCallback use RunLoops. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reuploading to re-run tests Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/base/test_completion_callback.cc » ('j') | net/base/test_completion_callback.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « no previous file | net/base/test_completion_callback.cc » ('j') | net/base/test_completion_callback.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698