From 69df934710c81d233d80a7143d4603cab8ff1969 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 10 Mar 2017 11:01:17 +0900 Subject: [PATCH] Converter for base::Callback is not thread safe --- atom/common/api/atom_api_asar.cc | 15 ++++++++------- atom/common/native_mate_converters/callback.cc | 2 -- atom/common/native_mate_converters/callback.h | 2 ++ atom/common/node_bindings.cc | 11 ----------- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/atom/common/api/atom_api_asar.cc b/atom/common/api/atom_api_asar.cc index e94099b..3151da6 100644 --- a/atom/common/api/atom_api_asar.cc +++ b/atom/common/api/atom_api_asar.cc @@ -141,15 +141,16 @@ void InitAsarSupport(v8::Isolate* isolate, v8::Local result = asar_init->Run(); // Initialize asar support. - base::Callback, - v8::Local, - std::string)> init; - if (mate::ConvertFromV8(isolate, result, &init)) { + if (result->IsFunction()) { const char* asar_native = reinterpret_cast( static_cast(node::asar_data)); - init.Run(process, - require, - std::string(asar_native, sizeof(node::asar_data) - 1)); + base::StringPiece asar_data(asar_native, sizeof(node::asar_data) - 1); + v8::Local args[] = { + process, + require, + mate::ConvertToV8(isolate, asar_data), + }; + result.As()->Call(result, 3, args); } } diff --git a/atom/common/native_mate_converters/callback.cc b/atom/common/native_mate_converters/callback.cc index dc6d30f..a6a500b 100644 --- a/atom/common/native_mate_converters/callback.cc +++ b/atom/common/native_mate_converters/callback.cc @@ -4,8 +4,6 @@ #include "atom/common/native_mate_converters/callback.h" -#include "content/public/browser/browser_thread.h" - using content::BrowserThread; namespace mate { diff --git a/atom/common/native_mate_converters/callback.h b/atom/common/native_mate_converters/callback.h index decc36e..f42ee87 100644 --- a/atom/common/native_mate_converters/callback.h +++ b/atom/common/native_mate_converters/callback.h @@ -10,7 +10,9 @@ #include "atom/common/api/locker.h" #include "base/bind.h" #include "base/callback.h" +#include "base/message_loop/message_loop.h" #include "base/memory/weak_ptr.h" +#include "content/public/browser/browser_thread.h" #include "native_mate/function_template.h" #include "native_mate/scoped_persistent.h" diff --git a/atom/common/node_bindings.cc b/atom/common/node_bindings.cc index cb6cf34..e6dcb4e 100644 --- a/atom/common/node_bindings.cc +++ b/atom/common/node_bindings.cc @@ -25,8 +25,6 @@ #include "atom/common/node_includes.h" -using content::BrowserThread; - // Force all builtin modules to be referenced so they can actually run their // DSO constructors, see http://git.io/DRIqCg. #define REFERENCE_MODULE(name) \ @@ -210,9 +208,6 @@ void NodeBindings::LoadEnvironment(node::Environment* env) { } void NodeBindings::PrepareMessageLoop() { - DCHECK(browser_env_ != BROWSER || - BrowserThread::CurrentlyOn(BrowserThread::UI)); - // Add dummy handle for libuv, otherwise libuv would quit when there is // nothing to do. uv_async_init(uv_loop_, &dummy_uv_handle_, nullptr); @@ -223,9 +218,6 @@ void NodeBindings::PrepareMessageLoop() { } void NodeBindings::RunMessageLoop() { - DCHECK(browser_env_ != BROWSER || - BrowserThread::CurrentlyOn(BrowserThread::UI)); - // The MessageLoop should have been created, remember the one in main thread. task_runner_ = base::ThreadTaskRunnerHandle::Get(); @@ -234,9 +226,6 @@ void NodeBindings::RunMessageLoop() { } void NodeBindings::UvRunOnce() { - DCHECK(browser_env_ != BROWSER || - BrowserThread::CurrentlyOn(BrowserThread::UI)); - node::Environment* env = uv_env(); // Use Locker in browser process. -- 2.7.4