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

Unified Diff: ppapi/proxy/proxy_completion_callback_factory.h

Issue 10696157: Add support for threadsafe completion callback factory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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
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..f0310522a95fcaa1445943f8f779b9f50b899058
--- /dev/null
+++ b/ppapi/proxy/proxy_completion_callback_factory.h
@@ -0,0 +1,79 @@
+// 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/logging.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() {
+ DCHECK(message_loop_ == MessageLoop::current());
+ }
+
+ int32_t AddRef() {
+ DCHECK(message_loop_ == MessageLoop::current());
+ return ++ref_;
+ }
+
+ int32_t Release() {
+ DCHECK(message_loop_ == MessageLoop::current());
+ DCHECK(ref_ > 0);
+ return --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_

Powered by Google App Engine
This is Rietveld 408576698