Index: ppapi/proxy/proxy_completion_callback_factory.h |
diff --git a/ppapi/proxy/proxy_completion_callback_factory.h b/ppapi/proxy/proxy_completion_callback_factory.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..edc5e93410aac356819a65cd77be1c3168a50d3d |
--- /dev/null |
+++ b/ppapi/proxy/proxy_completion_callback_factory.h |
@@ -0,0 +1,77 @@ |
+// Copyright (c) 2012 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 PPAPI_PROXY_PROXY_COMPLETION_CALLBACK_FACTORY_H_ |
+#define PPAPI_PROXY_PROXY_COMPLETION_CALLBACK_FACTORY_H_ |
+ |
+#include "base/message_loop.h" |
+#include "ppapi/cpp/completion_callback.h" |
+#include "ppapi/utility/completion_callback_factory.h" |
+ |
+namespace ppapi { |
+namespace proxy { |
+ |
+// This class is just like pp::NonThreadSafeThreadTraits but rather than using |
+// pp::Module::core (which doesn't exist), it uses Chrome threads which do. |
+class ProxyNonThreadSafeThreadTraits { |
+ public: |
+ class RefCount { |
+ public: |
+ RefCount() : ref_(0) { |
+#ifndef NDEBUG |
+ message_loop_ = MessageLoop::current(); |
+#endif |
+ } |
+ |
+ ~RefCount() { |
+ PP_DCHECK(message_loop_ == MessageLoop::current()); |
+ } |
+ |
+ int32_t AddRef() { |
+ PP_DCHECK(message_loop_ == MessageLoop::current()); |
+ return ++ref_; |
+ } |
+ |
+ int32_t Release() { |
+ PP_DCHECK(message_loop_ == MessageLoop::current()); |
+ return --ref_; |
viettrungluu
2012/07/10 22:47:58
What I said elsewhere about maybe dchecking ref >
|
+ } |
+ |
+ private: |
+ int32_t ref_; |
+#ifndef NDEBUG |
+ MessageLoop* message_loop_; |
+#endif |
+ }; |
+ |
+ // No-op lock class. |
+ class Lock { |
+ public: |
+ Lock() {} |
+ ~Lock() {} |
+ |
+ void Acquire() {} |
+ void Release() {} |
+ }; |
+ |
+ // No-op AutoLock class. |
+ class AutoLock { |
+ public: |
+ explicit AutoLock(Lock&) {} |
+ ~AutoLock() {} |
+ }; |
+}; |
+ |
+template<typename T> |
+class ProxyCompletionCallbackFactory |
+ : public pp::CompletionCallbackFactory<T, ProxyNonThreadSafeThreadTraits> { |
+ public: |
+ ProxyCompletionCallbackFactory() : CompletionCallbackFactory() {} |
+ ProxyCompletionCallbackFactory(T* t) : CompletionCallbackFactory(t) {} |
+}; |
+ |
+} // namespace proxy |
+} // namespace ppapi |
+ |
+#endif // PPAPI_PROXY_PROXY_COMPLETION_CALLBACK_FACTORY_H_ |