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

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: Fixed build error 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 | « ipc/mojo/BUILD.gn ('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"
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.
61 static scoped_ptr<ChannelMojo> Create( 65 // |host| must not be null.
62 const ChannelHandle &channel_handle, Mode mode, Listener* listener, 66 static scoped_ptr<ChannelMojo> Create(ChannelMojoHost* host,
63 scoped_refptr<base::TaskRunner> io_thread_task_runner); 67 const ChannelHandle& channel_handle,
68 Mode mode,
69 Listener* listener);
64 70
65 // Create a factory object for ChannelMojo. 71 // Create a factory object for ChannelMojo.
66 // The factory is used to create Mojo-based ChannelProxy family. 72 // The factory is used to create Mojo-based ChannelProxy family.
67 static scoped_ptr<ChannelFactory> CreateFactory( 73 // |host| must not be null.
68 const ChannelHandle &channel_handle, Mode mode, 74 static scoped_ptr<ChannelFactory> CreateServerFactory(
69 scoped_refptr<base::TaskRunner> io_thread_task_runner); 75 ChannelMojoHost* host,
76 const ChannelHandle& channel_handle);
77
78 static scoped_ptr<ChannelFactory> CreateClientFactory(
79 const ChannelHandle& channel_handle);
70 80
71 virtual ~ChannelMojo(); 81 virtual ~ChannelMojo();
72 82
83 // ChannelMojoHost tells the client handle using this API.
84 void OnClientLaunched(base::ProcessHandle handle);
85
73 // Channel implementation 86 // Channel implementation
74 virtual bool Connect() OVERRIDE; 87 virtual bool Connect() OVERRIDE;
75 virtual void Close() OVERRIDE; 88 virtual void Close() OVERRIDE;
76 virtual bool Send(Message* message) OVERRIDE; 89 virtual bool Send(Message* message) OVERRIDE;
77 virtual base::ProcessId GetPeerPID() const OVERRIDE; 90 virtual base::ProcessId GetPeerPID() const OVERRIDE;
78 virtual base::ProcessId GetSelfPID() const OVERRIDE; 91 virtual base::ProcessId GetSelfPID() const OVERRIDE;
79 virtual ChannelHandle TakePipeHandle() OVERRIDE; 92 virtual ChannelHandle TakePipeHandle() OVERRIDE;
80 93
81 #if defined(OS_POSIX) && !defined(OS_NACL) 94 #if defined(OS_POSIX) && !defined(OS_NACL)
82 virtual int GetClientFileDescriptor() const OVERRIDE; 95 virtual int GetClientFileDescriptor() const OVERRIDE;
83 virtual int TakeClientFileDescriptor() OVERRIDE; 96 virtual int TakeClientFileDescriptor() OVERRIDE;
84 97
85 // These access protected API of IPC::Message, which has ChannelMojo 98 // These access protected API of IPC::Message, which has ChannelMojo
86 // as a friend class. 99 // as a friend class.
87 static MojoResult WriteToFileDescriptorSet( 100 static MojoResult WriteToFileDescriptorSet(
88 const std::vector<MojoHandle>& handle_buffer, 101 const std::vector<MojoHandle>& handle_buffer,
89 Message* message); 102 Message* message);
90 static MojoResult ReadFromFileDescriptorSet(const Message& message, 103 static MojoResult ReadFromFileDescriptorSet(const Message& message,
91 std::vector<MojoHandle>* handles); 104 std::vector<MojoHandle>* handles);
92 105
93 #endif // defined(OS_POSIX) && !defined(OS_NACL) 106 #endif // defined(OS_POSIX) && !defined(OS_NACL)
94 107
108 // MojoBootstrapDelegate implementation
109 virtual void OnPipeAvailable(
110 mojo::embedder::ScopedPlatformHandle handle) OVERRIDE;
111 virtual void OnBootstrapError() OVERRIDE;
112
95 // Called from MessagePipeReader implementations 113 // Called from MessagePipeReader implementations
96 void OnMessageReceived(Message& message); 114 void OnMessageReceived(Message& message);
97 void OnConnected(mojo::ScopedMessagePipeHandle pipe); 115 void OnConnected(mojo::ScopedMessagePipeHandle pipe);
98 void OnPipeClosed(internal::MessagePipeReader* reader); 116 void OnPipeClosed(internal::MessagePipeReader* reader);
99 void OnPipeError(internal::MessagePipeReader* reader); 117 void OnPipeError(internal::MessagePipeReader* reader);
100 void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; } 118 void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; }
101 119
102 protected: 120 protected:
103 ChannelMojo(const ChannelHandle& channel_handle, 121 ChannelMojo(ChannelMojoHost* host,
122 const ChannelHandle& channel_handle,
104 Mode mode, 123 Mode mode,
105 Listener* listener, 124 Listener* listener);
106 scoped_refptr<base::TaskRunner> io_thread_task_runner);
107 125
108 private: 126 private:
109 struct ChannelInfoDeleter { 127 struct ChannelInfoDeleter {
110 void operator()(mojo::embedder::ChannelInfo* ptr) const; 128 void operator()(mojo::embedder::ChannelInfo* ptr) const;
111 }; 129 };
112 130
113 // ChannelMojo needs to kill its MessagePipeReader in delayed manner 131 // ChannelMojo needs to kill its MessagePipeReader in delayed manner
114 // because the channel wants to kill these readers during the 132 // because the channel wants to kill these readers during the
115 // notifications invoked by them. 133 // notifications invoked by them.
116 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter; 134 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter;
117 135
118 void InitOnIOThread(); 136 void InitControlReader(mojo::embedder::ScopedPlatformHandle handle);
119 137
120 scoped_ptr<Channel> bootstrap_; 138 scoped_ptr<MojoBootstrap> bootstrap_;
139 ChannelMojoHost* const host_;
121 Mode mode_; 140 Mode mode_;
122 Listener* listener_; 141 Listener* listener_;
123 base::ProcessId peer_pid_; 142 base::ProcessId peer_pid_;
124 scoped_ptr<mojo::embedder::ChannelInfo, 143 scoped_ptr<mojo::embedder::ChannelInfo,
125 ChannelInfoDeleter> channel_info_; 144 ChannelInfoDeleter> channel_info_;
126 145
127 scoped_ptr<internal::ControlReader, ReaderDeleter> control_reader_; 146 scoped_ptr<internal::ControlReader, ReaderDeleter> control_reader_;
128 scoped_ptr<internal::MessageReader, ReaderDeleter> message_reader_; 147 scoped_ptr<internal::MessageReader, ReaderDeleter> message_reader_;
129 ScopedVector<Message> pending_messages_; 148 ScopedVector<Message> pending_messages_;
130 149
131 base::WeakPtrFactory<ChannelMojo> weak_factory_; 150 base::WeakPtrFactory<ChannelMojo> weak_factory_;
132 151
133 DISALLOW_COPY_AND_ASSIGN(ChannelMojo); 152 DISALLOW_COPY_AND_ASSIGN(ChannelMojo);
134 }; 153 };
135 154
136 } // namespace IPC 155 } // namespace IPC
137 156
138 #endif // IPC_IPC_CHANNEL_MOJO_H_ 157 #endif // IPC_IPC_CHANNEL_MOJO_H_
OLDNEW
« no previous file with comments | « ipc/mojo/BUILD.gn ('k') | ipc/mojo/ipc_channel_mojo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698