OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef PPAPI_CPP_RESOURCE_H_ | 5 #ifndef PPAPI_CPP_RESOURCE_H_ |
6 #define PPAPI_CPP_RESOURCE_H_ | 6 #define PPAPI_CPP_RESOURCE_H_ |
7 | 7 |
8 #include "ppapi/c/pp_resource.h" | 8 #include "ppapi/c/pp_resource.h" |
| 9 #include "ppapi/cpp/instance_handle.h" |
| 10 #include "ppapi/cpp/pass_ref.h" |
9 | 11 |
10 /// @file | 12 /// @file |
11 /// This file defines a <code>Resource</code> type representing data associated | 13 /// This file defines a <code>Resource</code> type representing data associated |
12 /// with the module. | 14 /// with the module. |
13 namespace pp { | 15 namespace pp { |
14 | 16 |
15 /// A reference counted module resource. | 17 /// A reference counted module resource. |
16 class Resource { | 18 class Resource { |
17 public: | 19 public: |
18 | |
19 /// The default constructor. | 20 /// The default constructor. |
20 Resource(); | 21 Resource(); |
21 | 22 |
22 /// A constructor for copying a resource. | 23 /// A constructor for copying a resource. |
23 /// | 24 /// |
24 /// @param[in] other A <code>Resource</code>. | 25 /// @param[in] other A <code>Resource</code>. |
25 Resource(const Resource& other); | 26 Resource(const Resource& other); |
26 | 27 |
27 /// Destructor. | 28 /// Destructor. |
28 virtual ~Resource(); | 29 virtual ~Resource(); |
(...skipping 24 matching lines...) Expand all Loading... |
53 PP_Resource detach(); | 54 PP_Resource detach(); |
54 | 55 |
55 protected: | 56 protected: |
56 /// A constructor used when a <code>PP_Resource</code> is provided as a | 57 /// A constructor used when a <code>PP_Resource</code> is provided as a |
57 /// return value whose reference count we need to increment. | 58 /// return value whose reference count we need to increment. |
58 /// | 59 /// |
59 /// @param[in] resource A <code>PP_Resource</code> corresponding to a | 60 /// @param[in] resource A <code>PP_Resource</code> corresponding to a |
60 /// resource. | 61 /// resource. |
61 explicit Resource(PP_Resource resource); | 62 explicit Resource(PP_Resource resource); |
62 | 63 |
| 64 /// Constructor used when a <code>PP_Resource</code> already has a ref count |
| 65 /// assigned. Add additional refcount is not taken. |
| 66 Resource(PassRef, PP_Resource resource); |
| 67 |
63 /// PassRefFromConstructor is called by derived class' constructors to | 68 /// PassRefFromConstructor is called by derived class' constructors to |
64 /// initialize this <code>Resource</code> with a <code>PP_Resource</code> | 69 /// initialize this <code>Resource</code> with a <code>PP_Resource</code> |
65 /// that has already had its reference count incremented by | 70 /// that has already had its reference count incremented by |
66 /// <code>Core::AddRefResource</code>. It also assumes this object has no | 71 /// <code>Core::AddRefResource</code>. It also assumes this object has no |
67 /// current resource. | 72 /// current resource. |
68 /// | 73 /// |
69 /// The intended usage of this function that the derived class constructor | 74 /// The intended usage of this function that the derived class constructor |
70 /// will call the default <code>Resource</code> constructor, then make a call | 75 /// will call the default <code>Resource</code> constructor, then make a call |
71 /// to create a resource. It then wants to assign the new resource (which, | 76 /// to create a resource. It then wants to assign the new resource (which, |
72 /// since it was returned by the browser, already had its reference count | 77 /// since it was returned by the browser, already had its reference count |
73 /// increased). | 78 /// increased). |
74 /// | 79 /// |
75 /// @param[in] resource A <code>PP_Resource</code> corresponding to a | 80 /// @param[in] resource A <code>PP_Resource</code> corresponding to a |
76 /// resource. | 81 /// resource. |
77 void PassRefFromConstructor(PP_Resource resource); | 82 void PassRefFromConstructor(PP_Resource resource); |
78 | 83 |
79 private: | 84 private: |
80 PP_Resource pp_resource_; | 85 PP_Resource pp_resource_; |
81 }; | 86 }; |
82 | 87 |
83 } // namespace pp | 88 } // namespace pp |
84 | 89 |
85 inline bool operator==(const pp::Resource& lhs, const pp::Resource& rhs) { | 90 inline bool operator==(const pp::Resource& lhs, const pp::Resource& rhs) { |
86 return lhs.pp_resource() == rhs.pp_resource(); | 91 return lhs.pp_resource() == rhs.pp_resource(); |
87 } | 92 } |
88 | 93 |
89 #endif // PPAPI_CPP_RESOURCE_H_ | 94 #endif // PPAPI_CPP_RESOURCE_H_ |
OLD | NEW |