| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 class PluginVarTracker { | 37 class PluginVarTracker { |
| 38 public: | 38 public: |
| 39 typedef int64_t VarID; | 39 typedef int64_t VarID; |
| 40 | 40 |
| 41 // This uses the PluginDispatcher to identify the source of vars so that | 41 // This uses the PluginDispatcher to identify the source of vars so that |
| 42 // the proper messages can be sent back. However, since all we need is the | 42 // the proper messages can be sent back. However, since all we need is the |
| 43 // ability to send messages, we can always use the Sender base class of | 43 // ability to send messages, we can always use the Sender base class of |
| 44 // Dispatcher in this class, which makes it easy to unit test. | 44 // Dispatcher in this class, which makes it easy to unit test. |
| 45 typedef IPC::Channel::Sender Sender; | 45 typedef IPC::Channel::Sender Sender; |
| 46 | 46 |
| 47 // Called by tests that want to specify a specific VarTracker. This allows |
| 48 // them to use a unique one each time and avoids singletons sticking around |
| 49 // across tests. |
| 50 static void SetInstanceForTest(PluginVarTracker* tracker); |
| 51 |
| 47 // Returns the global var tracker for the plugin object. | 52 // Returns the global var tracker for the plugin object. |
| 48 static PluginVarTracker* GetInstance(); | 53 static PluginVarTracker* GetInstance(); |
| 49 | 54 |
| 50 // Allocates a string and returns the ID of it. The refcount will be 1. | 55 // Allocates a string and returns the ID of it. The refcount will be 1. |
| 51 VarID MakeString(const std::string& str); | 56 VarID MakeString(const std::string& str); |
| 52 VarID MakeString(const char* str, uint32_t len); | 57 VarID MakeString(const char* str, uint32_t len); |
| 53 | 58 |
| 54 // Returns the string associated with the given string var. The var must be | 59 // Returns the string associated with the given string var. The var must be |
| 55 // of type string and must be valid or this function will crash. | 60 // of type string and must be valid or this function will crash. |
| 56 std::string GetString(const PP_Var& plugin_var) const; | 61 std::string GetString(const PP_Var& plugin_var) const; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 68 PP_Var ReceiveObjectPassRef(const PP_Var& var, Sender* channel); | 73 PP_Var ReceiveObjectPassRef(const PP_Var& var, Sender* channel); |
| 69 | 74 |
| 70 PP_Var TrackObjectWithNoReference(const PP_Var& host_var, | 75 PP_Var TrackObjectWithNoReference(const PP_Var& host_var, |
| 71 Sender* channel); | 76 Sender* channel); |
| 72 void StopTrackingObjectWithNoReference(const PP_Var& plugin_var); | 77 void StopTrackingObjectWithNoReference(const PP_Var& plugin_var); |
| 73 | 78 |
| 74 // Returns the host var for the corresponding plugin object var. The object | 79 // Returns the host var for the corresponding plugin object var. The object |
| 75 // should be a VARTYPE_OBJECT | 80 // should be a VARTYPE_OBJECT |
| 76 PP_Var GetHostObject(const PP_Var& plugin_object) const; | 81 PP_Var GetHostObject(const PP_Var& plugin_object) const; |
| 77 | 82 |
| 83 // Like Release() but the var is identified by its host object ID (as |
| 84 // returned by GetHostObject). |
| 85 void ReleaseHostObject(Sender* sender, const PP_Var& host_object); |
| 86 |
| 78 // Retrieves the internal reference counts for testing. Returns 0 if we | 87 // Retrieves the internal reference counts for testing. Returns 0 if we |
| 79 // know about the object but the corresponding value is 0, or -1 if the | 88 // know about the object but the corresponding value is 0, or -1 if the |
| 80 // given object ID isn't in our map. | 89 // given object ID isn't in our map. |
| 81 int GetRefCountForObject(const PP_Var& plugin_object); | 90 int GetRefCountForObject(const PP_Var& plugin_object); |
| 82 int GetTrackedWithNoReferenceCountForObject(const PP_Var& plugin_object); | 91 int GetTrackedWithNoReferenceCountForObject(const PP_Var& plugin_object); |
| 83 | 92 |
| 84 private: | 93 private: |
| 85 friend struct DefaultSingletonTraits<PluginVarTracker>; | 94 friend struct DefaultSingletonTraits<PluginVarTracker>; |
| 86 friend class PluginVarTrackerTest; | 95 friend class PluginProxyTest; |
| 87 | 96 |
| 88 // Represents a var as received from the host. | 97 // Represents a var as received from the host. |
| 89 struct HostVar { | 98 struct HostVar { |
| 90 HostVar(Sender* s, int64_t i); | 99 HostVar(Sender* s, int64_t i); |
| 91 | 100 |
| 92 bool operator<(const HostVar& other) const; | 101 bool operator<(const HostVar& other) const; |
| 93 | 102 |
| 94 // The host that sent us this object. This is used so we know how to send | 103 // The host that sent us this object. This is used so we know how to send |
| 95 // back requests on this object. | 104 // back requests on this object. |
| 96 Sender* channel; | 105 Sender* channel; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 163 |
| 155 // The last plugin object ID we've handed out. This must be unique for the | 164 // The last plugin object ID we've handed out. This must be unique for the |
| 156 // process. | 165 // process. |
| 157 VarID last_plugin_object_id_; | 166 VarID last_plugin_object_id_; |
| 158 }; | 167 }; |
| 159 | 168 |
| 160 } // namespace proxy | 169 } // namespace proxy |
| 161 } // namespace pp | 170 } // namespace pp |
| 162 | 171 |
| 163 #endif // PPAPI_PROXY_PLUGIN_VAR_TRACKER_H_ | 172 #endif // PPAPI_PROXY_PLUGIN_VAR_TRACKER_H_ |
| OLD | NEW |