OLD | NEW |
---|---|
(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/message_loop.h" | |
9 #include "ppapi/cpp/completion_callback.h" | |
10 #include "ppapi/utility/completion_callback_factory.h" | |
11 | |
12 namespace ppapi { | |
13 namespace proxy { | |
14 | |
15 // This class is just like pp::NonThreadSafeThreadTraits but rather than using | |
16 // pp::Module::core (which doesn't exist), it uses Chrome threads which do. | |
17 class ProxyNonThreadSafeThreadTraits { | |
18 public: | |
19 class RefCount { | |
20 public: | |
21 RefCount() : ref_(0) { | |
22 #ifndef NDEBUG | |
23 message_loop_ = MessageLoop::current(); | |
24 #endif | |
25 } | |
26 | |
27 ~RefCount() { | |
28 PP_DCHECK(message_loop_ == MessageLoop::current()); | |
29 } | |
30 | |
31 int32_t AddRef() { | |
32 PP_DCHECK(message_loop_ == MessageLoop::current()); | |
33 return ++ref_; | |
34 } | |
35 | |
36 int32_t Release() { | |
37 PP_DCHECK(message_loop_ == MessageLoop::current()); | |
38 return --ref_; | |
viettrungluu
2012/07/10 22:47:58
What I said elsewhere about maybe dchecking ref >
| |
39 } | |
40 | |
41 private: | |
42 int32_t ref_; | |
43 #ifndef NDEBUG | |
44 MessageLoop* message_loop_; | |
45 #endif | |
46 }; | |
47 | |
48 // No-op lock class. | |
49 class Lock { | |
50 public: | |
51 Lock() {} | |
52 ~Lock() {} | |
53 | |
54 void Acquire() {} | |
55 void Release() {} | |
56 }; | |
57 | |
58 // No-op AutoLock class. | |
59 class AutoLock { | |
60 public: | |
61 explicit AutoLock(Lock&) {} | |
62 ~AutoLock() {} | |
63 }; | |
64 }; | |
65 | |
66 template<typename T> | |
67 class ProxyCompletionCallbackFactory | |
68 : public pp::CompletionCallbackFactory<T, ProxyNonThreadSafeThreadTraits> { | |
69 public: | |
70 ProxyCompletionCallbackFactory() : CompletionCallbackFactory() {} | |
71 ProxyCompletionCallbackFactory(T* t) : CompletionCallbackFactory(t) {} | |
72 }; | |
73 | |
74 } // namespace proxy | |
75 } // namespace ppapi | |
76 | |
77 #endif // PPAPI_PROXY_PROXY_COMPLETION_CALLBACK_FACTORY_H_ | |
OLD | NEW |