| 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 30 matching lines...) Expand all Loading... |
| 41 : ApplicationImpl(delegate, | 41 : ApplicationImpl(delegate, |
| 42 std::move(request), | 42 std::move(request), |
| 43 base::Bind(&DefaultTerminationClosure)) {} | 43 base::Bind(&DefaultTerminationClosure)) {} |
| 44 | 44 |
| 45 ApplicationImpl::ApplicationImpl( | 45 ApplicationImpl::ApplicationImpl( |
| 46 ApplicationDelegate* delegate, | 46 ApplicationDelegate* delegate, |
| 47 InterfaceRequest<shell::mojom::Application> request, | 47 InterfaceRequest<shell::mojom::Application> request, |
| 48 const Closure& termination_closure) | 48 const Closure& termination_closure) |
| 49 : delegate_(delegate), | 49 : delegate_(delegate), |
| 50 binding_(this, std::move(request)), | 50 binding_(this, std::move(request)), |
| 51 id_(shell::mojom::Shell::kInvalidApplicationID), | |
| 52 termination_closure_(termination_closure), | 51 termination_closure_(termination_closure), |
| 53 app_lifetime_helper_(this), | 52 app_lifetime_helper_(this), |
| 54 quit_requested_(false), | 53 quit_requested_(false), |
| 55 weak_factory_(this) {} | 54 weak_factory_(this) {} |
| 56 | 55 |
| 57 ApplicationImpl::~ApplicationImpl() { | 56 ApplicationImpl::~ApplicationImpl() { |
| 58 app_lifetime_helper_.OnQuit(); | 57 app_lifetime_helper_.OnQuit(); |
| 59 } | 58 } |
| 60 | 59 |
| 60 void ApplicationImpl::WaitForInitialize() { |
| 61 DCHECK(!shell_.is_bound()); |
| 62 binding_.WaitForIncomingMethodCall(); |
| 63 } |
| 64 |
| 61 scoped_ptr<ApplicationConnection> ApplicationImpl::ConnectToApplication( | 65 scoped_ptr<ApplicationConnection> ApplicationImpl::ConnectToApplication( |
| 62 const std::string& url) { | 66 const std::string& url) { |
| 63 ConnectParams params(url); | 67 ConnectParams params(url); |
| 64 params.set_filter(CreatePermissiveCapabilityFilter()); | 68 params.set_filter(CreatePermissiveCapabilityFilter()); |
| 65 return ConnectToApplication(¶ms); | 69 return ConnectToApplication(¶ms); |
| 66 } | 70 } |
| 67 | 71 |
| 68 scoped_ptr<ApplicationConnection> | 72 scoped_ptr<ApplicationConnection> |
| 69 ApplicationImpl::ConnectToApplication(ConnectParams* params) { | 73 ApplicationImpl::ConnectToApplication(ConnectParams* params) { |
| 70 if (!shell_) | 74 if (!shell_) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 87 application_url, application_url, | 91 application_url, application_url, |
| 88 shell::mojom::Shell::kInvalidApplicationID, std::move(remote_services), | 92 shell::mojom::Shell::kInvalidApplicationID, std::move(remote_services), |
| 89 std::move(local_request), allowed)); | 93 std::move(local_request), allowed)); |
| 90 shell_->ConnectToApplication(std::move(request), | 94 shell_->ConnectToApplication(std::move(request), |
| 91 std::move(remote_services_proxy), | 95 std::move(remote_services_proxy), |
| 92 std::move(local_services), params->TakeFilter(), | 96 std::move(local_services), params->TakeFilter(), |
| 93 registry->GetConnectToApplicationCallback()); | 97 registry->GetConnectToApplicationCallback()); |
| 94 return std::move(registry); | 98 return std::move(registry); |
| 95 } | 99 } |
| 96 | 100 |
| 97 void ApplicationImpl::WaitForInitialize() { | |
| 98 DCHECK(!shell_.is_bound()); | |
| 99 binding_.WaitForIncomingMethodCall(); | |
| 100 } | |
| 101 | |
| 102 void ApplicationImpl::Quit() { | 101 void ApplicationImpl::Quit() { |
| 103 // We can't quit immediately, since there could be in-flight requests from the | 102 // We can't quit immediately, since there could be in-flight requests from the |
| 104 // shell. So check with it first. | 103 // shell. So check with it first. |
| 105 if (shell_) { | 104 if (shell_) { |
| 106 quit_requested_ = true; | 105 quit_requested_ = true; |
| 107 shell_->QuitApplication(); | 106 shell_->QuitApplication(); |
| 108 } else { | 107 } else { |
| 109 QuitNow(); | 108 QuitNow(); |
| 110 } | 109 } |
| 111 } | 110 } |
| 112 | 111 |
| 112 scoped_ptr<AppRefCount> ApplicationImpl::CreateAppRefCount() { |
| 113 return app_lifetime_helper_.CreateAppRefCount(); |
| 114 } |
| 115 |
| 113 void ApplicationImpl::Initialize(shell::mojom::ShellPtr shell, | 116 void ApplicationImpl::Initialize(shell::mojom::ShellPtr shell, |
| 114 const mojo::String& url, | 117 const mojo::String& url, |
| 115 uint32_t id) { | 118 uint32_t id) { |
| 116 shell_ = std::move(shell); | 119 shell_ = std::move(shell); |
| 117 shell_.set_connection_error_handler([this]() { OnConnectionError(); }); | 120 shell_.set_connection_error_handler([this]() { OnConnectionError(); }); |
| 118 url_ = url; | 121 delegate_->Initialize(this, url, id); |
| 119 id_ = id; | |
| 120 delegate_->Initialize(this); | |
| 121 } | 122 } |
| 122 | 123 |
| 123 void ApplicationImpl::AcceptConnection( | 124 void ApplicationImpl::AcceptConnection( |
| 124 const String& requestor_url, | 125 const String& requestor_url, |
| 125 uint32_t requestor_id, | 126 uint32_t requestor_id, |
| 126 InterfaceRequest<ServiceProvider> services, | 127 InterfaceRequest<ServiceProvider> services, |
| 127 ServiceProviderPtr exposed_services, | 128 ServiceProviderPtr exposed_services, |
| 128 Array<String> allowed_interfaces, | 129 Array<String> allowed_interfaces, |
| 129 const String& url) { | 130 const String& url) { |
| 130 scoped_ptr<ApplicationConnection> registry(new internal::ServiceRegistry( | 131 scoped_ptr<ApplicationConnection> registry(new internal::ServiceRegistry( |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 shell::mojom::CapabilityFilterPtr CreatePermissiveCapabilityFilter() { | 181 shell::mojom::CapabilityFilterPtr CreatePermissiveCapabilityFilter() { |
| 181 shell::mojom::CapabilityFilterPtr filter( | 182 shell::mojom::CapabilityFilterPtr filter( |
| 182 shell::mojom::CapabilityFilter::New()); | 183 shell::mojom::CapabilityFilter::New()); |
| 183 Array<String> all_interfaces; | 184 Array<String> all_interfaces; |
| 184 all_interfaces.push_back("*"); | 185 all_interfaces.push_back("*"); |
| 185 filter->filter.insert("*", std::move(all_interfaces)); | 186 filter->filter.insert("*", std::move(all_interfaces)); |
| 186 return filter; | 187 return filter; |
| 187 } | 188 } |
| 188 | 189 |
| 189 } // namespace mojo | 190 } // namespace mojo |
| OLD | NEW |