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 WEBKIT_PLUGINS_PPAPI_RESOURCE_H_ | |
6 #define WEBKIT_PLUGINS_PPAPI_RESOURCE_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/compiler_specific.h" | |
10 #include "ppapi/c/pp_resource.h" | |
11 #include "ppapi/shared_impl/resource.h" | |
12 #include "webkit/plugins/ppapi/resource_tracker.h" | |
13 | |
14 namespace webkit { | |
15 namespace ppapi { | |
16 | |
17 class Resource : public ::ppapi::Resource { | |
18 public: | |
19 explicit Resource(PluginInstance* instance); | |
20 virtual ~Resource(); | |
21 | |
22 // Returns the instance owning this resource. This is generally to be | |
23 // non-NULL except if the instance is destroyed and some code internal to the | |
24 // PPAPI implementation is keeping a reference for some reason. | |
25 PluginInstance* instance() const { return instance_; } | |
26 | |
27 // Returns an resource id of this object. If the object doesn't have a | |
28 // resource id, new one is created with plugin refcount of 1. If it does, | |
29 // the refcount is incremented. Use this when you need to return a new | |
30 // reference to the plugin. | |
31 PP_Resource GetReference(); | |
32 | |
33 // When you need to ensure that a resource has a reference, but you do not | |
34 // want to increase the refcount (for example, if you need to call a plugin | |
35 // callback function with a reference), you can use this class. For example: | |
36 // | |
37 // plugin_callback(.., ScopedResourceId(resource).id, ...); | |
38 class ScopedResourceId { | |
39 public: | |
40 explicit ScopedResourceId(Resource* resource) | |
41 : id(resource->GetReference()) {} | |
42 ~ScopedResourceId() { | |
43 ResourceTracker::Get()->ReleaseResource(id); | |
44 } | |
45 const PP_Resource id; | |
46 }; | |
47 | |
48 // Resource implementation. | |
49 virtual void LastPluginRefWasDeleted() OVERRIDE; | |
50 virtual void InstanceWasDeleted() OVERRIDE; | |
51 | |
52 private: | |
53 // Non-owning pointer to our instance. See getter above. | |
54 PluginInstance* instance_; | |
55 | |
56 DISALLOW_COPY_AND_ASSIGN(Resource); | |
57 }; | |
58 | |
59 } // namespace ppapi | |
60 } // namespace webkit | |
61 | |
62 #endif // WEBKIT_PLUGINS_PPAPI_RESOURCE_H_ | |
OLD | NEW |