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 <memory> | 11 #include <memory> |
| 12 #include <string> |
11 #include <vector> | 13 #include <vector> |
12 | 14 |
13 #include "base/macros.h" | 15 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
16 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
17 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
18 #include "base/task_runner.h" | 20 #include "base/task_runner.h" |
19 #include "build/build_config.h" | 21 #include "build/build_config.h" |
20 #include "ipc/ipc_channel.h" | 22 #include "ipc/ipc_channel.h" |
(...skipping 30 matching lines...) Expand all Loading... |
51 mojo::ScopedMessagePipeHandle handle); | 53 mojo::ScopedMessagePipeHandle handle); |
52 | 54 |
53 static std::unique_ptr<ChannelFactory> CreateClientFactory( | 55 static std::unique_ptr<ChannelFactory> CreateClientFactory( |
54 mojo::ScopedMessagePipeHandle handle); | 56 mojo::ScopedMessagePipeHandle handle); |
55 | 57 |
56 ~ChannelMojo() override; | 58 ~ChannelMojo() override; |
57 | 59 |
58 // Channel implementation | 60 // Channel implementation |
59 bool Connect() override; | 61 bool Connect() override; |
60 void Close() override; | 62 void Close() override; |
| 63 mojo::AssociatedGroup* GetAssociatedGroup() override; |
| 64 void AddGenericAssociatedInterface( |
| 65 const std::string& name, |
| 66 const GenericAssociatedInterfaceFactory& factory) override; |
| 67 void GetGenericRemoteAssociatedInterface( |
| 68 const std::string& name, |
| 69 mojo::ScopedInterfaceEndpointHandle handle) override; |
61 bool Send(Message* message) override; | 70 bool Send(Message* message) override; |
62 bool IsSendThreadSafe() const override; | 71 bool IsSendThreadSafe() const override; |
63 base::ProcessId GetPeerPID() const override; | 72 base::ProcessId GetPeerPID() const override; |
64 base::ProcessId GetSelfPID() const override; | 73 base::ProcessId GetSelfPID() const override; |
65 | 74 |
66 #if defined(OS_POSIX) && !defined(OS_NACL_SFI) | 75 #if defined(OS_POSIX) && !defined(OS_NACL_SFI) |
67 int GetClientFileDescriptor() const override; | 76 int GetClientFileDescriptor() const override; |
68 base::ScopedFD TakeClientFileDescriptor() override; | 77 base::ScopedFD TakeClientFileDescriptor() override; |
69 #endif // defined(OS_POSIX) && !defined(OS_NACL_SFI) | 78 #endif // defined(OS_POSIX) && !defined(OS_NACL_SFI) |
70 | 79 |
71 // These access protected API of IPC::Message, which has ChannelMojo | 80 // These access protected API of IPC::Message, which has ChannelMojo |
72 // as a friend class. | 81 // as a friend class. |
73 static MojoResult WriteToMessageAttachmentSet( | 82 static MojoResult WriteToMessageAttachmentSet( |
74 mojo::Array<mojom::SerializedHandlePtr> handle_buffer, | 83 mojo::Array<mojom::SerializedHandlePtr> handle_buffer, |
75 Message* message); | 84 Message* message); |
76 static MojoResult ReadFromMessageAttachmentSet( | 85 static MojoResult ReadFromMessageAttachmentSet( |
77 Message* message, | 86 Message* message, |
78 mojo::Array<mojom::SerializedHandlePtr>* handles); | 87 mojo::Array<mojom::SerializedHandlePtr>* handles); |
79 | 88 |
80 // MojoBootstrapDelegate implementation | 89 // MojoBootstrapDelegate implementation |
81 void OnPipesAvailable(mojom::ChannelAssociatedPtrInfo send_channel, | 90 void OnPipesAvailable(mojom::ChannelAssociatedPtrInfo send_channel, |
82 mojom::ChannelAssociatedRequest receive_channel, | 91 mojom::ChannelAssociatedRequest receive_channel, |
83 int32_t peer_pid) override; | 92 int32_t peer_pid) override; |
84 void OnBootstrapError() override; | 93 void OnBootstrapError() override; |
| 94 void OnAssociatedInterfaceRequest( |
| 95 const std::string& name, |
| 96 mojo::ScopedInterfaceEndpointHandle handle) override; |
85 | 97 |
86 // MessagePipeReader::Delegate | 98 // MessagePipeReader::Delegate |
87 void OnMessageReceived(const Message& message) override; | 99 void OnMessageReceived(const Message& message) override; |
88 void OnPipeError() override; | 100 void OnPipeError() override; |
89 | 101 |
90 private: | 102 private: |
91 ChannelMojo(mojo::ScopedMessagePipeHandle handle, | 103 ChannelMojo(mojo::ScopedMessagePipeHandle handle, |
92 Mode mode, | 104 Mode mode, |
93 Listener* listener); | 105 Listener* listener); |
94 | 106 |
95 void InitMessageReader(mojom::ChannelAssociatedPtrInfo sender, | 107 void InitMessageReader(mojom::ChannelAssociatedPtrInfo sender, |
96 mojom::ChannelAssociatedRequest receiver, | 108 mojom::ChannelAssociatedRequest receiver, |
97 base::ProcessId peer_pid); | 109 base::ProcessId peer_pid); |
98 | 110 |
99 // ChannelMojo needs to kill its MessagePipeReader in delayed manner | 111 // ChannelMojo needs to kill its MessagePipeReader in delayed manner |
100 // because the channel wants to kill these readers during the | 112 // because the channel wants to kill these readers during the |
101 // notifications invoked by them. | 113 // notifications invoked by them. |
102 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter; | 114 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter; |
103 | 115 |
104 // A TaskRunner which runs tasks on the ChannelMojo's owning thread. | 116 // A TaskRunner which runs tasks on the ChannelMojo's owning thread. |
105 scoped_refptr<base::TaskRunner> task_runner_; | 117 scoped_refptr<base::TaskRunner> task_runner_; |
106 | 118 |
107 const mojo::MessagePipeHandle pipe_; | 119 const mojo::MessagePipeHandle pipe_; |
108 std::unique_ptr<MojoBootstrap> bootstrap_; | 120 std::unique_ptr<MojoBootstrap> bootstrap_; |
109 Listener* listener_; | 121 Listener* listener_; |
110 | 122 |
| 123 std::map<std::string, GenericAssociatedInterfaceFactory> |
| 124 associated_interfaces_; |
| 125 |
111 // Guards access to the fields below. | 126 // Guards access to the fields below. |
112 mutable base::Lock lock_; | 127 mutable base::Lock lock_; |
113 std::unique_ptr<internal::MessagePipeReader, ReaderDeleter> message_reader_; | 128 std::unique_ptr<internal::MessagePipeReader, ReaderDeleter> message_reader_; |
114 std::vector<std::unique_ptr<Message>> pending_messages_; | 129 std::vector<std::unique_ptr<Message>> pending_messages_; |
115 bool waiting_connect_; | 130 bool waiting_connect_; |
116 | 131 |
117 base::WeakPtrFactory<ChannelMojo> weak_factory_; | 132 base::WeakPtrFactory<ChannelMojo> weak_factory_; |
118 | 133 |
119 DISALLOW_COPY_AND_ASSIGN(ChannelMojo); | 134 DISALLOW_COPY_AND_ASSIGN(ChannelMojo); |
120 }; | 135 }; |
121 | 136 |
122 } // namespace IPC | 137 } // namespace IPC |
123 | 138 |
124 #endif // IPC_IPC_CHANNEL_MOJO_H_ | 139 #endif // IPC_IPC_CHANNEL_MOJO_H_ |
OLD | NEW |