Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2036)

Unified Diff: mojo/public/cpp/system/watcher.cc

Issue 2540903002: Remove MessageLoop destruction observer from mojo::Watcher. (Closed)
Patch Set: . Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/cpp/system/watcher.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/system/watcher.cc
diff --git a/mojo/public/cpp/system/watcher.cc b/mojo/public/cpp/system/watcher.cc
index d9319fb5bda1fc368378a77e15de03b941783a9e..fc03c5a0a0e8b1f4e41c01b29705d743e051d34c 100644
--- a/mojo/public/cpp/system/watcher.cc
+++ b/mojo/public/cpp/system/watcher.cc
@@ -7,45 +7,10 @@
#include "base/bind.h"
#include "base/location.h"
#include "base/macros.h"
-#include "base/message_loop/message_loop.h"
#include "mojo/public/c/system/functions.h"
namespace mojo {
-class Watcher::MessageLoopObserver
- : public base::MessageLoop::DestructionObserver {
- public:
- explicit MessageLoopObserver(Watcher* watcher) : watcher_(watcher) {
- base::MessageLoop::current()->AddDestructionObserver(this);
- }
-
- ~MessageLoopObserver() override {
- StopObservingIfNecessary();
- }
-
- private:
- // base::MessageLoop::DestructionObserver:
- void WillDestroyCurrentMessageLoop() override {
- StopObservingIfNecessary();
- if (watcher_->IsWatching()) {
- // TODO(yzshen): Remove this notification. crbug.com/604762
- watcher_->OnHandleReady(MOJO_RESULT_ABORTED);
- }
- }
-
- void StopObservingIfNecessary() {
- if (is_observing_) {
- is_observing_ = false;
- base::MessageLoop::current()->RemoveDestructionObserver(this);
- }
- }
-
- bool is_observing_ = true;
- Watcher* watcher_;
-
- DISALLOW_COPY_AND_ASSIGN(MessageLoopObserver);
-};
-
Watcher::Watcher(scoped_refptr<base::SingleThreadTaskRunner> runner)
: task_runner_(std::move(runner)),
is_default_task_runner_(task_runner_ ==
@@ -72,7 +37,6 @@ MojoResult Watcher::Start(Handle handle,
DCHECK(!IsWatching());
DCHECK(!callback.is_null());
- message_loop_observer_.reset(new MessageLoopObserver(this));
callback_ = callback;
handle_ = handle;
MojoResult result = MojoWatch(handle_.value(), signals,
@@ -81,7 +45,6 @@ MojoResult Watcher::Start(Handle handle,
if (result != MOJO_RESULT_OK) {
handle_.set_value(kInvalidHandleValue);
callback_.Reset();
- message_loop_observer_.reset();
DCHECK(result == MOJO_RESULT_FAILED_PRECONDITION ||
result == MOJO_RESULT_INVALID_ARGUMENT);
return result;
@@ -99,7 +62,6 @@ void Watcher::Cancel() {
MojoResult result =
MojoCancelWatch(handle_.value(), reinterpret_cast<uintptr_t>(this));
- message_loop_observer_.reset();
// |result| may be MOJO_RESULT_INVALID_ARGUMENT if |handle_| has closed, but
// OnHandleReady has not yet been called.
DCHECK(result == MOJO_RESULT_INVALID_ARGUMENT || result == MOJO_RESULT_OK);
@@ -112,7 +74,6 @@ void Watcher::OnHandleReady(MojoResult result) {
ReadyCallback callback = callback_;
if (result == MOJO_RESULT_CANCELLED) {
- message_loop_observer_.reset();
handle_.set_value(kInvalidHandleValue);
callback_.Reset();
}
« no previous file with comments | « mojo/public/cpp/system/watcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698