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