forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.cc
73 lines (60 loc) · 2.08 KB
/
init.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "mash/init/init.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/guid.h"
#include "mash/login/public/interfaces/login.mojom.h"
#include "services/shell/public/cpp/connection.h"
#include "services/shell/public/cpp/connector.h"
namespace mash {
namespace init {
Init::Init() {}
Init::~Init() {}
void Init::OnStart(const shell::Identity& identity) {
connector()->Connect("mojo:ui");
StartTracing();
StartLogin();
}
bool Init::OnConnect(const shell::Identity& remote_identity,
shell::InterfaceRegistry* registry) {
registry->AddInterface<mojom::Init>(this);
return true;
}
void Init::StartService(const mojo::String& name,
const mojo::String& user_id) {
if (user_services_.find(user_id) == user_services_.end()) {
shell::Connector::ConnectParams params(shell::Identity(name, user_id));
std::unique_ptr<shell::Connection> connection =
connector()->Connect(¶ms);
connection->SetConnectionLostClosure(
base::Bind(&Init::UserServiceQuit, base::Unretained(this), user_id));
user_services_[user_id] = std::move(connection);
}
}
void Init::StopServicesForUser(const mojo::String& user_id) {
auto it = user_services_.find(user_id);
if (it != user_services_.end())
user_services_.erase(it);
}
void Init::Create(const shell::Identity& remote_identity,
mojom::InitRequest request) {
init_bindings_.AddBinding(this, std::move(request));
}
void Init::UserServiceQuit(const std::string& user_id) {
auto it = user_services_.find(user_id);
DCHECK(it != user_services_.end());
user_services_.erase(it);
}
void Init::StartTracing() {
connector()->Connect("mojo:tracing");
}
void Init::StartLogin() {
login_connection_ = connector()->Connect("mojo:login");
mash::login::mojom::LoginPtr login;
login_connection_->GetInterface(&login);
login->ShowLoginUI();
}
} // namespace init
} // namespace main