blob: d770df62f9ff136c9b050a18a855e5bce1de7eb8 [file] [log] [blame]
[email protected]b73c6592013-03-30 17:08:131// 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
avie029c4132015-12-23 06:45:228#include "base/macros.h"
[email protected]b73c6592013-03-30 17:08:139#include "ppapi/shared_impl/ppapi_globals.h"
10#include "ppapi/shared_impl/proxy_lock.h"
11#include "ppapi/shared_impl/resource_tracker.h"
12
13namespace ppapi {
14namespace 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.
21class 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_