Converter for base::Callback is not thread safe
authorCheng Zhao <zcbenz@gmail.com>
Fri, 10 Mar 2017 02:01:17 +0000 (11:01 +0900)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 20 Mar 2017 19:52:45 +0000 (12:52 -0700)
atom/common/api/atom_api_asar.cc
atom/common/native_mate_converters/callback.cc
atom/common/native_mate_converters/callback.h
atom/common/node_bindings.cc

index e94099b..3151da6 100644 (file)
@@ -141,15 +141,16 @@ void InitAsarSupport(v8::Isolate* isolate,
   v8::Local<v8::Value> result = asar_init->Run();
 
   // Initialize asar support.
-  base::Callback<void(v8::Local<v8::Value>,
-                      v8::Local<v8::Value>,
-                      std::string)> init;
-  if (mate::ConvertFromV8(isolate, result, &init)) {
+  if (result->IsFunction()) {
     const char* asar_native = reinterpret_cast<const char*>(
         static_cast<const unsigned char*>(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<v8::Value> args[] = {
+        process,
+        require,
+        mate::ConvertToV8(isolate, asar_data),
+    };
+    result.As<v8::Function>()->Call(result, 3, args);
   }
 }
 
index dc6d30f..a6a500b 100644 (file)
@@ -4,8 +4,6 @@
 
 #include "atom/common/native_mate_converters/callback.h"
 
-#include "content/public/browser/browser_thread.h"
-
 using content::BrowserThread;
 
 namespace mate {
index decc36e..f42ee87 100644 (file)
@@ -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"
 
index cb6cf34..e6dcb4e 100644 (file)
@@ -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.