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

Unified Diff: content/renderer/pepper/plugin_object.cc

Issue 785213002: Cache function templates in PluginObject to avoid memory leak. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 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 | « content/renderer/pepper/plugin_object.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/pepper/plugin_object.cc
diff --git a/content/renderer/pepper/plugin_object.cc b/content/renderer/pepper/plugin_object.cc
index 729b4801452aac825eb4ea879d167b0009f3c413..93c4b72943d07557ef71b78553598335832f59e6 100644
--- a/content/renderer/pepper/plugin_object.cc
+++ b/content/renderer/pepper/plugin_object.cc
@@ -169,7 +169,8 @@ PluginObject::PluginObject(PepperPluginInstanceImpl* instance,
instance_(instance),
ppp_class_(ppp_class),
ppp_class_data_(ppp_class_data),
- weak_factory_(this) {
+ weak_factory_(this),
+ template_cache_(instance->GetIsolate()) {
instance_->AddPluginObject(this);
}
@@ -216,10 +217,7 @@ v8::Local<v8::Value> PluginObject::GetPropertyOrMethod(v8::Isolate* isolate,
if (has_method) {
const std::string& identifier =
StringVar::FromPPVar(identifier_var)->value();
- return gin::CreateFunctionTemplate(isolate,
- base::Bind(&PluginObject::Call,
- weak_factory_.GetWeakPtr(),
- identifier))->GetFunction();
+ return GetFunctionTemplate(isolate, identifier)->GetFunction();
}
return v8::Local<v8::Value>();
@@ -268,4 +266,18 @@ void PluginObject::Call(const std::string& identifier,
args->Return(result);
}
+v8::Local<v8::FunctionTemplate> PluginObject::GetFunctionTemplate(
+ v8::Isolate* isolate,
+ const std::string& name) {
+ v8::Local<v8::FunctionTemplate> function_template = template_cache_.Get(name);
+ if (!function_template.IsEmpty())
+ return function_template;
+ function_template =
+ gin::CreateFunctionTemplate(
+ isolate, base::Bind(&PluginObject::Call, weak_factory_.GetWeakPtr(),
+ name));
+ template_cache_.Set(name, function_template);
+ return function_template;
+}
+
} // namespace content
« no previous file with comments | « content/renderer/pepper/plugin_object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698