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

Side by Side Diff: content/child/npapi/np_channel_base.cc

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

Powered by Google App Engine
This is Rietveld 408576698