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" | |
6 | |
7 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <utility> |
8 | 7 |
9 #include "base/bind.h" | 8 #include "base/bind.h" |
10 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
11 #include "mojo/application/public/cpp/application_delegate.h" | 10 #include "mojo/application/public/cpp/application_delegate.h" |
| 11 #include "mojo/application/public/cpp/application_impl.h" |
12 #include "mojo/application/public/cpp/lib/service_registry.h" | 12 #include "mojo/application/public/cpp/lib/service_registry.h" |
13 #include "mojo/converters/network/network_type_converters.h" | 13 #include "mojo/converters/network/network_type_converters.h" |
14 #include "mojo/public/cpp/bindings/interface_ptr.h" | 14 #include "mojo/public/cpp/bindings/interface_ptr.h" |
15 #include "mojo/public/cpp/environment/logging.h" | 15 #include "mojo/public/cpp/environment/logging.h" |
16 | 16 |
17 namespace mojo { | 17 namespace mojo { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 void DefaultTerminationClosure() { | 21 void DefaultTerminationClosure() { |
22 if (base::MessageLoop::current() && | 22 if (base::MessageLoop::current() && |
23 base::MessageLoop::current()->is_running()) | 23 base::MessageLoop::current()->is_running()) |
24 base::MessageLoop::current()->QuitWhenIdle(); | 24 base::MessageLoop::current()->QuitWhenIdle(); |
25 } | 25 } |
26 | 26 |
27 } // namespace | 27 } // namespace |
28 | 28 |
29 ApplicationImpl::ConnectParams::ConnectParams(const std::string& url) | 29 ApplicationImpl::ConnectParams::ConnectParams(const std::string& url) |
30 : ConnectParams(URLRequest::From(url)) {} | 30 : ConnectParams(URLRequest::From(url)) {} |
31 ApplicationImpl::ConnectParams::ConnectParams(URLRequestPtr request) | 31 ApplicationImpl::ConnectParams::ConnectParams(URLRequestPtr request) |
32 : request_(request.Pass()), filter_(CapabilityFilter::New()) { | 32 : request_(std::move(request)), filter_(CapabilityFilter::New()) { |
33 filter_->filter.mark_non_null(); | 33 filter_->filter.mark_non_null(); |
34 } | 34 } |
35 ApplicationImpl::ConnectParams::~ConnectParams() {} | 35 ApplicationImpl::ConnectParams::~ConnectParams() {} |
36 | 36 |
37 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, | 37 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, |
38 InterfaceRequest<Application> request) | 38 InterfaceRequest<Application> request) |
39 : ApplicationImpl(delegate, request.Pass(), | 39 : ApplicationImpl(delegate, |
40 base::Bind(&DefaultTerminationClosure)) { | 40 std::move(request), |
41 } | 41 base::Bind(&DefaultTerminationClosure)) {} |
42 | 42 |
43 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, | 43 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, |
44 InterfaceRequest<Application> request, | 44 InterfaceRequest<Application> request, |
45 const Closure& termination_closure) | 45 const Closure& termination_closure) |
46 : delegate_(delegate), | 46 : delegate_(delegate), |
47 binding_(this, request.Pass()), | 47 binding_(this, std::move(request)), |
48 termination_closure_(termination_closure), | 48 termination_closure_(termination_closure), |
49 app_lifetime_helper_(this), | 49 app_lifetime_helper_(this), |
50 quit_requested_(false), | 50 quit_requested_(false), |
51 weak_factory_(this) {} | 51 weak_factory_(this) {} |
52 | 52 |
53 ApplicationImpl::~ApplicationImpl() { | 53 ApplicationImpl::~ApplicationImpl() { |
54 app_lifetime_helper_.OnQuit(); | 54 app_lifetime_helper_.OnQuit(); |
55 } | 55 } |
56 | 56 |
57 scoped_ptr<ApplicationConnection> ApplicationImpl::ConnectToApplication( | 57 scoped_ptr<ApplicationConnection> ApplicationImpl::ConnectToApplication( |
(...skipping 15 matching lines...) Expand all Loading... |
73 std::string application_url = request->url.To<std::string>(); | 73 std::string application_url = request->url.To<std::string>(); |
74 // We allow all interfaces on outgoing connections since we are presumably in | 74 // We allow all interfaces on outgoing connections since we are presumably in |
75 // a position to know who we're talking to. | 75 // a position to know who we're talking to. |
76 // TODO(beng): is this a valid assumption or do we need to figure some way to | 76 // TODO(beng): is this a valid assumption or do we need to figure some way to |
77 // filter here too? | 77 // filter here too? |
78 std::set<std::string> allowed; | 78 std::set<std::string> allowed; |
79 allowed.insert("*"); | 79 allowed.insert("*"); |
80 InterfaceRequest<ServiceProvider> remote_services_proxy = | 80 InterfaceRequest<ServiceProvider> remote_services_proxy = |
81 GetProxy(&remote_services); | 81 GetProxy(&remote_services); |
82 scoped_ptr<internal::ServiceRegistry> registry(new internal::ServiceRegistry( | 82 scoped_ptr<internal::ServiceRegistry> registry(new internal::ServiceRegistry( |
83 application_url, application_url, remote_services.Pass(), | 83 application_url, application_url, std::move(remote_services), |
84 local_request.Pass(), allowed)); | 84 std::move(local_request), allowed)); |
85 shell_->ConnectToApplication(request.Pass(), remote_services_proxy.Pass(), | 85 shell_->ConnectToApplication(std::move(request), |
86 local_services.Pass(), | 86 std::move(remote_services_proxy), |
87 params->TakeFilter().Pass(), | 87 std::move(local_services), params->TakeFilter(), |
88 registry->GetConnectToApplicationCallback()); | 88 registry->GetConnectToApplicationCallback()); |
89 if (!delegate_->ConfigureOutgoingConnection(registry.get())) | 89 if (!delegate_->ConfigureOutgoingConnection(registry.get())) |
90 return nullptr; | 90 return nullptr; |
91 return registry.Pass(); | 91 return std::move(registry); |
92 } | 92 } |
93 | 93 |
94 void ApplicationImpl::WaitForInitialize() { | 94 void ApplicationImpl::WaitForInitialize() { |
95 DCHECK(!shell_.is_bound()); | 95 DCHECK(!shell_.is_bound()); |
96 binding_.WaitForIncomingMethodCall(); | 96 binding_.WaitForIncomingMethodCall(); |
97 } | 97 } |
98 | 98 |
99 void ApplicationImpl::Quit() { | 99 void ApplicationImpl::Quit() { |
100 // We can't quit immediately, since there could be in-flight requests from the | 100 // We can't quit immediately, since there could be in-flight requests from the |
101 // shell. So check with it first. | 101 // shell. So check with it first. |
102 if (shell_) { | 102 if (shell_) { |
103 quit_requested_ = true; | 103 quit_requested_ = true; |
104 shell_->QuitApplication(); | 104 shell_->QuitApplication(); |
105 } else { | 105 } else { |
106 QuitNow(); | 106 QuitNow(); |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 void ApplicationImpl::Initialize(ShellPtr shell, const mojo::String& url) { | 110 void ApplicationImpl::Initialize(ShellPtr shell, const mojo::String& url) { |
111 shell_ = shell.Pass(); | 111 shell_ = std::move(shell); |
112 shell_.set_connection_error_handler([this]() { OnConnectionError(); }); | 112 shell_.set_connection_error_handler([this]() { OnConnectionError(); }); |
113 url_ = url; | 113 url_ = url; |
114 delegate_->Initialize(this); | 114 delegate_->Initialize(this); |
115 } | 115 } |
116 | 116 |
117 void ApplicationImpl::AcceptConnection( | 117 void ApplicationImpl::AcceptConnection( |
118 const String& requestor_url, | 118 const String& requestor_url, |
119 InterfaceRequest<ServiceProvider> services, | 119 InterfaceRequest<ServiceProvider> services, |
120 ServiceProviderPtr exposed_services, | 120 ServiceProviderPtr exposed_services, |
121 Array<String> allowed_interfaces, | 121 Array<String> allowed_interfaces, |
122 const String& url) { | 122 const String& url) { |
123 scoped_ptr<ApplicationConnection> registry(new internal::ServiceRegistry( | 123 scoped_ptr<ApplicationConnection> registry(new internal::ServiceRegistry( |
124 url, requestor_url, exposed_services.Pass(), services.Pass(), | 124 url, requestor_url, std::move(exposed_services), std::move(services), |
125 allowed_interfaces.To<std::set<std::string>>())); | 125 allowed_interfaces.To<std::set<std::string>>())); |
126 if (!delegate_->ConfigureIncomingConnection(registry.get())) | 126 if (!delegate_->ConfigureIncomingConnection(registry.get())) |
127 return; | 127 return; |
128 | 128 |
129 // If we were quitting because we thought there were no more services for this | 129 // If we were quitting because we thought there were no more services for this |
130 // app in use, then that has changed so cancel the quit request. | 130 // app in use, then that has changed so cancel the quit request. |
131 if (quit_requested_) | 131 if (quit_requested_) |
132 quit_requested_ = false; | 132 quit_requested_ = false; |
133 | 133 |
134 incoming_connections_.push_back(registry.Pass()); | 134 incoming_connections_.push_back(std::move(registry)); |
135 } | 135 } |
136 | 136 |
137 void ApplicationImpl::OnQuitRequested(const Callback<void(bool)>& callback) { | 137 void ApplicationImpl::OnQuitRequested(const Callback<void(bool)>& callback) { |
138 // If by the time we got the reply from the shell, more requests had come in | 138 // If by the time we got the reply from the shell, more requests had come in |
139 // then we don't want to quit the app anymore so we return false. Otherwise | 139 // then we don't want to quit the app anymore so we return false. Otherwise |
140 // |quit_requested_| is true so we tell the shell to proceed with the quit. | 140 // |quit_requested_| is true so we tell the shell to proceed with the quit. |
141 callback.Run(quit_requested_); | 141 callback.Run(quit_requested_); |
142 if (quit_requested_) | 142 if (quit_requested_) |
143 QuitNow(); | 143 QuitNow(); |
144 } | 144 } |
(...skipping 22 matching lines...) Expand all Loading... |
167 InterfaceRequest<Application>* application_request, | 167 InterfaceRequest<Application>* application_request, |
168 ShellPtr* shell) { | 168 ShellPtr* shell) { |
169 *application_request = binding_.Unbind(); | 169 *application_request = binding_.Unbind(); |
170 shell->Bind(shell_.PassInterface()); | 170 shell->Bind(shell_.PassInterface()); |
171 } | 171 } |
172 | 172 |
173 CapabilityFilterPtr CreatePermissiveCapabilityFilter() { | 173 CapabilityFilterPtr CreatePermissiveCapabilityFilter() { |
174 CapabilityFilterPtr filter(CapabilityFilter::New()); | 174 CapabilityFilterPtr filter(CapabilityFilter::New()); |
175 Array<String> all_interfaces; | 175 Array<String> all_interfaces; |
176 all_interfaces.push_back("*"); | 176 all_interfaces.push_back("*"); |
177 filter->filter.insert("*", all_interfaces.Pass()); | 177 filter->filter.insert("*", std::move(all_interfaces)); |
178 return filter.Pass(); | 178 return filter; |
179 } | 179 } |
180 | 180 |
181 } // namespace mojo | 181 } // namespace mojo |
OLD | NEW |