Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: ppapi/native_client/src/shared/ppapi_proxy/plugin_resource_tracker.h

Issue 7740013: Cloning a bunch of stuff from the native_client repository at r6528 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Native Client 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_GLUE_PLUGINS_PEPPER_RESOURCE_TRACKER_H_
6 #define WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_TRACKER_H_
7
8 #include <map>
9 #include <utility>
10
11 #include "native_client/src/include/nacl_base.h"
12 #include "native_client/src/include/ref_counted.h"
13 #include "ppapi/c/pp_instance.h"
14 #include "ppapi/c/pp_module.h"
15 #include "ppapi/c/pp_resource.h"
16
17 namespace ppapi_proxy {
18
19 class PluginInstance;
20 class PluginResource;
21
22 // This class maintains a global list of all live pepper resources. It allows
23 // us to check resource ID validity and to map them to a specific module.
24 //
25 // This object is threadsafe.
26 class PluginResourceTracker {
27 public:
28 // Returns the pointer to the singleton object.
29 static PluginResourceTracker* Get() {
30 static PluginResourceTracker tracker;
31 return &tracker;
32 }
33
34 // PP_Resources --------------------------------------------------------------
35
36 // Increment resource's plugin refcount. See ResourceAndRefCount.
37 bool AddRefResource(PP_Resource res);
38 bool UnrefResource(PP_Resource res);
39
40 private:
41 friend class PluginResource;
42
43 // Prohibit creation other then by the Singleton class.
44 PluginResourceTracker();
45
46 // Adds the given resource to the tracker and assigns it a resource ID, local
47 // refcount of 1, and initializes the browser reference count to
48 // |browser_refcount|. Used only by the Resource class.
49 void AddResource(PluginResource* resource, PP_Resource id,
50 size_t browser_refcount);
51
52 // The returned pointer will be NULL if there is no resource. Note that this
53 // return value is a scoped_refptr so that we ensure the resource is valid
54 // from the point of the lookup to the point that the calling code needs it.
55 // Otherwise, the plugin could Release() the resource on another thread and
56 // the object will get deleted out from under us.
57 scoped_refptr<PluginResource> GetExistingResource(PP_Resource res) const;
58
59 // Get or create a new PluginResource from a browser resource.
60 // If we are already tracking this resource, we bump its browser_refcount to
61 // reflect that we took ownership of it. If this is a new resource, we create
62 // a PluginResource for it with the given browser_refcount.
63 template<typename T> scoped_refptr<T> AdoptBrowserResource(
64 PP_Resource res, size_t browser_refcount);
65
66 // Try to get a browser-side refcount for an existing resource.
67 void ObtainBrowserResource(PP_Resource res);
68
69 // Release browser-side refcount.
70 void ReleaseBrowserResource(PP_Resource res, size_t refcount);
71
72 // Last assigned resource ID.
73 PP_Resource last_id_;
74
75 struct ResourceAndRefCounts {
76 scoped_refptr<PluginResource> resource;
77 size_t browser_refcount;
78 size_t plugin_refcount;
79 ResourceAndRefCounts(PluginResource* r, size_t browser_refcount);
80 ~ResourceAndRefCounts();
81 };
82 typedef std::map<PP_Resource, ResourceAndRefCounts> ResourceMap;
83 ResourceMap live_resources_;
84
85 DISALLOW_COPY_AND_ASSIGN(PluginResourceTracker);
86 };
87
88 } // namespace ppapi_proxy
89
90 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_TRACKER_H_
91
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698