OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef PPAPI_PROXY_PLUGIN_VAR_TRACKER_H_ |
| 6 #define PPAPI_PROXY_PLUGIN_VAR_TRACKER_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 |
| 11 #include "ppapi/c/pp_stdint.h" |
| 12 #include "ppapi/c/pp_var.h" |
| 13 |
| 14 struct PPB_Var; |
| 15 |
| 16 namespace pp { |
| 17 namespace proxy { |
| 18 |
| 19 class PluginDispatcher; |
| 20 |
| 21 // Tracks live strings and objects in the plugin process. We maintain our own |
| 22 // reference count for these objects. In the case of JS objects, we maintain |
| 23 // a single ref in the browser process whenever we have a nonzero refcount |
| 24 // in the plugin process. This allows AddRef and Release to not initiate too |
| 25 // much IPC chat. |
| 26 class PluginVarTracker { |
| 27 public: |
| 28 // You must call Init() after creation to set up the correct interfaces. We |
| 29 // do this to avoid having to depend on the dispatcher in the constructor, |
| 30 // which is probably just being created from our constructor. |
| 31 PluginVarTracker(PluginDispatcher* dispatcher); |
| 32 |
| 33 // Must be called after construction. |
| 34 void Init(); |
| 35 |
| 36 // Allocates a string and returns the ID of it. The refcount will be 1. |
| 37 int64_t MakeString(const std::string& str); |
| 38 |
| 39 // Returns the string associated with the given string var. The var must be |
| 40 // of type string and must be valid or this function will crash. |
| 41 std::string GetString(const PP_Var& var) const; |
| 42 |
| 43 // Returns a pointer to the given string if it exists, or NULL if the var |
| 44 // isn't a string var. |
| 45 const std::string* GetExistingString(const PP_Var& var) const; |
| 46 |
| 47 void AddRef(const PP_Var& var); |
| 48 void Release(const PP_Var& var); |
| 49 |
| 50 // Manages tracking for receiving a VARTYPE_OBJECT from the remote side |
| 51 // (either the plugin or the renderer) that has already had its reference |
| 52 // count incremented on behalf of the caller. |
| 53 void ReceiveObjectPassRef(const PP_Var& var); |
| 54 |
| 55 private: |
| 56 // Sends an addref or release message to the browser for the given object ID. |
| 57 void SendAddRefObjectMsg(int64_t id); |
| 58 void SendReleaseObjectMsg(int64_t id); |
| 59 |
| 60 PluginDispatcher* dispatcher_; |
| 61 |
| 62 // When !is_plugin_ (we're in the renderer) this points to the actual var |
| 63 // interface implementation which is how we create strings and manage |
| 64 // refcounts. |
| 65 const PPB_Var* browser_var_interface_; |
| 66 |
| 67 // Tracks object references to the reference count of that object on the |
| 68 // plugin side. |
| 69 typedef std::map<int64_t, int> ObjectRefCount; |
| 70 ObjectRefCount object_ref_count_; |
| 71 }; |
| 72 |
| 73 } // namespace proxy |
| 74 } // namespace pp |
| 75 |
| 76 #endif // PPAPI_PROXY_PLUGIN_VAR_TRACKER_H_ |
OLD | NEW |