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

Side by Side Diff: ipc/ipc_channel_factory.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
« no previous file with comments | « content/common/sandbox_mac_system_access_unittest.mm ('k') | ipc/unix_domain_socket_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ipc/ipc_channel_factory.h" 5 #include "ipc/ipc_channel_factory.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_file.h"
9 #include "base/logging.h" 8 #include "base/logging.h"
10 #include "ipc/unix_domain_socket_util.h" 9 #include "ipc/unix_domain_socket_util.h"
11 10
12 namespace IPC { 11 namespace IPC {
13 12
14 ChannelFactory::ChannelFactory(const base::FilePath& path, Delegate* delegate) 13 ChannelFactory::ChannelFactory(const base::FilePath& path, Delegate* delegate)
15 : path_(path), delegate_(delegate), listen_fd_(-1) { 14 : path_(path), delegate_(delegate), listen_fd_(-1) {
16 DCHECK(delegate_); 15 DCHECK(delegate_);
17 CreateSocket(); 16 CreateSocket();
18 } 17 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 delegate_->OnListenError(); 51 delegate_->OnListenError();
53 return; 52 return;
54 } 53 }
55 54
56 if (new_fd < 0) { 55 if (new_fd < 0) {
57 // The accept() failed, but not in such a way that the factory needs to be 56 // The accept() failed, but not in such a way that the factory needs to be
58 // shut down. 57 // shut down.
59 return; 58 return;
60 } 59 }
61 60
62 base::ScopedFD scoped_fd(new_fd); 61 file_util::ScopedFD scoped_fd(&new_fd);
63 62
64 // Verify that the IPC channel peer is running as the same user. 63 // Verify that the IPC channel peer is running as the same user.
65 if (!IsPeerAuthorized(new_fd)) 64 if (!IsPeerAuthorized(new_fd))
66 return; 65 return;
67 66
68 ChannelHandle handle(std::string(), 67 ChannelHandle handle(std::string(),
69 base::FileDescriptor(scoped_fd.release(), true)); 68 base::FileDescriptor(*scoped_fd.release(), true));
70 delegate_->OnClientConnected(handle); 69 delegate_->OnClientConnected(handle);
71 } 70 }
72 71
73 void ChannelFactory::OnFileCanWriteWithoutBlocking(int fd) { 72 void ChannelFactory::OnFileCanWriteWithoutBlocking(int fd) {
74 NOTREACHED() << "Listen fd should never be writable."; 73 NOTREACHED() << "Listen fd should never be writable.";
75 } 74 }
76 75
77 void ChannelFactory::Close() { 76 void ChannelFactory::Close() {
78 if (listen_fd_ < 0) 77 if (listen_fd_ < 0)
79 return; 78 return;
80 if (IGNORE_EINTR(close(listen_fd_)) < 0) 79 if (IGNORE_EINTR(close(listen_fd_)) < 0)
81 PLOG(ERROR) << "close"; 80 PLOG(ERROR) << "close";
82 listen_fd_ = -1; 81 listen_fd_ = -1;
83 if (unlink(path_.value().c_str()) < 0) 82 if (unlink(path_.value().c_str()) < 0)
84 PLOG(ERROR) << "unlink"; 83 PLOG(ERROR) << "unlink";
85 84
86 // Unregister libevent for the listening socket and close it. 85 // Unregister libevent for the listening socket and close it.
87 server_listen_connection_watcher_.StopWatchingFileDescriptor(); 86 server_listen_connection_watcher_.StopWatchingFileDescriptor();
88 } 87 }
89 88
90 } // namespace IPC 89 } // namespace IPC
OLDNEW
« no previous file with comments | « content/common/sandbox_mac_system_access_unittest.mm ('k') | ipc/unix_domain_socket_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698