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

Side by Side Diff: ppapi/proxy/plugin_resource_tracker.h

Issue 7578001: Unify var tracking between webkit and the proxy. (Closed) Base URL: svn://chrome-svn/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
« no previous file with comments | « ppapi/ppapi_shared.gypi ('k') | ppapi/proxy/plugin_resource_tracker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_PROXY_PLUGIN_RESOURCE_TRACKER_H_ 5 #ifndef PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_
6 #define PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_ 6 #define PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/memory/linked_ptr.h" 12 #include "base/memory/linked_ptr.h"
13 #include "ppapi/c/pp_completion_callback.h" 13 #include "ppapi/c/pp_completion_callback.h"
14 #include "ppapi/c/pp_instance.h" 14 #include "ppapi/c/pp_instance.h"
15 #include "ppapi/c/pp_stdint.h" 15 #include "ppapi/c/pp_stdint.h"
16 #include "ppapi/c/pp_resource.h" 16 #include "ppapi/c/pp_resource.h"
17 #include "ppapi/c/pp_var.h" 17 #include "ppapi/c/pp_var.h"
18 #include "ppapi/proxy/host_resource.h" 18 #include "ppapi/proxy/host_resource.h"
19 #include "ppapi/proxy/plugin_var_tracker.h"
19 #include "ppapi/shared_impl/tracker_base.h" 20 #include "ppapi/shared_impl/tracker_base.h"
20 21
21 template<typename T> struct DefaultSingletonTraits; 22 template<typename T> struct DefaultSingletonTraits;
22 23
23 namespace ppapi { 24 namespace ppapi {
24 class Var; 25 class Var;
25 } 26 }
26 27
27 namespace pp { 28 namespace pp {
28 namespace proxy { 29 namespace proxy {
(...skipping 23 matching lines...) Expand all
52 PP_Resource AddResource(linked_ptr<PluginResource> object); 53 PP_Resource AddResource(linked_ptr<PluginResource> object);
53 54
54 void AddRefResource(PP_Resource resource); 55 void AddRefResource(PP_Resource resource);
55 void ReleaseResource(PP_Resource resource); 56 void ReleaseResource(PP_Resource resource);
56 57
57 // Given a host resource, maps it to an existing plugin resource ID if it 58 // Given a host resource, maps it to an existing plugin resource ID if it
58 // exists, or returns 0 on failure. 59 // exists, or returns 0 on failure.
59 PP_Resource PluginResourceForHostResource( 60 PP_Resource PluginResourceForHostResource(
60 const HostResource& resource) const; 61 const HostResource& resource) const;
61 62
63 PluginVarTracker& var_tracker() {
64 return var_tracker_test_override_ ? *var_tracker_test_override_
65 : var_tracker_;
66 }
67
68 void set_var_tracker_test_override(PluginVarTracker* t) {
69 var_tracker_test_override_ = t;
70 }
71
62 // TrackerBase. 72 // TrackerBase.
63 virtual ::ppapi::ResourceObjectBase* GetResourceAPI( 73 virtual ppapi::ResourceObjectBase* GetResourceAPI(
64 PP_Resource res) OVERRIDE; 74 PP_Resource res) OVERRIDE;
65 virtual ::ppapi::FunctionGroupBase* GetFunctionAPI( 75 virtual ppapi::FunctionGroupBase* GetFunctionAPI(
66 PP_Instance inst, 76 PP_Instance inst,
67 pp::proxy::InterfaceID id) OVERRIDE; 77 pp::proxy::InterfaceID id) OVERRIDE;
68 virtual PP_Instance GetInstanceForResource(PP_Resource resource) OVERRIDE; 78 virtual PP_Instance GetInstanceForResource(PP_Resource resource) OVERRIDE;
69 virtual int32 AddVar(ppapi::Var* var); 79 virtual ppapi::VarTracker* GetVarTracker() OVERRIDE;
70 virtual scoped_refptr< ::ppapi::Var > GetVar(int32 var_id) const;
71 virtual bool AddRefVar(int32 var_id);
72 virtual bool UnrefVar(int32 var_id);
73 80
74 private: 81 private:
75 friend struct DefaultSingletonTraits<PluginResourceTracker>; 82 friend struct DefaultSingletonTraits<PluginResourceTracker>;
76 friend class PluginResourceTrackerTest; 83 friend class PluginResourceTrackerTest;
77 friend class PluginProxyTestHarness; 84 friend class PluginProxyTestHarness;
78 85
79 PluginResourceTracker(); 86 PluginResourceTracker();
80 virtual ~PluginResourceTracker(); 87 virtual ~PluginResourceTracker();
81 88
82 struct ResourceInfo { 89 struct ResourceInfo {
83 ResourceInfo(); 90 ResourceInfo();
84 ResourceInfo(int ref_count, linked_ptr<PluginResource> r); 91 ResourceInfo(int ref_count, linked_ptr<PluginResource> r);
85 ResourceInfo(const ResourceInfo& other); 92 ResourceInfo(const ResourceInfo& other);
86 ~ResourceInfo(); 93 ~ResourceInfo();
87 94
88 ResourceInfo& operator=(const ResourceInfo& other); 95 ResourceInfo& operator=(const ResourceInfo& other);
89 96
90 int ref_count; 97 int ref_count;
91 linked_ptr<PluginResource> resource; // May be NULL. 98 linked_ptr<PluginResource> resource; // May be NULL.
92 }; 99 };
93 100
94 void ReleasePluginResourceRef(const PP_Resource& var, 101 void ReleasePluginResourceRef(const PP_Resource& var,
95 bool notify_browser_on_release); 102 bool notify_browser_on_release);
96 103
104 // Use the var_tracker_test_override_ instead if it's non-NULL.
105 //
106 // TODO(brettw) this should be somehow separated out from here. I'm thinking
107 // of some global object that manages PPAPI globals, including separate var
108 // and resource trackers.
109 PluginVarTracker var_tracker_;
110
111 // Non-owning pointer to a var tracker mock used by tests. NULL when no
112 // test implementation is provided.
113 PluginVarTracker* var_tracker_test_override_;
114
97 // Map of plugin resource IDs to the information tracking that resource. 115 // Map of plugin resource IDs to the information tracking that resource.
98 typedef std::map<PP_Resource, ResourceInfo> ResourceMap; 116 typedef std::map<PP_Resource, ResourceInfo> ResourceMap;
99 ResourceMap resource_map_; 117 ResourceMap resource_map_;
100 118
101 // Map of host instance/resource pairs to a plugin resource ID. 119 // Map of host instance/resource pairs to a plugin resource ID.
102 typedef std::map<HostResource, PP_Resource> HostResourceMap; 120 typedef std::map<HostResource, PP_Resource> HostResourceMap;
103 HostResourceMap host_resource_map_; 121 HostResourceMap host_resource_map_;
104 122
105 // Tracks the last ID we've sent out as a plugin resource so we don't send 123 // Tracks the last ID we've sent out as a plugin resource so we don't send
106 // duplicates. 124 // duplicates.
107 PP_Resource last_resource_id_; 125 PP_Resource last_resource_id_;
108 126
109 DISALLOW_COPY_AND_ASSIGN(PluginResourceTracker); 127 DISALLOW_COPY_AND_ASSIGN(PluginResourceTracker);
110 }; 128 };
111 129
112 } // namespace proxy 130 } // namespace proxy
113 } // namespace pp 131 } // namespace pp
114 132
115 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_ 133 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_
OLDNEW
« no previous file with comments | « ppapi/ppapi_shared.gypi ('k') | ppapi/proxy/plugin_resource_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698