| 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 "mash/init/init.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/command_line.h" | |
| 9 #include "base/guid.h" | |
| 10 #include "mash/login/public/interfaces/constants.mojom.h" | |
| 11 #include "mash/login/public/interfaces/login.mojom.h" | |
| 12 #include "services/service_manager/public/cpp/connection.h" | |
| 13 #include "services/service_manager/public/cpp/connector.h" | |
| 14 #include "services/service_manager/public/cpp/interface_registry.h" | |
| 15 #include "services/service_manager/public/cpp/service_context.h" | |
| 16 #include "services/tracing/public/interfaces/constants.mojom.h" | |
| 17 #include "services/ui/public/interfaces/constants.mojom.h" | |
| 18 | |
| 19 namespace mash { | |
| 20 namespace init { | |
| 21 | |
| 22 Init::Init() {} | |
| 23 Init::~Init() {} | |
| 24 | |
| 25 void Init::OnStart() { | |
| 26 context()->connector()->Connect(ui::mojom::kServiceName); | |
| 27 StartTracing(); | |
| 28 StartLogin(); | |
| 29 } | |
| 30 | |
| 31 bool Init::OnConnect(const service_manager::ServiceInfo& remote_info, | |
| 32 service_manager::InterfaceRegistry* registry) { | |
| 33 registry->AddInterface<mojom::Init>(this); | |
| 34 return true; | |
| 35 } | |
| 36 | |
| 37 void Init::StartService(const std::string& name, const std::string& user_id) { | |
| 38 if (user_services_.find(user_id) == user_services_.end()) { | |
| 39 service_manager::Connector::ConnectParams params( | |
| 40 service_manager::Identity(name, user_id)); | |
| 41 std::unique_ptr<service_manager::Connection> connection = | |
| 42 context()->connector()->Connect(¶ms); | |
| 43 connection->SetConnectionLostClosure( | |
| 44 base::Bind(&Init::UserServiceQuit, base::Unretained(this), user_id)); | |
| 45 user_services_[user_id] = std::move(connection); | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 void Init::StopServicesForUser(const std::string& user_id) { | |
| 50 auto it = user_services_.find(user_id); | |
| 51 if (it != user_services_.end()) | |
| 52 user_services_.erase(it); | |
| 53 } | |
| 54 | |
| 55 void Init::Create(const service_manager::Identity& remote_identity, | |
| 56 mojom::InitRequest request) { | |
| 57 init_bindings_.AddBinding(this, std::move(request)); | |
| 58 } | |
| 59 | |
| 60 void Init::UserServiceQuit(const std::string& user_id) { | |
| 61 auto it = user_services_.find(user_id); | |
| 62 DCHECK(it != user_services_.end()); | |
| 63 user_services_.erase(it); | |
| 64 } | |
| 65 | |
| 66 void Init::StartTracing() { | |
| 67 context()->connector()->Connect(tracing::mojom::kServiceName); | |
| 68 } | |
| 69 | |
| 70 void Init::StartLogin() { | |
| 71 login_connection_ = | |
| 72 context()->connector()->Connect(login::mojom::kServiceName); | |
| 73 mash::login::mojom::LoginPtr login; | |
| 74 login_connection_->GetInterface(&login); | |
| 75 login->ShowLoginUI(); | |
| 76 } | |
| 77 | |
| 78 } // namespace init | |
| 79 } // namespace main | |
| OLD | NEW |