OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/shell/renderer/gc_controller.h" |
| 6 |
| 7 #include "gin/arguments.h" |
| 8 #include "gin/handle.h" |
| 9 #include "gin/object_template_builder.h" |
| 10 #include "third_party/WebKit/public/web/WebFrame.h" |
| 11 #include "third_party/WebKit/public/web/WebKit.h" |
| 12 #include "v8/include/v8.h" |
| 13 |
| 14 namespace content { |
| 15 |
| 16 gin::WrapperInfo GCController::kWrapperInfo = {gin::kEmbedderNativeGin}; |
| 17 |
| 18 // static |
| 19 void GCController::Install(blink::WebFrame* frame) { |
| 20 v8::Isolate* isolate = blink::mainThreadIsolate(); |
| 21 v8::HandleScope handle_scope(isolate); |
| 22 v8::Handle<v8::Context> context = frame->mainWorldScriptContext(); |
| 23 if (context.IsEmpty()) |
| 24 return; |
| 25 |
| 26 v8::Context::Scope context_scope(context); |
| 27 |
| 28 gin::Handle<GCController> controller = |
| 29 gin::CreateHandle(isolate, new GCController()); |
| 30 v8::Handle<v8::Object> global = context->Global(); |
| 31 global->Set(gin::StringToV8(isolate, "GCController"), controller.ToV8()); |
| 32 } |
| 33 |
| 34 GCController::GCController() {} |
| 35 |
| 36 GCController::~GCController() {} |
| 37 |
| 38 gin::ObjectTemplateBuilder GCController::GetObjectTemplateBuilder( |
| 39 v8::Isolate* isolate) { |
| 40 return gin::Wrappable<GCController>::GetObjectTemplateBuilder(isolate) |
| 41 .SetMethod("collect", &GCController::Collect) |
| 42 .SetMethod("minorCollect", &GCController::MinorCollect); |
| 43 } |
| 44 |
| 45 void GCController::Collect(const gin::Arguments& args) { |
| 46 args.isolate()->RequestGarbageCollectionForTesting( |
| 47 v8::Isolate::kFullGarbageCollection); |
| 48 } |
| 49 |
| 50 void GCController::MinorCollect(const gin::Arguments& args) { |
| 51 args.isolate()->RequestGarbageCollectionForTesting( |
| 52 v8::Isolate::kMinorGarbageCollection); |
| 53 } |
| 54 |
| 55 } // namespace content |
OLD | NEW |