| Index: ppapi/shared_impl/scoped_pp_resource.h
|
| diff --git a/ppapi/shared_impl/scoped_pp_resource.h b/ppapi/shared_impl/scoped_pp_resource.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..74cb9eb2d8cf853f1f17b4c0922e1a3cad872e2b
|
| --- /dev/null
|
| +++ b/ppapi/shared_impl/scoped_pp_resource.h
|
| @@ -0,0 +1,53 @@
|
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef PPAPI_SHARED_IMPL_SCOPED_RESOURCE_H_
|
| +#define PPAPI_SHARED_IMPL_SCOPED_RESOURCE_H_
|
| +
|
| +#include "ppapi/c/pp_resource.h"
|
| +
|
| +namespace ppapi {
|
| +
|
| +class Resource;
|
| +
|
| +// This is a version of scoped_refptr but for PP_Resources.
|
| +class ScopedPPResource {
|
| + public:
|
| + ScopedPPResource();
|
| +
|
| + // Takes one reference to the given resource.
|
| + explicit ScopedPPResource(PP_Resource resource);
|
| +
|
| + // Helper to get the PP_Resource out of the given object and take a reference
|
| + // to it.
|
| + explicit ScopedPPResource(Resource* resource);
|
| +
|
| + // Implicit copy constructor allowed.
|
| + ScopedPPResource(const ScopedPPResource& other);
|
| +
|
| + ~ScopedPPResource();
|
| +
|
| + ScopedPPResource& operator=(PP_Resource resource);
|
| + ScopedPPResource& operator=(const ScopedPPResource& resource);
|
| +
|
| + // Returns the PP_Resource without affecting the refcounting.
|
| + PP_Resource get() const { return id_; }
|
| + operator PP_Resource() const { return id_; }
|
| +
|
| + // Returns the PP_Resource, passing the reference to the caller. This class
|
| + // will no longer hold the resource.
|
| + PP_Resource Release();
|
| +
|
| + private:
|
| + // Helpers to addref or release the id_ if it's non-NULL. The id_ value will
|
| + // be unchanged.
|
| + void CallAddRef();
|
| + void CallRelease();
|
| +
|
| + PP_Resource id_;
|
| +};
|
| +
|
| +} // namespace ppapi
|
| +
|
| +#endif // PPAPI_SHARED_IMPL_SCOPED_RESOURCE_H_
|
|
|