threading.cc revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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 "mojo/apps/js/bindings/threading.h" 6 7#include "base/bind.h" 8#include "base/message_loop/message_loop.h" 9#include "gin/function_template.h" 10#include "gin/object_template_builder.h" 11#include "gin/per_isolate_data.h" 12#include "mojo/apps/js/bindings/handle.h" 13 14namespace mojo { 15namespace apps { 16 17namespace { 18 19void Quit() { 20 base::MessageLoop::current()->QuitNow(); 21} 22 23gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin }; 24 25} // namespace 26 27const char Threading::kModuleName[] = "mojo/apps/js/bindings/threading"; 28 29v8::Local<v8::ObjectTemplate> Threading::GetTemplate(v8::Isolate* isolate) { 30 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); 31 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate( 32 &g_wrapper_info); 33 34 if (templ.IsEmpty()) { 35 templ = gin::ObjectTemplateBuilder(isolate) 36 .SetMethod("quit", Quit) 37 .Build(); 38 39 data->SetObjectTemplate(&g_wrapper_info, templ); 40 } 41 42 return templ; 43} 44 45} // namespace apps 46} // namespace mojo 47