| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/child/npapi/np_channel_base.h" | 5 #include "content/child/npapi/np_channel_base.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/containers/hash_tables.h" | 8 #include "base/containers/hash_tables.h" |
| 9 #include "base/files/scoped_file.h" | 9 #include "base/files/scoped_file.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 } | 61 } |
| 62 | 62 |
| 63 } // namespace | 63 } // namespace |
| 64 | 64 |
| 65 NPChannelBase* NPChannelBase::GetChannel( | 65 NPChannelBase* NPChannelBase::GetChannel( |
| 66 const IPC::ChannelHandle& channel_handle, | 66 const IPC::ChannelHandle& channel_handle, |
| 67 IPC::Channel::Mode mode, | 67 IPC::Channel::Mode mode, |
| 68 ChannelFactory factory, | 68 ChannelFactory factory, |
| 69 base::SingleThreadTaskRunner* ipc_task_runner, | 69 base::SingleThreadTaskRunner* ipc_task_runner, |
| 70 bool create_pipe_now, | 70 bool create_pipe_now, |
| 71 base::WaitableEvent* shutdown_event, | 71 base::WaitableEvent* shutdown_event) { |
| 72 IPC::AttachmentBroker* broker) { | |
| 73 #if defined(OS_POSIX) | 72 #if defined(OS_POSIX) |
| 74 // On POSIX the channel_handle conveys an FD (socket) which is duped by the | 73 // On POSIX the channel_handle conveys an FD (socket) which is duped by the |
| 75 // kernel during the IPC message exchange (via the SCM_RIGHTS mechanism). | 74 // kernel during the IPC message exchange (via the SCM_RIGHTS mechanism). |
| 76 // Ensure we do not leak this FD. | 75 // Ensure we do not leak this FD. |
| 77 base::ScopedFD fd(channel_handle.socket.auto_close ? | 76 base::ScopedFD fd(channel_handle.socket.auto_close ? |
| 78 channel_handle.socket.fd : -1); | 77 channel_handle.socket.fd : -1); |
| 79 #endif | 78 #endif |
| 80 | 79 |
| 81 scoped_refptr<NPChannelBase> channel; | 80 scoped_refptr<NPChannelBase> channel; |
| 82 std::string channel_key = channel_handle.name; | 81 std::string channel_key = channel_handle.name; |
| 83 ChannelMap::const_iterator iter = GetChannelMap()->find(channel_key); | 82 ChannelMap::const_iterator iter = GetChannelMap()->find(channel_key); |
| 84 if (iter == GetChannelMap()->end()) { | 83 if (iter == GetChannelMap()->end()) { |
| 85 channel = factory(); | 84 channel = factory(); |
| 86 } else { | 85 } else { |
| 87 channel = iter->second; | 86 channel = iter->second; |
| 88 } | 87 } |
| 89 | 88 |
| 90 DCHECK(channel.get() != NULL); | 89 DCHECK(channel.get() != NULL); |
| 91 | 90 |
| 92 if (!channel->channel_valid()) { | 91 if (!channel->channel_valid()) { |
| 93 channel->channel_handle_ = channel_handle; | 92 channel->channel_handle_ = channel_handle; |
| 94 #if defined(OS_POSIX) | 93 #if defined(OS_POSIX) |
| 95 ignore_result(fd.release()); | 94 ignore_result(fd.release()); |
| 96 #endif | 95 #endif |
| 97 if (mode & IPC::Channel::MODE_SERVER_FLAG) { | 96 if (mode & IPC::Channel::MODE_SERVER_FLAG) { |
| 98 channel->channel_handle_.name = | 97 channel->channel_handle_.name = |
| 99 IPC::Channel::GenerateVerifiedChannelID(channel_key); | 98 IPC::Channel::GenerateVerifiedChannelID(channel_key); |
| 100 } | 99 } |
| 101 channel->mode_ = mode; | 100 channel->mode_ = mode; |
| 102 if (channel->Init(ipc_task_runner, create_pipe_now, shutdown_event, | 101 if (channel->Init(ipc_task_runner, create_pipe_now, shutdown_event)) { |
| 103 broker)) { | |
| 104 (*GetChannelMap())[channel_key] = channel; | 102 (*GetChannelMap())[channel_key] = channel; |
| 105 } else { | 103 } else { |
| 106 channel = NULL; | 104 channel = NULL; |
| 107 } | 105 } |
| 108 } | 106 } |
| 109 | 107 |
| 110 return channel.get(); | 108 return channel.get(); |
| 111 } | 109 } |
| 112 | 110 |
| 113 void NPChannelBase::Broadcast(IPC::Message* message) { | 111 void NPChannelBase::Broadcast(IPC::Message* message) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 } | 167 } |
| 170 return iter->second; | 168 return iter->second; |
| 171 } | 169 } |
| 172 | 170 |
| 173 base::WaitableEvent* NPChannelBase::GetModalDialogEvent(int render_view_id) { | 171 base::WaitableEvent* NPChannelBase::GetModalDialogEvent(int render_view_id) { |
| 174 return NULL; | 172 return NULL; |
| 175 } | 173 } |
| 176 | 174 |
| 177 bool NPChannelBase::Init(base::SingleThreadTaskRunner* ipc_task_runner, | 175 bool NPChannelBase::Init(base::SingleThreadTaskRunner* ipc_task_runner, |
| 178 bool create_pipe_now, | 176 bool create_pipe_now, |
| 179 base::WaitableEvent* shutdown_event, | 177 base::WaitableEvent* shutdown_event) { |
| 180 IPC::AttachmentBroker* broker) { | |
| 181 #if defined(OS_POSIX) | 178 #if defined(OS_POSIX) |
| 182 // Attempting to initialize with an invalid channel handle. | 179 // Attempting to initialize with an invalid channel handle. |
| 183 // See http://crbug.com/97285 for details. | 180 // See http://crbug.com/97285 for details. |
| 184 if (mode_ == IPC::Channel::MODE_CLIENT && -1 == channel_handle_.socket.fd) | 181 if (mode_ == IPC::Channel::MODE_CLIENT && -1 == channel_handle_.socket.fd) |
| 185 return false; | 182 return false; |
| 186 #endif | 183 #endif |
| 187 | 184 |
| 188 channel_ = | 185 channel_ = |
| 189 IPC::SyncChannel::Create(channel_handle_, mode_, this, ipc_task_runner, | 186 IPC::SyncChannel::Create(channel_handle_, mode_, this, ipc_task_runner, |
| 190 create_pipe_now, shutdown_event, broker); | 187 create_pipe_now, shutdown_event); |
| 191 | 188 |
| 192 #if defined(OS_POSIX) | 189 #if defined(OS_POSIX) |
| 193 // Check the validity of fd for bug investigation. Remove after fixed. | 190 // Check the validity of fd for bug investigation. Remove after fixed. |
| 194 // See crbug.com/97285 for details. | 191 // See crbug.com/97285 for details. |
| 195 if (mode_ == IPC::Channel::MODE_SERVER) | 192 if (mode_ == IPC::Channel::MODE_SERVER) |
| 196 CHECK_NE(-1, channel_->GetClientFileDescriptor()); | 193 CHECK_NE(-1, channel_->GetClientFileDescriptor()); |
| 197 #endif | 194 #endif |
| 198 | 195 |
| 199 channel_valid_ = true; | 196 channel_valid_ = true; |
| 200 return true; | 197 return true; |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 RouteToOwnerMap::iterator iter = route_to_owner_.find(route_id); | 381 RouteToOwnerMap::iterator iter = route_to_owner_.find(route_id); |
| 385 return iter != route_to_owner_.end() ? iter->second : default_owner_; | 382 return iter != route_to_owner_.end() ? iter->second : default_owner_; |
| 386 } | 383 } |
| 387 | 384 |
| 388 int NPChannelBase::GetExistingRouteForNPObjectOwner(NPP owner) { | 385 int NPChannelBase::GetExistingRouteForNPObjectOwner(NPP owner) { |
| 389 OwnerToRouteMap::iterator iter = owner_to_route_.find(owner); | 386 OwnerToRouteMap::iterator iter = owner_to_route_.find(owner); |
| 390 return iter != owner_to_route_.end() ? iter->second : MSG_ROUTING_NONE; | 387 return iter != owner_to_route_.end() ? iter->second : MSG_ROUTING_NONE; |
| 391 } | 388 } |
| 392 | 389 |
| 393 } // namespace content | 390 } // namespace content |
| OLD | NEW |