| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "mojo/public/cpp/application/application_impl_base.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 #include <utility> | |
| 9 | |
| 10 #include "mojo/public/cpp/application/connection_context.h" | |
| 11 #include "mojo/public/cpp/application/run_application.h" | |
| 12 #include "mojo/public/cpp/application/service_provider_impl.h" | |
| 13 #include "mojo/public/cpp/environment/logging.h" | |
| 14 | |
| 15 namespace mojo { | |
| 16 | |
| 17 ApplicationImplBase::~ApplicationImplBase() {} | |
| 18 | |
| 19 void ApplicationImplBase::Bind( | |
| 20 InterfaceRequest<Application> application_request) { | |
| 21 application_binding_.Bind(application_request.Pass()); | |
| 22 } | |
| 23 | |
| 24 bool ApplicationImplBase::HasArg(const std::string& arg) const { | |
| 25 return std::find(args_.begin(), args_.end(), arg) != args_.end(); | |
| 26 } | |
| 27 | |
| 28 void ApplicationImplBase::OnInitialize() {} | |
| 29 | |
| 30 bool ApplicationImplBase::OnAcceptConnection( | |
| 31 ServiceProviderImpl* service_provider_impl) { | |
| 32 return false; | |
| 33 } | |
| 34 | |
| 35 void ApplicationImplBase::OnQuit() {} | |
| 36 | |
| 37 void ApplicationImplBase::Terminate(MojoResult result) { | |
| 38 TerminateApplication(result); | |
| 39 } | |
| 40 | |
| 41 ApplicationImplBase::ApplicationImplBase() : application_binding_(this) {} | |
| 42 | |
| 43 void ApplicationImplBase::Initialize(InterfaceHandle<Shell> shell, | |
| 44 Array<String> args, | |
| 45 const mojo::String& url) { | |
| 46 shell_ = ShellPtr::Create(std::move(shell)); | |
| 47 shell_.set_connection_error_handler([this]() { | |
| 48 OnQuit(); | |
| 49 service_provider_impls_.clear(); | |
| 50 // TODO(vtl): Maybe this should be |MOJO_RESULT_UNKNOWN| or something else, | |
| 51 // but currently tests fail if we don't just report "OK". | |
| 52 Terminate(MOJO_RESULT_OK); | |
| 53 }); | |
| 54 url_ = url; | |
| 55 args_ = args.To<std::vector<std::string>>(); | |
| 56 OnInitialize(); | |
| 57 } | |
| 58 | |
| 59 void ApplicationImplBase::AcceptConnection( | |
| 60 const String& requestor_url, | |
| 61 const String& url, | |
| 62 InterfaceRequest<ServiceProvider> services) { | |
| 63 std::unique_ptr<ServiceProviderImpl> service_provider_impl( | |
| 64 new ServiceProviderImpl( | |
| 65 ConnectionContext(ConnectionContext::Type::INCOMING, requestor_url, | |
| 66 url), | |
| 67 services.Pass())); | |
| 68 if (!OnAcceptConnection(service_provider_impl.get())) | |
| 69 return; | |
| 70 service_provider_impls_.push_back(std::move(service_provider_impl)); | |
| 71 } | |
| 72 | |
| 73 void ApplicationImplBase::RequestQuit() { | |
| 74 OnQuit(); | |
| 75 Terminate(MOJO_RESULT_OK); | |
| 76 } | |
| 77 | |
| 78 } // namespace mojo | |
| OLD | NEW |