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