OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 void AddFilter(MessageFilter* filter); | 161 void AddFilter(MessageFilter* filter); |
162 void RemoveFilter(MessageFilter* filter); | 162 void RemoveFilter(MessageFilter* filter); |
163 | 163 |
164 void set_outgoing_message_filter(OutgoingMessageFilter* filter) { | 164 void set_outgoing_message_filter(OutgoingMessageFilter* filter) { |
165 outgoing_message_filter_ = filter; | 165 outgoing_message_filter_ = filter; |
166 } | 166 } |
167 | 167 |
168 // Called to clear the pointer to the IPC message loop when it's going away. | 168 // Called to clear the pointer to the IPC message loop when it's going away. |
169 void ClearIPCMessageLoop(); | 169 void ClearIPCMessageLoop(); |
170 | 170 |
| 171 // Get the process ID for the connected peer. |
| 172 // Returns base::kNullProcessId if the peer is not connected yet. |
| 173 base::ProcessId peer_pid() const { return context_->peer_pid_; } |
| 174 |
171 #if defined(OS_POSIX) | 175 #if defined(OS_POSIX) |
172 // Calls through to the underlying channel's methods. | 176 // Calls through to the underlying channel's methods. |
173 int GetClientFileDescriptor(); | 177 int GetClientFileDescriptor(); |
174 int TakeClientFileDescriptor(); | 178 int TakeClientFileDescriptor(); |
175 bool GetClientEuid(uid_t* client_euid) const; | 179 bool GetClientEuid(uid_t* client_euid) const; |
176 #endif // defined(OS_POSIX) | 180 #endif // defined(OS_POSIX) |
177 | 181 |
178 protected: | 182 protected: |
179 class Context; | 183 class Context; |
180 // A subclass uses this constructor if it needs to add more information | 184 // A subclass uses this constructor if it needs to add more information |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 void OnDispatchError(); | 243 void OnDispatchError(); |
240 | 244 |
241 scoped_refptr<base::MessageLoopProxy> listener_message_loop_; | 245 scoped_refptr<base::MessageLoopProxy> listener_message_loop_; |
242 Channel::Listener* listener_; | 246 Channel::Listener* listener_; |
243 | 247 |
244 // List of filters. This is only accessed on the IPC thread. | 248 // List of filters. This is only accessed on the IPC thread. |
245 std::vector<scoped_refptr<MessageFilter> > filters_; | 249 std::vector<scoped_refptr<MessageFilter> > filters_; |
246 scoped_refptr<base::MessageLoopProxy> ipc_message_loop_; | 250 scoped_refptr<base::MessageLoopProxy> ipc_message_loop_; |
247 scoped_ptr<Channel> channel_; | 251 scoped_ptr<Channel> channel_; |
248 std::string channel_id_; | 252 std::string channel_id_; |
249 int peer_pid_; | |
250 bool channel_connected_called_; | 253 bool channel_connected_called_; |
251 | 254 |
252 // Holds filters between the AddFilter call on the listerner thread and the | 255 // Holds filters between the AddFilter call on the listerner thread and the |
253 // IPC thread when they're added to filters_. | 256 // IPC thread when they're added to filters_. |
254 std::vector<scoped_refptr<MessageFilter> > pending_filters_; | 257 std::vector<scoped_refptr<MessageFilter> > pending_filters_; |
255 // Lock for pending_filters_. | 258 // Lock for pending_filters_. |
256 base::Lock pending_filters_lock_; | 259 base::Lock pending_filters_lock_; |
| 260 |
| 261 // Cached copy of the peer process ID. Set on IPC but read on both IPC and |
| 262 // listener threads. |
| 263 base::ProcessId peer_pid_; |
257 }; | 264 }; |
258 | 265 |
259 Context* context() { return context_; } | 266 Context* context() { return context_; } |
260 | 267 |
261 OutgoingMessageFilter* outgoing_message_filter() { | 268 OutgoingMessageFilter* outgoing_message_filter() { |
262 return outgoing_message_filter_; | 269 return outgoing_message_filter_; |
263 } | 270 } |
264 | 271 |
265 private: | 272 private: |
266 friend class SendCallbackHelper; | 273 friend class SendCallbackHelper; |
267 | 274 |
268 // By maintaining this indirection (ref-counted) to our internal state, we | 275 // By maintaining this indirection (ref-counted) to our internal state, we |
269 // can safely be destroyed while the background thread continues to do stuff | 276 // can safely be destroyed while the background thread continues to do stuff |
270 // that involves this data. | 277 // that involves this data. |
271 scoped_refptr<Context> context_; | 278 scoped_refptr<Context> context_; |
272 | 279 |
273 OutgoingMessageFilter* outgoing_message_filter_; | 280 OutgoingMessageFilter* outgoing_message_filter_; |
274 | 281 |
275 // Whether the channel has been initialized. | 282 // Whether the channel has been initialized. |
276 bool did_init_; | 283 bool did_init_; |
277 }; | 284 }; |
278 | 285 |
279 } // namespace IPC | 286 } // namespace IPC |
280 | 287 |
281 #endif // IPC_IPC_CHANNEL_PROXY_H_ | 288 #endif // IPC_IPC_CHANNEL_PROXY_H_ |
OLD | NEW |