Roll leveldb from r73 to r75.
[chromium-blink-merge.git] / ppapi / cpp / resource.h
blob8f5a92d2e1214815bd1762800fe39ae1b396739d
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_CPP_RESOURCE_H_
6 #define PPAPI_CPP_RESOURCE_H_
8 #include "ppapi/c/pp_resource.h"
9 #include "ppapi/cpp/instance_handle.h"
10 #include "ppapi/cpp/pass_ref.h"
12 /// @file
13 /// This file defines a <code>Resource</code> type representing data associated
14 /// with the module.
15 namespace pp {
17 /// A reference counted module resource.
18 class Resource {
19 public:
20 /// The default constructor.
21 Resource();
23 /// A constructor for copying a resource.
24 ///
25 /// @param[in] other A <code>Resource</code>.
26 Resource(const Resource& other);
28 /// Destructor.
29 virtual ~Resource();
31 /// This function assigns one <code>Resource</code> to another
32 /// <code>Resource</code>.
33 ///
34 /// @param[in] other A Resource.
35 ///
36 /// @return A Resource containing the assigned Resource.
37 Resource& operator=(const Resource& other);
39 /// This functions determines if this resource is invalid or
40 /// uninitialized.
41 ///
42 /// @return true if this resource is invalid or uninitialized.
43 bool is_null() const { return !pp_resource_; }
45 PP_Resource pp_resource() const { return pp_resource_; }
47 /// This function releases ownership of this resource and returns it to the
48 /// caller.
49 ///
50 /// Note that the reference count on the resource is unchanged and the caller
51 /// needs to release the resource.
52 ///
53 /// @return The detached <code>PP_Resource</code>.
54 PP_Resource detach();
56 protected:
57 /// A constructor used when a <code>PP_Resource</code> is provided as a
58 /// return value whose reference count we need to increment.
59 ///
60 /// @param[in] resource A <code>PP_Resource</code> corresponding to a
61 /// resource.
62 explicit Resource(PP_Resource resource);
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);
68 /// PassRefFromConstructor is called by derived class' constructors to
69 /// initialize this <code>Resource</code> with a <code>PP_Resource</code>
70 /// that has already had its reference count incremented by
71 /// <code>Core::AddRefResource</code>. It also assumes this object has no
72 /// current resource.
73 ///
74 /// The intended usage of this function that the derived class constructor
75 /// will call the default <code>Resource</code> constructor, then make a call
76 /// to create a resource. It then wants to assign the new resource (which,
77 /// since it was returned by the browser, already had its reference count
78 /// increased).
79 ///
80 /// @param[in] resource A <code>PP_Resource</code> corresponding to a
81 /// resource.
82 void PassRefFromConstructor(PP_Resource resource);
84 private:
85 PP_Resource pp_resource_;
88 } // namespace pp
90 inline bool operator==(const pp::Resource& lhs, const pp::Resource& rhs) {
91 return lhs.pp_resource() == rhs.pp_resource();
94 inline bool operator!=(const pp::Resource& lhs, const pp::Resource& rhs) {
95 return !(lhs == rhs);
98 #endif // PPAPI_CPP_RESOURCE_H_