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" |
11 #include "mojo/application/public/cpp/application_delegate.h" | 11 #include "mojo/application/public/cpp/application_delegate.h" |
12 #include "mojo/application/public/cpp/lib/service_registry.h" | 12 #include "mojo/application/public/cpp/lib/service_registry.h" |
13 #include "mojo/public/cpp/bindings/interface_ptr.h" | 13 #include "mojo/public/cpp/bindings/interface_ptr.h" |
14 #include "mojo/public/cpp/environment/logging.h" | 14 #include "mojo/public/cpp/environment/logging.h" |
15 | 15 |
16 namespace mojo { | 16 namespace mojo { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 void DefaultTerminationClosure() { | 20 void DefaultTerminationClosure() { |
21 if (base::MessageLoop::current() && | 21 if (base::MessageLoop::current() && |
22 base::MessageLoop::current()->is_running()) | 22 base::MessageLoop::current()->is_running()) |
23 base::MessageLoop::current()->Quit(); | 23 base::MessageLoop::current()->Quit(); |
24 } | 24 } |
25 | 25 |
26 template <typename E, typename T> | |
27 struct TypeConverter < std::set<E>, Array<T> > { | |
sky
2015/07/22 15:57:44
You shouldn't need the extra spaces anymore, eg <s
| |
28 static std::set<E> Convert(const Array<T>& input) { | |
29 std::set<E> result; | |
30 if (!input.is_null()) { | |
31 for (size_t i = 0; i < input.size(); ++i) | |
32 result.insert(TypeConverter<E, T>::Convert(input[i])); | |
33 } | |
34 return result; | |
35 } | |
36 }; | |
37 | |
26 } // namespace | 38 } // namespace |
27 | 39 |
28 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, | 40 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, |
29 InterfaceRequest<Application> request) | 41 InterfaceRequest<Application> request) |
30 : ApplicationImpl(delegate, request.Pass(), | 42 : ApplicationImpl(delegate, request.Pass(), |
31 base::Bind(&DefaultTerminationClosure)) { | 43 base::Bind(&DefaultTerminationClosure)) { |
32 } | 44 } |
33 | 45 |
34 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, | 46 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, |
35 InterfaceRequest<Application> request, | 47 InterfaceRequest<Application> request, |
(...skipping 22 matching lines...) Expand all Loading... | |
58 } | 70 } |
59 | 71 |
60 ApplicationImpl::~ApplicationImpl() { | 72 ApplicationImpl::~ApplicationImpl() { |
61 DCHECK(!in_destructor_); | 73 DCHECK(!in_destructor_); |
62 in_destructor_ = true; | 74 in_destructor_ = true; |
63 ClearConnections(); | 75 ClearConnections(); |
64 app_lifetime_helper_.ApplicationTerminated(); | 76 app_lifetime_helper_.ApplicationTerminated(); |
65 } | 77 } |
66 | 78 |
67 ApplicationConnection* ApplicationImpl::ConnectToApplication( | 79 ApplicationConnection* ApplicationImpl::ConnectToApplication( |
68 mojo::URLRequestPtr request) { | 80 mojo::URLRequestPtr request, |
81 CapabilityFilterPtr filter) { | |
69 if (!shell_) | 82 if (!shell_) |
70 return nullptr; | 83 return nullptr; |
71 ServiceProviderPtr local_services; | 84 ServiceProviderPtr local_services; |
72 InterfaceRequest<ServiceProvider> local_request = GetProxy(&local_services); | 85 InterfaceRequest<ServiceProvider> local_request = GetProxy(&local_services); |
73 ServiceProviderPtr remote_services; | 86 ServiceProviderPtr remote_services; |
74 std::string application_url = request->url.To<std::string>(); | 87 std::string application_url = request->url.To<std::string>(); |
75 shell_->ConnectToApplication(request.Pass(), GetProxy(&remote_services), | 88 shell_->ConnectToApplication(request.Pass(), GetProxy(&remote_services), |
76 local_services.Pass()); | 89 local_services.Pass(), filter.Pass()); |
77 internal::ServiceRegistry* registry = new internal::ServiceRegistry( | 90 internal::ServiceRegistry* registry = new internal::ServiceRegistry( |
78 this, application_url, application_url, remote_services.Pass(), | 91 this, application_url, application_url, remote_services.Pass(), |
79 local_request.Pass()); | 92 local_request.Pass(), std::set<std::string>()); |
80 if (!delegate_->ConfigureOutgoingConnection(registry)) { | 93 if (!delegate_->ConfigureOutgoingConnection(registry)) { |
81 registry->CloseConnection(); | 94 registry->CloseConnection(); |
82 return nullptr; | 95 return nullptr; |
83 } | 96 } |
84 outgoing_service_registries_.push_back(registry); | 97 outgoing_service_registries_.push_back(registry); |
85 return registry; | 98 return registry; |
86 } | 99 } |
87 | 100 |
88 void ApplicationImpl::CloseConnection(ApplicationConnection* connection) { | 101 void ApplicationImpl::CloseConnection(ApplicationConnection* connection) { |
89 if (!in_destructor_) | 102 if (!in_destructor_) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 | 147 |
135 void ApplicationImpl::QuitNow() { | 148 void ApplicationImpl::QuitNow() { |
136 delegate_->Quit(); | 149 delegate_->Quit(); |
137 termination_closure_.Run(); | 150 termination_closure_.Run(); |
138 } | 151 } |
139 | 152 |
140 void ApplicationImpl::AcceptConnection( | 153 void ApplicationImpl::AcceptConnection( |
141 const String& requestor_url, | 154 const String& requestor_url, |
142 InterfaceRequest<ServiceProvider> services, | 155 InterfaceRequest<ServiceProvider> services, |
143 ServiceProviderPtr exposed_services, | 156 ServiceProviderPtr exposed_services, |
157 Array<String> allowed_interfaces, | |
144 const String& url) { | 158 const String& url) { |
145 internal::ServiceRegistry* registry = new internal::ServiceRegistry( | 159 internal::ServiceRegistry* registry = new internal::ServiceRegistry( |
146 this, url, requestor_url, exposed_services.Pass(), services.Pass()); | 160 this, url, requestor_url, exposed_services.Pass(), services.Pass(), |
161 allowed_interfaces.To<std::set<std::string> >()); | |
sky
2015/07/22 15:57:45
nit: '> >' -> '>>'
| |
147 if (!delegate_->ConfigureIncomingConnection(registry)) { | 162 if (!delegate_->ConfigureIncomingConnection(registry)) { |
148 registry->CloseConnection(); | 163 registry->CloseConnection(); |
149 return; | 164 return; |
150 } | 165 } |
151 incoming_service_registries_.push_back(registry); | 166 incoming_service_registries_.push_back(registry); |
152 | 167 |
153 // If we were quitting because we thought there were no more services for this | 168 // If we were quitting because we thought there were no more services for this |
154 // app in use, then that has changed so cancel the quit request. | 169 // app in use, then that has changed so cancel the quit request. |
155 if (quit_requested_) | 170 if (quit_requested_) |
156 quit_requested_ = false; | 171 quit_requested_ = false; |
(...skipping 17 matching lines...) Expand all Loading... | |
174 // than the one to the shell. | 189 // than the one to the shell. |
175 bool quit_now = delegate_->OnShellConnectionError(); | 190 bool quit_now = delegate_->OnShellConnectionError(); |
176 if (quit_now) | 191 if (quit_now) |
177 QuitNow(); | 192 QuitNow(); |
178 if (!ptr) | 193 if (!ptr) |
179 return; | 194 return; |
180 shell_ = nullptr; | 195 shell_ = nullptr; |
181 } | 196 } |
182 | 197 |
183 } // namespace mojo | 198 } // namespace mojo |
OLD | NEW |