[email protected] | b73c659 | 2013-03-30 17:08:13 | [diff] [blame] | 1 | // Copyright (c) 2013 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_LOCKING_RESOURCE_RELEASER_H_ |
| 6 | #define PPAPI_PROXY_LOCKING_RESOURCE_RELEASER_H_ |
| 7 | |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 8 | #include "base/macros.h" |
[email protected] | b73c659 | 2013-03-30 17:08:13 | [diff] [blame] | 9 | #include "ppapi/shared_impl/ppapi_globals.h" |
| 10 | #include "ppapi/shared_impl/proxy_lock.h" |
| 11 | #include "ppapi/shared_impl/resource_tracker.h" |
| 12 | |
| 13 | namespace ppapi { |
| 14 | namespace proxy { |
| 15 | |
| 16 | // LockingResourceReleaser is a simple RAII class for releasing a resource at |
| 17 | // the end of scope. This acquires the ProxyLock before releasing the resource. |
| 18 | // It is for use in unit tests. Most proxy or implementation code should use |
| 19 | // ScopedPPResource instead. Unit tests sometimes can't use ScopedPPResource |
| 20 | // because it asserts that the ProxyLock is already held. |
| 21 | class LockingResourceReleaser { |
| 22 | public: |
| 23 | explicit LockingResourceReleaser(PP_Resource resource) |
| 24 | : resource_(resource) { |
| 25 | } |
| 26 | ~LockingResourceReleaser() { |
| 27 | ProxyAutoLock lock; |
| 28 | PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(resource_); |
| 29 | } |
| 30 | |
| 31 | PP_Resource get() { return resource_; } |
| 32 | |
| 33 | private: |
| 34 | PP_Resource resource_; |
| 35 | |
| 36 | DISALLOW_COPY_AND_ASSIGN(LockingResourceReleaser); |
| 37 | }; |
| 38 | |
| 39 | } // namespace proxy |
| 40 | } // namespace ppapi |
| 41 | |
| 42 | #endif // PPAPI_PROXY_LOCKING_RESOURCE_RELEASER_H_ |