Rewrite HpackRoundTripTest::RandomizedExamples.
[chromium-blink-merge.git] / ppapi / shared_impl / scoped_pp_resource.h
blobb42e21e0998f9d3c5b40f7fd10bd2eb80caf1650
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"
11 namespace ppapi {
13 class Resource;
15 // This is a version of scoped_refptr but for PP_Resources.
16 class PPAPI_SHARED_EXPORT ScopedPPResource {
17 public:
18 struct PassRef {};
20 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
29 // to it.
30 explicit ScopedPPResource(Resource* resource);
32 // Implicit copy constructor allowed.
33 ScopedPPResource(const ScopedPPResource& other);
35 ~ScopedPPResource();
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();
48 private:
49 // Helpers to addref or release the id_ if it's non-NULL. The id_ value will
50 // be unchanged.
51 void CallAddRef();
52 void CallRelease();
54 PP_Resource id_;
57 } // namespace ppapi
59 #endif // PPAPI_SHARED_IMPL_SCOPED_RESOURCE_H_