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

Side by Side Diff: ipc/ipc_channel_mojo.h

Issue 2163633003: Support early associated interface binding on ChannelMojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@explicit-channel-ipc-task-runner
Patch Set: . Created 4 years, 5 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/ipc_channel.h ('k') | ipc/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 <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 24 matching lines...) Expand all
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
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
127 // ChannelMojo needs to kill its MessagePipeReader in delayed manner
128 // because the channel wants to kill these readers during the
129 // notifications invoked by them.
130 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter;
131 119
132 // A TaskRunner which runs tasks on the ChannelMojo's owning thread. 120 // A TaskRunner which runs tasks on the ChannelMojo's owning thread.
133 scoped_refptr<base::TaskRunner> task_runner_; 121 scoped_refptr<base::TaskRunner> task_runner_;
134 122
135 const mojo::MessagePipeHandle pipe_; 123 const mojo::MessagePipeHandle pipe_;
136 std::unique_ptr<MojoBootstrap> bootstrap_; 124 std::unique_ptr<MojoBootstrap> bootstrap_;
137 Listener* listener_; 125 Listener* listener_;
138 126
127 std::unique_ptr<internal::MessagePipeReader> message_reader_;
128
129 base::Lock associated_interface_lock_;
139 std::map<std::string, GenericAssociatedInterfaceFactory> 130 std::map<std::string, GenericAssociatedInterfaceFactory>
140 associated_interfaces_; 131 associated_interfaces_;
141 132
142 // Guards access to the fields below.
143 mutable base::Lock lock_;
144 std::unique_ptr<internal::MessagePipeReader, ReaderDeleter> message_reader_;
145 std::vector<std::unique_ptr<Message>> pending_messages_;
146 bool waiting_connect_;
147
148 base::WeakPtrFactory<ChannelMojo> weak_factory_; 133 base::WeakPtrFactory<ChannelMojo> weak_factory_;
149 134
150 DISALLOW_COPY_AND_ASSIGN(ChannelMojo); 135 DISALLOW_COPY_AND_ASSIGN(ChannelMojo);
151 }; 136 };
152 137
153 } // namespace IPC 138 } // namespace IPC
154 139
155 #endif // IPC_IPC_CHANNEL_MOJO_H_ 140 #endif // IPC_IPC_CHANNEL_MOJO_H_
OLDNEW
« no previous file with comments | « ipc/ipc_channel.h ('k') | ipc/ipc_channel_mojo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698