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

Side by Side Diff: shell/incoming_connection_listener_posix.cc

Issue 775343004: Move //mojo/shell to //shell (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "mojo/shell/incoming_connection_listener_posix.h" 5 #include "shell/incoming_connection_listener_posix.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/sequenced_task_runner.h" 12 #include "base/sequenced_task_runner.h"
13 #include "base/tracked_objects.h" 13 #include "base/tracked_objects.h"
14 #include "mojo/shell/domain_socket/net_errors.h" 14 #include "shell/domain_socket/net_errors.h"
15 #include "mojo/shell/domain_socket/socket_descriptor.h" 15 #include "shell/domain_socket/socket_descriptor.h"
16 #include "mojo/shell/domain_socket/unix_domain_server_socket_posix.h" 16 #include "shell/domain_socket/unix_domain_server_socket_posix.h"
17 17
18 namespace mojo { 18 namespace mojo {
19 namespace shell { 19 namespace shell {
20 20
21 namespace { 21 namespace {
22 // TODO(cmasone): Figure out what we should be doing about "authenticating" the 22 // TODO(cmasone): Figure out what we should be doing about "authenticating" the
23 // process trying to connect. 23 // process trying to connect.
24 bool Yes(const UnixDomainServerSocket::Credentials& ignored) { 24 bool Yes(const UnixDomainServerSocket::Credentials& ignored) {
25 return true; 25 return true;
26 } 26 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // Call OnListening() before Accept(), so that the delegate is certain to 64 // Call OnListening() before Accept(), so that the delegate is certain to
65 // hear about listening before a connection might be accepted below. 65 // hear about listening before a connection might be accepted below.
66 delegate_->OnListening(rv); 66 delegate_->OnListening(rv);
67 if (rv == net::OK) 67 if (rv == net::OK)
68 Accept(); 68 Accept();
69 } 69 }
70 70
71 void IncomingConnectionListenerPosix::Accept() { 71 void IncomingConnectionListenerPosix::Accept() {
72 DCHECK(listen_thread_checker_.CalledOnValidThread()); 72 DCHECK(listen_thread_checker_.CalledOnValidThread());
73 int rv = listen_socket_.Accept( 73 int rv = listen_socket_.Accept(
74 &incoming_socket_, 74 &incoming_socket_, base::Bind(&IncomingConnectionListenerPosix::OnAccept,
75 base::Bind(&IncomingConnectionListenerPosix::OnAccept, 75 weak_ptr_factory_.GetWeakPtr()));
76 weak_ptr_factory_.GetWeakPtr()));
77 76
78 // If rv == net::ERR_IO_PENDING), listen_socket_ will call 77 // If rv == net::ERR_IO_PENDING), listen_socket_ will call
79 // OnAccept() later, when a connection attempt comes in. 78 // OnAccept() later, when a connection attempt comes in.
80 if (rv != net::ERR_IO_PENDING) { 79 if (rv != net::ERR_IO_PENDING) {
81 DVLOG_IF(1, rv == net::OK) << "Accept succeeded immediately"; 80 DVLOG_IF(1, rv == net::OK) << "Accept succeeded immediately";
82 OnAccept(rv); 81 OnAccept(rv);
83 } 82 }
84 } 83 }
85 84
86 void IncomingConnectionListenerPosix::OnAccept(int rv) { 85 void IncomingConnectionListenerPosix::OnAccept(int rv) {
87 DCHECK(listen_thread_checker_.CalledOnValidThread()); 86 DCHECK(listen_thread_checker_.CalledOnValidThread());
88 87
89 if (rv != net::OK || incoming_socket_ == kInvalidSocket) { 88 if (rv != net::OK || incoming_socket_ == kInvalidSocket) {
90 LOG_IF(ERROR, rv != net::OK) << "Accept failed " << net::ErrorToString(rv); 89 LOG_IF(ERROR, rv != net::OK) << "Accept failed " << net::ErrorToString(rv);
91 PLOG_IF(ERROR, rv == net::OK) << "Socket invalid"; 90 PLOG_IF(ERROR, rv == net::OK) << "Socket invalid";
92 } else { 91 } else {
93 // Passes ownership of incoming_socket_ to delegate_. 92 // Passes ownership of incoming_socket_ to delegate_.
94 delegate_->OnConnection(incoming_socket_); 93 delegate_->OnConnection(incoming_socket_);
95 incoming_socket_ = kInvalidSocket; 94 incoming_socket_ = kInvalidSocket;
96 } 95 }
97 96
98 // Continue waiting to accept incoming connections... 97 // Continue waiting to accept incoming connections...
99 Accept(); 98 Accept();
100 } 99 }
101 100
102 } // namespace shell 101 } // namespace shell
103 } // namespace mojo 102 } // namespace mojo
OLDNEW
« no previous file with comments | « shell/incoming_connection_listener_posix.h ('k') | shell/incoming_connection_listener_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698