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