diff --git a/common/node_bindings.cc b/common/node_bindings.cc index 317f679599dc..5bd69a680d9a 100644 --- a/common/node_bindings.cc +++ b/common/node_bindings.cc @@ -65,7 +65,8 @@ NodeBindings::NodeBindings(bool is_browser) : is_browser_(is_browser), message_loop_(NULL), uv_loop_(uv_default_loop()), - embed_closed_(false) { + embed_closed_(false), + weak_factory_(this) { } NodeBindings::~NodeBindings() { @@ -76,7 +77,6 @@ NodeBindings::~NodeBindings() { // Wait for everything to be done. uv_thread_join(&embed_thread_); - message_loop_->RunUntilIdle(); // Clear uv. uv_sem_destroy(&embed_sem_); @@ -209,7 +209,7 @@ void NodeBindings::UvRunOnce() { void NodeBindings::WakeupMainThread() { DCHECK(message_loop_); message_loop_->PostTask(FROM_HERE, base::Bind(&NodeBindings::UvRunOnce, - base::Unretained(this))); + weak_factory_.GetWeakPtr())); } void NodeBindings::WakeupEmbedThread() { diff --git a/common/node_bindings.h b/common/node_bindings.h index 7ed22806d115..f777c220afc1 100644 --- a/common/node_bindings.h +++ b/common/node_bindings.h @@ -6,6 +6,7 @@ #define ATOM_COMMON_NODE_BINDINGS_H_ #include "base/basictypes.h" +#include "base/memory/weak_ptr.h" #include "v8/include/v8.h" #include "vendor/node/deps/uv/include/uv.h" @@ -83,6 +84,8 @@ class NodeBindings { // Semaphore to wait for main loop in the embed thread. uv_sem_t embed_sem_; + base::WeakPtrFactory weak_factory_; + DISALLOW_COPY_AND_ASSIGN(NodeBindings); };