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

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: Fixing windows build error 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_delegate.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
28 class MojoBootstrap;
29
27 // Mojo-based IPC::Channel implementation over a platform handle. 30 // Mojo-based IPC::Channel implementation over a platform handle.
28 // 31 //
29 // ChannelMojo builds Mojo MessagePipe using underlying pipe given by 32 // ChannelMojo builds Mojo MessagePipe using underlying pipe given by
30 // "bootstrap" IPC::Channel which creates and owns platform pipe like 33 // "bootstrap" IPC::Channel which creates and owns platform pipe like
31 // named socket. The bootstrap Channel is used only for establishing 34 // named socket. The bootstrap Channel is used only for establishing
32 // the underlying connection. ChannelMojo takes its handle over once 35 // the underlying connection. ChannelMojo takes its handle over once
33 // the it is made and puts MessagePipe on it. 36 // the it is made and puts MessagePipe on it.
34 // 37 //
35 // ChannelMojo has a couple of MessagePipes: 38 // ChannelMojo has a couple of MessagePipes:
36 // 39 //
37 // * The first MessagePipe, which is built on top of bootstrap handle, 40 // * The first MessagePipe, which is built on top of bootstrap handle,
38 // is the "control" pipe. It is used to communicate out-of-band 41 // is the "control" pipe. It is used to communicate out-of-band
39 // control messages that aren't visible from IPC::Listener. 42 // control messages that aren't visible from IPC::Listener.
40 // 43 //
41 // * The second MessagePipe, which is created by the server channel 44 // * The second MessagePipe, which is created by the server channel
42 // and sent to client Channel over the control pipe, is used 45 // and sent to client Channel over the control pipe, is used
43 // to send IPC::Messages as an IPC::Sender. 46 // to send IPC::Messages as an IPC::Sender.
44 // 47 //
45 // TODO(morrita): Extract handle creation part of IPC::Channel into 48 // TODO(morrita): Extract handle creation part of IPC::Channel into
46 // separate class to clarify what ChannelMojo relies 49 // separate class to clarify what ChannelMojo relies
47 // on. 50 // on.
48 // TODO(morrita): Add APIs to create extra MessagePipes to let 51 // TODO(morrita): Add APIs to create extra MessagePipes to let
49 // Mojo-based objects talk over this Channel. 52 // Mojo-based objects talk over this Channel.
50 // 53 //
51 class IPC_MOJO_EXPORT ChannelMojo : public Channel { 54 class IPC_MOJO_EXPORT ChannelMojo : public Channel,
55 public MojoBootstrapDelegate {
52 public: 56 public:
53 // Create ChannelMojo. A bootstrap channel is created as well. 57 // Create ChannelMojo. A bootstrap channel is created as well.
54 static scoped_ptr<ChannelMojo> Create( 58 static scoped_ptr<ChannelMojo> Create(
55 const ChannelHandle &channel_handle, Mode mode, Listener* listener, 59 const ChannelHandle &channel_handle, Mode mode, Listener* listener,
56 scoped_refptr<base::TaskRunner> io_thread_task_runner); 60 scoped_refptr<base::TaskRunner> io_thread_task_runner);
57 61
58 // Create a factory object for ChannelMojo. 62 // Create a factory object for ChannelMojo.
59 // The factory is used to create Mojo-based ChannelProxy family. 63 // The factory is used to create Mojo-based ChannelProxy family.
60 static scoped_ptr<ChannelFactory> CreateFactory( 64 static scoped_ptr<ChannelFactory> CreateFactory(
61 const ChannelHandle &channel_handle, Mode mode, 65 const ChannelHandle &channel_handle, Mode mode,
62 scoped_refptr<base::TaskRunner> io_thread_task_runner); 66 scoped_refptr<base::TaskRunner> io_thread_task_runner);
63 67
64 virtual ~ChannelMojo(); 68 virtual ~ChannelMojo();
65 69
66 // Channel implementation 70 // Channel implementation
67 virtual bool Connect() OVERRIDE; 71 virtual bool Connect() OVERRIDE;
68 virtual void Close() OVERRIDE; 72 virtual void Close() OVERRIDE;
69 virtual bool Send(Message* message) OVERRIDE; 73 virtual bool Send(Message* message) OVERRIDE;
70 virtual base::ProcessId GetPeerPID() const OVERRIDE; 74 virtual base::ProcessId GetPeerPID() const OVERRIDE;
71 virtual base::ProcessId GetSelfPID() const OVERRIDE; 75 virtual base::ProcessId GetSelfPID() const OVERRIDE;
72 virtual ChannelHandle TakePipeHandle() OVERRIDE; 76 virtual ChannelHandle TakePipeHandle() OVERRIDE;
77 virtual void OnClientLaunched(base::ProcessHandle handle) OVERRIDE;
73 78
74 #if defined(OS_POSIX) && !defined(OS_NACL) 79 #if defined(OS_POSIX) && !defined(OS_NACL)
75 virtual int GetClientFileDescriptor() const OVERRIDE; 80 virtual int GetClientFileDescriptor() const OVERRIDE;
76 virtual int TakeClientFileDescriptor() OVERRIDE; 81 virtual int TakeClientFileDescriptor() OVERRIDE;
77 #endif // defined(OS_POSIX) && !defined(OS_NACL) 82 #endif // defined(OS_POSIX) && !defined(OS_NACL)
78 83
84 // MojoBootstrapDelegate implementation
85 virtual void OnPipeAvailable(
86 mojo::embedder::ScopedPlatformHandle handle) OVERRIDE;
87 virtual void OnBootstrapError() OVERRIDE;
88
79 // Called from MessagePipeReader implementations 89 // Called from MessagePipeReader implementations
80 void OnMessageReceived(Message& message); 90 void OnMessageReceived(Message& message);
81 void OnConnected(mojo::ScopedMessagePipeHandle pipe); 91 void OnConnected(mojo::ScopedMessagePipeHandle pipe);
82 void OnPipeClosed(internal::MessagePipeReader* reader); 92 void OnPipeClosed(internal::MessagePipeReader* reader);
83 void OnPipeError(internal::MessagePipeReader* reader); 93 void OnPipeError(internal::MessagePipeReader* reader);
84 void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; } 94 void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; }
85 95
86 private: 96 private:
87 struct ChannelInfoDeleter { 97 struct ChannelInfoDeleter {
88 void operator()(mojo::embedder::ChannelInfo* ptr) const; 98 void operator()(mojo::embedder::ChannelInfo* ptr) const;
89 }; 99 };
90 100
91 // ChannelMojo needs to kill its MessagePipeReader in delayed manner 101 // ChannelMojo needs to kill its MessagePipeReader in delayed manner
92 // because the channel wants to kill these readers during the 102 // because the channel wants to kill these readers during the
93 // notifications invoked by them. 103 // notifications invoked by them.
94 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter; 104 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter;
95 105
96 class ControlReader; 106 class ControlReader;
97 class ServerControlReader; 107 class ServerControlReader;
98 class ClientControlReader; 108 class ClientControlReader;
99 class MessageReader; 109 class MessageReader;
100 110
101 ChannelMojo(scoped_ptr<Channel> bootstrap, Mode mode, Listener* listener, 111 ChannelMojo(ChannelHandle handle,
112 Mode mode,
113 Listener* listener,
102 scoped_refptr<base::TaskRunner> io_thread_task_runner); 114 scoped_refptr<base::TaskRunner> io_thread_task_runner);
103 115
104 void InitOnIOThread(); 116 void InitBootstrap(ChannelHandle handle);
117 void InitControlReader(mojo::embedder::ScopedPlatformHandle handle);
105 118
106 scoped_ptr<Channel> bootstrap_; 119 scoped_ptr<MojoBootstrap> bootstrap_;
107 Mode mode_; 120 Mode mode_;
108 Listener* listener_; 121 Listener* listener_;
109 base::ProcessId peer_pid_; 122 base::ProcessId peer_pid_;
110 scoped_ptr<mojo::embedder::ChannelInfo, 123 scoped_ptr<mojo::embedder::ChannelInfo,
111 ChannelInfoDeleter> channel_info_; 124 ChannelInfoDeleter> channel_info_;
112 125
113 scoped_ptr<ControlReader, ReaderDeleter> control_reader_; 126 scoped_ptr<ControlReader, ReaderDeleter> control_reader_;
114 scoped_ptr<MessageReader, ReaderDeleter> message_reader_; 127 scoped_ptr<MessageReader, ReaderDeleter> message_reader_;
115 ScopedVector<Message> pending_messages_; 128 ScopedVector<Message> pending_messages_;
116 129
117 base::WeakPtrFactory<ChannelMojo> weak_factory_; 130 base::WeakPtrFactory<ChannelMojo> weak_factory_;
118 131
119 DISALLOW_COPY_AND_ASSIGN(ChannelMojo); 132 DISALLOW_COPY_AND_ASSIGN(ChannelMojo);
120 }; 133 };
121 134
122 } // namespace IPC 135 } // namespace IPC
123 136
124 #endif // IPC_IPC_CHANNEL_MOJO_H_ 137 #endif // IPC_IPC_CHANNEL_MOJO_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698