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

Unified Diff: ipc/mojo/ipc_channel_mojo_host.h

Issue 599333002: ChannelMojo: Handle when ChannelMojo outlives ChannelMojoHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
Index: ipc/mojo/ipc_channel_mojo_host.h
diff --git a/ipc/mojo/ipc_channel_mojo_host.h b/ipc/mojo/ipc_channel_mojo_host.h
index e0d94beddc119903cac771a1e04bbf08f00f943f..378a71bff75a01145254aba3c325fb9f1db8bc8f 100644
--- a/ipc/mojo/ipc_channel_mojo_host.h
+++ b/ipc/mojo/ipc_channel_mojo_host.h
@@ -22,28 +22,46 @@ class ChannelMojo;
// its client provides, including the child process's process handle. Every
// server process that uses ChannelMojo must have a ChannelMojoHost
// instance and call OnClientLaunched().
+//
+// Thread safety:
+// ChannelMojoHost is accessed from both UI thread (from its clients)
+// and IO thread (from hosting channels).
+// The public API including OnClientLaunched is available for UI thread,
+// some API which touches |channel_| is safe only in IO thread.
viettrungluu 2014/09/25 19:38:34 You should explicitly say which things are I/O-thr
+// As its weak ptr is held by the hosting channel, clients should delete
+// ChannelMojoHost in IO thread using ChannelMojoHostDeleter.
+//
class IPC_MOJO_EXPORT ChannelMojoHost {
public:
explicit ChannelMojoHost(scoped_refptr<base::TaskRunner> task_runner);
viettrungluu 2014/09/25 19:38:34 You should document what task runner this is (or m
Hajime Morrita 2014/09/25 22:00:04 Done.
~ChannelMojoHost();
void OnClientLaunched(base::ProcessHandle process);
+ scoped_refptr<base::TaskRunner> task_runner() const { return task_runner_; }
viettrungluu 2014/09/25 19:38:34 Does this need to be public? Why?
Hajime Morrita 2014/09/25 22:00:03 Removed. Garbage made by try-n-error :-(
private:
friend class ChannelMojo;
+ friend class ChannelMojoHostDeleter;
- void OnChannelCreated(ChannelMojo* channel);
- void OnChannelDestroyed();
-
- void InvokeOnClientLaunched(base::ProcessHandle process);
+ base::WeakPtr<ChannelMojoHost> ToWeakPtr();
+ void OnChannelCreated(base::WeakPtr<ChannelMojo> channel);
+ void DeleteThisSoon();
base::WeakPtrFactory<ChannelMojoHost> weak_factory_;
scoped_refptr<base::TaskRunner> task_runner_;
viettrungluu 2014/09/25 19:38:34 Can this be made const?
Hajime Morrita 2014/09/25 22:00:03 Done.
- ChannelMojo* channel_;
+ base::WeakPtr<ChannelMojo> channel_;
viettrungluu 2014/09/25 19:38:34 You should say that this should only be used on th
DISALLOW_COPY_AND_ASSIGN(ChannelMojoHost);
};
+// Specialized to post the deletion to the ChannelMojoHost::task_runner()
+// thread.
+// This is needed as IPC::ChannelMojo touches its host when it dies.
+class IPC_MOJO_EXPORT ChannelMojoHostDeleter {
+ public:
+ void operator()(IPC::ChannelMojoHost* ptr) const;
+};
+
} // namespace IPC
#endif // IPC_IPC_CHANNEL_MOJO_HOST_H_

Powered by Google App Engine
This is Rietveld 408576698