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