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

Unified Diff: mojo/public/cpp/bindings/connector.h

Issue 2350883003: Mojo C++ bindings: fix Connector teardown. (Closed)
Patch Set: Created 4 years, 3 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 | « no previous file | mojo/public/cpp/bindings/lib/connector.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/connector.h
diff --git a/mojo/public/cpp/bindings/connector.h b/mojo/public/cpp/bindings/connector.h
index 1548a5a7e662e4d167d94343dc76b453239ec77c..8976c9c865aba7fdde40ddffa5b94a75b4f93712 100644
--- a/mojo/public/cpp/bindings/connector.h
+++ b/mojo/public/cpp/bindings/connector.h
@@ -138,6 +138,7 @@ class Connector : public MessageReceiver {
// Whether currently the control flow is inside the sync handle watcher
// callback.
+ // It always returns false after CloseMessagePipe()/PassMessagePipe().
bool during_sync_handle_watcher_callback() const {
return sync_handle_watcher_callback_count_ > 0;
}
@@ -155,7 +156,8 @@ class Connector : public MessageReceiver {
void WaitToReadMore();
- // Returns false if |this| was destroyed during message dispatch.
+ // Returns false if it is impossible to receive more messages in the future.
+ // |this| may have been destroyed in that case.
WARN_UNUSED_RESULT bool ReadSingleMessage(MojoResult* read_result);
// |this| can be destroyed during message dispatch.
@@ -178,7 +180,7 @@ class Connector : public MessageReceiver {
MessageReceiver* incoming_receiver_ = nullptr;
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
- Watcher handle_watcher_;
+ std::unique_ptr<Watcher> handle_watcher_;
bool error_ = false;
bool drop_writes_ = false;
@@ -203,6 +205,8 @@ class Connector : public MessageReceiver {
// Create a single weak ptr and use it everywhere, to avoid the malloc/free
// cost of creating a new weak ptr whenever it is needed.
+ // NOTE: This weak pointer is invalidated when the message pipe is closed or
+ // transferred (i.e., when |connected_| is set to false).
base::WeakPtr<Connector> weak_self_;
base::WeakPtrFactory<Connector> weak_factory_;
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/lib/connector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698