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 "mojo/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" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 if (rv != net::ERR_IO_PENDING) { | 46 if (rv != net::ERR_IO_PENDING) { |
47 DVLOG(1) << "Connect returning immediately: " << net::ErrorToString(rv); | 47 DVLOG(1) << "Connect returning immediately: " << net::ErrorToString(rv); |
48 OnConnect(callback, rv); | 48 OnConnect(callback, rv); |
49 return; | 49 return; |
50 } | 50 } |
51 DVLOG(1) << "Waiting for connection."; | 51 DVLOG(1) << "Waiting for connection."; |
52 } | 52 } |
53 | 53 |
54 void ExternalApplicationRegistrarConnection::Register( | 54 void ExternalApplicationRegistrarConnection::Register( |
55 const GURL& app_url, | 55 const GURL& app_url, |
56 ShellPtr* shell, | 56 base::Callback<void(ShellPtr)> register_complete_callback) { |
57 base::Closure register_complete_callback) { | |
58 DCHECK(!client_socket_); | 57 DCHECK(!client_socket_); |
59 registrar_->Register( | 58 registrar_->Register(String::From(app_url), register_complete_callback); |
60 String::From(app_url), Get(shell), register_complete_callback); | |
61 } | 59 } |
62 | 60 |
63 void ExternalApplicationRegistrarConnection::OnConnect( | 61 void ExternalApplicationRegistrarConnection::OnConnect( |
64 net::CompletionCallback callback, | 62 net::CompletionCallback callback, |
65 int rv) { | 63 int rv) { |
66 DVLOG(1) << "OnConnect called: " << net::ErrorToString(rv); | 64 DVLOG(1) << "OnConnect called: " << net::ErrorToString(rv); |
67 if (rv != net::OK) { | 65 if (rv != net::OK) { |
68 callback.Run(rv); | 66 callback.Run(rv); |
69 return; | 67 return; |
70 } | 68 } |
71 | 69 |
72 mojo::ScopedMessagePipeHandle ptr_message_pipe_handle = | 70 mojo::ScopedMessagePipeHandle ptr_message_pipe_handle = |
73 channel_init_.Init(client_socket_->ReleaseConnectedSocket(), | 71 channel_init_.Init(client_socket_->ReleaseConnectedSocket(), |
74 base::MessageLoopProxy::current()); | 72 base::MessageLoopProxy::current()); |
75 CHECK(ptr_message_pipe_handle.is_valid()); | 73 CHECK(ptr_message_pipe_handle.is_valid()); |
76 client_socket_.reset(); // This is dead now, ensure it can't be reused. | 74 client_socket_.reset(); // This is dead now, ensure it can't be reused. |
77 | 75 |
78 registrar_.Bind(ptr_message_pipe_handle.Pass()); | 76 registrar_.Bind(ptr_message_pipe_handle.Pass()); |
79 callback.Run(rv); | 77 callback.Run(rv); |
80 } | 78 } |
81 | 79 |
82 } // namespace shell | 80 } // namespace shell |
83 } // namespace mojo | 81 } // namespace mojo |
OLD | NEW |