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/application/public/cpp/application_impl.h" | 5 #include "mojo/application/public/cpp/application_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 InterfaceRequest<Application> request, | 48 InterfaceRequest<Application> request, |
49 const Closure& termination_closure) | 49 const Closure& termination_closure) |
50 : delegate_(delegate), | 50 : delegate_(delegate), |
51 binding_(this, request.Pass()), | 51 binding_(this, request.Pass()), |
52 termination_closure_(termination_closure), | 52 termination_closure_(termination_closure), |
53 app_lifetime_helper_(this), | 53 app_lifetime_helper_(this), |
54 quit_requested_(false), | 54 quit_requested_(false), |
55 in_destructor_(false), | 55 in_destructor_(false), |
56 weak_factory_(this) {} | 56 weak_factory_(this) {} |
57 | 57 |
58 void ApplicationImpl::ClearConnections() { | |
59 // Copy the ServiceRegistryLists because they will be mutated by | |
60 // ApplicationConnection::CloseConnection. | |
61 ServiceRegistryList incoming_service_registries(incoming_service_registries_); | |
62 for (internal::ServiceRegistry* registry : incoming_service_registries) | |
63 registry->CloseConnection(); | |
64 DCHECK(incoming_service_registries_.empty()); | |
65 | |
66 ServiceRegistryList outgoing_service_registries(outgoing_service_registries_); | |
67 for (internal::ServiceRegistry* registry : outgoing_service_registries) | |
68 registry->CloseConnection(); | |
69 DCHECK(outgoing_service_registries_.empty()); | |
70 } | |
71 | |
72 ApplicationImpl::~ApplicationImpl() { | 58 ApplicationImpl::~ApplicationImpl() { |
73 DCHECK(!in_destructor_); | 59 DCHECK(!in_destructor_); |
74 in_destructor_ = true; | 60 in_destructor_ = true; |
75 ClearConnections(); | 61 ClearConnections(); |
76 app_lifetime_helper_.ApplicationTerminated(); | 62 app_lifetime_helper_.OnQuit(); |
77 } | 63 } |
78 | 64 |
79 ApplicationConnection* ApplicationImpl::ConnectToApplication( | 65 ApplicationConnection* ApplicationImpl::ConnectToApplication( |
80 mojo::URLRequestPtr request, | 66 mojo::URLRequestPtr request, |
81 CapabilityFilterPtr filter) { | 67 CapabilityFilterPtr filter) { |
82 if (!shell_) | 68 if (!shell_) |
83 return nullptr; | 69 return nullptr; |
84 ServiceProviderPtr local_services; | 70 ServiceProviderPtr local_services; |
85 InterfaceRequest<ServiceProvider> local_request = GetProxy(&local_services); | 71 InterfaceRequest<ServiceProvider> local_request = GetProxy(&local_services); |
86 ServiceProviderPtr remote_services; | 72 ServiceProviderPtr remote_services; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 binding_.WaitForIncomingMethodCall(); | 119 binding_.WaitForIncomingMethodCall(); |
134 } | 120 } |
135 | 121 |
136 void ApplicationImpl::UnbindConnections( | 122 void ApplicationImpl::UnbindConnections( |
137 InterfaceRequest<Application>* application_request, | 123 InterfaceRequest<Application>* application_request, |
138 ShellPtr* shell) { | 124 ShellPtr* shell) { |
139 *application_request = binding_.Unbind(); | 125 *application_request = binding_.Unbind(); |
140 shell->Bind(shell_.PassInterface()); | 126 shell->Bind(shell_.PassInterface()); |
141 } | 127 } |
142 | 128 |
143 void ApplicationImpl::Terminate() { | 129 void ApplicationImpl::Quit() { |
144 // We can't quit immediately, since there could be in-flight requests from the | 130 // We can't quit immediately, since there could be in-flight requests from the |
145 // shell. So check with it first. | 131 // shell. So check with it first. |
146 if (shell_) { | 132 if (shell_) { |
147 quit_requested_ = true; | 133 quit_requested_ = true; |
148 shell_->QuitApplication(); | 134 shell_->QuitApplication(); |
149 } else { | 135 } else { |
150 QuitNow(); | 136 QuitNow(); |
151 } | 137 } |
152 } | 138 } |
153 | 139 |
154 void ApplicationImpl::QuitNow() { | |
155 delegate_->Quit(); | |
156 termination_closure_.Run(); | |
157 } | |
158 | |
159 void ApplicationImpl::AcceptConnection( | 140 void ApplicationImpl::AcceptConnection( |
160 const String& requestor_url, | 141 const String& requestor_url, |
161 InterfaceRequest<ServiceProvider> services, | 142 InterfaceRequest<ServiceProvider> services, |
162 ServiceProviderPtr exposed_services, | 143 ServiceProviderPtr exposed_services, |
163 Array<String> allowed_interfaces, | 144 Array<String> allowed_interfaces, |
164 const String& url) { | 145 const String& url) { |
165 internal::ServiceRegistry* registry = new internal::ServiceRegistry( | 146 internal::ServiceRegistry* registry = new internal::ServiceRegistry( |
166 this, url, requestor_url, exposed_services.Pass(), services.Pass(), | 147 this, url, requestor_url, exposed_services.Pass(), services.Pass(), |
167 allowed_interfaces.To<std::set<std::string>>()); | 148 allowed_interfaces.To<std::set<std::string>>()); |
168 if (!delegate_->ConfigureIncomingConnection(registry)) { | 149 if (!delegate_->ConfigureIncomingConnection(registry)) { |
(...skipping 25 matching lines...) Expand all Loading... |
194 // loop. The application might want to continue servicing connections other | 175 // loop. The application might want to continue servicing connections other |
195 // than the one to the shell. | 176 // than the one to the shell. |
196 bool quit_now = delegate_->OnShellConnectionError(); | 177 bool quit_now = delegate_->OnShellConnectionError(); |
197 if (quit_now) | 178 if (quit_now) |
198 QuitNow(); | 179 QuitNow(); |
199 if (!ptr) | 180 if (!ptr) |
200 return; | 181 return; |
201 shell_ = nullptr; | 182 shell_ = nullptr; |
202 } | 183 } |
203 | 184 |
| 185 void ApplicationImpl::ClearConnections() { |
| 186 // Copy the ServiceRegistryLists because they will be mutated by |
| 187 // ApplicationConnection::CloseConnection. |
| 188 ServiceRegistryList incoming_service_registries(incoming_service_registries_); |
| 189 for (internal::ServiceRegistry* registry : incoming_service_registries) |
| 190 registry->CloseConnection(); |
| 191 DCHECK(incoming_service_registries_.empty()); |
| 192 |
| 193 ServiceRegistryList outgoing_service_registries(outgoing_service_registries_); |
| 194 for (internal::ServiceRegistry* registry : outgoing_service_registries) |
| 195 registry->CloseConnection(); |
| 196 DCHECK(outgoing_service_registries_.empty()); |
| 197 } |
| 198 |
| 199 void ApplicationImpl::QuitNow() { |
| 200 delegate_->Quit(); |
| 201 termination_closure_.Run(); |
| 202 } |
| 203 |
204 } // namespace mojo | 204 } // namespace mojo |
OLD | NEW |