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 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 delete this; | 59 delete this; |
60 } | 60 } |
61 | 61 |
62 //------------------------------------------------------------------------------ | 62 //------------------------------------------------------------------------------ |
63 | 63 |
64 ChannelProxy::Context::Context(Channel::Listener* listener, | 64 ChannelProxy::Context::Context(Channel::Listener* listener, |
65 base::MessageLoopProxy* ipc_message_loop) | 65 base::MessageLoopProxy* ipc_message_loop) |
66 : listener_message_loop_(base::MessageLoopProxy::current()), | 66 : listener_message_loop_(base::MessageLoopProxy::current()), |
67 listener_(listener), | 67 listener_(listener), |
68 ipc_message_loop_(ipc_message_loop), | 68 ipc_message_loop_(ipc_message_loop), |
69 peer_pid_(0), | 69 channel_connected_called_(false), |
70 channel_connected_called_(false) { | 70 peer_pid_(base::kNullProcessId) { |
71 } | 71 } |
72 | 72 |
73 ChannelProxy::Context::~Context() { | 73 ChannelProxy::Context::~Context() { |
74 } | 74 } |
75 | 75 |
76 void ChannelProxy::Context::CreateChannel(const IPC::ChannelHandle& handle, | 76 void ChannelProxy::Context::CreateChannel(const IPC::ChannelHandle& handle, |
77 const Channel::Mode& mode) { | 77 const Channel::Mode& mode) { |
78 DCHECK(channel_.get() == NULL); | 78 DCHECK(channel_.get() == NULL); |
79 channel_id_ = handle.name; | 79 channel_id_ = handle.name; |
80 channel_.reset(new Channel(handle, mode, this)); | 80 channel_.reset(new Channel(handle, mode, this)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 } | 119 } |
120 | 120 |
121 // Called on the IPC::Channel thread | 121 // Called on the IPC::Channel thread |
122 void ChannelProxy::Context::OnChannelConnected(int32 peer_pid) { | 122 void ChannelProxy::Context::OnChannelConnected(int32 peer_pid) { |
123 // Add any pending filters. This avoids a race condition where someone | 123 // Add any pending filters. This avoids a race condition where someone |
124 // creates a ChannelProxy, calls AddFilter, and then right after starts the | 124 // creates a ChannelProxy, calls AddFilter, and then right after starts the |
125 // peer process. The IO thread could receive a message before the task to add | 125 // peer process. The IO thread could receive a message before the task to add |
126 // the filter is run on the IO thread. | 126 // the filter is run on the IO thread. |
127 OnAddFilter(); | 127 OnAddFilter(); |
128 | 128 |
129 peer_pid_ = peer_pid; | 129 // We cache off the peer_pid so it can be safely accessed from both threads. |
130 peer_pid_ = channel_->peer_pid(); | |
130 for (size_t i = 0; i < filters_.size(); ++i) | 131 for (size_t i = 0; i < filters_.size(); ++i) |
131 filters_[i]->OnChannelConnected(peer_pid); | 132 filters_[i]->OnChannelConnected(peer_pid); |
132 | 133 |
133 // See above comment about using listener_message_loop_ here. | 134 // See above comment about using listener_message_loop_ here. |
134 listener_message_loop_->PostTask( | 135 listener_message_loop_->PostTask( |
135 FROM_HERE, base::Bind(&Context::OnDispatchConnected, this)); | 136 FROM_HERE, base::Bind(&Context::OnDispatchConnected, this)); |
136 } | 137 } |
137 | 138 |
138 // Called on the IPC::Channel thread | 139 // Called on the IPC::Channel thread |
139 void ChannelProxy::Context::OnChannelError() { | 140 void ChannelProxy::Context::OnChannelError() { |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 void ChannelProxy::RemoveFilter(MessageFilter* filter) { | 380 void ChannelProxy::RemoveFilter(MessageFilter* filter) { |
380 context_->ipc_message_loop()->PostTask( | 381 context_->ipc_message_loop()->PostTask( |
381 FROM_HERE, base::Bind(&Context::OnRemoveFilter, context_.get(), | 382 FROM_HERE, base::Bind(&Context::OnRemoveFilter, context_.get(), |
382 make_scoped_refptr(filter))); | 383 make_scoped_refptr(filter))); |
383 } | 384 } |
384 | 385 |
385 void ChannelProxy::ClearIPCMessageLoop() { | 386 void ChannelProxy::ClearIPCMessageLoop() { |
386 context()->ClearIPCMessageLoop(); | 387 context()->ClearIPCMessageLoop(); |
387 } | 388 } |
388 | 389 |
390 base::ProcessId ChannelProxy::peer_pid() const { | |
391 return context_.get() ? context_->peer_pid_ : base::kNullProcessId; | |
jam
2012/04/05 00:11:42
are you sure you need to null check context_?
jschuh
2012/04/05 00:23:06
You're right. It's always passed or created in the
| |
392 } | |
393 | |
389 #if defined(OS_POSIX) && !defined(OS_NACL) | 394 #if defined(OS_POSIX) && !defined(OS_NACL) |
390 // See the TODO regarding lazy initialization of the channel in | 395 // See the TODO regarding lazy initialization of the channel in |
391 // ChannelProxy::Init(). | 396 // ChannelProxy::Init(). |
392 int ChannelProxy::GetClientFileDescriptor() { | 397 int ChannelProxy::GetClientFileDescriptor() { |
393 Channel* channel = context_.get()->channel_.get(); | 398 Channel* channel = context_.get()->channel_.get(); |
394 // Channel must have been created first. | 399 // Channel must have been created first. |
395 DCHECK(channel) << context_.get()->channel_id_; | 400 DCHECK(channel) << context_.get()->channel_id_; |
396 return channel->GetClientFileDescriptor(); | 401 return channel->GetClientFileDescriptor(); |
397 } | 402 } |
398 | 403 |
399 int ChannelProxy::TakeClientFileDescriptor() { | 404 int ChannelProxy::TakeClientFileDescriptor() { |
400 Channel* channel = context_.get()->channel_.get(); | 405 Channel* channel = context_.get()->channel_.get(); |
401 // Channel must have been created first. | 406 // Channel must have been created first. |
402 DCHECK(channel) << context_.get()->channel_id_; | 407 DCHECK(channel) << context_.get()->channel_id_; |
403 return channel->TakeClientFileDescriptor(); | 408 return channel->TakeClientFileDescriptor(); |
404 } | 409 } |
405 | 410 |
406 bool ChannelProxy::GetClientEuid(uid_t* client_euid) const { | 411 bool ChannelProxy::GetClientEuid(uid_t* client_euid) const { |
407 Channel* channel = context_.get()->channel_.get(); | 412 Channel* channel = context_.get()->channel_.get(); |
408 // Channel must have been created first. | 413 // Channel must have been created first. |
409 DCHECK(channel) << context_.get()->channel_id_; | 414 DCHECK(channel) << context_.get()->channel_id_; |
410 return channel->GetClientEuid(client_euid); | 415 return channel->GetClientEuid(client_euid); |
411 } | 416 } |
412 #endif | 417 #endif |
413 | 418 |
414 //----------------------------------------------------------------------------- | 419 //----------------------------------------------------------------------------- |
415 | 420 |
416 } // namespace IPC | 421 } // namespace IPC |
OLD | NEW |