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

Side by Side Diff: shell/external_application_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/external_application_listener_posix.h" 5 #include "shell/external_application_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/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/sequenced_task_runner.h" 14 #include "base/sequenced_task_runner.h"
15 #include "base/synchronization/waitable_event.h" 15 #include "base/synchronization/waitable_event.h"
16 #include "base/threading/thread_checker.h" 16 #include "base/threading/thread_checker.h"
17 #include "base/tracked_objects.h" 17 #include "base/tracked_objects.h"
18 #include "mojo/common/common_type_converters.h" 18 #include "mojo/common/common_type_converters.h"
19 #include "mojo/edk/embedder/channel_init.h" 19 #include "mojo/edk/embedder/channel_init.h"
20 #include "mojo/public/cpp/bindings/error_handler.h" 20 #include "mojo/public/cpp/bindings/error_handler.h"
21 #include "mojo/shell/domain_socket/net_errors.h" 21 #include "shell/domain_socket/net_errors.h"
22 #include "mojo/shell/domain_socket/socket_descriptor.h" 22 #include "shell/domain_socket/socket_descriptor.h"
23 #include "mojo/shell/external_application_registrar.mojom.h" 23 #include "shell/external_application_registrar.mojom.h"
24 #include "mojo/shell/incoming_connection_listener_posix.h" 24 #include "shell/incoming_connection_listener_posix.h"
25 #include "url/gurl.h" 25 #include "url/gurl.h"
26 26
27 namespace mojo { 27 namespace mojo {
28 namespace shell { 28 namespace shell {
29 29
30 namespace { 30 namespace {
31 const char kDefaultListenSocketPath[] = "/var/run/mojo/system_socket"; 31 const char kDefaultListenSocketPath[] = "/var/run/mojo/system_socket";
32 } // namespace 32 } // namespace
33 33
34 // static 34 // static
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 } 75 }
76 76
77 ExternalApplicationListenerPosix::~ExternalApplicationListenerPosix() { 77 ExternalApplicationListenerPosix::~ExternalApplicationListenerPosix() {
78 DCHECK(register_thread_checker_.CalledOnValidThread()); 78 DCHECK(register_thread_checker_.CalledOnValidThread());
79 weak_ptr_factory_.InvalidateWeakPtrs(); 79 weak_ptr_factory_.InvalidateWeakPtrs();
80 80
81 // listener_ needs to be destroyed on io_runner_, and it has to die before 81 // listener_ needs to be destroyed on io_runner_, and it has to die before
82 // this object does, as it holds a pointer back to this instance. 82 // this object does, as it holds a pointer back to this instance.
83 base::WaitableEvent stop_listening_event(true, false); 83 base::WaitableEvent stop_listening_event(true, false);
84 io_runner_->PostTask( 84 io_runner_->PostTask(
85 FROM_HERE, 85 FROM_HERE, base::Bind(&ExternalApplicationListenerPosix::StopListening,
86 base::Bind(&ExternalApplicationListenerPosix::StopListening, 86 base::Unretained(this), &stop_listening_event));
87 base::Unretained(this),
88 &stop_listening_event));
89 stop_listening_event.Wait(); 87 stop_listening_event.Wait();
90 } 88 }
91 89
92 void ExternalApplicationListenerPosix::ListenInBackground( 90 void ExternalApplicationListenerPosix::ListenInBackground(
93 const base::FilePath& listen_socket_path, 91 const base::FilePath& listen_socket_path,
94 const RegisterCallback& register_callback) { 92 const RegisterCallback& register_callback) {
95 DCHECK(register_thread_checker_.CalledOnValidThread()); 93 DCHECK(register_thread_checker_.CalledOnValidThread());
96 ListenInBackgroundWithErrorCallback( 94 ListenInBackgroundWithErrorCallback(listen_socket_path, register_callback,
97 listen_socket_path, register_callback, ErrorCallback()); 95 ErrorCallback());
98 } 96 }
99 97
100 void ExternalApplicationListenerPosix::ListenInBackgroundWithErrorCallback( 98 void ExternalApplicationListenerPosix::ListenInBackgroundWithErrorCallback(
101 const base::FilePath& listen_socket_path, 99 const base::FilePath& listen_socket_path,
102 const RegisterCallback& register_callback, 100 const RegisterCallback& register_callback,
103 const ErrorCallback& error_callback) { 101 const ErrorCallback& error_callback) {
104 DCHECK(register_thread_checker_.CalledOnValidThread()); 102 DCHECK(register_thread_checker_.CalledOnValidThread());
105 register_callback_ = register_callback; 103 register_callback_ = register_callback;
106 error_callback_ = error_callback; 104 error_callback_ = error_callback;
107 105
108 io_runner_->PostTask( 106 io_runner_->PostTask(
109 FROM_HERE, 107 FROM_HERE, base::Bind(&ExternalApplicationListenerPosix::StartListening,
110 base::Bind(&ExternalApplicationListenerPosix::StartListening, 108 base::Unretained(this), listen_socket_path));
111 base::Unretained(this),
112 listen_socket_path));
113 } 109 }
114 110
115 void ExternalApplicationListenerPosix::WaitForListening() { 111 void ExternalApplicationListenerPosix::WaitForListening() {
116 DCHECK(register_thread_checker_.CalledOnValidThread()); 112 DCHECK(register_thread_checker_.CalledOnValidThread());
117 signal_on_listening_.Wait(); 113 signal_on_listening_.Wait();
118 } 114 }
119 115
120 void ExternalApplicationListenerPosix::StartListening( 116 void ExternalApplicationListenerPosix::StartListening(
121 const base::FilePath& listen_socket_path) { 117 const base::FilePath& listen_socket_path) {
122 CHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_IO); 118 CHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_IO);
(...skipping 10 matching lines...) Expand all
133 event->Signal(); 129 event->Signal();
134 } 130 }
135 131
136 void ExternalApplicationListenerPosix::OnListening(int rv) { 132 void ExternalApplicationListenerPosix::OnListening(int rv) {
137 DCHECK(listener_thread_checker_.CalledOnValidThread()); 133 DCHECK(listener_thread_checker_.CalledOnValidThread());
138 signal_on_listening_.Signal(); 134 signal_on_listening_.Signal();
139 shell_runner_->PostTask( 135 shell_runner_->PostTask(
140 FROM_HERE, 136 FROM_HERE,
141 base::Bind( 137 base::Bind(
142 &ExternalApplicationListenerPosix::RunErrorCallbackIfListeningFailed, 138 &ExternalApplicationListenerPosix::RunErrorCallbackIfListeningFailed,
143 weak_ptr_factory_.GetWeakPtr(), 139 weak_ptr_factory_.GetWeakPtr(), rv));
144 rv));
145 } 140 }
146 141
147 void ExternalApplicationListenerPosix::OnConnection(SocketDescriptor incoming) { 142 void ExternalApplicationListenerPosix::OnConnection(SocketDescriptor incoming) {
148 DCHECK(listener_thread_checker_.CalledOnValidThread()); 143 DCHECK(listener_thread_checker_.CalledOnValidThread());
149 shell_runner_->PostTask( 144 shell_runner_->PostTask(
150 FROM_HERE, 145 FROM_HERE,
151 base::Bind( 146 base::Bind(
152 &ExternalApplicationListenerPosix::CreatePipeAndBindToRegistrarImpl, 147 &ExternalApplicationListenerPosix::CreatePipeAndBindToRegistrarImpl,
153 weak_ptr_factory_.GetWeakPtr(), 148 weak_ptr_factory_.GetWeakPtr(), incoming));
154 incoming));
155 } 149 }
156 150
157 void ExternalApplicationListenerPosix::RunErrorCallbackIfListeningFailed( 151 void ExternalApplicationListenerPosix::RunErrorCallbackIfListeningFailed(
158 int rv) { 152 int rv) {
159 DCHECK(register_thread_checker_.CalledOnValidThread()); 153 DCHECK(register_thread_checker_.CalledOnValidThread());
160 if (rv != net::OK && !error_callback_.is_null()) { 154 if (rv != net::OK && !error_callback_.is_null()) {
161 error_callback_.Run(rv); 155 error_callback_.Run(rv);
162 } 156 }
163 } 157 }
164 158
(...skipping 26 matching lines...) Expand all
191 void ExternalApplicationListenerPosix::RegistrarImpl::Register( 185 void ExternalApplicationListenerPosix::RegistrarImpl::Register(
192 const String& app_url, 186 const String& app_url,
193 const mojo::Callback<void(ShellPtr)>& callback) { 187 const mojo::Callback<void(ShellPtr)>& callback) {
194 MessagePipe pipe; 188 MessagePipe pipe;
195 register_callback_.Run(app_url.To<GURL>(), pipe.handle0.Pass()); 189 register_callback_.Run(app_url.To<GURL>(), pipe.handle0.Pass());
196 callback.Run(MakeProxy<Shell>(pipe.handle1.Pass())); 190 callback.Run(MakeProxy<Shell>(pipe.handle1.Pass()));
197 } 191 }
198 192
199 } // namespace shell 193 } // namespace shell
200 } // namespace mojo 194 } // namespace mojo
OLDNEW
« no previous file with comments | « shell/external_application_listener_posix.h ('k') | shell/external_application_listener_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698