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/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
10 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
11 #include "base/threading/thread_local.h" | 12 #include "base/threading/thread_local.h" |
12 #include "ipc/ipc_sync_message.h" | 13 #include "ipc/ipc_sync_message.h" |
13 | 14 |
14 #if defined(OS_POSIX) | 15 #if defined(OS_POSIX) |
15 #include "base/file_util.h" | 16 #include "base/file_util.h" |
16 #include "ipc/ipc_channel_posix.h" | 17 #include "ipc/ipc_channel_posix.h" |
17 #endif | 18 #endif |
18 | 19 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 } // namespace | 62 } // namespace |
62 | 63 |
63 NPChannelBase* NPChannelBase::GetChannel( | 64 NPChannelBase* NPChannelBase::GetChannel( |
64 const IPC::ChannelHandle& channel_handle, IPC::Channel::Mode mode, | 65 const IPC::ChannelHandle& channel_handle, IPC::Channel::Mode mode, |
65 ChannelFactory factory, base::MessageLoopProxy* ipc_message_loop, | 66 ChannelFactory factory, base::MessageLoopProxy* ipc_message_loop, |
66 bool create_pipe_now, base::WaitableEvent* shutdown_event) { | 67 bool create_pipe_now, base::WaitableEvent* shutdown_event) { |
67 #if defined(OS_POSIX) | 68 #if defined(OS_POSIX) |
68 // On POSIX the channel_handle conveys an FD (socket) which is duped by the | 69 // On POSIX the channel_handle conveys an FD (socket) which is duped by the |
69 // kernel during the IPC message exchange (via the SCM_RIGHTS mechanism). | 70 // kernel during the IPC message exchange (via the SCM_RIGHTS mechanism). |
70 // Ensure we do not leak this FD. | 71 // Ensure we do not leak this FD. |
71 int fd = channel_handle.socket.auto_close ? channel_handle.socket.fd : -1; | 72 base::ScopedFD fd(channel_handle.socket.auto_close ? |
72 file_util::ScopedFD auto_close_fd(&fd); | 73 channel_handle.socket.fd : -1); |
73 #endif | 74 #endif |
74 | 75 |
75 scoped_refptr<NPChannelBase> channel; | 76 scoped_refptr<NPChannelBase> channel; |
76 std::string channel_key = channel_handle.name; | 77 std::string channel_key = channel_handle.name; |
77 ChannelMap::const_iterator iter = GetChannelMap()->find(channel_key); | 78 ChannelMap::const_iterator iter = GetChannelMap()->find(channel_key); |
78 if (iter == GetChannelMap()->end()) { | 79 if (iter == GetChannelMap()->end()) { |
79 channel = factory(); | 80 channel = factory(); |
80 } else { | 81 } else { |
81 channel = iter->second; | 82 channel = iter->second; |
82 } | 83 } |
83 | 84 |
84 DCHECK(channel.get() != NULL); | 85 DCHECK(channel.get() != NULL); |
85 | 86 |
86 if (!channel->channel_valid()) { | 87 if (!channel->channel_valid()) { |
87 channel->channel_handle_ = channel_handle; | 88 channel->channel_handle_ = channel_handle; |
88 #if defined(OS_POSIX) | 89 #if defined(OS_POSIX) |
89 ignore_result(auto_close_fd.release()); | 90 ignore_result(fd.release()); |
90 #endif | 91 #endif |
91 if (mode & IPC::Channel::MODE_SERVER_FLAG) { | 92 if (mode & IPC::Channel::MODE_SERVER_FLAG) { |
92 channel->channel_handle_.name = | 93 channel->channel_handle_.name = |
93 IPC::Channel::GenerateVerifiedChannelID(channel_key); | 94 IPC::Channel::GenerateVerifiedChannelID(channel_key); |
94 } | 95 } |
95 channel->mode_ = mode; | 96 channel->mode_ = mode; |
96 if (channel->Init(ipc_message_loop, create_pipe_now, shutdown_event)) { | 97 if (channel->Init(ipc_message_loop, create_pipe_now, shutdown_event)) { |
97 (*GetChannelMap())[channel_key] = channel; | 98 (*GetChannelMap())[channel_key] = channel; |
98 } else { | 99 } else { |
99 channel = NULL; | 100 channel = NULL; |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 RouteToOwnerMap::iterator iter = route_to_owner_.find(route_id); | 377 RouteToOwnerMap::iterator iter = route_to_owner_.find(route_id); |
377 return iter != route_to_owner_.end() ? iter->second : default_owner_; | 378 return iter != route_to_owner_.end() ? iter->second : default_owner_; |
378 } | 379 } |
379 | 380 |
380 int NPChannelBase::GetExistingRouteForNPObjectOwner(NPP owner) { | 381 int NPChannelBase::GetExistingRouteForNPObjectOwner(NPP owner) { |
381 OwnerToRouteMap::iterator iter = owner_to_route_.find(owner); | 382 OwnerToRouteMap::iterator iter = owner_to_route_.find(owner); |
382 return iter != owner_to_route_.end() ? iter->second : MSG_ROUTING_NONE; | 383 return iter != owner_to_route_.end() ? iter->second : MSG_ROUTING_NONE; |
383 } | 384 } |
384 | 385 |
385 } // namespace content | 386 } // namespace content |
OLD | NEW |