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

Side by Side Diff: ipc/ipc_channel_mojo.h

Issue 2668153003: Mojo C++ Bindings: Eliminate unbound ThreadSafeInterfacePtr (Closed)
Patch Set: format and rebase... Created 3 years, 10 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>
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_vector.h" 17 #include "base/memory/scoped_vector.h"
18 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
19 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
20 #include "base/synchronization/lock.h" 20 #include "base/synchronization/lock.h"
21 #include "base/task_runner.h" 21 #include "base/task_runner.h"
22 #include "base/threading/thread_task_runner_handle.h" 22 #include "base/threading/thread_task_runner_handle.h"
23 #include "build/build_config.h" 23 #include "build/build_config.h"
24 #include "ipc/ipc.mojom.h"
24 #include "ipc/ipc_channel.h" 25 #include "ipc/ipc_channel.h"
25 #include "ipc/ipc_channel_factory.h" 26 #include "ipc/ipc_channel_factory.h"
26 #include "ipc/ipc_export.h" 27 #include "ipc/ipc_export.h"
27 #include "ipc/ipc_message_pipe_reader.h" 28 #include "ipc/ipc_message_pipe_reader.h"
28 #include "ipc/ipc_mojo_bootstrap.h" 29 #include "ipc/ipc_mojo_bootstrap.h"
30 #include "mojo/public/cpp/bindings/thread_safe_interface_ptr.h"
29 #include "mojo/public/cpp/system/core.h" 31 #include "mojo/public/cpp/system/core.h"
30 32
31 namespace IPC { 33 namespace IPC {
32 34
33 // Mojo-based IPC::Channel implementation over a Mojo message pipe. 35 // Mojo-based IPC::Channel implementation over a Mojo message pipe.
34 // 36 //
35 // ChannelMojo builds a Mojo MessagePipe using the provided message pipe 37 // ChannelMojo builds a Mojo MessagePipe using the provided message pipe
36 // |handle| and builds an associated interface for each direction on the 38 // |handle| and builds an associated interface for each direction on the
37 // channel. 39 // channel.
38 // 40 //
39 // TODO(morrita): Add APIs to create extra MessagePipes to let 41 // TODO(morrita): Add APIs to create extra MessagePipes to let
40 // Mojo-based objects talk over this Channel. 42 // Mojo-based objects talk over this Channel.
41 // 43 //
42 class IPC_EXPORT ChannelMojo 44 class IPC_EXPORT ChannelMojo
43 : public Channel, 45 : public Channel,
44 public Channel::AssociatedInterfaceSupport, 46 public Channel::AssociatedInterfaceSupport,
45 public NON_EXPORTED_BASE(MojoBootstrap::Delegate),
46 public NON_EXPORTED_BASE(internal::MessagePipeReader::Delegate) { 47 public NON_EXPORTED_BASE(internal::MessagePipeReader::Delegate) {
47 public: 48 public:
48 // Creates a ChannelMojo. 49 // Creates a ChannelMojo.
49 static std::unique_ptr<ChannelMojo> 50 static std::unique_ptr<ChannelMojo>
50 Create(mojo::ScopedMessagePipeHandle handle, 51 Create(mojo::ScopedMessagePipeHandle handle,
51 Mode mode, 52 Mode mode,
52 Listener* listener, 53 Listener* listener,
53 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner = 54 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner =
54 base::ThreadTaskRunnerHandle::Get()); 55 base::ThreadTaskRunnerHandle::Get());
55 56
(...skipping 21 matching lines...) Expand all
77 78
78 // These access protected API of IPC::Message, which has ChannelMojo 79 // These access protected API of IPC::Message, which has ChannelMojo
79 // as a friend class. 80 // as a friend class.
80 static MojoResult WriteToMessageAttachmentSet( 81 static MojoResult WriteToMessageAttachmentSet(
81 base::Optional<std::vector<mojom::SerializedHandlePtr>> handle_buffer, 82 base::Optional<std::vector<mojom::SerializedHandlePtr>> handle_buffer,
82 Message* message); 83 Message* message);
83 static MojoResult ReadFromMessageAttachmentSet( 84 static MojoResult ReadFromMessageAttachmentSet(
84 Message* message, 85 Message* message,
85 base::Optional<std::vector<mojom::SerializedHandlePtr>>* handles); 86 base::Optional<std::vector<mojom::SerializedHandlePtr>>* handles);
86 87
87 // MojoBootstrapDelegate implementation
88 void OnPipesAvailable(mojom::ChannelAssociatedPtr sender,
89 mojom::ChannelAssociatedRequest receiver) override;
90
91 // MessagePipeReader::Delegate 88 // MessagePipeReader::Delegate
92 void OnPeerPidReceived(int32_t peer_pid) override; 89 void OnPeerPidReceived(int32_t peer_pid) override;
93 void OnMessageReceived(const Message& message) override; 90 void OnMessageReceived(const Message& message) override;
94 void OnPipeError() override; 91 void OnPipeError() override;
95 void OnAssociatedInterfaceRequest( 92 void OnAssociatedInterfaceRequest(
96 const std::string& name, 93 const std::string& name,
97 mojo::ScopedInterfaceEndpointHandle handle) override; 94 mojo::ScopedInterfaceEndpointHandle handle) override;
98 95
99 private: 96 private:
100 ChannelMojo( 97 ChannelMojo(
101 mojo::ScopedMessagePipeHandle handle, 98 mojo::ScopedMessagePipeHandle handle,
102 Mode mode, 99 Mode mode,
103 Listener* listener, 100 Listener* listener,
104 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner); 101 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner);
105 102
103 void ForwardMessageFromThreadSafePtr(mojo::Message message);
104 void ForwardMessageWithResponderFromThreadSafePtr(
105 mojo::Message message,
106 std::unique_ptr<mojo::MessageReceiver> responder);
107
106 // Channel::AssociatedInterfaceSupport: 108 // Channel::AssociatedInterfaceSupport:
107 mojo::AssociatedGroup* GetAssociatedGroup() override; 109 mojo::AssociatedGroup* GetAssociatedGroup() override;
110 std::unique_ptr<mojo::ThreadSafeForwarder<mojom::Channel>>
111 CreateThreadSafeChannel() override;
108 void AddGenericAssociatedInterface( 112 void AddGenericAssociatedInterface(
109 const std::string& name, 113 const std::string& name,
110 const GenericAssociatedInterfaceFactory& factory) override; 114 const GenericAssociatedInterfaceFactory& factory) override;
111 void GetGenericRemoteAssociatedInterface( 115 void GetGenericRemoteAssociatedInterface(
112 const std::string& name, 116 const std::string& name,
113 mojo::ScopedInterfaceEndpointHandle handle) override; 117 mojo::ScopedInterfaceEndpointHandle handle) override;
114 118
115 // A TaskRunner which runs tasks on the ChannelMojo's owning thread. 119 // A TaskRunner which runs tasks on the ChannelMojo's owning thread.
116 scoped_refptr<base::TaskRunner> task_runner_; 120 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
117 121
118 const mojo::MessagePipeHandle pipe_; 122 const mojo::MessagePipeHandle pipe_;
119 std::unique_ptr<MojoBootstrap> bootstrap_; 123 std::unique_ptr<MojoBootstrap> bootstrap_;
120 Listener* listener_; 124 Listener* listener_;
121 125
122 std::unique_ptr<internal::MessagePipeReader> message_reader_; 126 std::unique_ptr<internal::MessagePipeReader> message_reader_;
123 127
124 base::Lock associated_interface_lock_; 128 base::Lock associated_interface_lock_;
125 std::map<std::string, GenericAssociatedInterfaceFactory> 129 std::map<std::string, GenericAssociatedInterfaceFactory>
126 associated_interfaces_; 130 associated_interfaces_;
127 131
128 base::WeakPtrFactory<ChannelMojo> weak_factory_; 132 base::WeakPtrFactory<ChannelMojo> weak_factory_;
129 133
130 DISALLOW_COPY_AND_ASSIGN(ChannelMojo); 134 DISALLOW_COPY_AND_ASSIGN(ChannelMojo);
131 }; 135 };
132 136
133 } // namespace IPC 137 } // namespace IPC
134 138
135 #endif // IPC_IPC_CHANNEL_MOJO_H_ 139 #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