Index: remoting/host/mock_callback.h |
diff --git a/remoting/host/mock_callback.h b/remoting/host/mock_callback.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3334670ca2d4aeaeac199da0fcc427a98819d64c |
--- /dev/null |
+++ b/remoting/host/mock_callback.h |
@@ -0,0 +1,43 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef REMOTING_HOST_MOCK_CALLBACK_H_ |
+#define REMOTING_HOST_MOCK_CALLBACK_H_ |
+ |
+// TODO(lukasza): If possible, move this header file to base/mock_callback.h |
+ |
+#include "base/bind.h" |
+#include "base/callback.h" |
Lambros
2014/11/18 00:19:29
Could you use base/callback_forward.h instead?
Łukasz Anforowicz
2014/11/18 01:03:22
Done. It builds fine. OTOH, I have a feeling it
Lambros
2014/11/18 02:33:52
Yes you're right, you do need the full definition
Łukasz Anforowicz
2014/11/18 17:30:45
Ok, I'll go back to including base/callback.h
|
+#include "base/memory/weak_ptr.h" |
+ |
+#include "testing/gmock/include/gmock/gmock.h" |
+ |
+namespace remoting { |
+ |
+template <typename Sig> |
+class MockCallback; |
+ |
+template <typename R> |
+class MockCallback<R()> { |
+ public: |
+ MOCK_CONST_METHOD0_T(Run, R()); |
Lambros
2014/11/18 00:19:29
Hmm. This could be tricky to generalize to the n-p
Łukasz Anforowicz
2014/11/18 01:03:22
I am doing this in part#3. I am not very happy wi
Lambros
2014/11/18 02:33:52
You're renaming this in a later CL? Why not do it
Łukasz Anforowicz
2014/11/18 17:30:45
No, not renaming. In part#3 I am adding an extra
|
+ |
+ MockCallback() : weak_factory_(this) { |
+ } |
+ |
+ base::Callback<R()> GetCallback() { |
+ return base::Bind(&MockCallback<R()>::Run, weak_factory_.GetWeakPtr()); |
+ } |
+ |
+ private: |
+ base::WeakPtrFactory<MockCallback<R()>> weak_factory_; |
Lambros
2014/11/18 00:19:29
I'm not convinced we should use WeakPtr in this co
Łukasz Anforowicz
2014/11/18 01:03:22
Yes - this needs more discussion. I think one way
Lambros
2014/11/18 02:33:52
No, this is too strong a condition. A test could l
Łukasz Anforowicz
2014/11/18 17:30:45
I've been thinking about this a bit more and I am
|
+ |
+ DISALLOW_COPY_AND_ASSIGN(MockCallback); |
+}; |
+ |
+typedef MockCallback<void(void)> MockClosure; |
+ |
+} // namespace remoting |
+ |
+#endif // REMOTING_HOST_MOCK_CALLBACK_H_ |