prune resources in MemoryCache
[chromium-blink-merge.git] / ppapi / proxy / proxy_completion_callback_factory.h
blobc8dabf183b4257435dc9079a8226372f4fb33283
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.
5 #ifndef PPAPI_PROXY_PROXY_COMPLETION_CALLBACK_FACTORY_H_
6 #define PPAPI_PROXY_PROXY_COMPLETION_CALLBACK_FACTORY_H_
8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h"
10 #include "ppapi/cpp/completion_callback.h"
11 #include "ppapi/utility/completion_callback_factory.h"
13 namespace ppapi {
14 namespace proxy {
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_ = base::MessageLoop::current();
25 #endif
28 ~RefCount() {
29 #ifndef NDEBUG
30 DCHECK(message_loop_ == base::MessageLoop::current());
31 #endif
34 int32_t AddRef() {
35 #ifndef NDEBUG
36 DCHECK(message_loop_ == base::MessageLoop::current());
37 #endif
38 return ++ref_;
41 int32_t Release() {
42 #ifndef NDEBUG
43 DCHECK(message_loop_ == base::MessageLoop::current());
44 #endif
45 DCHECK(ref_ > 0);
46 return --ref_;
49 private:
50 int32_t ref_;
51 #ifndef NDEBUG
52 base::MessageLoop* message_loop_;
53 #endif
56 // No-op lock class.
57 class Lock {
58 public:
59 Lock() {}
60 ~Lock() {}
62 void Acquire() {}
63 void Release() {}
66 // No-op AutoLock class.
67 class AutoLock {
68 public:
69 explicit AutoLock(Lock&) {}
70 ~AutoLock() {}
74 template<typename T>
75 class ProxyCompletionCallbackFactory
76 : public pp::CompletionCallbackFactory<T, ProxyNonThreadSafeThreadTraits> {
77 public:
78 ProxyCompletionCallbackFactory()
79 : pp::CompletionCallbackFactory<T, ProxyNonThreadSafeThreadTraits>() {}
80 ProxyCompletionCallbackFactory(T* t)
81 : pp::CompletionCallbackFactory<T, ProxyNonThreadSafeThreadTraits>(t) {}
84 } // namespace proxy
85 } // namespace ppapi
87 #endif // PPAPI_PROXY_PROXY_COMPLETION_CALLBACK_FACTORY_H_