Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: mash/shell/shell_application_delegate.cc

Issue 1817443002: Rename mash_shell to mash_session. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mash/shell/shell_application_delegate.h ('k') | mash/wm/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mash/shell/shell_application_delegate.h"
6
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/message_loop/message_loop.h"
10 #include "mash/login/public/interfaces/login.mojom.h"
11 #include "mojo/shell/public/cpp/connection.h"
12 #include "mojo/shell/public/cpp/connector.h"
13
14 namespace mash {
15 namespace shell {
16
17 ShellApplicationDelegate::ShellApplicationDelegate()
18 : connector_(nullptr), screen_locked_(false) {}
19
20 ShellApplicationDelegate::~ShellApplicationDelegate() {}
21
22 void ShellApplicationDelegate::Initialize(mojo::Connector* connector,
23 const mojo::Identity& identity,
24 uint32_t id) {
25 connector_ = connector;
26 StartBrowserDriver();
27 StartWindowManager();
28 StartSystemUI();
29 StartQuickLaunch();
30 }
31
32 bool ShellApplicationDelegate::AcceptConnection(mojo::Connection* connection) {
33 connection->AddInterface<mojom::Shell>(this);
34 return true;
35 }
36
37 void ShellApplicationDelegate::Logout() {
38 // TODO(beng): Notify connected listeners that login is happening, potentially
39 // give them the option to stop it.
40 mash::login::mojom::LoginPtr login;
41 connector_->ConnectToInterface("mojo:login", &login);
42 login->ShowLoginUI();
43 // This kills the user environment.
44 base::MessageLoop::current()->QuitWhenIdle();
45 }
46
47 void ShellApplicationDelegate::SwitchUser() {
48 mash::login::mojom::LoginPtr login;
49 connector_->ConnectToInterface("mojo:login", &login);
50 login->SwitchUser();
51 }
52
53 void ShellApplicationDelegate::AddScreenlockStateListener(
54 mojom::ScreenlockStateListenerPtr listener) {
55 listener->ScreenlockStateChanged(screen_locked_);
56 screenlock_listeners_.AddInterfacePtr(std::move(listener));
57 }
58
59 void ShellApplicationDelegate::LockScreen() {
60 if (screen_locked_)
61 return;
62 screen_locked_ = true;
63 screenlock_listeners_.ForAllPtrs(
64 [](mojom::ScreenlockStateListener* listener) {
65 listener->ScreenlockStateChanged(true);
66 });
67 StartScreenlock();
68 }
69 void ShellApplicationDelegate::UnlockScreen() {
70 if (!screen_locked_)
71 return;
72 screen_locked_ = false;
73 screenlock_listeners_.ForAllPtrs(
74 [](mojom::ScreenlockStateListener* listener) {
75 listener->ScreenlockStateChanged(false);
76 });
77 StopScreenlock();
78 }
79
80 void ShellApplicationDelegate::Create(
81 mojo::Connection* connection,
82 mojom::ShellRequest request) {
83 bindings_.AddBinding(this, std::move(request));
84 }
85
86 void ShellApplicationDelegate::StartWindowManager() {
87 StartRestartableService(
88 "mojo:desktop_wm",
89 base::Bind(&ShellApplicationDelegate::StartWindowManager,
90 base::Unretained(this)));
91 }
92
93 void ShellApplicationDelegate::StartSystemUI() {
94 StartRestartableService("mojo:ash_sysui",
95 base::Bind(&ShellApplicationDelegate::StartSystemUI,
96 base::Unretained(this)));
97 }
98
99 void ShellApplicationDelegate::StartBrowserDriver() {
100 StartRestartableService(
101 "mojo:browser_driver",
102 base::Bind(&ShellApplicationDelegate::StartBrowserDriver,
103 base::Unretained(this)));
104 }
105
106 void ShellApplicationDelegate::StartQuickLaunch() {
107 StartRestartableService(
108 "mojo:quick_launch",
109 base::Bind(&ShellApplicationDelegate::StartQuickLaunch,
110 base::Unretained(this)));
111 }
112
113 void ShellApplicationDelegate::StartScreenlock() {
114 StartRestartableService(
115 "mojo:screenlock",
116 base::Bind(&ShellApplicationDelegate::StartScreenlock,
117 base::Unretained(this)));
118 }
119
120 void ShellApplicationDelegate::StopScreenlock() {
121 auto connection = connections_.find("mojo:screenlock");
122 DCHECK(connections_.end() != connection);
123 connections_.erase(connection);
124 }
125
126 void ShellApplicationDelegate::StartRestartableService(
127 const std::string& url,
128 const base::Closure& restart_callback) {
129 // TODO(beng): This would be the place to insert logic that counted restarts
130 // to avoid infinite crash-restart loops.
131 scoped_ptr<mojo::Connection> connection = connector_->Connect(url);
132 // Note: |connection| may be null if we've lost our connection to the shell.
133 if (connection) {
134 connection->SetConnectionLostClosure(restart_callback);
135 connection->AddInterface<mojom::Shell>(this);
136 connections_[url] = std::move(connection);
137 }
138 }
139
140 } // namespace shell
141 } // namespace main
OLDNEW
« no previous file with comments | « mash/shell/shell_application_delegate.h ('k') | mash/wm/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698