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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef PPAPI_PROXY_PROXY_COMPLETION_CALLBACK_FACTORY_H_
6 #define PPAPI_PROXY_PROXY_COMPLETION_CALLBACK_FACTORY_H_
7
8 #include "base/logging.h"
9 #include "base/message_loop.h"
10 #include "ppapi/cpp/completion_callback.h"
11 #include "ppapi/utility/completion_callback_factory.h"
12
13 namespace ppapi {
14 namespace proxy {
15
16 // This class is just like pp::NonThreadSafeThreadTraits but rather than using
17 // pp::Module::core (which doesn't exist), it uses Chrome threads which do.
18 class ProxyNonThreadSafeThreadTraits {
19 public:
20 class RefCount {
21 public:
22 RefCount() : ref_(0) {
23 #ifndef NDEBUG
24 message_loop_ = MessageLoop::current();
25 #endif
26 }
27
28 ~RefCount() {
29 DCHECK(message_loop_ == MessageLoop::current());
30 }
31
32 int32_t AddRef() {
33 DCHECK(message_loop_ == MessageLoop::current());
34 return ++ref_;
35 }
36
37 int32_t Release() {
38 DCHECK(message_loop_ == MessageLoop::current());
39 DCHECK(ref_ > 0);
40 return --ref_;
41 }
42
43 private:
44 int32_t ref_;
45 #ifndef NDEBUG
46 MessageLoop* message_loop_;
47 #endif
48 };
49
50 // No-op lock class.
51 class Lock {
52 public:
53 Lock() {}
54 ~Lock() {}
55
56 void Acquire() {}
57 void Release() {}
58 };
59
60 // No-op AutoLock class.
61 class AutoLock {
62 public:
63 explicit AutoLock(Lock&) {}
64 ~AutoLock() {}
65 };
66 };
67
68 template<typename T>
69 class ProxyCompletionCallbackFactory
70 : public pp::CompletionCallbackFactory<T, ProxyNonThreadSafeThreadTraits> {
71 public:
72 ProxyCompletionCallbackFactory() : CompletionCallbackFactory() {}
73 ProxyCompletionCallbackFactory(T* t) : CompletionCallbackFactory(t) {}
74 };
75
76 } // namespace proxy
77 } // namespace ppapi
78
79 #endif // PPAPI_PROXY_PROXY_COMPLETION_CALLBACK_FACTORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698