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

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: 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
(...skipping 21 matching lines...) Expand all
48 // * The second MessagePipe, which is created by the server channel 49 // * The second MessagePipe, which is created by the server channel
49 // and sent to client Channel over the control pipe, is used 50 // and sent to client Channel over the control pipe, is used
50 // to send IPC::Messages as an IPC::Sender. 51 // to send IPC::Messages as an IPC::Sender.
51 // 52 //
52 // TODO(morrita): Extract handle creation part of IPC::Channel into 53 // TODO(morrita): Extract handle creation part of IPC::Channel into
53 // separate class to clarify what ChannelMojo relies 54 // separate class to clarify what ChannelMojo relies
54 // on. 55 // on.
55 // TODO(morrita): Add APIs to create extra MessagePipes to let 56 // TODO(morrita): Add APIs to create extra MessagePipes to let
56 // Mojo-based objects talk over this Channel. 57 // Mojo-based objects talk over this Channel.
57 // 58 //
58 class IPC_MOJO_EXPORT ChannelMojo : public Channel { 59 class IPC_MOJO_EXPORT ChannelMojo : public Channel,
60 public MojoBootstrap::Delegate {
59 public: 61 public:
60 // Create ChannelMojo. A bootstrap channel is created as well. 62 // Create ChannelMojo. A bootstrap channel is created as well.
61 static scoped_ptr<ChannelMojo> Create( 63 static scoped_ptr<ChannelMojo> Create(
62 const ChannelHandle &channel_handle, Mode mode, Listener* listener, 64 const ChannelHandle &channel_handle, Mode mode, Listener* listener,
63 scoped_refptr<base::TaskRunner> io_thread_task_runner); 65 scoped_refptr<base::TaskRunner> io_thread_task_runner);
64 66
65 // Create a factory object for ChannelMojo. 67 // Create a factory object for ChannelMojo.
66 // The factory is used to create Mojo-based ChannelProxy family. 68 // The factory is used to create Mojo-based ChannelProxy family.
67 static scoped_ptr<ChannelFactory> CreateFactory( 69 static scoped_ptr<ChannelFactory> CreateFactory(
68 const ChannelHandle &channel_handle, Mode mode, 70 const ChannelHandle &channel_handle, Mode mode,
69 scoped_refptr<base::TaskRunner> io_thread_task_runner); 71 scoped_refptr<base::TaskRunner> io_thread_task_runner);
70 72
71 virtual ~ChannelMojo(); 73 virtual ~ChannelMojo();
72 74
73 // Channel implementation 75 // Channel implementation
74 virtual bool Connect() OVERRIDE; 76 virtual bool Connect() OVERRIDE;
75 virtual void Close() OVERRIDE; 77 virtual void Close() OVERRIDE;
76 virtual bool Send(Message* message) OVERRIDE; 78 virtual bool Send(Message* message) OVERRIDE;
77 virtual base::ProcessId GetPeerPID() const OVERRIDE; 79 virtual base::ProcessId GetPeerPID() const OVERRIDE;
78 virtual base::ProcessId GetSelfPID() const OVERRIDE; 80 virtual base::ProcessId GetSelfPID() const OVERRIDE;
79 virtual ChannelHandle TakePipeHandle() OVERRIDE; 81 virtual ChannelHandle TakePipeHandle() OVERRIDE;
82 virtual void OnClientLaunched(base::ProcessHandle handle) OVERRIDE;
80 83
81 #if defined(OS_POSIX) && !defined(OS_NACL) 84 #if defined(OS_POSIX) && !defined(OS_NACL)
82 virtual int GetClientFileDescriptor() const OVERRIDE; 85 virtual int GetClientFileDescriptor() const OVERRIDE;
83 virtual int TakeClientFileDescriptor() OVERRIDE; 86 virtual int TakeClientFileDescriptor() OVERRIDE;
84 87
85 // These access protected API of IPC::Message, which has ChannelMojo 88 // These access protected API of IPC::Message, which has ChannelMojo
86 // as a friend class. 89 // as a friend class.
87 static MojoResult WriteToFileDescriptorSet( 90 static MojoResult WriteToFileDescriptorSet(
88 const std::vector<MojoHandle>& handle_buffer, 91 const std::vector<MojoHandle>& handle_buffer,
89 Message* message); 92 Message* message);
90 static MojoResult ReadFromFileDescriptorSet(const Message& message, 93 static MojoResult ReadFromFileDescriptorSet(const Message& message,
91 std::vector<MojoHandle>* handles); 94 std::vector<MojoHandle>* handles);
92 95
93 #endif // defined(OS_POSIX) && !defined(OS_NACL) 96 #endif // defined(OS_POSIX) && !defined(OS_NACL)
94 97
98 // MojoBootstrapDelegate implementation
99 virtual void OnPipeAvailable(
100 mojo::embedder::ScopedPlatformHandle handle) OVERRIDE;
101 virtual void OnBootstrapError() OVERRIDE;
102
95 // Called from MessagePipeReader implementations 103 // Called from MessagePipeReader implementations
96 void OnMessageReceived(Message& message); 104 void OnMessageReceived(Message& message);
97 void OnConnected(mojo::ScopedMessagePipeHandle pipe); 105 void OnConnected(mojo::ScopedMessagePipeHandle pipe);
98 void OnPipeClosed(internal::MessagePipeReader* reader); 106 void OnPipeClosed(internal::MessagePipeReader* reader);
99 void OnPipeError(internal::MessagePipeReader* reader); 107 void OnPipeError(internal::MessagePipeReader* reader);
100 void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; } 108 void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; }
101 109
102 protected: 110 protected:
103 ChannelMojo(const ChannelHandle& channel_handle, 111 ChannelMojo(const ChannelHandle& channel_handle,
104 Mode mode, 112 Mode mode,
105 Listener* listener, 113 Listener* listener,
106 scoped_refptr<base::TaskRunner> io_thread_task_runner); 114 scoped_refptr<base::TaskRunner> io_thread_task_runner);
107 115
108 private: 116 private:
109 struct ChannelInfoDeleter { 117 struct ChannelInfoDeleter {
110 void operator()(mojo::embedder::ChannelInfo* ptr) const; 118 void operator()(mojo::embedder::ChannelInfo* ptr) const;
111 }; 119 };
112 120
113 // ChannelMojo needs to kill its MessagePipeReader in delayed manner 121 // ChannelMojo needs to kill its MessagePipeReader in delayed manner
114 // because the channel wants to kill these readers during the 122 // because the channel wants to kill these readers during the
115 // notifications invoked by them. 123 // notifications invoked by them.
116 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter; 124 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter;
117 125
118 void InitOnIOThread(); 126 void InitBootstrap(ChannelHandle handle);
127 void InitControlReader(mojo::embedder::ScopedPlatformHandle handle);
119 128
120 scoped_ptr<Channel> bootstrap_; 129 scoped_ptr<MojoBootstrap> bootstrap_;
121 Mode mode_; 130 Mode mode_;
122 Listener* listener_; 131 Listener* listener_;
123 base::ProcessId peer_pid_; 132 base::ProcessId peer_pid_;
124 scoped_ptr<mojo::embedder::ChannelInfo, 133 scoped_ptr<mojo::embedder::ChannelInfo,
125 ChannelInfoDeleter> channel_info_; 134 ChannelInfoDeleter> channel_info_;
126 135
127 scoped_ptr<internal::ControlReader, ReaderDeleter> control_reader_; 136 scoped_ptr<internal::ControlReader, ReaderDeleter> control_reader_;
128 scoped_ptr<internal::MessageReader, ReaderDeleter> message_reader_; 137 scoped_ptr<internal::MessageReader, ReaderDeleter> message_reader_;
129 ScopedVector<Message> pending_messages_; 138 ScopedVector<Message> pending_messages_;
130 139
131 base::WeakPtrFactory<ChannelMojo> weak_factory_; 140 base::WeakPtrFactory<ChannelMojo> weak_factory_;
132 141
133 DISALLOW_COPY_AND_ASSIGN(ChannelMojo); 142 DISALLOW_COPY_AND_ASSIGN(ChannelMojo);
134 }; 143 };
135 144
136 } // namespace IPC 145 } // namespace IPC
137 146
138 #endif // IPC_IPC_CHANNEL_MOJO_H_ 147 #endif // IPC_IPC_CHANNEL_MOJO_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698