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

Side by Side Diff: ipc/ipc_channel_factory.cc

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

Powered by Google App Engine
This is Rietveld 408576698