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