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_resource_tracker.cc | |
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_resource_tracker.cc')
-rw-r--r-- | ppapi/proxy/plugin_resource_tracker.cc | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/ppapi/proxy/plugin_resource_tracker.cc b/ppapi/proxy/plugin_resource_tracker.cc new file mode 100644 index 0000000..a285311 --- /dev/null +++ b/ppapi/proxy/plugin_resource_tracker.cc @@ -0,0 +1,87 @@ +// 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. + +#include "ppapi/proxy/plugin_resource_tracker.h" + +#include "base/logging.h" +#include "ppapi/proxy/plugin_dispatcher.h" +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/proxy/serialized_var.h" + +namespace pp { +namespace proxy { + +PluginResourceTracker::ResourceInfo::ResourceInfo() : ref_count(0) { +} + +PluginResourceTracker::ResourceInfo::ResourceInfo(int rc, + linked_ptr<PluginResource> r) + : ref_count(rc), + resource(r) { +} + +PluginResourceTracker::ResourceInfo::ResourceInfo(const ResourceInfo& other) + : ref_count(other.ref_count), + resource(other.resource) { +} + +PluginResourceTracker::ResourceInfo::~ResourceInfo() { +} + +PluginResourceTracker::ResourceInfo& +PluginResourceTracker::ResourceInfo::operator=( + const ResourceInfo& other) { + ref_count = other.ref_count; + resource = other.resource; + return *this; +} + +PluginResourceTracker::PluginResourceTracker(PluginDispatcher* dispatcher) + : dispatcher_(dispatcher) { +} + +PluginResourceTracker::~PluginResourceTracker() { +} + +PluginResource* PluginResourceTracker::GetResourceObject( + PP_Resource pp_resource) { + ResourceMap::iterator found = resource_map_.find(pp_resource); + if (found == resource_map_.end()) + return NULL; + return found->second.resource.get(); +} + +void PluginResourceTracker::AddResource(PP_Resource pp_resource, + linked_ptr<PluginResource> object) { + DCHECK(resource_map_.find(pp_resource) == resource_map_.end()); + resource_map_[pp_resource] = ResourceInfo(1, object); +} + +void PluginResourceTracker::AddRefResource(PP_Resource resource) { + resource_map_[resource].ref_count++; +} + +void PluginResourceTracker::ReleaseResource(PP_Resource resource) { + ReleasePluginResourceRef(resource, true); +} + +void PluginResourceTracker::ReleasePluginResourceRef( + const PP_Resource& resource, + bool notify_browser_on_release) { + ResourceMap::iterator found = resource_map_.find(resource); + if (found == resource_map_.end()) + return; + found->second.ref_count--; + if (found->second.ref_count == 0) { + if (notify_browser_on_release) { + dispatcher_->Send(new PpapiHostMsg_PPBCore_ReleaseResource( + INTERFACE_ID_PPB_CORE, resource)); + } + resource_map_.erase(found); + } +} + +} // namespace proxy +} // namespace pp |