Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Unified Diff: src/shared/ppapi_proxy/plugin_resource_tracker.cc

Issue 5581011: Resource tracking done right. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Updated for CoreInterface->PPBCoreInterface rename Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/shared/ppapi_proxy/plugin_resource_tracker.h ('k') | src/shared/ppapi_proxy/ppb_core.srpc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/shared/ppapi_proxy/plugin_resource_tracker.cc
diff --git a/src/shared/ppapi_proxy/plugin_resource_tracker.cc b/src/shared/ppapi_proxy/plugin_resource_tracker.cc
index f5d39839128e970ee8b570f91ec4cd98965d92b4..56ec9c02959b4a7af8f83192b4fadfd4365b7d17 100644
--- a/src/shared/ppapi_proxy/plugin_resource_tracker.cc
+++ b/src/shared/ppapi_proxy/plugin_resource_tracker.cc
@@ -7,36 +7,38 @@
#include <limits>
#include <set>
+#include "native_client/src/include/nacl_macros.h"
+#include "native_client/src/include/portability.h"
+#include "native_client/src/shared/ppapi_proxy/plugin_globals.h"
#include "native_client/src/shared/ppapi_proxy/plugin_resource.h"
#include "ppapi/c/pp_resource.h"
+#include "srpcgen/ppb_rpc.h"
namespace ppapi_proxy {
-scoped_refptr<PluginResource>
-PluginResourceTracker::GetResource(PP_Resource res) const {
- ResourceMap::const_iterator result = live_resources_.find(res);
- if (result == live_resources_.end()) {
- return scoped_refptr<PluginResource>();
- }
- return result->second.first;
+PluginResourceTracker::ResourceAndRefCounts::ResourceAndRefCounts(
+ PluginResource* r) : resource(r), browser_refcount(1), plugin_refcount(1) {
+}
+
+PluginResourceTracker::ResourceAndRefCounts::~ResourceAndRefCounts() {
}
-PluginResourceTracker::PluginResourceTracker()
- : last_id_(0) {
+scoped_refptr<PluginResource> PluginResourceTracker::GetExistingResource(
+ PP_Resource res) const {
+ ResourceMap::const_iterator result = live_resources_.find(res);
+ if (result == live_resources_.end())
+ return scoped_refptr<PluginResource>();
+ else
+ return result->second.resource;
}
-PluginResourceTracker::~PluginResourceTracker() {
+PluginResourceTracker::PluginResourceTracker() : last_id_(0) {
}
-PP_Resource PluginResourceTracker::AddResource(PluginResource* resource) {
- // If the plugin manages to create 4B resources...
- if (last_id_ == std::numeric_limits<PP_Resource>::max()) {
- return 0;
- }
+void PluginResourceTracker::AddResource(PluginResource* resource,
+ PP_Resource id) {
// Add the resource with plugin use-count 1.
- ++last_id_;
- live_resources_.insert(std::make_pair(last_id_, std::make_pair(resource, 1)));
- return last_id_;
+ live_resources_.insert(std::make_pair(id, ResourceAndRefCounts(resource)));
}
bool PluginResourceTracker::AddRefResource(PP_Resource res) {
@@ -47,7 +49,7 @@ bool PluginResourceTracker::AddRefResource(PP_Resource res) {
// We don't protect against overflow, since a plugin as malicious as to ref
// once per every byte in the address space could have just as well unrefed
// one time too many.
- ++i->second.second;
+ i->second.plugin_refcount++;
return true;
}
}
@@ -55,9 +57,14 @@ bool PluginResourceTracker::AddRefResource(PP_Resource res) {
bool PluginResourceTracker::UnrefResource(PP_Resource res) {
ResourceMap::iterator i = live_resources_.find(res);
if (i != live_resources_.end()) {
- if (!--i->second.second) {
- i->second.first->StoppedTracking();
+ i->second.plugin_refcount--;
+ if (0 == i->second.plugin_refcount) {
+ size_t browser_refcount = i->second.browser_refcount;
+ i->second.resource->StoppedTracking();
live_resources_.erase(i);
+
+ // Release all browser references.
+ ReleaseBrowserResource(res, browser_refcount);
}
return true;
} else {
@@ -65,5 +72,22 @@ bool PluginResourceTracker::UnrefResource(PP_Resource res) {
}
}
+void PluginResourceTracker::ObtainBrowserResource(PP_Resource res) {
+ if (res) {
+ NaClSrpcChannel* channel = ppapi_proxy::GetMainSrpcChannel();
+ PpbCoreRpcClient::PPB_Core_AddRefResource(channel, res);
+ }
+}
+
+void PluginResourceTracker::ReleaseBrowserResource(PP_Resource res,
+ size_t browser_refcount) {
+ // Release all browser references.
+ if (res) {
+ NaClSrpcChannel* channel = ppapi_proxy::GetMainSrpcChannel();
+ PpbCoreRpcClient::ReleaseResourceMultipleTimes(channel, res,
+ browser_refcount);
+ }
+}
+
} // namespace ppapi_proxy
« no previous file with comments | « src/shared/ppapi_proxy/plugin_resource_tracker.h ('k') | src/shared/ppapi_proxy/ppb_core.srpc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698