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

Side by Side Diff: chrome/renderer/extensions/native_handler.cc

Issue 10918042: Use MakeWeak() to clean up function pointers in NativeHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/extensions/native_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/extensions/native_handler.h" 5 #include "chrome/renderer/extensions/native_handler.h"
6 6
7 #include "base/memory/linked_ptr.h" 7 #include "base/memory/linked_ptr.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "chrome/renderer/extensions/module_system.h" 9 #include "chrome/renderer/extensions/module_system.h"
10 #include "v8/include/v8.h" 10 #include "v8/include/v8.h"
(...skipping 20 matching lines...) Expand all
31 // HandlerFunction below point to freed memory. 31 // HandlerFunction below point to freed memory.
32 if (!ModuleSystem::IsPresentInCurrentContext()) { 32 if (!ModuleSystem::IsPresentInCurrentContext()) {
33 return v8::ThrowException(v8::Exception::Error( 33 return v8::ThrowException(v8::Exception::Error(
34 v8::String::New("ModuleSystem has been deleted"))); 34 v8::String::New("ModuleSystem has been deleted")));
35 } 35 }
36 HandlerFunction* handler_function = static_cast<HandlerFunction*>( 36 HandlerFunction* handler_function = static_cast<HandlerFunction*>(
37 args.Data().As<v8::External>()->Value()); 37 args.Data().As<v8::External>()->Value());
38 return handler_function->Run(args); 38 return handler_function->Run(args);
39 } 39 }
40 40
41 // static
42 void NativeHandler::DisposeFunction(v8::Persistent<v8::Value> object,
43 void* parameter) {
44 v8::HandleScope handle_scope;
not at google - send to devlin 2013/01/07 19:43:43 do you really need a handle scope here?
koz (OOO until 15th September) 2013/01/07 22:55:28 Done.
45 HandlerFunction* handler_function =
46 reinterpret_cast<HandlerFunction*>(parameter);
47
48 object.Dispose();
49 delete handler_function;
50 }
51
41 void NativeHandler::RouteFunction(const std::string& name, 52 void NativeHandler::RouteFunction(const std::string& name,
42 const HandlerFunction& handler_function) { 53 const HandlerFunction& handler_function) {
43 linked_ptr<HandlerFunction> function(new HandlerFunction(handler_function)); 54 HandlerFunction* function = new HandlerFunction(handler_function);
not at google - send to devlin 2013/01/07 19:43:43 Comment "deleted in DisposeFunction once v8 garbag
koz (OOO until 15th September) 2013/01/07 22:55:28 Done.
44 // TODO(koz): Investigate using v8's MakeWeak() function instead of holding 55 v8::Persistent<v8::External> function_value =
45 // on to these pointers here. 56 v8::Persistent<v8::External>::New(v8::External::New(function));
46 handler_functions_.push_back(function); 57 function_value.MakeWeak(function, DisposeFunction);
47 v8::Handle<v8::FunctionTemplate> function_template = 58 v8::Handle<v8::FunctionTemplate> function_template =
48 v8::FunctionTemplate::New(Router, 59 v8::FunctionTemplate::New(Router, function_value);
49 v8::External::New(function.get()));
50 object_template_->Set(name.c_str(), function_template); 60 object_template_->Set(name.c_str(), function_template);
51 } 61 }
52 62
53 void NativeHandler::RouteStaticFunction(const std::string& name, 63 void NativeHandler::RouteStaticFunction(const std::string& name,
54 const HandlerFunc handler_func) { 64 const HandlerFunc handler_func) {
55 v8::Handle<v8::FunctionTemplate> function_template = 65 v8::Handle<v8::FunctionTemplate> function_template =
56 v8::FunctionTemplate::New(handler_func, v8::External::New(this)); 66 v8::FunctionTemplate::New(handler_func, v8::External::New(this));
57 object_template_->Set(name.c_str(), function_template); 67 object_template_->Set(name.c_str(), function_template);
58 } 68 }
59 69
60 } // extensions 70 } // extensions
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/native_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698