diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-20 21:50:11 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-20 21:50:11 +0000 |
commit | 0bc2efd12616518e3952be87a078d53ab5adfca5 (patch) | |
tree | 5cb3aea9931d3d629a3dcc3d30a6806b4c411bb8 /webkit/plugins/ppapi/host_var_tracker.h | |
parent | a0c33d1073c9f10672aef2ab6e2eec4eb712827e (diff) | |
download | chromium_src-0bc2efd12616518e3952be87a078d53ab5adfca5.zip chromium_src-0bc2efd12616518e3952be87a078d53ab5adfca5.tar.gz chromium_src-0bc2efd12616518e3952be87a078d53ab5adfca5.tar.bz2 |
Split HostVarTracker out of HostResourceTracker.
For the shared stuff we have a ppapi/shared_impl/VarTracker and a
ppapi/shared_impl/ResourceTracker. The host side of the proxy inherits
HostResourceTracker from ResourceTracker and then adds a bunch of var tracking
stuff to that, which makes no sense.
This moves the var tracking stuff out into a separate HostVarTracker so that's
all in one object. The host version just adds the NPObject tracking on top of
the shared VarTracking.
BUG=
TEST=
Review URL: http://codereview.chromium.org/8322017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106593 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/plugins/ppapi/host_var_tracker.h')
-rw-r--r-- | webkit/plugins/ppapi/host_var_tracker.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/webkit/plugins/ppapi/host_var_tracker.h b/webkit/plugins/ppapi/host_var_tracker.h new file mode 100644 index 0000000..dcb96c8 --- /dev/null +++ b/webkit/plugins/ppapi/host_var_tracker.h @@ -0,0 +1,83 @@ +// Copyright (c) 2011 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 WEBKIT_PLUGINS_PPAPI_HOST_VAR_TRACKER_H_ +#define WEBKIT_PLUGINS_PPAPI_HOST_VAR_TRACKER_H_ + +#include <map> + +#include "base/basictypes.h" +#include "base/gtest_prod_util.h" +#include "base/hash_tables.h" +#include "base/memory/linked_ptr.h" +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "ppapi/c/pp_instance.h" +#include "ppapi/c/pp_module.h" +#include "ppapi/c/pp_resource.h" +#include "ppapi/proxy/interface_id.h" +#include "ppapi/shared_impl/function_group_base.h" +#include "ppapi/shared_impl/resource_tracker.h" +#include "ppapi/shared_impl/tracker_base.h" +#include "ppapi/shared_impl/var_tracker.h" + +typedef struct NPObject NPObject; + +namespace ppapi { +class NPObjectVar; +class Var; +} + +namespace webkit { +namespace ppapi { + +// Adds NPObject var tracking to the standard PPAPI VarTracker for use in the +// renderer. +class HostVarTracker : public ::ppapi::VarTracker { + public: + HostVarTracker(); + virtual ~HostVarTracker(); + + // Tracks all live NPObjectVar. This is so we can map between instance + + // NPObject and get the NPObjectVar corresponding to it. This Add/Remove + // function is called by the NPObjectVar when it is created and + // destroyed. + void AddNPObjectVar(::ppapi::NPObjectVar* object_var); + void RemoveNPObjectVar(::ppapi::NPObjectVar* object_var); + + // Looks up a previously registered NPObjectVar for the given NPObject and + // instance. Returns NULL if there is no NPObjectVar corresponding to the + // given NPObject for the given instance. See AddNPObjectVar above. + ::ppapi::NPObjectVar* NPObjectVarForNPObject(PP_Instance instance, + NPObject* np_object); + + // Returns the number of NPObjectVar's associated with the given instance. + // Returns 0 if the instance isn't known. + int GetLiveNPObjectVarsForInstance(PP_Instance instance) const; + + // Forcibly deletes all np object vars for the given instance. Used for + // instance cleanup. + void ForceFreeNPObjectsForInstance(PP_Instance instance); + + private: + typedef std::map<NPObject*, ::ppapi::NPObjectVar*> NPObjectToNPObjectVarMap; + + // Lists all known NPObjects, first indexed by the corresponding instance, + // then by the NPObject*. This allows us to look up an NPObjectVar given + // these two pieces of information. + // + // The instance map is lazily managed, so we'll add the + // NPObjectToNPObjectVarMap lazily when the first NPObject var is created, + // and delete it when it's empty. + typedef std::map<PP_Instance, linked_ptr<NPObjectToNPObjectVarMap> > + InstanceMap; + InstanceMap instance_map_; + + DISALLOW_COPY_AND_ASSIGN(HostVarTracker); +}; + +} // namespace ppapi +} // namespace webkit + +#endif // WEBKIT_PLUGINS_PPAPI_HOST_VAR_TRACKER_H_ |