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

Side by Side Diff: ipc/mojo/ipc_channel_mojo.h

Issue 599333002: ChannelMojo: Handle when ChannelMojo outlives ChannelMojoHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Landing Created 6 years, 2 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 unified diff | Download patch
« no previous file with comments | « content/browser/renderer_host/render_process_host_impl.cc ('k') | ipc/mojo/ipc_channel_mojo.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef IPC_IPC_CHANNEL_MOJO_H_ 5 #ifndef IPC_IPC_CHANNEL_MOJO_H_
6 #define IPC_IPC_CHANNEL_MOJO_H_ 6 #define IPC_IPC_CHANNEL_MOJO_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 14 matching lines...) Expand all
25 25
26 namespace IPC { 26 namespace IPC {
27 27
28 namespace internal { 28 namespace internal {
29 class ControlReader; 29 class ControlReader;
30 class ServerControlReader; 30 class ServerControlReader;
31 class ClientControlReader; 31 class ClientControlReader;
32 class MessageReader; 32 class MessageReader;
33 } 33 }
34 34
35 class ChannelMojoHost;
36
37 // Mojo-based IPC::Channel implementation over a platform handle. 35 // Mojo-based IPC::Channel implementation over a platform handle.
38 // 36 //
39 // ChannelMojo builds Mojo MessagePipe using underlying pipe given by 37 // ChannelMojo builds Mojo MessagePipe using underlying pipe given by
40 // "bootstrap" IPC::Channel which creates and owns platform pipe like 38 // "bootstrap" IPC::Channel which creates and owns platform pipe like
41 // named socket. The bootstrap Channel is used only for establishing 39 // named socket. The bootstrap Channel is used only for establishing
42 // the underlying connection. ChannelMojo takes its handle over once 40 // the underlying connection. ChannelMojo takes its handle over once
43 // the it is made and puts MessagePipe on it. 41 // the it is made and puts MessagePipe on it.
44 // 42 //
45 // ChannelMojo has a couple of MessagePipes: 43 // ChannelMojo has a couple of MessagePipes:
46 // 44 //
47 // * The first MessagePipe, which is built on top of bootstrap handle, 45 // * The first MessagePipe, which is built on top of bootstrap handle,
48 // is the "control" pipe. It is used to communicate out-of-band 46 // is the "control" pipe. It is used to communicate out-of-band
49 // control messages that aren't visible from IPC::Listener. 47 // control messages that aren't visible from IPC::Listener.
50 // 48 //
51 // * The second MessagePipe, which is created by the server channel 49 // * The second MessagePipe, which is created by the server channel
52 // and sent to client Channel over the control pipe, is used 50 // and sent to client Channel over the control pipe, is used
53 // to send IPC::Messages as an IPC::Sender. 51 // to send IPC::Messages as an IPC::Sender.
54 // 52 //
55 // TODO(morrita): Extract handle creation part of IPC::Channel into 53 // TODO(morrita): Extract handle creation part of IPC::Channel into
56 // separate class to clarify what ChannelMojo relies 54 // separate class to clarify what ChannelMojo relies
57 // on. 55 // on.
58 // TODO(morrita): Add APIs to create extra MessagePipes to let 56 // TODO(morrita): Add APIs to create extra MessagePipes to let
59 // Mojo-based objects talk over this Channel. 57 // Mojo-based objects talk over this Channel.
60 // 58 //
61 class IPC_MOJO_EXPORT ChannelMojo : public Channel, 59 class IPC_MOJO_EXPORT ChannelMojo : public Channel,
62 public MojoBootstrap::Delegate { 60 public MojoBootstrap::Delegate {
63 public: 61 public:
62 class Delegate {
63 public:
64 virtual ~Delegate() {}
65 virtual base::WeakPtr<Delegate> ToWeakPtr() = 0;
66 virtual scoped_refptr<base::TaskRunner> GetIOTaskRunner() = 0;
67 virtual void OnChannelCreated(base::WeakPtr<ChannelMojo> channel) = 0;
68 };
69
64 // Create ChannelMojo. A bootstrap channel is created as well. 70 // Create ChannelMojo. A bootstrap channel is created as well.
65 // |host| must not be null. 71 // |host| must not be null for server channels.
66 static scoped_ptr<ChannelMojo> Create(ChannelMojoHost* host, 72 static scoped_ptr<ChannelMojo> Create(Delegate* delegate,
67 const ChannelHandle& channel_handle, 73 const ChannelHandle& channel_handle,
68 Mode mode, 74 Mode mode,
69 Listener* listener); 75 Listener* listener);
70 76
71 // Create a factory object for ChannelMojo. 77 // Create a factory object for ChannelMojo.
72 // The factory is used to create Mojo-based ChannelProxy family. 78 // The factory is used to create Mojo-based ChannelProxy family.
73 // |host| must not be null. 79 // |host| must not be null.
74 static scoped_ptr<ChannelFactory> CreateServerFactory( 80 static scoped_ptr<ChannelFactory> CreateServerFactory(
75 ChannelMojoHost* host, 81 Delegate* delegate,
76 const ChannelHandle& channel_handle); 82 const ChannelHandle& channel_handle);
77 83
78 static scoped_ptr<ChannelFactory> CreateClientFactory( 84 static scoped_ptr<ChannelFactory> CreateClientFactory(
79 const ChannelHandle& channel_handle); 85 const ChannelHandle& channel_handle);
80 86
81 virtual ~ChannelMojo(); 87 virtual ~ChannelMojo();
82 88
83 // ChannelMojoHost tells the client handle using this API. 89 // ChannelMojoHost tells the client handle using this API.
84 void OnClientLaunched(base::ProcessHandle handle); 90 void OnClientLaunched(base::ProcessHandle handle);
85 91
(...skipping 25 matching lines...) Expand all
111 virtual void OnBootstrapError() OVERRIDE; 117 virtual void OnBootstrapError() OVERRIDE;
112 118
113 // Called from MessagePipeReader implementations 119 // Called from MessagePipeReader implementations
114 void OnMessageReceived(Message& message); 120 void OnMessageReceived(Message& message);
115 void OnConnected(mojo::ScopedMessagePipeHandle pipe); 121 void OnConnected(mojo::ScopedMessagePipeHandle pipe);
116 void OnPipeClosed(internal::MessagePipeReader* reader); 122 void OnPipeClosed(internal::MessagePipeReader* reader);
117 void OnPipeError(internal::MessagePipeReader* reader); 123 void OnPipeError(internal::MessagePipeReader* reader);
118 void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; } 124 void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; }
119 125
120 protected: 126 protected:
121 ChannelMojo(ChannelMojoHost* host, 127 ChannelMojo(Delegate* delegate,
122 const ChannelHandle& channel_handle, 128 const ChannelHandle& channel_handle,
123 Mode mode, 129 Mode mode,
124 Listener* listener); 130 Listener* listener);
125 131
126 private: 132 private:
127 struct ChannelInfoDeleter { 133 struct ChannelInfoDeleter {
128 void operator()(mojo::embedder::ChannelInfo* ptr) const; 134 void operator()(mojo::embedder::ChannelInfo* ptr) const;
129 }; 135 };
130 136
131 // ChannelMojo needs to kill its MessagePipeReader in delayed manner 137 // ChannelMojo needs to kill its MessagePipeReader in delayed manner
132 // because the channel wants to kill these readers during the 138 // because the channel wants to kill these readers during the
133 // notifications invoked by them. 139 // notifications invoked by them.
134 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter; 140 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter;
135 141
142 void InitDelegate(ChannelMojo::Delegate* delegate);
136 void InitControlReader(mojo::embedder::ScopedPlatformHandle handle); 143 void InitControlReader(mojo::embedder::ScopedPlatformHandle handle);
137 144
138 scoped_ptr<MojoBootstrap> bootstrap_; 145 scoped_ptr<MojoBootstrap> bootstrap_;
139 ChannelMojoHost* const host_; 146 base::WeakPtr<Delegate> delegate_;
140 Mode mode_; 147 Mode mode_;
141 Listener* listener_; 148 Listener* listener_;
142 base::ProcessId peer_pid_; 149 base::ProcessId peer_pid_;
143 scoped_ptr<mojo::embedder::ChannelInfo, 150 scoped_ptr<mojo::embedder::ChannelInfo,
144 ChannelInfoDeleter> channel_info_; 151 ChannelInfoDeleter> channel_info_;
145 152
146 scoped_ptr<internal::ControlReader, ReaderDeleter> control_reader_; 153 scoped_ptr<internal::ControlReader, ReaderDeleter> control_reader_;
147 scoped_ptr<internal::MessageReader, ReaderDeleter> message_reader_; 154 scoped_ptr<internal::MessageReader, ReaderDeleter> message_reader_;
148 ScopedVector<Message> pending_messages_; 155 ScopedVector<Message> pending_messages_;
149 156
150 base::WeakPtrFactory<ChannelMojo> weak_factory_; 157 base::WeakPtrFactory<ChannelMojo> weak_factory_;
151 158
152 DISALLOW_COPY_AND_ASSIGN(ChannelMojo); 159 DISALLOW_COPY_AND_ASSIGN(ChannelMojo);
153 }; 160 };
154 161
155 } // namespace IPC 162 } // namespace IPC
156 163
157 #endif // IPC_IPC_CHANNEL_MOJO_H_ 164 #endif // IPC_IPC_CHANNEL_MOJO_H_
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_process_host_impl.cc ('k') | ipc/mojo/ipc_channel_mojo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698