| 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) {} | 18 : connector_(nullptr) {} |
| 19 Init::~Init() {} | 19 Init::~Init() {} |
| 20 | 20 |
| 21 void Init::Initialize(mojo::Connector* connector, | 21 void Init::Initialize(shell::Connector* connector, |
| 22 const mojo::Identity& identity, | 22 const shell::Identity& identity, |
| 23 uint32_t id) { | 23 uint32_t id) { |
| 24 connector_ = connector; | 24 connector_ = connector; |
| 25 connector_->Connect("mojo:mus"); | 25 connector_->Connect("mojo:mus"); |
| 26 StartTracing(); | 26 StartTracing(); |
| 27 StartResourceProvider(); | 27 StartResourceProvider(); |
| 28 StartLogin(); | 28 StartLogin(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 bool Init::AcceptConnection(mojo::Connection* connection) { | 31 bool Init::AcceptConnection(shell::Connection* connection) { |
| 32 connection->AddInterface<mojom::Init>(this); | 32 connection->AddInterface<mojom::Init>(this); |
| 33 return true; | 33 return true; |
| 34 } | 34 } |
| 35 | 35 |
| 36 void Init::StartService(const mojo::String& name, | 36 void Init::StartService(const mojo::String& name, |
| 37 const mojo::String& user_id) { | 37 const mojo::String& user_id) { |
| 38 if (user_services_.find(user_id) == user_services_.end()) { | 38 if (user_services_.find(user_id) == user_services_.end()) { |
| 39 mojo::Connector::ConnectParams params(mojo::Identity(name, user_id)); | 39 shell::Connector::ConnectParams params(shell::Identity(name, user_id)); |
| 40 std::unique_ptr<mojo::Connection> connection = connector_->Connect(¶ms); | 40 std::unique_ptr<shell::Connection> connection = |
| 41 connector_->Connect(¶ms); |
| 41 connection->SetConnectionLostClosure( | 42 connection->SetConnectionLostClosure( |
| 42 base::Bind(&Init::UserServiceQuit, base::Unretained(this), user_id)); | 43 base::Bind(&Init::UserServiceQuit, base::Unretained(this), user_id)); |
| 43 user_services_[user_id] = std::move(connection); | 44 user_services_[user_id] = std::move(connection); |
| 44 } | 45 } |
| 45 } | 46 } |
| 46 | 47 |
| 47 void Init::StopServicesForUser(const mojo::String& user_id) { | 48 void Init::StopServicesForUser(const mojo::String& user_id) { |
| 48 auto it = user_services_.find(user_id); | 49 auto it = user_services_.find(user_id); |
| 49 if (it != user_services_.end()) | 50 if (it != user_services_.end()) |
| 50 user_services_.erase(it); | 51 user_services_.erase(it); |
| 51 } | 52 } |
| 52 | 53 |
| 53 void Init::Create(mojo::Connection* connection, mojom::InitRequest request) { | 54 void Init::Create(shell::Connection* connection, 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 connector_->Connect("mojo:tracing"); | 65 connector_->Connect("mojo:tracing"); |
| 65 } | 66 } |
| 66 | 67 |
| 67 void Init::StartResourceProvider() { | 68 void Init::StartResourceProvider() { |
| 68 connector_->Connect("mojo:resource_provider"); | 69 connector_->Connect("mojo:resource_provider"); |
| 69 } | 70 } |
| 70 | 71 |
| 71 void Init::StartLogin() { | 72 void Init::StartLogin() { |
| 72 login_connection_ = connector_->Connect("mojo:login"); | 73 login_connection_ = connector_->Connect("mojo:login"); |
| 73 login_connection_->AddInterface<mojom::Init>(this); | 74 login_connection_->AddInterface<mojom::Init>(this); |
| 74 mash::login::mojom::LoginPtr login; | 75 mash::login::mojom::LoginPtr login; |
| 75 login_connection_->GetInterface(&login); | 76 login_connection_->GetInterface(&login); |
| 76 login->ShowLoginUI(); | 77 login->ShowLoginUI(); |
| 77 } | 78 } |
| 78 | 79 |
| 79 } // namespace init | 80 } // namespace init |
| 80 } // namespace main | 81 } // namespace main |
| OLD | NEW |