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

Side by Side Diff: net/socket/unix_domain_socket_posix.cc

Issue 20142003: Remove ref-counting from StreamListenSocket (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments Created 7 years, 3 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 | « net/socket/unix_domain_socket_posix.h ('k') | net/socket/unix_domain_socket_posix_unittest.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/socket/unix_domain_socket_posix.h" 5 #include "net/socket/unix_domain_socket_posix.h"
6 6
7 #include <cstring> 7 #include <cstring>
8 #include <string> 8 #include <string>
9 9
10 #include <errno.h> 10 #include <errno.h>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 } 47 }
48 48
49 } // namespace 49 } // namespace
50 50
51 // static 51 // static
52 UnixDomainSocket::AuthCallback UnixDomainSocket::NoAuthentication() { 52 UnixDomainSocket::AuthCallback UnixDomainSocket::NoAuthentication() {
53 return base::Bind(NoAuthenticationCallback); 53 return base::Bind(NoAuthenticationCallback);
54 } 54 }
55 55
56 // static 56 // static
57 UnixDomainSocket* UnixDomainSocket::CreateAndListenInternal( 57 scoped_ptr<UnixDomainSocket> UnixDomainSocket::CreateAndListenInternal(
58 const std::string& path, 58 const std::string& path,
59 const std::string& fallback_path, 59 const std::string& fallback_path,
60 StreamListenSocket::Delegate* del, 60 StreamListenSocket::Delegate* del,
61 const AuthCallback& auth_callback, 61 const AuthCallback& auth_callback,
62 bool use_abstract_namespace) { 62 bool use_abstract_namespace) {
63 SocketDescriptor s = CreateAndBind(path, use_abstract_namespace); 63 SocketDescriptor s = CreateAndBind(path, use_abstract_namespace);
64 if (s == kInvalidSocket && !fallback_path.empty()) 64 if (s == kInvalidSocket && !fallback_path.empty())
65 s = CreateAndBind(fallback_path, use_abstract_namespace); 65 s = CreateAndBind(fallback_path, use_abstract_namespace);
66 if (s == kInvalidSocket) 66 if (s == kInvalidSocket)
67 return NULL; 67 return scoped_ptr<UnixDomainSocket>();
68 UnixDomainSocket* sock = new UnixDomainSocket(s, del, auth_callback); 68 scoped_ptr<UnixDomainSocket> sock(
69 new UnixDomainSocket(s, del, auth_callback));
69 sock->Listen(); 70 sock->Listen();
70 return sock; 71 return sock.Pass();
71 } 72 }
72 73
73 // static 74 // static
74 scoped_refptr<UnixDomainSocket> UnixDomainSocket::CreateAndListen( 75 scoped_ptr<UnixDomainSocket> UnixDomainSocket::CreateAndListen(
75 const std::string& path, 76 const std::string& path,
76 StreamListenSocket::Delegate* del, 77 StreamListenSocket::Delegate* del,
77 const AuthCallback& auth_callback) { 78 const AuthCallback& auth_callback) {
78 return CreateAndListenInternal(path, "", del, auth_callback, false); 79 return CreateAndListenInternal(path, "", del, auth_callback, false);
79 } 80 }
80 81
81 #if defined(SOCKET_ABSTRACT_NAMESPACE_SUPPORTED) 82 #if defined(SOCKET_ABSTRACT_NAMESPACE_SUPPORTED)
82 // static 83 // static
83 scoped_refptr<UnixDomainSocket> 84 scoped_ptr<UnixDomainSocket>
84 UnixDomainSocket::CreateAndListenWithAbstractNamespace( 85 UnixDomainSocket::CreateAndListenWithAbstractNamespace(
85 const std::string& path, 86 const std::string& path,
86 const std::string& fallback_path, 87 const std::string& fallback_path,
87 StreamListenSocket::Delegate* del, 88 StreamListenSocket::Delegate* del,
88 const AuthCallback& auth_callback) { 89 const AuthCallback& auth_callback) {
89 return make_scoped_refptr( 90 return
90 CreateAndListenInternal(path, fallback_path, del, auth_callback, true)); 91 CreateAndListenInternal(path, fallback_path, del, auth_callback, true);
91 } 92 }
92 #endif 93 #endif
93 94
94 UnixDomainSocket::UnixDomainSocket( 95 UnixDomainSocket::UnixDomainSocket(
95 SocketDescriptor s, 96 SocketDescriptor s,
96 StreamListenSocket::Delegate* del, 97 StreamListenSocket::Delegate* del,
97 const AuthCallback& auth_callback) 98 const AuthCallback& auth_callback)
98 : StreamListenSocket(s, del), 99 : StreamListenSocket(s, del),
99 auth_callback_(auth_callback) {} 100 auth_callback_(auth_callback) {}
100 101
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 if (conn == kInvalidSocket) 142 if (conn == kInvalidSocket)
142 return; 143 return;
143 uid_t user_id; 144 uid_t user_id;
144 gid_t group_id; 145 gid_t group_id;
145 if (!GetPeerIds(conn, &user_id, &group_id) || 146 if (!GetPeerIds(conn, &user_id, &group_id) ||
146 !auth_callback_.Run(user_id, group_id)) { 147 !auth_callback_.Run(user_id, group_id)) {
147 if (HANDLE_EINTR(close(conn)) < 0) 148 if (HANDLE_EINTR(close(conn)) < 0)
148 LOG(ERROR) << "close() error"; 149 LOG(ERROR) << "close() error";
149 return; 150 return;
150 } 151 }
151 scoped_refptr<UnixDomainSocket> sock( 152 scoped_ptr<UnixDomainSocket> sock(
152 new UnixDomainSocket(conn, socket_delegate_, auth_callback_)); 153 new UnixDomainSocket(conn, socket_delegate_, auth_callback_));
153 // It's up to the delegate to AddRef if it wants to keep it around. 154 // It's up to the delegate to AddRef if it wants to keep it around.
154 sock->WatchSocket(WAITING_READ); 155 sock->WatchSocket(WAITING_READ);
155 socket_delegate_->DidAccept(this, sock.get()); 156 socket_delegate_->DidAccept(this, sock.PassAs<StreamListenSocket>());
156 } 157 }
157 158
158 UnixDomainSocketFactory::UnixDomainSocketFactory( 159 UnixDomainSocketFactory::UnixDomainSocketFactory(
159 const std::string& path, 160 const std::string& path,
160 const UnixDomainSocket::AuthCallback& auth_callback) 161 const UnixDomainSocket::AuthCallback& auth_callback)
161 : path_(path), 162 : path_(path),
162 auth_callback_(auth_callback) {} 163 auth_callback_(auth_callback) {}
163 164
164 UnixDomainSocketFactory::~UnixDomainSocketFactory() {} 165 UnixDomainSocketFactory::~UnixDomainSocketFactory() {}
165 166
166 scoped_refptr<StreamListenSocket> UnixDomainSocketFactory::CreateAndListen( 167 scoped_ptr<StreamListenSocket> UnixDomainSocketFactory::CreateAndListen(
167 StreamListenSocket::Delegate* delegate) const { 168 StreamListenSocket::Delegate* delegate) const {
168 return UnixDomainSocket::CreateAndListen( 169 return UnixDomainSocket::CreateAndListen(
169 path_, delegate, auth_callback_); 170 path_, delegate, auth_callback_).PassAs<StreamListenSocket>();
170 } 171 }
171 172
172 #if defined(SOCKET_ABSTRACT_NAMESPACE_SUPPORTED) 173 #if defined(SOCKET_ABSTRACT_NAMESPACE_SUPPORTED)
173 174
174 UnixDomainSocketWithAbstractNamespaceFactory:: 175 UnixDomainSocketWithAbstractNamespaceFactory::
175 UnixDomainSocketWithAbstractNamespaceFactory( 176 UnixDomainSocketWithAbstractNamespaceFactory(
176 const std::string& path, 177 const std::string& path,
177 const std::string& fallback_path, 178 const std::string& fallback_path,
178 const UnixDomainSocket::AuthCallback& auth_callback) 179 const UnixDomainSocket::AuthCallback& auth_callback)
179 : UnixDomainSocketFactory(path, auth_callback), 180 : UnixDomainSocketFactory(path, auth_callback),
180 fallback_path_(fallback_path) {} 181 fallback_path_(fallback_path) {}
181 182
182 UnixDomainSocketWithAbstractNamespaceFactory:: 183 UnixDomainSocketWithAbstractNamespaceFactory::
183 ~UnixDomainSocketWithAbstractNamespaceFactory() {} 184 ~UnixDomainSocketWithAbstractNamespaceFactory() {}
184 185
185 scoped_refptr<StreamListenSocket> 186 scoped_ptr<StreamListenSocket>
186 UnixDomainSocketWithAbstractNamespaceFactory::CreateAndListen( 187 UnixDomainSocketWithAbstractNamespaceFactory::CreateAndListen(
187 StreamListenSocket::Delegate* delegate) const { 188 StreamListenSocket::Delegate* delegate) const {
188 return UnixDomainSocket::CreateAndListenWithAbstractNamespace( 189 return UnixDomainSocket::CreateAndListenWithAbstractNamespace(
189 path_, fallback_path_, delegate, auth_callback_); 190 path_, fallback_path_, delegate, auth_callback_)
191 .PassAs<StreamListenSocket>();
190 } 192 }
191 193
192 #endif 194 #endif
193 195
194 } // namespace net 196 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/unix_domain_socket_posix.h ('k') | net/socket/unix_domain_socket_posix_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698