| 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 "mojo/shell/public/cpp/connection.h" | 9 #include "mojo/shell/public/cpp/connection.h" |
| 10 #include "mojo/shell/public/cpp/connector.h" | 10 #include "mojo/shell/public/cpp/connector.h" |
| 11 | 11 |
| 12 namespace mash { | 12 namespace mash { |
| 13 namespace init { | 13 namespace init { |
| 14 | 14 |
| 15 Init::Init() : connector_(nullptr) {} | 15 Init::Init() : connector_(nullptr) {} |
| 16 Init::~Init() {} | 16 Init::~Init() {} |
| 17 | 17 |
| 18 void Init::Initialize(mojo::Connector* connector, const std::string& url, | 18 void Init::Initialize(mojo::Connector* connector, const std::string& url, |
| 19 uint32_t id, uint32_t user_id) { | 19 const std::string& user_id, uint32_t id) { |
| 20 connector_ = connector; | 20 connector_ = connector; |
| 21 mus_connection_ = connector_->Connect("mojo:mus"); | 21 mus_connection_ = connector_->Connect("mojo:mus"); |
| 22 StartWindowManager(); | 22 StartWindowManager(); |
| 23 StartLogin(); | 23 StartLogin(); |
| 24 } | 24 } |
| 25 | 25 |
| 26 void Init::LoginAs(uint32_t user_id) { | 26 void Init::LoginAs(const mojo::String& user_id) { |
| 27 connections_["mojo:mash_login"].reset(); | 27 connections_["mojo:mash_login"].reset(); |
| 28 connections_["mojo:desktop_wm"].reset(); | 28 connections_["mojo:desktop_wm"].reset(); |
| 29 mojo::Connector::ConnectParams params("mojo:mash_shell"); | 29 mojo::Connector::ConnectParams params("mojo:mash_shell"); |
| 30 params.set_user_id(user_id); | 30 params.set_user_id(user_id); |
| 31 connector_->Connect(¶ms); | 31 connector_->Connect(¶ms); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void Init::Create(mojo::Connection* connection, mojom::LoginRequest request) { | 34 void Init::Create(mojo::Connection* connection, mojom::LoginRequest request) { |
| 35 login_bindings_.AddBinding(this, std::move(request)); | 35 login_bindings_.AddBinding(this, std::move(request)); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void Init::StartWindowManager() { | 38 void Init::StartWindowManager() { |
| 39 mojo::Connector::ConnectParams params("mojo:desktop_wm"); | 39 mojo::Connector::ConnectParams params("mojo:desktop_wm"); |
| 40 params.set_user_id(2); | 40 params.set_user_id("2"); |
| 41 StartRestartableService( | 41 StartRestartableService( |
| 42 ¶ms, | 42 ¶ms, |
| 43 base::Bind(&Init::StartWindowManager, base::Unretained(this))); | 43 base::Bind(&Init::StartWindowManager, base::Unretained(this))); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void Init::StartLogin() { | 46 void Init::StartLogin() { |
| 47 mojo::Connector::ConnectParams params("mojo:mash_login"); | 47 mojo::Connector::ConnectParams params("mojo:mash_login"); |
| 48 params.set_user_id(2); | 48 params.set_user_id("2"); |
| 49 StartRestartableService( | 49 StartRestartableService( |
| 50 ¶ms, | 50 ¶ms, |
| 51 base::Bind(&Init::StartLogin, base::Unretained(this))); | 51 base::Bind(&Init::StartLogin, base::Unretained(this))); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void Init::StartRestartableService(mojo::Connector::ConnectParams* params, | 54 void Init::StartRestartableService(mojo::Connector::ConnectParams* params, |
| 55 const base::Closure& restart_callback) { | 55 const base::Closure& restart_callback) { |
| 56 // TODO(beng): This would be the place to insert logic that counted restarts | 56 // TODO(beng): This would be the place to insert logic that counted restarts |
| 57 // to avoid infinite crash-restart loops. | 57 // to avoid infinite crash-restart loops. |
| 58 scoped_ptr<mojo::Connection> connection = connector_->Connect(params); | 58 scoped_ptr<mojo::Connection> connection = connector_->Connect(params); |
| 59 // Note: |connection| may be null if we've lost our connection to the shell. | 59 // Note: |connection| may be null if we've lost our connection to the shell. |
| 60 if (connection) { | 60 if (connection) { |
| 61 connection->SetRemoteInterfaceProviderConnectionErrorHandler( | 61 connection->SetRemoteInterfaceProviderConnectionErrorHandler( |
| 62 restart_callback); | 62 restart_callback); |
| 63 connection->AddInterface<mojom::Login>(this); | 63 connection->AddInterface<mojom::Login>(this); |
| 64 connections_[params->name()] = std::move(connection); | 64 connections_[params->name()] = std::move(connection); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 } // namespace init | 68 } // namespace init |
| 69 } // namespace main | 69 } // namespace main |
| OLD | NEW |