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_PROXY_PLUGIN_VAR_TRACKER_H_ | 5 #ifndef PPAPI_PROXY_PLUGIN_VAR_TRACKER_H_ |
6 #define PPAPI_PROXY_PLUGIN_VAR_TRACKER_H_ | 6 #define PPAPI_PROXY_PLUGIN_VAR_TRACKER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "ppapi/c/pp_stdint.h" | 14 #include "ppapi/c/pp_stdint.h" |
15 #include "ppapi/c/pp_var.h" | 15 #include "ppapi/c/pp_var.h" |
16 #include "ppapi/shared_impl/var_tracker.h" | 16 #include "ppapi/shared_impl/var_tracker.h" |
17 | 17 |
18 struct PPB_Var; | 18 struct PPB_Var; |
19 | 19 |
20 template<typename T> struct DefaultSingletonTraits; | 20 template<typename T> struct DefaultSingletonTraits; |
21 | 21 |
22 namespace ppapi { | 22 namespace ppapi { |
| 23 |
23 class ProxyObjectVar; | 24 class ProxyObjectVar; |
24 } | |
25 | 25 |
26 namespace pp { | |
27 namespace proxy { | 26 namespace proxy { |
28 | 27 |
29 class PluginDispatcher; | 28 class PluginDispatcher; |
30 | 29 |
31 // Tracks live strings and objects in the plugin process. | 30 // Tracks live strings and objects in the plugin process. |
32 class PluginVarTracker : public ppapi::VarTracker { | 31 class PluginVarTracker : public VarTracker { |
33 public: | 32 public: |
34 PluginVarTracker(); | 33 PluginVarTracker(); |
35 ~PluginVarTracker(); | 34 ~PluginVarTracker(); |
36 | 35 |
37 // Manages tracking for receiving a VARTYPE_OBJECT from the remote side | 36 // Manages tracking for receiving a VARTYPE_OBJECT from the remote side |
38 // (either the plugin or the renderer) that has already had its reference | 37 // (either the plugin or the renderer) that has already had its reference |
39 // count incremented on behalf of the caller. | 38 // count incremented on behalf of the caller. |
40 PP_Var ReceiveObjectPassRef(const PP_Var& var, PluginDispatcher* dispatcher); | 39 PP_Var ReceiveObjectPassRef(const PP_Var& var, PluginDispatcher* dispatcher); |
41 | 40 |
42 // See the comment in var_tracker.h for more about what a tracked object is. | 41 // See the comment in var_tracker.h for more about what a tracked object is. |
(...skipping 16 matching lines...) Expand all Loading... |
59 const PP_Var& host_object); | 58 const PP_Var& host_object); |
60 | 59 |
61 // Retrieves the internal reference counts for testing. Returns 0 if we | 60 // Retrieves the internal reference counts for testing. Returns 0 if we |
62 // know about the object but the corresponding value is 0, or -1 if the | 61 // know about the object but the corresponding value is 0, or -1 if the |
63 // given object ID isn't in our map. | 62 // given object ID isn't in our map. |
64 int GetRefCountForObject(const PP_Var& plugin_object); | 63 int GetRefCountForObject(const PP_Var& plugin_object); |
65 int GetTrackedWithNoReferenceCountForObject(const PP_Var& plugin_object); | 64 int GetTrackedWithNoReferenceCountForObject(const PP_Var& plugin_object); |
66 | 65 |
67 protected: | 66 protected: |
68 // VarTracker protected overrides. | 67 // VarTracker protected overrides. |
69 virtual int32 AddVarInternal(::ppapi::Var* var, AddVarRefMode mode) OVERRIDE; | 68 virtual int32 AddVarInternal(Var* var, AddVarRefMode mode) OVERRIDE; |
70 virtual void TrackedObjectGettingOneRef(VarMap::const_iterator iter) OVERRIDE; | 69 virtual void TrackedObjectGettingOneRef(VarMap::const_iterator iter) OVERRIDE; |
71 virtual void ObjectGettingZeroRef(VarMap::iterator iter) OVERRIDE; | 70 virtual void ObjectGettingZeroRef(VarMap::iterator iter) OVERRIDE; |
72 virtual bool DeleteObjectInfoIfNecessary(VarMap::iterator iter) OVERRIDE; | 71 virtual bool DeleteObjectInfoIfNecessary(VarMap::iterator iter) OVERRIDE; |
73 | 72 |
74 private: | 73 private: |
75 friend struct DefaultSingletonTraits<PluginVarTracker>; | 74 friend struct DefaultSingletonTraits<PluginVarTracker>; |
76 friend class PluginProxyTestHarness; | 75 friend class PluginProxyTestHarness; |
77 | 76 |
78 // Represents a var as received from the host. | 77 // Represents a var as received from the host. |
79 struct HostVar { | 78 struct HostVar { |
80 HostVar(PluginDispatcher* d, int32 i); | 79 HostVar(PluginDispatcher* d, int32 i); |
81 | 80 |
82 bool operator<(const HostVar& other) const; | 81 bool operator<(const HostVar& other) const; |
83 | 82 |
84 // The dispatcher that sent us this object. This is used so we know how to | 83 // The dispatcher that sent us this object. This is used so we know how to |
85 // send back requests on this object. | 84 // send back requests on this object. |
86 PluginDispatcher* dispatcher; | 85 PluginDispatcher* dispatcher; |
87 | 86 |
88 // The object ID that the host generated to identify the object. This is | 87 // The object ID that the host generated to identify the object. This is |
89 // unique only within that host: different hosts could give us different | 88 // unique only within that host: different hosts could give us different |
90 // objects with the same ID. | 89 // objects with the same ID. |
91 int32 host_object_id; | 90 int32 host_object_id; |
92 }; | 91 }; |
93 | 92 |
94 // Returns the existing var ID for the given object var, creating and | 93 // Returns the existing var ID for the given object var, creating and |
95 // assigning an ID to it if necessary. This does not affect the reference | 94 // assigning an ID to it if necessary. This does not affect the reference |
96 // count, so in the creation case the refcount will be 0. It's assumed in | 95 // count, so in the creation case the refcount will be 0. It's assumed in |
97 // this case the caller will either adjust the refcount or the | 96 // this case the caller will either adjust the refcount or the |
98 // track_with_no_reference_count. | 97 // track_with_no_reference_count. |
99 PP_Var GetOrCreateObjectVarID(ppapi::ProxyObjectVar* object); | 98 PP_Var GetOrCreateObjectVarID(ProxyObjectVar* object); |
100 | 99 |
101 // Sends an addref or release message to the browser for the given object ID. | 100 // Sends an addref or release message to the browser for the given object ID. |
102 void SendAddRefObjectMsg(const ppapi::ProxyObjectVar& proxy_object); | 101 void SendAddRefObjectMsg(const ProxyObjectVar& proxy_object); |
103 void SendReleaseObjectMsg(const ppapi::ProxyObjectVar& proxy_object); | 102 void SendReleaseObjectMsg(const ProxyObjectVar& proxy_object); |
104 | 103 |
105 // Looks up the given host var. If we already know about it, returns a | 104 // Looks up the given host var. If we already know about it, returns a |
106 // reference to the already-tracked object. If it doesn't creates a new one | 105 // reference to the already-tracked object. If it doesn't creates a new one |
107 // and returns it. If it's created, it's not added to the map. | 106 // and returns it. If it's created, it's not added to the map. |
108 scoped_refptr<ppapi::ProxyObjectVar> FindOrMakePluginVarFromHostVar( | 107 scoped_refptr<ProxyObjectVar> FindOrMakePluginVarFromHostVar( |
109 const PP_Var& var, | 108 const PP_Var& var, |
110 PluginDispatcher* dispatcher); | 109 PluginDispatcher* dispatcher); |
111 | 110 |
112 // Maps host vars in the host to IDs in the plugin process. | 111 // Maps host vars in the host to IDs in the plugin process. |
113 typedef std::map<HostVar, int32> HostVarToPluginVarMap; | 112 typedef std::map<HostVar, int32> HostVarToPluginVarMap; |
114 HostVarToPluginVarMap host_var_to_plugin_var_; | 113 HostVarToPluginVarMap host_var_to_plugin_var_; |
115 | 114 |
116 DISALLOW_COPY_AND_ASSIGN(PluginVarTracker); | 115 DISALLOW_COPY_AND_ASSIGN(PluginVarTracker); |
117 }; | 116 }; |
118 | 117 |
119 } // namespace proxy | 118 } // namespace proxy |
120 } // namespace pp | 119 } // namespace ppapi |
121 | 120 |
122 #endif // PPAPI_PROXY_PLUGIN_VAR_TRACKER_H_ | 121 #endif // PPAPI_PROXY_PLUGIN_VAR_TRACKER_H_ |
OLD | NEW |