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/public/cpp/application/application_impl.h" | 5 #include "mojo/public/cpp/application/application_impl.h" |
6 | 6 |
7 #include <utility> | |
8 | |
9 #include "mojo/public/cpp/application/application_delegate.h" | 7 #include "mojo/public/cpp/application/application_delegate.h" |
10 #include "mojo/public/cpp/application/connection_context.h" | |
11 #include "mojo/public/cpp/application/service_provider_impl.h" | |
12 #include "mojo/public/cpp/bindings/interface_ptr.h" | |
13 #include "mojo/public/cpp/bindings/interface_request.h" | |
14 #include "mojo/public/cpp/environment/logging.h" | |
15 | 8 |
16 namespace mojo { | 9 namespace mojo { |
17 | 10 |
18 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, | 11 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, |
19 InterfaceRequest<Application> request) | 12 InterfaceRequest<Application> request) |
20 : delegate_(delegate), application_binding_(this, request.Pass()) {} | 13 : ApplicationImplBase(request.Pass()), delegate_(delegate) {} |
21 | 14 |
22 ApplicationImpl::~ApplicationImpl() {} | 15 ApplicationImpl::~ApplicationImpl() {} |
23 | 16 |
24 bool ApplicationImpl::HasArg(const std::string& arg) const { | 17 void ApplicationImpl::OnInitialize() { |
25 return std::find(args_.begin(), args_.end(), arg) != args_.end(); | |
26 } | |
27 | |
28 void ApplicationImpl::Initialize(InterfaceHandle<Shell> shell, | |
29 Array<String> args, | |
30 const mojo::String& url) { | |
31 shell_ = ShellPtr::Create(std::move(shell)); | |
32 shell_.set_connection_error_handler([this]() { | |
33 delegate_->Quit(); | |
34 service_provider_impls_.clear(); | |
35 Terminate(); | |
36 }); | |
37 url_ = url; | |
38 args_ = args.To<std::vector<std::string>>(); | |
39 delegate_->Initialize(this); | 18 delegate_->Initialize(this); |
40 } | 19 } |
41 | 20 |
42 void ApplicationImpl::AcceptConnection( | 21 bool ApplicationImpl::OnAcceptConnection( |
43 const String& requestor_url, | 22 ServiceProviderImpl* service_provider_impl) { |
44 InterfaceRequest<ServiceProvider> services, | 23 return delegate_->ConfigureIncomingConnection(service_provider_impl); |
45 InterfaceHandle<ServiceProvider> exposed_services, | |
46 const String& url) { | |
47 // Note: The shell no longer actually connects |exposed_services|, so a) we | |
48 // never actually get valid |exposed_services| here, b) it should be OK to | |
49 // drop it on the floor. | |
50 MOJO_LOG_IF(ERROR, exposed_services) | |
51 << "DEPRECATED: exposed_services is going away"; | |
52 std::unique_ptr<ServiceProviderImpl> service_provider_impl( | |
53 new ServiceProviderImpl( | |
54 ConnectionContext(ConnectionContext::Type::INCOMING, requestor_url, | |
55 url), | |
56 services.Pass())); | |
57 if (!delegate_->ConfigureIncomingConnection(service_provider_impl.get())) | |
58 return; | |
59 service_provider_impls_.push_back(std::move(service_provider_impl)); | |
60 } | 24 } |
61 | 25 |
62 void ApplicationImpl::RequestQuit() { | 26 void ApplicationImpl::OnQuit() { |
63 delegate_->Quit(); | 27 delegate_->Quit(); |
64 Terminate(); | |
65 } | 28 } |
66 | 29 |
67 } // namespace mojo | 30 } // namespace mojo |
OLD | NEW |