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

Side by Side Diff: ipc/ipc_message_pipe_reader.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
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_MESSAGE_PIPE_READER_H_ 5 #ifndef IPC_IPC_MESSAGE_PIPE_READER_H_
6 #define IPC_IPC_MESSAGE_PIPE_READER_H_ 6 #define IPC_IPC_MESSAGE_PIPE_READER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/atomicops.h" 13 #include "base/atomicops.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/process/process_handle.h"
16 #include "base/threading/thread_checker.h" 17 #include "base/threading/thread_checker.h"
17 #include "ipc/ipc.mojom.h" 18 #include "ipc/ipc.mojom.h"
18 #include "ipc/ipc_export.h" 19 #include "ipc/ipc_export.h"
19 #include "ipc/ipc_message.h" 20 #include "ipc/ipc_message.h"
20 #include "mojo/public/cpp/bindings/associated_binding.h" 21 #include "mojo/public/cpp/bindings/associated_binding.h"
21 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" 22 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
22 #include "mojo/public/cpp/system/core.h" 23 #include "mojo/public/cpp/system/core.h"
23 #include "mojo/public/cpp/system/message_pipe.h" 24 #include "mojo/public/cpp/system/message_pipe.h"
24 25
25 namespace IPC { 26 namespace IPC {
(...skipping 14 matching lines...) Expand all
40 // The constructor automatically start listening on the pipe. 41 // The constructor automatically start listening on the pipe.
41 // 42 //
42 // All functions must be called on the IO thread, except for Send(), which can 43 // All functions must be called on the IO thread, except for Send(), which can
43 // be called on any thread. All |Delegate| functions will be called on the IO 44 // be called on any thread. All |Delegate| functions will be called on the IO
44 // thread. 45 // thread.
45 // 46 //
46 class IPC_EXPORT MessagePipeReader : public NON_EXPORTED_BASE(mojom::Channel) { 47 class IPC_EXPORT MessagePipeReader : public NON_EXPORTED_BASE(mojom::Channel) {
47 public: 48 public:
48 class Delegate { 49 class Delegate {
49 public: 50 public:
51 virtual void OnPeerPidReceived() = 0;
50 virtual void OnMessageReceived(const Message& message) = 0; 52 virtual void OnMessageReceived(const Message& message) = 0;
51 virtual void OnPipeError() = 0; 53 virtual void OnPipeError() = 0;
52 virtual void OnAssociatedInterfaceRequest( 54 virtual void OnAssociatedInterfaceRequest(
53 const std::string& name, 55 const std::string& name,
54 mojo::ScopedInterfaceEndpointHandle handle) = 0; 56 mojo::ScopedInterfaceEndpointHandle handle) = 0;
55 }; 57 };
56 58
57 // Delay the object deletion using the current message loop. 59 // Delay the object deletion using the current message loop.
58 // This is intended to used by MessagePipeReader owners. 60 // This is intended to used by MessagePipeReader owners.
59 class DelayedDeleter { 61 class DelayedDeleter {
(...skipping 15 matching lines...) Expand all
75 // |pipe| is the message pipe handle corresponding to the channel's master 77 // |pipe| is the message pipe handle corresponding to the channel's master
76 // interface. This is the message pipe underlying both |sender| and 78 // interface. This is the message pipe underlying both |sender| and
77 // |receiver|. 79 // |receiver|.
78 // 80 //
79 // Both |sender| and |receiver| must be non-null. 81 // Both |sender| and |receiver| must be non-null.
80 // 82 //
81 // Note that MessagePipeReader doesn't delete |delegate|. 83 // Note that MessagePipeReader doesn't delete |delegate|.
82 MessagePipeReader(mojo::MessagePipeHandle pipe, 84 MessagePipeReader(mojo::MessagePipeHandle pipe,
83 mojom::ChannelAssociatedPtr sender, 85 mojom::ChannelAssociatedPtr sender,
84 mojo::AssociatedInterfaceRequest<mojom::Channel> receiver, 86 mojo::AssociatedInterfaceRequest<mojom::Channel> receiver,
85 base::ProcessId peer_pid,
86 Delegate* delegate); 87 Delegate* delegate);
87 ~MessagePipeReader() override; 88 ~MessagePipeReader() override;
88 89
89 // Close and destroy the MessagePipe. 90 // Close and destroy the MessagePipe.
90 void Close(); 91 void Close();
91 92
92 // Return true if the MessagePipe is alive. 93 // Return true if the MessagePipe is alive.
93 bool IsValid() { return sender_; } 94 bool IsValid() { return sender_; }
94 95
95 // Sends an IPC::Message to the other end of the pipe. Safe to call from any 96 // Sends an IPC::Message to the other end of the pipe. Safe to call from any
96 // thread. 97 // thread.
97 bool Send(std::unique_ptr<Message> message); 98 bool Send(std::unique_ptr<Message> message);
98 99
99 // Requests an associated interface from the other end of the pipe. 100 // Requests an associated interface from the other end of the pipe.
100 void GetRemoteInterface(const std::string& name, 101 void GetRemoteInterface(const std::string& name,
101 mojo::ScopedInterfaceEndpointHandle handle); 102 mojo::ScopedInterfaceEndpointHandle handle);
102 103
103 base::ProcessId GetPeerPid() const { return peer_pid_; } 104 base::ProcessId GetPeerPid() const { return peer_pid_; }
104 105
105 protected: 106 protected:
106 void OnPipeClosed(); 107 void OnPipeClosed();
107 void OnPipeError(MojoResult error); 108 void OnPipeError(MojoResult error);
108 109
109 private: 110 private:
110 // mojom::Channel: 111 // mojom::Channel:
112 void SetPeerPid(int32_t peer_pid) override;
111 void Receive(mojo::Array<uint8_t> data, 113 void Receive(mojo::Array<uint8_t> data,
112 mojo::Array<mojom::SerializedHandlePtr> handles) override; 114 mojo::Array<mojom::SerializedHandlePtr> handles) override;
113 void GetAssociatedInterface( 115 void GetAssociatedInterface(
114 const mojo::String& name, 116 const mojo::String& name,
115 mojom::GenericInterfaceAssociatedRequest request) override; 117 mojom::GenericInterfaceAssociatedRequest request) override;
116 118
117 // |delegate_| is null once the message pipe is closed. 119 // |delegate_| is null once the message pipe is closed.
118 Delegate* delegate_; 120 Delegate* delegate_;
119 base::ProcessId peer_pid_; 121 base::ProcessId peer_pid_ = base::kNullProcessId;
120 mojom::ChannelAssociatedPtr sender_; 122 mojom::ChannelAssociatedPtr sender_;
121 mojo::AssociatedBinding<mojom::Channel> binding_; 123 mojo::AssociatedBinding<mojom::Channel> binding_;
122 124
123 // Raw message pipe handle and interface ID we use to send legacy IPC messages 125 // Raw message pipe handle and interface ID we use to send legacy IPC messages
124 // over the associated pipe. 126 // over the associated pipe.
125 const uint32_t sender_interface_id_; 127 const uint32_t sender_interface_id_;
126 const mojo::MessagePipeHandle sender_pipe_; 128 const mojo::MessagePipeHandle sender_pipe_;
127 129
128 base::ThreadChecker thread_checker_; 130 base::ThreadChecker thread_checker_;
129 131
130 DISALLOW_COPY_AND_ASSIGN(MessagePipeReader); 132 DISALLOW_COPY_AND_ASSIGN(MessagePipeReader);
131 }; 133 };
132 134
133 } // namespace internal 135 } // namespace internal
134 } // namespace IPC 136 } // namespace IPC
135 137
136 #endif // IPC_IPC_MESSAGE_PIPE_READER_H_ 138 #endif // IPC_IPC_MESSAGE_PIPE_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698