OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef PPAPI_SHARED_IMPL_SCOPED_RESOURCE_H_ |
| 6 #define PPAPI_SHARED_IMPL_SCOPED_RESOURCE_H_ |
| 7 |
| 8 #include "ppapi/c/pp_resource.h" |
| 9 |
| 10 namespace ppapi { |
| 11 |
| 12 class Resource; |
| 13 |
| 14 // This is a version of scoped_refptr but for PP_Resources. |
| 15 class ScopedPPResource { |
| 16 public: |
| 17 ScopedPPResource(); |
| 18 |
| 19 // Takes one reference to the given resource. |
| 20 explicit ScopedPPResource(PP_Resource resource); |
| 21 |
| 22 // Helper to get the PP_Resource out of the given object and take a reference |
| 23 // to it. |
| 24 explicit ScopedPPResource(Resource* resource); |
| 25 |
| 26 // Implicit copy constructor allowed. |
| 27 ScopedPPResource(const ScopedPPResource& other); |
| 28 |
| 29 ~ScopedPPResource(); |
| 30 |
| 31 ScopedPPResource& operator=(PP_Resource resource); |
| 32 ScopedPPResource& operator=(const ScopedPPResource& resource); |
| 33 |
| 34 // Returns the PP_Resource without affecting the refcounting. |
| 35 PP_Resource get() const { return id_; } |
| 36 operator PP_Resource() const { return id_; } |
| 37 |
| 38 // Returns the PP_Resource, passing the reference to the caller. This class |
| 39 // will no longer hold the resource. |
| 40 PP_Resource Release(); |
| 41 |
| 42 private: |
| 43 // Helpers to addref or release the id_ if it's non-NULL. The id_ value will |
| 44 // be unchanged. |
| 45 void CallAddRef(); |
| 46 void CallRelease(); |
| 47 |
| 48 PP_Resource id_; |
| 49 }; |
| 50 |
| 51 } // namespace ppapi |
| 52 |
| 53 #endif // PPAPI_SHARED_IMPL_SCOPED_RESOURCE_H_ |
OLD | NEW |