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

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: Updated 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
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 void OnChannelCreated(base::WeakPtr<ChannelMojo> channel) = 0;
67 };
68
64 // Create ChannelMojo. A bootstrap channel is created as well. 69 // Create ChannelMojo. A bootstrap channel is created as well.
65 // |host| must not be null. 70 // |host| must not be null for server channels.
66 static scoped_ptr<ChannelMojo> Create(ChannelMojoHost* host, 71 static scoped_ptr<ChannelMojo> Create(Delegate* delegate,
67 const ChannelHandle& channel_handle, 72 const ChannelHandle& channel_handle,
68 Mode mode, 73 Mode mode,
69 Listener* listener); 74 Listener* listener);
70 75
71 // Create a factory object for ChannelMojo. 76 // Create a factory object for ChannelMojo.
72 // The factory is used to create Mojo-based ChannelProxy family. 77 // The factory is used to create Mojo-based ChannelProxy family.
73 // |host| must not be null. 78 // |host| must not be null.
74 static scoped_ptr<ChannelFactory> CreateServerFactory( 79 static scoped_ptr<ChannelFactory> CreateServerFactory(
75 ChannelMojoHost* host, 80 Delegate* delegate,
76 const ChannelHandle& channel_handle); 81 const ChannelHandle& channel_handle);
77 82
78 static scoped_ptr<ChannelFactory> CreateClientFactory( 83 static scoped_ptr<ChannelFactory> CreateClientFactory(
79 const ChannelHandle& channel_handle); 84 const ChannelHandle& channel_handle);
80 85
81 virtual ~ChannelMojo(); 86 virtual ~ChannelMojo();
82 87
83 // ChannelMojoHost tells the client handle using this API. 88 // ChannelMojoHost tells the client handle using this API.
84 void OnClientLaunched(base::ProcessHandle handle); 89 void OnClientLaunched(base::ProcessHandle handle);
85 90
(...skipping 25 matching lines...) Expand all
111 virtual void OnBootstrapError() OVERRIDE; 116 virtual void OnBootstrapError() OVERRIDE;
112 117
113 // Called from MessagePipeReader implementations 118 // Called from MessagePipeReader implementations
114 void OnMessageReceived(Message& message); 119 void OnMessageReceived(Message& message);
115 void OnConnected(mojo::ScopedMessagePipeHandle pipe); 120 void OnConnected(mojo::ScopedMessagePipeHandle pipe);
116 void OnPipeClosed(internal::MessagePipeReader* reader); 121 void OnPipeClosed(internal::MessagePipeReader* reader);
117 void OnPipeError(internal::MessagePipeReader* reader); 122 void OnPipeError(internal::MessagePipeReader* reader);
118 void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; } 123 void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; }
119 124
120 protected: 125 protected:
121 ChannelMojo(ChannelMojoHost* host, 126 ChannelMojo(Delegate* delegate,
122 const ChannelHandle& channel_handle, 127 const ChannelHandle& channel_handle,
123 Mode mode, 128 Mode mode,
124 Listener* listener); 129 Listener* listener);
125 130
126 private: 131 private:
127 struct ChannelInfoDeleter { 132 struct ChannelInfoDeleter {
128 void operator()(mojo::embedder::ChannelInfo* ptr) const; 133 void operator()(mojo::embedder::ChannelInfo* ptr) const;
129 }; 134 };
130 135
131 // ChannelMojo needs to kill its MessagePipeReader in delayed manner 136 // ChannelMojo needs to kill its MessagePipeReader in delayed manner
132 // because the channel wants to kill these readers during the 137 // because the channel wants to kill these readers during the
133 // notifications invoked by them. 138 // notifications invoked by them.
134 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter; 139 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter;
135 140
136 void InitControlReader(mojo::embedder::ScopedPlatformHandle handle); 141 void InitControlReader(mojo::embedder::ScopedPlatformHandle handle);
137 142
138 scoped_ptr<MojoBootstrap> bootstrap_; 143 scoped_ptr<MojoBootstrap> bootstrap_;
139 ChannelMojoHost* const host_; 144 base::WeakPtr<Delegate> delegate_;
140 Mode mode_; 145 Mode mode_;
141 Listener* listener_; 146 Listener* listener_;
142 base::ProcessId peer_pid_; 147 base::ProcessId peer_pid_;
143 scoped_ptr<mojo::embedder::ChannelInfo, 148 scoped_ptr<mojo::embedder::ChannelInfo,
144 ChannelInfoDeleter> channel_info_; 149 ChannelInfoDeleter> channel_info_;
145 150
146 scoped_ptr<internal::ControlReader, ReaderDeleter> control_reader_; 151 scoped_ptr<internal::ControlReader, ReaderDeleter> control_reader_;
147 scoped_ptr<internal::MessageReader, ReaderDeleter> message_reader_; 152 scoped_ptr<internal::MessageReader, ReaderDeleter> message_reader_;
148 ScopedVector<Message> pending_messages_; 153 ScopedVector<Message> pending_messages_;
149 154
150 base::WeakPtrFactory<ChannelMojo> weak_factory_; 155 base::WeakPtrFactory<ChannelMojo> weak_factory_;
151 156
152 DISALLOW_COPY_AND_ASSIGN(ChannelMojo); 157 DISALLOW_COPY_AND_ASSIGN(ChannelMojo);
153 }; 158 };
154 159
155 } // namespace IPC 160 } // namespace IPC
156 161
157 #endif // IPC_IPC_CHANNEL_MOJO_H_ 162 #endif // IPC_IPC_CHANNEL_MOJO_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698