1 // Copyright (c) 2011 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_SHARED_IMPL_SCOPED_RESOURCE_H_
6 #define PPAPI_SHARED_IMPL_SCOPED_RESOURCE_H_
8 #include "ppapi/c/pp_resource.h"
9 #include "ppapi/shared_impl/ppapi_shared_export.h"
15 // This is a version of scoped_refptr but for PP_Resources.
16 class PPAPI_SHARED_EXPORT ScopedPPResource
{
22 // Takes one reference to the given resource.
23 explicit ScopedPPResource(PP_Resource resource
);
25 // Assumes responsibility for one ref that the resource already has.
26 explicit ScopedPPResource(const PassRef
&, PP_Resource resource
);
28 // Helper to get the PP_Resource out of the given object and take a reference
30 explicit ScopedPPResource(Resource
* resource
);
32 // Implicit copy constructor allowed.
33 ScopedPPResource(const ScopedPPResource
& other
);
37 ScopedPPResource
& operator=(PP_Resource resource
);
38 ScopedPPResource
& operator=(const ScopedPPResource
& resource
);
40 // Returns the PP_Resource without affecting the refcounting.
41 PP_Resource
get() const { return id_
; }
42 operator PP_Resource() const { return id_
; }
44 // Returns the PP_Resource, passing the reference to the caller. This class
45 // will no longer hold the resource.
46 PP_Resource
Release();
49 // Helpers to addref or release the id_ if it's non-NULL. The id_ value will
59 #endif // PPAPI_SHARED_IMPL_SCOPED_RESOURCE_H_