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 <algorithm> | 5 #include <algorithm> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "mojo/converters/network/network_type_converters.h" | 10 #include "mojo/converters/network/network_type_converters.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 InterfaceRequest<Application> request) | 38 InterfaceRequest<Application> request) |
39 : ApplicationImpl(delegate, | 39 : ApplicationImpl(delegate, |
40 std::move(request), | 40 std::move(request), |
41 base::Bind(&DefaultTerminationClosure)) {} | 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, std::move(request)), | 47 binding_(this, std::move(request)), |
| 48 id_(Shell::kInvalidApplicationID), |
48 termination_closure_(termination_closure), | 49 termination_closure_(termination_closure), |
49 app_lifetime_helper_(this), | 50 app_lifetime_helper_(this), |
50 quit_requested_(false), | 51 quit_requested_(false), |
51 weak_factory_(this) {} | 52 weak_factory_(this) {} |
52 | 53 |
53 ApplicationImpl::~ApplicationImpl() { | 54 ApplicationImpl::~ApplicationImpl() { |
54 app_lifetime_helper_.OnQuit(); | 55 app_lifetime_helper_.OnQuit(); |
55 } | 56 } |
56 | 57 |
57 scoped_ptr<ApplicationConnection> ApplicationImpl::ConnectToApplication( | 58 scoped_ptr<ApplicationConnection> ApplicationImpl::ConnectToApplication( |
(...skipping 15 matching lines...) Expand all Loading... |
73 std::string application_url = request->url.To<std::string>(); | 74 std::string application_url = request->url.To<std::string>(); |
74 // We allow all interfaces on outgoing connections since we are presumably in | 75 // We allow all interfaces on outgoing connections since we are presumably in |
75 // a position to know who we're talking to. | 76 // 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 | 77 // TODO(beng): is this a valid assumption or do we need to figure some way to |
77 // filter here too? | 78 // filter here too? |
78 std::set<std::string> allowed; | 79 std::set<std::string> allowed; |
79 allowed.insert("*"); | 80 allowed.insert("*"); |
80 InterfaceRequest<ServiceProvider> remote_services_proxy = | 81 InterfaceRequest<ServiceProvider> remote_services_proxy = |
81 GetProxy(&remote_services); | 82 GetProxy(&remote_services); |
82 scoped_ptr<internal::ServiceRegistry> registry(new internal::ServiceRegistry( | 83 scoped_ptr<internal::ServiceRegistry> registry(new internal::ServiceRegistry( |
83 application_url, application_url, std::move(remote_services), | 84 application_url, application_url, Shell::kInvalidApplicationID, |
84 std::move(local_request), allowed)); | 85 std::move(remote_services), std::move(local_request), allowed)); |
85 shell_->ConnectToApplication(std::move(request), | 86 shell_->ConnectToApplication(std::move(request), |
86 std::move(remote_services_proxy), | 87 std::move(remote_services_proxy), |
87 std::move(local_services), params->TakeFilter(), | 88 std::move(local_services), params->TakeFilter(), |
88 registry->GetConnectToApplicationCallback()); | 89 registry->GetConnectToApplicationCallback()); |
89 if (!delegate_->ConfigureOutgoingConnection(registry.get())) | 90 if (!delegate_->ConfigureOutgoingConnection(registry.get())) |
90 return nullptr; | 91 return nullptr; |
91 return std::move(registry); | 92 return std::move(registry); |
92 } | 93 } |
93 | 94 |
94 void ApplicationImpl::WaitForInitialize() { | 95 void ApplicationImpl::WaitForInitialize() { |
95 DCHECK(!shell_.is_bound()); | 96 DCHECK(!shell_.is_bound()); |
96 binding_.WaitForIncomingMethodCall(); | 97 binding_.WaitForIncomingMethodCall(); |
97 } | 98 } |
98 | 99 |
99 void ApplicationImpl::Quit() { | 100 void ApplicationImpl::Quit() { |
100 // We can't quit immediately, since there could be in-flight requests from the | 101 // We can't quit immediately, since there could be in-flight requests from the |
101 // shell. So check with it first. | 102 // shell. So check with it first. |
102 if (shell_) { | 103 if (shell_) { |
103 quit_requested_ = true; | 104 quit_requested_ = true; |
104 shell_->QuitApplication(); | 105 shell_->QuitApplication(); |
105 } else { | 106 } else { |
106 QuitNow(); | 107 QuitNow(); |
107 } | 108 } |
108 } | 109 } |
109 | 110 |
110 void ApplicationImpl::Initialize(ShellPtr shell, const mojo::String& url) { | 111 void ApplicationImpl::Initialize(ShellPtr shell, |
| 112 const mojo::String& url, |
| 113 uint32_t id) { |
111 shell_ = std::move(shell); | 114 shell_ = std::move(shell); |
112 shell_.set_connection_error_handler([this]() { OnConnectionError(); }); | 115 shell_.set_connection_error_handler([this]() { OnConnectionError(); }); |
113 url_ = url; | 116 url_ = url; |
| 117 id_ = id; |
114 delegate_->Initialize(this); | 118 delegate_->Initialize(this); |
115 } | 119 } |
116 | 120 |
117 void ApplicationImpl::AcceptConnection( | 121 void ApplicationImpl::AcceptConnection( |
118 const String& requestor_url, | 122 const String& requestor_url, |
| 123 uint32_t requestor_id, |
119 InterfaceRequest<ServiceProvider> services, | 124 InterfaceRequest<ServiceProvider> services, |
120 ServiceProviderPtr exposed_services, | 125 ServiceProviderPtr exposed_services, |
121 Array<String> allowed_interfaces, | 126 Array<String> allowed_interfaces, |
122 const String& url) { | 127 const String& url) { |
123 scoped_ptr<ApplicationConnection> registry(new internal::ServiceRegistry( | 128 scoped_ptr<ApplicationConnection> registry(new internal::ServiceRegistry( |
124 url, requestor_url, std::move(exposed_services), std::move(services), | 129 url, requestor_url, requestor_id, std::move(exposed_services), |
125 allowed_interfaces.To<std::set<std::string>>())); | 130 std::move(services), allowed_interfaces.To<std::set<std::string>>())); |
126 if (!delegate_->ConfigureIncomingConnection(registry.get())) | 131 if (!delegate_->ConfigureIncomingConnection(registry.get())) |
127 return; | 132 return; |
128 | 133 |
129 // If we were quitting because we thought there were no more services for this | 134 // 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. | 135 // app in use, then that has changed so cancel the quit request. |
131 if (quit_requested_) | 136 if (quit_requested_) |
132 quit_requested_ = false; | 137 quit_requested_ = false; |
133 | 138 |
134 incoming_connections_.push_back(std::move(registry)); | 139 incoming_connections_.push_back(std::move(registry)); |
135 } | 140 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 | 177 |
173 CapabilityFilterPtr CreatePermissiveCapabilityFilter() { | 178 CapabilityFilterPtr CreatePermissiveCapabilityFilter() { |
174 CapabilityFilterPtr filter(CapabilityFilter::New()); | 179 CapabilityFilterPtr filter(CapabilityFilter::New()); |
175 Array<String> all_interfaces; | 180 Array<String> all_interfaces; |
176 all_interfaces.push_back("*"); | 181 all_interfaces.push_back("*"); |
177 filter->filter.insert("*", std::move(all_interfaces)); | 182 filter->filter.insert("*", std::move(all_interfaces)); |
178 return filter; | 183 return filter; |
179 } | 184 } |
180 | 185 |
181 } // namespace mojo | 186 } // namespace mojo |
OLD | NEW |