OLD | NEW |
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_registrar_connection.h" | 5 #include "shell/external_application_registrar_connection.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "mojo/edk/embedder/channel_init.h" | 11 #include "mojo/edk/embedder/channel_init.h" |
12 #include "mojo/public/cpp/bindings/error_handler.h" | 12 #include "mojo/public/cpp/bindings/error_handler.h" |
13 #include "mojo/public/interfaces/application/application.mojom.h" | 13 #include "mojo/public/interfaces/application/application.mojom.h" |
14 #include "mojo/public/interfaces/application/shell.mojom.h" | 14 #include "mojo/public/interfaces/application/shell.mojom.h" |
15 #include "mojo/shell/domain_socket/net_errors.h" | 15 #include "shell/domain_socket/net_errors.h" |
16 #include "mojo/shell/domain_socket/socket_descriptor.h" | 16 #include "shell/domain_socket/socket_descriptor.h" |
17 #include "mojo/shell/domain_socket/unix_domain_client_socket_posix.h" | 17 #include "shell/domain_socket/unix_domain_client_socket_posix.h" |
18 #include "mojo/shell/external_application_registrar.mojom.h" | 18 #include "shell/external_application_registrar.mojom.h" |
19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
20 | 20 |
21 namespace mojo { | 21 namespace mojo { |
22 namespace shell { | 22 namespace shell { |
23 | 23 |
24 ExternalApplicationRegistrarConnection::ExternalApplicationRegistrarConnection( | 24 ExternalApplicationRegistrarConnection::ExternalApplicationRegistrarConnection( |
25 const base::FilePath& socket_path) | 25 const base::FilePath& socket_path) |
26 : client_socket_(new UnixDomainClientSocket(socket_path.value(), false)) { | 26 : client_socket_(new UnixDomainClientSocket(socket_path.value(), false)) { |
27 } | 27 } |
28 | 28 |
29 ExternalApplicationRegistrarConnection:: | 29 ExternalApplicationRegistrarConnection:: |
30 ~ExternalApplicationRegistrarConnection() { | 30 ~ExternalApplicationRegistrarConnection() { |
31 channel_init_.WillDestroySoon(); | 31 channel_init_.WillDestroySoon(); |
32 } | 32 } |
33 | 33 |
34 void ExternalApplicationRegistrarConnection::OnConnectionError() { | 34 void ExternalApplicationRegistrarConnection::OnConnectionError() { |
35 channel_init_.WillDestroySoon(); | 35 channel_init_.WillDestroySoon(); |
36 } | 36 } |
37 | 37 |
38 void ExternalApplicationRegistrarConnection::Connect( | 38 void ExternalApplicationRegistrarConnection::Connect( |
39 const CompletionCallback& callback) { | 39 const CompletionCallback& callback) { |
40 DCHECK(client_socket_) << "Single use only."; | 40 DCHECK(client_socket_) << "Single use only."; |
41 int rv = client_socket_->Connect( | 41 int rv = client_socket_->Connect( |
42 base::Bind(&ExternalApplicationRegistrarConnection::OnConnect, | 42 base::Bind(&ExternalApplicationRegistrarConnection::OnConnect, |
43 base::Unretained(this), | 43 base::Unretained(this), callback)); |
44 callback)); | |
45 if (rv != net::ERR_IO_PENDING) { | 44 if (rv != net::ERR_IO_PENDING) { |
46 DVLOG(1) << "Connect returning immediately: " << net::ErrorToString(rv); | 45 DVLOG(1) << "Connect returning immediately: " << net::ErrorToString(rv); |
47 OnConnect(callback, rv); | 46 OnConnect(callback, rv); |
48 return; | 47 return; |
49 } | 48 } |
50 DVLOG(1) << "Waiting for connection."; | 49 DVLOG(1) << "Waiting for connection."; |
51 } | 50 } |
52 | 51 |
53 void ExternalApplicationRegistrarConnection::Register( | 52 void ExternalApplicationRegistrarConnection::Register( |
54 const GURL& app_url, | 53 const GURL& app_url, |
(...skipping 16 matching lines...) Expand all Loading... |
71 base::MessageLoopProxy::current()); | 70 base::MessageLoopProxy::current()); |
72 CHECK(ptr_message_pipe_handle.is_valid()); | 71 CHECK(ptr_message_pipe_handle.is_valid()); |
73 client_socket_.reset(); // This is dead now, ensure it can't be reused. | 72 client_socket_.reset(); // This is dead now, ensure it can't be reused. |
74 | 73 |
75 registrar_.Bind(ptr_message_pipe_handle.Pass()); | 74 registrar_.Bind(ptr_message_pipe_handle.Pass()); |
76 callback.Run(rv); | 75 callback.Run(rv); |
77 } | 76 } |
78 | 77 |
79 } // namespace shell | 78 } // namespace shell |
80 } // namespace mojo | 79 } // namespace mojo |
OLD | NEW |