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