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

Side by Side Diff: ipc/ipc_channel_proxy.h

Issue 2522333002: Provide a Mojo equivalent of ThreadSafeSender. (Closed)
Patch Set: Addresses @tsepez comment Created 4 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_PROXY_H_ 5 #ifndef IPC_IPC_CHANNEL_PROXY_H_
6 #define IPC_IPC_CHANNEL_PROXY_H_ 6 #define IPC_IPC_CHANNEL_PROXY_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 mojo::GetProxy(proxy, GetAssociatedGroup()); 223 mojo::GetProxy(proxy, GetAssociatedGroup());
224 GetGenericRemoteAssociatedInterface(Interface::Name_, request.PassHandle()); 224 GetGenericRemoteAssociatedInterface(Interface::Name_, request.PassHandle());
225 } 225 }
226 226
227 #if defined(ENABLE_IPC_FUZZER) 227 #if defined(ENABLE_IPC_FUZZER)
228 void set_outgoing_message_filter(OutgoingMessageFilter* filter) { 228 void set_outgoing_message_filter(OutgoingMessageFilter* filter) {
229 outgoing_message_filter_ = filter; 229 outgoing_message_filter_ = filter;
230 } 230 }
231 #endif 231 #endif
232 232
233 template <typename Interface>
234 using AssociatedInterfaceRetrievedCallback =
235 base::Callback<void(mojo::AssociatedInterfacePtr<Interface>)>;
236 // Creates an AssociatedInterfacePtr to |Interface| on the IO thread and
237 // passes it to |callback|, also invoked on the IO thread.
238 template <typename Interface>
239 void RetrieveAssociatedInterfaceOnIOThread(
240 const AssociatedInterfaceRetrievedCallback<Interface>& callback) {
241 context_->ipc_task_runner()->PostTask(
242 FROM_HERE, base::Bind(&Context::RetrieveAssociatedInterface<Interface>,
243 context_, callback));
244 }
245
233 // Called to clear the pointer to the IPC task runner when it's going away. 246 // Called to clear the pointer to the IPC task runner when it's going away.
234 void ClearIPCTaskRunner(); 247 void ClearIPCTaskRunner();
235 248
236 protected: 249 protected:
237 class Context; 250 class Context;
238 // A subclass uses this constructor if it needs to add more information 251 // A subclass uses this constructor if it needs to add more information
239 // to the internal state. 252 // to the internal state.
240 explicit ChannelProxy(Context* context); 253 explicit ChannelProxy(Context* context);
241 254
242
243 // Used internally to hold state that is referenced on the IPC thread. 255 // Used internally to hold state that is referenced on the IPC thread.
244 class Context : public base::RefCountedThreadSafe<Context>, 256 class Context : public base::RefCountedThreadSafe<Context>,
245 public Listener { 257 public Listener {
246 public: 258 public:
247 Context(Listener* listener, 259 Context(Listener* listener,
248 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_thread); 260 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_thread);
249 void ClearIPCTaskRunner(); 261 void ClearIPCTaskRunner();
250 base::SingleThreadTaskRunner* ipc_task_runner() const { 262 base::SingleThreadTaskRunner* ipc_task_runner() const {
251 return ipc_task_runner_.get(); 263 return ipc_task_runner_.get();
252 } 264 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 friend class ChannelProxy; 309 friend class ChannelProxy;
298 friend class IpcSecurityTestUtil; 310 friend class IpcSecurityTestUtil;
299 311
300 // Create the Channel 312 // Create the Channel
301 void CreateChannel(std::unique_ptr<ChannelFactory> factory); 313 void CreateChannel(std::unique_ptr<ChannelFactory> factory);
302 314
303 // Methods called on the IO thread. 315 // Methods called on the IO thread.
304 void OnSendMessage(std::unique_ptr<Message> message_ptr); 316 void OnSendMessage(std::unique_ptr<Message> message_ptr);
305 void OnAddFilter(); 317 void OnAddFilter();
306 void OnRemoveFilter(MessageFilter* filter); 318 void OnRemoveFilter(MessageFilter* filter);
319 template <typename Interface>
320 void RetrieveAssociatedInterface(
321 const AssociatedInterfaceRetrievedCallback<Interface>& callback) {
322 mojo::AssociatedInterfacePtr<Interface> interface_ptr;
323 channel_->GetAssociatedInterfaceSupport()->GetRemoteAssociatedInterface(
324 &interface_ptr);
325 callback.Run(std::move(interface_ptr));
326 }
307 327
308 // Methods called on the listener thread. 328 // Methods called on the listener thread.
309 void AddFilter(MessageFilter* filter); 329 void AddFilter(MessageFilter* filter);
310 void OnDispatchConnected(); 330 void OnDispatchConnected();
311 void OnDispatchError(); 331 void OnDispatchError();
312 void OnDispatchBadMessage(const Message& message); 332 void OnDispatchBadMessage(const Message& message);
313 void OnDispatchAssociatedInterfaceRequest( 333 void OnDispatchAssociatedInterfaceRequest(
314 const std::string& interface_name, 334 const std::string& interface_name,
315 mojo::ScopedInterfaceEndpointHandle handle); 335 mojo::ScopedInterfaceEndpointHandle handle);
316 336
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 bool did_init_; 423 bool did_init_;
404 424
405 #if defined(ENABLE_IPC_FUZZER) 425 #if defined(ENABLE_IPC_FUZZER)
406 OutgoingMessageFilter* outgoing_message_filter_; 426 OutgoingMessageFilter* outgoing_message_filter_;
407 #endif 427 #endif
408 }; 428 };
409 429
410 } // namespace IPC 430 } // namespace IPC
411 431
412 #endif // IPC_IPC_CHANNEL_PROXY_H_ 432 #endif // IPC_IPC_CHANNEL_PROXY_H_
OLDNEW
« no previous file with comments | « content/renderer/render_thread_impl.cc ('k') | mojo/public/cpp/bindings/tests/associated_interface_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698