| 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 "mojo/shell/public/cpp/connection.h" | 11 #include "mojo/shell/public/cpp/connection.h" |
| 11 #include "mojo/shell/public/cpp/connector.h" | 12 #include "mojo/shell/public/cpp/connector.h" |
| 12 | 13 |
| 13 namespace mash { | 14 namespace mash { |
| 14 namespace init { | 15 namespace init { |
| 15 | 16 |
| 16 Init::Init() : connector_(nullptr), login_user_id_(base::GenerateGUID()) {} | 17 Init::Init() : connector_(nullptr), login_user_id_(base::GenerateGUID()) {} |
| 17 Init::~Init() {} | 18 Init::~Init() {} |
| 18 | 19 |
| 19 void Init::Initialize(mojo::Connector* connector, | 20 void Init::Initialize(mojo::Connector* connector, |
| 20 const mojo::Identity& identity, | 21 const mojo::Identity& identity, |
| 21 uint32_t id) { | 22 uint32_t id) { |
| 22 connector_ = connector; | 23 connector_ = connector; |
| 23 mus_connection_ = connector_->Connect("mojo:mus"); | 24 connector_->Connect("mojo:mus"); |
| 24 mus_connection_->GetInterface(&user_access_manager_); | |
| 25 user_access_manager_->SetActiveUser(login_user_id_); | |
| 26 StartWindowManager(); | |
| 27 StartLogin(); | 25 StartLogin(); |
| 28 } | 26 } |
| 29 | 27 |
| 30 bool Init::AcceptConnection(mojo::Connection* connection) { | 28 void Init::StartService(const mojo::String& name, |
| 31 connection->AddInterface<mojom::Login>(this); | 29 const mojo::String& user_id) { |
| 32 return true; | 30 DCHECK(user_services_.find(user_id) == user_services_.end()); |
| 31 mojo::Connector::ConnectParams params(mojo::Identity(name, user_id)); |
| 32 user_services_[user_id] = connector_->Connect(¶ms); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void Init::LoginAs(const mojo::String& user_id) { | 35 void Init::StopServicesForUser(const mojo::String& user_id) { |
| 36 user_access_manager_->SetActiveUser(user_id); | 36 // TODO(beng): Make shell cascade shutdown of services. |
| 37 connections_["mojo:mash_login"].reset(); | 37 auto it = user_services_.find(user_id); |
| 38 connections_["mojo:desktop_wm"].reset(); | 38 if (it != user_services_.end()) |
| 39 mojo::Connector::ConnectParams params( | 39 user_services_.erase(it); |
| 40 mojo::Identity("mojo:mash_shell", user_id)); | |
| 41 connector_->Connect(¶ms); | |
| 42 } | 40 } |
| 43 | 41 |
| 44 void Init::Logout() { | 42 void Init::Create(mojo::Connection* connection, mojom::InitRequest request) { |
| 45 // TODO(beng): need to kill the user session. | 43 init_bindings_.AddBinding(this, std::move(request)); |
| 46 user_access_manager_->SetActiveUser(login_user_id_); | |
| 47 StartWindowManager(); | |
| 48 StartLogin(); | |
| 49 } | |
| 50 | |
| 51 void Init::SwitchUser() { | |
| 52 // This doesn't kill the user session, merely starts the login UI. | |
| 53 user_access_manager_->SetActiveUser(login_user_id_); | |
| 54 StartWindowManager(); | |
| 55 StartLogin(); | |
| 56 } | |
| 57 | |
| 58 void Init::Create(mojo::Connection* connection, mojom::LoginRequest request) { | |
| 59 login_bindings_.AddBinding(this, std::move(request)); | |
| 60 } | |
| 61 | |
| 62 void Init::StartWindowManager() { | |
| 63 mojo::Connector::ConnectParams params( | |
| 64 mojo::Identity("mojo:desktop_wm", login_user_id_)); | |
| 65 StartRestartableService( | |
| 66 ¶ms, | |
| 67 base::Bind(&Init::StartWindowManager, base::Unretained(this))); | |
| 68 } | 44 } |
| 69 | 45 |
| 70 void Init::StartLogin() { | 46 void Init::StartLogin() { |
| 71 mojo::Connector::ConnectParams params( | 47 mojo::Connector::ConnectParams params( |
| 72 mojo::Identity("mojo:mash_login", login_user_id_)); | 48 mojo::Identity("mojo:login", login_user_id_)); |
| 73 StartRestartableService( | 49 login_connection_ = connector_->Connect(¶ms); |
| 74 ¶ms, | 50 login_connection_->AddInterface<mojom::Init>(this); |
| 51 login_connection_->SetConnectionLostClosure( |
| 75 base::Bind(&Init::StartLogin, base::Unretained(this))); | 52 base::Bind(&Init::StartLogin, base::Unretained(this))); |
| 76 } | 53 mash::login::mojom::LoginPtr login; |
| 77 | 54 login_connection_->GetInterface(&login); |
| 78 void Init::StartRestartableService(mojo::Connector::ConnectParams* params, | 55 login->ShowLoginUI(); |
| 79 const base::Closure& restart_callback) { | |
| 80 // TODO(beng): This would be the place to insert logic that counted restarts | |
| 81 // to avoid infinite crash-restart loops. | |
| 82 scoped_ptr<mojo::Connection> connection = connector_->Connect(params); | |
| 83 // Note: |connection| may be null if we've lost our connection to the shell. | |
| 84 if (connection) { | |
| 85 connection->SetConnectionLostClosure(restart_callback); | |
| 86 connection->AddInterface<mojom::Login>(this); | |
| 87 connections_[params->target().name()] = std::move(connection); | |
| 88 } | |
| 89 } | 56 } |
| 90 | 57 |
| 91 } // namespace init | 58 } // namespace init |
| 92 } // namespace main | 59 } // namespace main |
| OLD | NEW |