OLD | NEW |
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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 24 matching lines...) Expand all Loading... |
35 // ChannelMojo builds a Mojo MessagePipe using the provided message pipe | 35 // ChannelMojo builds a Mojo MessagePipe using the provided message pipe |
36 // |handle| and builds an associated interface for each direction on the | 36 // |handle| and builds an associated interface for each direction on the |
37 // channel. | 37 // channel. |
38 // | 38 // |
39 // TODO(morrita): Add APIs to create extra MessagePipes to let | 39 // TODO(morrita): Add APIs to create extra MessagePipes to let |
40 // Mojo-based objects talk over this Channel. | 40 // Mojo-based objects talk over this Channel. |
41 // | 41 // |
42 class IPC_EXPORT ChannelMojo | 42 class IPC_EXPORT ChannelMojo |
43 : public Channel, | 43 : public Channel, |
44 public Channel::AssociatedInterfaceSupport, | 44 public Channel::AssociatedInterfaceSupport, |
45 public MojoBootstrap::Delegate, | 45 public NON_EXPORTED_BASE(MojoBootstrap::Delegate), |
46 public NON_EXPORTED_BASE(internal::MessagePipeReader::Delegate) { | 46 public NON_EXPORTED_BASE(internal::MessagePipeReader::Delegate) { |
47 public: | 47 public: |
48 // Creates a ChannelMojo. | 48 // Creates a ChannelMojo. |
49 static std::unique_ptr<ChannelMojo> | 49 static std::unique_ptr<ChannelMojo> |
50 Create(mojo::ScopedMessagePipeHandle handle, | 50 Create(mojo::ScopedMessagePipeHandle handle, |
51 Mode mode, | 51 Mode mode, |
52 Listener* listener, | 52 Listener* listener, |
53 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner = | 53 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner = |
54 base::ThreadTaskRunnerHandle::Get()); | 54 base::ThreadTaskRunnerHandle::Get()); |
55 | 55 |
(...skipping 27 matching lines...) Expand all Loading... |
83 // These access protected API of IPC::Message, which has ChannelMojo | 83 // These access protected API of IPC::Message, which has ChannelMojo |
84 // as a friend class. | 84 // as a friend class. |
85 static MojoResult WriteToMessageAttachmentSet( | 85 static MojoResult WriteToMessageAttachmentSet( |
86 mojo::Array<mojom::SerializedHandlePtr> handle_buffer, | 86 mojo::Array<mojom::SerializedHandlePtr> handle_buffer, |
87 Message* message); | 87 Message* message); |
88 static MojoResult ReadFromMessageAttachmentSet( | 88 static MojoResult ReadFromMessageAttachmentSet( |
89 Message* message, | 89 Message* message, |
90 mojo::Array<mojom::SerializedHandlePtr>* handles); | 90 mojo::Array<mojom::SerializedHandlePtr>* handles); |
91 | 91 |
92 // MojoBootstrapDelegate implementation | 92 // MojoBootstrapDelegate implementation |
93 void OnPipesAvailable(mojom::ChannelAssociatedPtrInfo send_channel, | 93 void OnPipesAvailable(mojom::ChannelAssociatedPtr sender, |
94 mojom::ChannelAssociatedRequest receive_channel, | 94 mojom::ChannelAssociatedRequest receiver) override; |
95 int32_t peer_pid) override; | 95 |
96 void OnBootstrapError() override; | 96 // MessagePipeReader::Delegate |
| 97 void OnPeerPidReceived() override; |
| 98 void OnMessageReceived(const Message& message) override; |
| 99 void OnPipeError() override; |
97 void OnAssociatedInterfaceRequest( | 100 void OnAssociatedInterfaceRequest( |
98 const std::string& name, | 101 const std::string& name, |
99 mojo::ScopedInterfaceEndpointHandle handle) override; | 102 mojo::ScopedInterfaceEndpointHandle handle) override; |
100 | 103 |
101 // MessagePipeReader::Delegate | |
102 void OnMessageReceived(const Message& message) override; | |
103 void OnPipeError() override; | |
104 | |
105 private: | 104 private: |
106 ChannelMojo( | 105 ChannelMojo( |
107 mojo::ScopedMessagePipeHandle handle, | 106 mojo::ScopedMessagePipeHandle handle, |
108 Mode mode, | 107 Mode mode, |
109 Listener* listener, | 108 Listener* listener, |
110 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner); | 109 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner); |
111 | 110 |
112 void InitMessageReader(mojom::ChannelAssociatedPtrInfo sender, | |
113 mojom::ChannelAssociatedRequest receiver, | |
114 base::ProcessId peer_pid); | |
115 | |
116 // Channel::AssociatedInterfaceSupport: | 111 // Channel::AssociatedInterfaceSupport: |
117 mojo::AssociatedGroup* GetAssociatedGroup() override; | 112 mojo::AssociatedGroup* GetAssociatedGroup() override; |
118 void AddGenericAssociatedInterface( | 113 void AddGenericAssociatedInterface( |
119 const std::string& name, | 114 const std::string& name, |
120 const GenericAssociatedInterfaceFactory& factory) override; | 115 const GenericAssociatedInterfaceFactory& factory) override; |
121 void GetGenericRemoteAssociatedInterface( | 116 void GetGenericRemoteAssociatedInterface( |
122 const std::string& name, | 117 const std::string& name, |
123 mojo::ScopedInterfaceEndpointHandle handle) override; | 118 mojo::ScopedInterfaceEndpointHandle handle) override; |
124 void SetProxyTaskRunner( | |
125 scoped_refptr<base::SingleThreadTaskRunner> task_runner) override; | |
126 | 119 |
127 // ChannelMojo needs to kill its MessagePipeReader in delayed manner | 120 // ChannelMojo needs to kill its MessagePipeReader in delayed manner |
128 // because the channel wants to kill these readers during the | 121 // because the channel wants to kill these readers during the |
129 // notifications invoked by them. | 122 // notifications invoked by them. |
130 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter; | 123 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter; |
131 | 124 |
132 // A TaskRunner which runs tasks on the ChannelMojo's owning thread. | 125 // A TaskRunner which runs tasks on the ChannelMojo's owning thread. |
133 scoped_refptr<base::TaskRunner> task_runner_; | 126 scoped_refptr<base::TaskRunner> task_runner_; |
134 | 127 |
135 const mojo::MessagePipeHandle pipe_; | 128 const mojo::MessagePipeHandle pipe_; |
136 std::unique_ptr<MojoBootstrap> bootstrap_; | 129 std::unique_ptr<MojoBootstrap> bootstrap_; |
137 Listener* listener_; | 130 Listener* listener_; |
138 | 131 |
| 132 base::Lock associated_interface_lock_; |
139 std::map<std::string, GenericAssociatedInterfaceFactory> | 133 std::map<std::string, GenericAssociatedInterfaceFactory> |
140 associated_interfaces_; | 134 associated_interfaces_; |
141 | 135 |
142 // Guards access to the fields below. | 136 // Guards access to the fields below. |
143 mutable base::Lock lock_; | 137 mutable base::Lock lock_; |
144 std::unique_ptr<internal::MessagePipeReader, ReaderDeleter> message_reader_; | 138 std::unique_ptr<internal::MessagePipeReader, ReaderDeleter> message_reader_; |
145 std::vector<std::unique_ptr<Message>> pending_messages_; | |
146 bool waiting_connect_; | |
147 | 139 |
148 base::WeakPtrFactory<ChannelMojo> weak_factory_; | 140 base::WeakPtrFactory<ChannelMojo> weak_factory_; |
149 | 141 |
150 DISALLOW_COPY_AND_ASSIGN(ChannelMojo); | 142 DISALLOW_COPY_AND_ASSIGN(ChannelMojo); |
151 }; | 143 }; |
152 | 144 |
153 } // namespace IPC | 145 } // namespace IPC |
154 | 146 |
155 #endif // IPC_IPC_CHANNEL_MOJO_H_ | 147 #endif // IPC_IPC_CHANNEL_MOJO_H_ |
OLD | NEW |