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

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

Issue 553283002: IPC::ChannelMojo: Introduce IPC::MojoBootstrap for Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added ChannelMojoHost 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 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"
11 #include "base/memory/scoped_vector.h" 11 #include "base/memory/scoped_vector.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "ipc/ipc_channel.h" 13 #include "ipc/ipc_channel.h"
14 #include "ipc/ipc_channel_factory.h" 14 #include "ipc/ipc_channel_factory.h"
15 #include "ipc/ipc_export.h" 15 #include "ipc/ipc_export.h"
16 #include "ipc/mojo/ipc_message_pipe_reader.h" 16 #include "ipc/mojo/ipc_message_pipe_reader.h"
17 #include "ipc/mojo/ipc_mojo_bootstrap.h"
17 #include "mojo/public/cpp/system/core.h" 18 #include "mojo/public/cpp/system/core.h"
18 19
19 namespace mojo { 20 namespace mojo {
20 namespace embedder { 21 namespace embedder {
21 struct ChannelInfo; 22 struct ChannelInfo;
22 } 23 }
23 } 24 }
24 25
25 namespace IPC { 26 namespace IPC {
26 27
27 namespace internal { 28 namespace internal {
28 class ControlReader; 29 class ControlReader;
29 class ServerControlReader; 30 class ServerControlReader;
30 class ClientControlReader; 31 class ClientControlReader;
31 class MessageReader; 32 class MessageReader;
32 } 33 }
33 34
35 class ChannelMojoHost;
36
34 // Mojo-based IPC::Channel implementation over a platform handle. 37 // Mojo-based IPC::Channel implementation over a platform handle.
35 // 38 //
36 // ChannelMojo builds Mojo MessagePipe using underlying pipe given by 39 // ChannelMojo builds Mojo MessagePipe using underlying pipe given by
37 // "bootstrap" IPC::Channel which creates and owns platform pipe like 40 // "bootstrap" IPC::Channel which creates and owns platform pipe like
38 // named socket. The bootstrap Channel is used only for establishing 41 // named socket. The bootstrap Channel is used only for establishing
39 // the underlying connection. ChannelMojo takes its handle over once 42 // the underlying connection. ChannelMojo takes its handle over once
40 // the it is made and puts MessagePipe on it. 43 // the it is made and puts MessagePipe on it.
41 // 44 //
42 // ChannelMojo has a couple of MessagePipes: 45 // ChannelMojo has a couple of MessagePipes:
43 // 46 //
44 // * The first MessagePipe, which is built on top of bootstrap handle, 47 // * The first MessagePipe, which is built on top of bootstrap handle,
45 // is the "control" pipe. It is used to communicate out-of-band 48 // is the "control" pipe. It is used to communicate out-of-band
46 // control messages that aren't visible from IPC::Listener. 49 // control messages that aren't visible from IPC::Listener.
47 // 50 //
48 // * The second MessagePipe, which is created by the server channel 51 // * The second MessagePipe, which is created by the server channel
49 // and sent to client Channel over the control pipe, is used 52 // and sent to client Channel over the control pipe, is used
50 // to send IPC::Messages as an IPC::Sender. 53 // to send IPC::Messages as an IPC::Sender.
51 // 54 //
52 // TODO(morrita): Extract handle creation part of IPC::Channel into 55 // TODO(morrita): Extract handle creation part of IPC::Channel into
53 // separate class to clarify what ChannelMojo relies 56 // separate class to clarify what ChannelMojo relies
54 // on. 57 // on.
55 // TODO(morrita): Add APIs to create extra MessagePipes to let 58 // TODO(morrita): Add APIs to create extra MessagePipes to let
56 // Mojo-based objects talk over this Channel. 59 // Mojo-based objects talk over this Channel.
57 // 60 //
58 class IPC_MOJO_EXPORT ChannelMojo : public Channel { 61 class IPC_MOJO_EXPORT ChannelMojo : public Channel,
62 public MojoBootstrap::Delegate {
59 public: 63 public:
60 // Create ChannelMojo. A bootstrap channel is created as well. 64 // Create ChannelMojo. A bootstrap channel is created as well.
viettrungluu 2014/09/17 17:33:15 You should indicate when |host| must be non-null.
Hajime Morrita 2014/09/17 19:33:48 Done.
61 static scoped_ptr<ChannelMojo> Create( 65 static scoped_ptr<ChannelMojo> Create(ChannelMojoHost* host,
62 const ChannelHandle &channel_handle, Mode mode, Listener* listener, 66 const ChannelHandle& channel_handle,
63 scoped_refptr<base::TaskRunner> io_thread_task_runner); 67 Mode mode,
68 Listener* listener);
64 69
65 // Create a factory object for ChannelMojo. 70 // Create a factory object for ChannelMojo.
66 // The factory is used to create Mojo-based ChannelProxy family. 71 // The factory is used to create Mojo-based ChannelProxy family.
67 static scoped_ptr<ChannelFactory> CreateFactory( 72 static scoped_ptr<ChannelFactory> CreateServerFactory(
68 const ChannelHandle &channel_handle, Mode mode, 73 ChannelMojoHost* host,
69 scoped_refptr<base::TaskRunner> io_thread_task_runner); 74 const ChannelHandle& channel_handle);
75
76 static scoped_ptr<ChannelFactory> CreateClientFactory(
77 const ChannelHandle& channel_handle);
70 78
71 virtual ~ChannelMojo(); 79 virtual ~ChannelMojo();
72 80
81 // ChannelMojoHost tells the client handle using this API.
82 void OnClientLaunched(base::ProcessHandle handle);
83
73 // Channel implementation 84 // Channel implementation
74 virtual bool Connect() OVERRIDE; 85 virtual bool Connect() OVERRIDE;
75 virtual void Close() OVERRIDE; 86 virtual void Close() OVERRIDE;
76 virtual bool Send(Message* message) OVERRIDE; 87 virtual bool Send(Message* message) OVERRIDE;
77 virtual base::ProcessId GetPeerPID() const OVERRIDE; 88 virtual base::ProcessId GetPeerPID() const OVERRIDE;
78 virtual base::ProcessId GetSelfPID() const OVERRIDE; 89 virtual base::ProcessId GetSelfPID() const OVERRIDE;
79 virtual ChannelHandle TakePipeHandle() OVERRIDE; 90 virtual ChannelHandle TakePipeHandle() OVERRIDE;
80 91
81 #if defined(OS_POSIX) && !defined(OS_NACL) 92 #if defined(OS_POSIX) && !defined(OS_NACL)
82 virtual int GetClientFileDescriptor() const OVERRIDE; 93 virtual int GetClientFileDescriptor() const OVERRIDE;
83 virtual int TakeClientFileDescriptor() OVERRIDE; 94 virtual int TakeClientFileDescriptor() OVERRIDE;
84 95
85 // These access protected API of IPC::Message, which has ChannelMojo 96 // These access protected API of IPC::Message, which has ChannelMojo
86 // as a friend class. 97 // as a friend class.
87 static MojoResult WriteToFileDescriptorSet( 98 static MojoResult WriteToFileDescriptorSet(
88 const std::vector<MojoHandle>& handle_buffer, 99 const std::vector<MojoHandle>& handle_buffer,
89 Message* message); 100 Message* message);
90 static MojoResult ReadFromFileDescriptorSet(const Message& message, 101 static MojoResult ReadFromFileDescriptorSet(const Message& message,
91 std::vector<MojoHandle>* handles); 102 std::vector<MojoHandle>* handles);
92 103
93 #endif // defined(OS_POSIX) && !defined(OS_NACL) 104 #endif // defined(OS_POSIX) && !defined(OS_NACL)
94 105
106 // MojoBootstrapDelegate implementation
107 virtual void OnPipeAvailable(
108 mojo::embedder::ScopedPlatformHandle handle) OVERRIDE;
109 virtual void OnBootstrapError() OVERRIDE;
110
95 // Called from MessagePipeReader implementations 111 // Called from MessagePipeReader implementations
96 void OnMessageReceived(Message& message); 112 void OnMessageReceived(Message& message);
97 void OnConnected(mojo::ScopedMessagePipeHandle pipe); 113 void OnConnected(mojo::ScopedMessagePipeHandle pipe);
98 void OnPipeClosed(internal::MessagePipeReader* reader); 114 void OnPipeClosed(internal::MessagePipeReader* reader);
99 void OnPipeError(internal::MessagePipeReader* reader); 115 void OnPipeError(internal::MessagePipeReader* reader);
100 void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; } 116 void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; }
101 117
102 protected: 118 protected:
103 ChannelMojo(const ChannelHandle& channel_handle, 119 ChannelMojo(ChannelMojoHost* host,
120 const ChannelHandle& channel_handle,
104 Mode mode, 121 Mode mode,
105 Listener* listener, 122 Listener* listener);
106 scoped_refptr<base::TaskRunner> io_thread_task_runner);
107 123
108 private: 124 private:
109 struct ChannelInfoDeleter { 125 struct ChannelInfoDeleter {
110 void operator()(mojo::embedder::ChannelInfo* ptr) const; 126 void operator()(mojo::embedder::ChannelInfo* ptr) const;
111 }; 127 };
112 128
113 // ChannelMojo needs to kill its MessagePipeReader in delayed manner 129 // ChannelMojo needs to kill its MessagePipeReader in delayed manner
114 // because the channel wants to kill these readers during the 130 // because the channel wants to kill these readers during the
115 // notifications invoked by them. 131 // notifications invoked by them.
116 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter; 132 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter;
117 133
118 void InitOnIOThread(); 134 void InitControlReader(mojo::embedder::ScopedPlatformHandle handle);
119 135
120 scoped_ptr<Channel> bootstrap_; 136 scoped_ptr<MojoBootstrap> bootstrap_;
137 ChannelMojoHost* host_;
viettrungluu 2014/09/17 17:33:15 ChannelMojoHost* const (so it's obvious it's never
Hajime Morrita 2014/09/17 19:33:48 Done.
121 Mode mode_; 138 Mode mode_;
122 Listener* listener_; 139 Listener* listener_;
123 base::ProcessId peer_pid_; 140 base::ProcessId peer_pid_;
124 scoped_ptr<mojo::embedder::ChannelInfo, 141 scoped_ptr<mojo::embedder::ChannelInfo,
125 ChannelInfoDeleter> channel_info_; 142 ChannelInfoDeleter> channel_info_;
126 143
127 scoped_ptr<internal::ControlReader, ReaderDeleter> control_reader_; 144 scoped_ptr<internal::ControlReader, ReaderDeleter> control_reader_;
128 scoped_ptr<internal::MessageReader, ReaderDeleter> message_reader_; 145 scoped_ptr<internal::MessageReader, ReaderDeleter> message_reader_;
129 ScopedVector<Message> pending_messages_; 146 ScopedVector<Message> pending_messages_;
130 147
131 base::WeakPtrFactory<ChannelMojo> weak_factory_; 148 base::WeakPtrFactory<ChannelMojo> weak_factory_;
132 149
133 DISALLOW_COPY_AND_ASSIGN(ChannelMojo); 150 DISALLOW_COPY_AND_ASSIGN(ChannelMojo);
134 }; 151 };
135 152
136 } // namespace IPC 153 } // namespace IPC
137 154
138 #endif // IPC_IPC_CHANNEL_MOJO_H_ 155 #endif // IPC_IPC_CHANNEL_MOJO_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698