summaryrefslogtreecommitdiffstats
path: root/ppapi/proxy/plugin_resource_tracker.h
diff options
context:
space:
mode:
authorgrt@chromium.org <grt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-19 16:14:55 +0000
committergrt@chromium.org <grt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-19 16:14:55 +0000
commit1e78967ed2f1937b3809c19d91e7dd62d756d307 (patch)
tree054c19343eaced71ac5edf8d5425e83fb878ca0d /ppapi/proxy/plugin_resource_tracker.h
parent5d4451ebf298d9d71f716cc0135f465cec41fcd0 (diff)
parentcd18d6f39a965004529d5800a7067a3d3b29a2ba (diff)
downloadchromium_src-1e78967ed2f1937b3809c19d91e7dd62d756d307.zip
chromium_src-1e78967ed2f1937b3809c19d91e7dd62d756d307.tar.gz
chromium_src-1e78967ed2f1937b3809c19d91e7dd62d756d307.tar.bz2
FileManagerDialogTest.SelectFileAndCancel flaky.
BUG=89733 TBR=robertshield@chromium.org TEST=browser_tests Review URL: http://codereview.chromium.org/7447001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93027 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy/plugin_resource_tracker.h')
-rw-r--r--ppapi/proxy/plugin_resource_tracker.h107
1 files changed, 107 insertions, 0 deletions
diff --git a/ppapi/proxy/plugin_resource_tracker.h b/ppapi/proxy/plugin_resource_tracker.h
new file mode 100644
index 0000000..83b7840
--- /dev/null
+++ b/ppapi/proxy/plugin_resource_tracker.h
@@ -0,0 +1,107 @@
+// 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 PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_
+#define PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_
+
+#include <map>
+#include <utility>
+
+#include "base/compiler_specific.h"
+#include "base/memory/linked_ptr.h"
+#include "ppapi/c/pp_completion_callback.h"
+#include "ppapi/c/pp_instance.h"
+#include "ppapi/c/pp_stdint.h"
+#include "ppapi/c/pp_resource.h"
+#include "ppapi/c/pp_var.h"
+#include "ppapi/proxy/host_resource.h"
+#include "ppapi/shared_impl/tracker_base.h"
+
+template<typename T> struct DefaultSingletonTraits;
+
+namespace pp {
+namespace proxy {
+
+class PluginDispatcher;
+class PluginResource;
+
+class PluginResourceTracker : public ::ppapi::TrackerBase {
+ public:
+ // Called by tests that want to specify a specific ResourceTracker. This
+ // allows them to use a unique one each time and avoids singletons sticking
+ // around across tests.
+ static void SetInstanceForTest(PluginResourceTracker* tracker);
+
+ // Returns the global singleton resource tracker for the plugin.
+ static PluginResourceTracker* GetInstance();
+ static ::ppapi::TrackerBase* GetTrackerBaseInstance();
+
+ // Returns the object associated with the given resource ID, or NULL if
+ // there isn't one.
+ PluginResource* GetResourceObject(PP_Resource pp_resource);
+
+ // Adds the given resource object to the tracked list, and returns the
+ // plugin-local PP_Resource ID that identifies the resource. Note that this
+ // PP_Resource is not valid to send to the host, use
+ // PluginResource.host_resource() to get that.
+ PP_Resource AddResource(linked_ptr<PluginResource> object);
+
+ void AddRefResource(PP_Resource resource);
+ void ReleaseResource(PP_Resource resource);
+
+ // Given a host resource, maps it to an existing plugin resource ID if it
+ // exists, or returns 0 on failure.
+ PP_Resource PluginResourceForHostResource(
+ const HostResource& resource) const;
+
+ // TrackerBase.
+ virtual ::ppapi::ResourceObjectBase* GetResourceAPI(
+ PP_Resource res) OVERRIDE;
+ virtual ::ppapi::FunctionGroupBase* GetFunctionAPI(
+ PP_Instance inst,
+ pp::proxy::InterfaceID id) OVERRIDE;
+ virtual PP_Instance GetInstanceForResource(PP_Resource resource) OVERRIDE;
+
+ private:
+ friend struct DefaultSingletonTraits<PluginResourceTracker>;
+ friend class PluginResourceTrackerTest;
+ friend class PluginProxyTestHarness;
+
+ PluginResourceTracker();
+ virtual ~PluginResourceTracker();
+
+ struct ResourceInfo {
+ ResourceInfo();
+ ResourceInfo(int ref_count, linked_ptr<PluginResource> r);
+ ResourceInfo(const ResourceInfo& other);
+ ~ResourceInfo();
+
+ ResourceInfo& operator=(const ResourceInfo& other);
+
+ int ref_count;
+ linked_ptr<PluginResource> resource; // May be NULL.
+ };
+
+ void ReleasePluginResourceRef(const PP_Resource& var,
+ bool notify_browser_on_release);
+
+ // Map of plugin resource IDs to the information tracking that resource.
+ typedef std::map<PP_Resource, ResourceInfo> ResourceMap;
+ ResourceMap resource_map_;
+
+ // Map of host instance/resource pairs to a plugin resource ID.
+ typedef std::map<HostResource, PP_Resource> HostResourceMap;
+ HostResourceMap host_resource_map_;
+
+ // Tracks the last ID we've sent out as a plugin resource so we don't send
+ // duplicates.
+ PP_Resource last_resource_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(PluginResourceTracker);
+};
+
+} // namespace proxy
+} // namespace pp
+
+#endif // PPAPI_PROXY_PLUGIN_RESOURCE_TRACKER_H_