diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-03 03:10:13 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-03 03:10:13 +0000 |
commit | 4bcab1c571c6b11a51e4493e3387733a6c95bbac (patch) | |
tree | 49c5a05d14c81b4061eda1a5f07d46d9545b46cb /ppapi/proxy/plugin_var_tracker.h | |
parent | 6ed2a5a54b7bb8ccd33da7bc948fee169f128459 (diff) | |
download | chromium_src-4bcab1c571c6b11a51e4493e3387733a6c95bbac.zip chromium_src-4bcab1c571c6b11a51e4493e3387733a6c95bbac.tar.gz chromium_src-4bcab1c571c6b11a51e4493e3387733a6c95bbac.tar.bz2 |
Core PPAPI proxy files. This includes the dispatcher which is the control point
on each end of the IPC channel. It includes the IPC message definitions. It
also includes the base class for the interface proxying, and the core resource
and var tracking.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/4229002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64869 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy/plugin_var_tracker.h')
-rw-r--r-- | ppapi/proxy/plugin_var_tracker.h | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/ppapi/proxy/plugin_var_tracker.h b/ppapi/proxy/plugin_var_tracker.h new file mode 100644 index 0000000..b519ee6 --- /dev/null +++ b/ppapi/proxy/plugin_var_tracker.h @@ -0,0 +1,76 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_PROXY_PLUGIN_VAR_TRACKER_H_ +#define PPAPI_PROXY_PLUGIN_VAR_TRACKER_H_ + +#include <map> +#include <string> + +#include "ppapi/c/pp_stdint.h" +#include "ppapi/c/pp_var.h" + +struct PPB_Var; + +namespace pp { +namespace proxy { + +class PluginDispatcher; + +// Tracks live strings and objects in the plugin process. We maintain our own +// reference count for these objects. In the case of JS objects, we maintain +// a single ref in the browser process whenever we have a nonzero refcount +// in the plugin process. This allows AddRef and Release to not initiate too +// much IPC chat. +class PluginVarTracker { + public: + // You must call Init() after creation to set up the correct interfaces. We + // do this to avoid having to depend on the dispatcher in the constructor, + // which is probably just being created from our constructor. + PluginVarTracker(PluginDispatcher* dispatcher); + + // Must be called after construction. + void Init(); + + // Allocates a string and returns the ID of it. The refcount will be 1. + int64_t MakeString(const std::string& str); + + // Returns the string associated with the given string var. The var must be + // of type string and must be valid or this function will crash. + std::string GetString(const PP_Var& var) const; + + // Returns a pointer to the given string if it exists, or NULL if the var + // isn't a string var. + const std::string* GetExistingString(const PP_Var& var) const; + + void AddRef(const PP_Var& var); + void Release(const PP_Var& var); + + // Manages tracking for receiving a VARTYPE_OBJECT from the remote side + // (either the plugin or the renderer) that has already had its reference + // count incremented on behalf of the caller. + void ReceiveObjectPassRef(const PP_Var& var); + + private: + // Sends an addref or release message to the browser for the given object ID. + void SendAddRefObjectMsg(int64_t id); + void SendReleaseObjectMsg(int64_t id); + + PluginDispatcher* dispatcher_; + + // When !is_plugin_ (we're in the renderer) this points to the actual var + // interface implementation which is how we create strings and manage + // refcounts. + const PPB_Var* browser_var_interface_; + + // Tracks object references to the reference count of that object on the + // plugin side. + typedef std::map<int64_t, int> ObjectRefCount; + ObjectRefCount object_ref_count_; +}; + +} // namespace proxy +} // namespace pp + +#endif // PPAPI_PROXY_PLUGIN_VAR_TRACKER_H_ |