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

Unified Diff: mojo/public/cpp/bindings/lib/connector.cc

Issue 1720093002: Revert of Mojo C++ bindings: support sync methods - part 2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months 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/bindings/lib/connector.h ('k') | mojo/public/cpp/bindings/lib/interface_ptr_state.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/lib/connector.cc
diff --git a/mojo/public/cpp/bindings/lib/connector.cc b/mojo/public/cpp/bindings/lib/connector.cc
index 4eff31d2acef7230ee289064735223d7e3e63919..ceccaa9a109128d0d64d13c82165702beccec1aa 100644
--- a/mojo/public/cpp/bindings/lib/connector.cc
+++ b/mojo/public/cpp/bindings/lib/connector.cc
@@ -7,11 +7,9 @@
#include <stdint.h>
#include <utility>
-#include "base/bind.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/synchronization/lock.h"
-#include "mojo/public/cpp/bindings/lib/sync_handle_watcher.h"
namespace mojo {
namespace internal {
@@ -54,11 +52,8 @@
drop_writes_(false),
enforce_errors_from_incoming_receiver_(true),
paused_(false),
- lock_(config == MULTI_THREADED_SEND ? new base::Lock : nullptr),
- register_sync_handle_watch_count_(0),
- registered_with_sync_handle_watcher_(false),
- sync_handle_watcher_callback_count_(0),
- weak_factory_(this) {
+ destroyed_flag_(nullptr),
+ lock_(config == MULTI_THREADED_SEND ? new base::Lock : nullptr) {
// Even though we don't have an incoming receiver, we still want to monitor
// the message pipe to know if is closed or encounters an error.
WaitToReadMore();
@@ -66,6 +61,9 @@
Connector::~Connector() {
DCHECK(thread_checker_.CalledOnValidThread());
+
+ if (destroyed_flag_)
+ *destroyed_flag_ = true;
CancelWait();
}
@@ -193,76 +191,17 @@
return true;
}
-bool Connector::RegisterSyncHandleWatch() {
- DCHECK(thread_checker_.CalledOnValidThread());
-
- if (error_)
- return false;
-
- register_sync_handle_watch_count_++;
-
- if (!registered_with_sync_handle_watcher_ && !paused_) {
- registered_with_sync_handle_watcher_ =
- SyncHandleWatcher::current()->RegisterHandle(
- message_pipe_.get(), MOJO_HANDLE_SIGNAL_READABLE,
- base::Bind(&Connector::OnSyncHandleWatcherHandleReady,
- base::Unretained(this)));
- }
- return true;
-}
-
-void Connector::UnregisterSyncHandleWatch() {
- DCHECK(thread_checker_.CalledOnValidThread());
-
- if (register_sync_handle_watch_count_ == 0) {
- NOTREACHED();
- return;
- }
-
- register_sync_handle_watch_count_--;
- if (register_sync_handle_watch_count_ > 0)
- return;
-
- if (registered_with_sync_handle_watcher_) {
- SyncHandleWatcher::current()->UnregisterHandle(message_pipe_.get());
- registered_with_sync_handle_watcher_ = false;
- }
-}
-
-bool Connector::RunSyncHandleWatch(const bool* should_stop) {
- DCHECK(thread_checker_.CalledOnValidThread());
- DCHECK_GT(register_sync_handle_watch_count_, 0u);
-
- if (error_)
- return false;
-
- ResumeIncomingMethodCallProcessing();
-
- return SyncHandleWatcher::current()->WatchAllHandles(message_pipe_.get(),
- should_stop);
-}
-
// static
void Connector::CallOnHandleReady(void* closure, MojoResult result) {
Connector* self = static_cast<Connector*>(closure);
- CHECK(self->async_wait_id_ != 0);
- self->async_wait_id_ = 0;
- self->OnHandleReadyInternal(result);
-}
-
-void Connector::OnSyncHandleWatcherHandleReady(MojoResult result) {
- base::WeakPtr<Connector> weak_self(weak_factory_.GetWeakPtr());
-
- sync_handle_watcher_callback_count_++;
- OnHandleReadyInternal(result);
- // At this point, this object might have been deleted.
- if (weak_self)
- sync_handle_watcher_callback_count_--;
-}
-
-void Connector::OnHandleReadyInternal(MojoResult result) {
- DCHECK(thread_checker_.CalledOnValidThread());
-
+ self->OnHandleReady(result);
+}
+
+void Connector::OnHandleReady(MojoResult result) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ CHECK(async_wait_id_ != 0);
+ async_wait_id_ = 0;
if (result != MOJO_RESULT_OK) {
HandleError(result != MOJO_RESULT_FAILED_PRECONDITION, false);
return;
@@ -279,15 +218,6 @@
MOJO_DEADLINE_INDEFINITE,
&Connector::CallOnHandleReady,
this);
-
- if (register_sync_handle_watch_count_ > 0 &&
- !registered_with_sync_handle_watcher_) {
- registered_with_sync_handle_watcher_ =
- SyncHandleWatcher::current()->RegisterHandle(
- message_pipe_.get(), MOJO_HANDLE_SIGNAL_READABLE,
- base::Bind(&Connector::OnSyncHandleWatcherHandleReady,
- base::Unretained(this)));
- }
}
bool Connector::ReadSingleMessage(MojoResult* read_result) {
@@ -297,7 +227,9 @@
// Detect if |this| was destroyed during message dispatch. Allow for the
// possibility of re-entering ReadMore() through message dispatch.
- base::WeakPtr<Connector> weak_self = weak_factory_.GetWeakPtr();
+ bool was_destroyed_during_dispatch = false;
+ bool* previous_destroyed_flag = destroyed_flag_;
+ destroyed_flag_ = &was_destroyed_during_dispatch;
Message message;
const MojoResult rv = ReadMessage(message_pipe_.get(), &message);
@@ -315,8 +247,13 @@
incoming_receiver_ && incoming_receiver_->Accept(&message);
}
- if (!weak_self)
- return false;
+ if (was_destroyed_during_dispatch) {
+ if (previous_destroyed_flag)
+ *previous_destroyed_flag = true; // Propagate flag.
+ return false;
+ }
+
+ destroyed_flag_ = previous_destroyed_flag;
if (rv == MOJO_RESULT_SHOULD_WAIT)
return true;
@@ -358,15 +295,11 @@
}
void Connector::CancelWait() {
- if (async_wait_id_) {
- waiter_->CancelWait(async_wait_id_);
- async_wait_id_ = 0;
- }
-
- if (registered_with_sync_handle_watcher_) {
- SyncHandleWatcher::current()->UnregisterHandle(message_pipe_.get());
- registered_with_sync_handle_watcher_ = false;
- }
+ if (!async_wait_id_)
+ return;
+
+ waiter_->CancelWait(async_wait_id_);
+ async_wait_id_ = 0;
}
void Connector::HandleError(bool force_pipe_reset, bool force_async_handler) {
« no previous file with comments | « mojo/public/cpp/bindings/lib/connector.h ('k') | mojo/public/cpp/bindings/lib/interface_ptr_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698