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 |
58 ApplicationImpl::~ApplicationImpl() { | 72 ApplicationImpl::~ApplicationImpl() { |
59 DCHECK(!in_destructor_); | 73 DCHECK(!in_destructor_); |
60 in_destructor_ = true; | 74 in_destructor_ = true; |
61 ClearConnections(); | 75 ClearConnections(); |
62 app_lifetime_helper_.OnQuit(); | 76 app_lifetime_helper_.ApplicationTerminated(); |
63 } | 77 } |
64 | 78 |
65 ApplicationConnection* ApplicationImpl::ConnectToApplication( | 79 ApplicationConnection* ApplicationImpl::ConnectToApplication( |
66 mojo::URLRequestPtr request, | 80 mojo::URLRequestPtr request, |
67 CapabilityFilterPtr filter) { | 81 CapabilityFilterPtr filter) { |
68 if (!shell_) | 82 if (!shell_) |
69 return nullptr; | 83 return nullptr; |
70 ServiceProviderPtr local_services; | 84 ServiceProviderPtr local_services; |
71 InterfaceRequest<ServiceProvider> local_request = GetProxy(&local_services); | 85 InterfaceRequest<ServiceProvider> local_request = GetProxy(&local_services); |
72 ServiceProviderPtr remote_services; | 86 ServiceProviderPtr remote_services; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 binding_.WaitForIncomingMethodCall(); | 133 binding_.WaitForIncomingMethodCall(); |
120 } | 134 } |
121 | 135 |
122 void ApplicationImpl::UnbindConnections( | 136 void ApplicationImpl::UnbindConnections( |
123 InterfaceRequest<Application>* application_request, | 137 InterfaceRequest<Application>* application_request, |
124 ShellPtr* shell) { | 138 ShellPtr* shell) { |
125 *application_request = binding_.Unbind(); | 139 *application_request = binding_.Unbind(); |
126 shell->Bind(shell_.PassInterface()); | 140 shell->Bind(shell_.PassInterface()); |
127 } | 141 } |
128 | 142 |
129 void ApplicationImpl::Quit() { | 143 void ApplicationImpl::Terminate() { |
130 // We can't quit immediately, since there could be in-flight requests from the | 144 // We can't quit immediately, since there could be in-flight requests from the |
131 // shell. So check with it first. | 145 // shell. So check with it first. |
132 if (shell_) { | 146 if (shell_) { |
133 quit_requested_ = true; | 147 quit_requested_ = true; |
134 shell_->QuitApplication(); | 148 shell_->QuitApplication(); |
135 } else { | 149 } else { |
136 QuitNow(); | 150 QuitNow(); |
137 } | 151 } |
138 } | 152 } |
139 | 153 |
| 154 void ApplicationImpl::QuitNow() { |
| 155 delegate_->Quit(); |
| 156 termination_closure_.Run(); |
| 157 } |
| 158 |
140 void ApplicationImpl::AcceptConnection( | 159 void ApplicationImpl::AcceptConnection( |
141 const String& requestor_url, | 160 const String& requestor_url, |
142 InterfaceRequest<ServiceProvider> services, | 161 InterfaceRequest<ServiceProvider> services, |
143 ServiceProviderPtr exposed_services, | 162 ServiceProviderPtr exposed_services, |
144 Array<String> allowed_interfaces, | 163 Array<String> allowed_interfaces, |
145 const String& url) { | 164 const String& url) { |
146 internal::ServiceRegistry* registry = new internal::ServiceRegistry( | 165 internal::ServiceRegistry* registry = new internal::ServiceRegistry( |
147 this, url, requestor_url, exposed_services.Pass(), services.Pass(), | 166 this, url, requestor_url, exposed_services.Pass(), services.Pass(), |
148 allowed_interfaces.To<std::set<std::string>>()); | 167 allowed_interfaces.To<std::set<std::string>>()); |
149 if (!delegate_->ConfigureIncomingConnection(registry)) { | 168 if (!delegate_->ConfigureIncomingConnection(registry)) { |
(...skipping 25 matching lines...) Expand all Loading... |
175 // loop. The application might want to continue servicing connections other | 194 // loop. The application might want to continue servicing connections other |
176 // than the one to the shell. | 195 // than the one to the shell. |
177 bool quit_now = delegate_->OnShellConnectionError(); | 196 bool quit_now = delegate_->OnShellConnectionError(); |
178 if (quit_now) | 197 if (quit_now) |
179 QuitNow(); | 198 QuitNow(); |
180 if (!ptr) | 199 if (!ptr) |
181 return; | 200 return; |
182 shell_ = nullptr; | 201 shell_ = nullptr; |
183 } | 202 } |
184 | 203 |
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 |