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

Side by Side Diff: mash/session/session.cc

Issue 2179023004: Make Service own ServiceContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 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/session/session.h ('k') | mash/task_viewer/task_viewer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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/session/session.h" 5 #include "mash/session/session.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/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "mash/login/public/interfaces/login.mojom.h" 10 #include "mash/login/public/interfaces/login.mojom.h"
11 #include "services/shell/public/cpp/connection.h" 11 #include "services/shell/public/cpp/connection.h"
12 #include "services/shell/public/cpp/connector.h" 12 #include "services/shell/public/cpp/connector.h"
13 13
14 namespace { 14 namespace {
15 15
16 void LogAndCallServiceRestartCallback(const std::string& url, 16 void LogAndCallServiceRestartCallback(const std::string& url,
17 const base::Closure& callback) { 17 const base::Closure& callback) {
18 LOG(ERROR) << "Restarting service: " << url; 18 LOG(ERROR) << "Restarting service: " << url;
19 callback.Run(); 19 callback.Run();
20 } 20 }
21 21
22 } // namespace 22 } // namespace
23 23
24 namespace mash { 24 namespace mash {
25 namespace session { 25 namespace session {
26 26
27 Session::Session() : connector_(nullptr), screen_locked_(false) {} 27 Session::Session() : screen_locked_(false) {}
28 Session::~Session() {} 28 Session::~Session() {}
29 29
30 void Session::OnStart(shell::Connector* connector, 30 void Session::OnStart(const shell::Identity& identity) {
31 const shell::Identity& identity,
32 uint32_t id) {
33 connector_ = connector;
34 StartAppDriver(); 31 StartAppDriver();
35 StartWindowManager(); 32 StartWindowManager();
36 StartSystemUI(); 33 StartSystemUI();
37 StartQuickLaunch(); 34 StartQuickLaunch();
38 } 35 }
39 36
40 bool Session::OnConnect(shell::Connection* connection) { 37 bool Session::OnConnect(shell::Connection* connection) {
41 connection->AddInterface<mojom::Session>(this); 38 connection->AddInterface<mojom::Session>(this);
42 return true; 39 return true;
43 } 40 }
44 41
45 void Session::Logout() { 42 void Session::Logout() {
46 // TODO(beng): Notify connected listeners that login is happening, potentially 43 // TODO(beng): Notify connected listeners that login is happening, potentially
47 // give them the option to stop it. 44 // give them the option to stop it.
48 mash::login::mojom::LoginPtr login; 45 mash::login::mojom::LoginPtr login;
49 connector_->ConnectToInterface("mojo:login", &login); 46 connector()->ConnectToInterface("mojo:login", &login);
50 login->ShowLoginUI(); 47 login->ShowLoginUI();
51 // This kills the user environment. 48 // This kills the user environment.
52 base::MessageLoop::current()->QuitWhenIdle(); 49 base::MessageLoop::current()->QuitWhenIdle();
53 } 50 }
54 51
55 void Session::SwitchUser() { 52 void Session::SwitchUser() {
56 mash::login::mojom::LoginPtr login; 53 mash::login::mojom::LoginPtr login;
57 connector_->ConnectToInterface("mojo:login", &login); 54 connector()->ConnectToInterface("mojo:login", &login);
58 login->SwitchUser(); 55 login->SwitchUser();
59 } 56 }
60 57
61 void Session::AddScreenlockStateListener( 58 void Session::AddScreenlockStateListener(
62 mojom::ScreenlockStateListenerPtr listener) { 59 mojom::ScreenlockStateListenerPtr listener) {
63 listener->ScreenlockStateChanged(screen_locked_); 60 listener->ScreenlockStateChanged(screen_locked_);
64 screenlock_listeners_.AddPtr(std::move(listener)); 61 screenlock_listeners_.AddPtr(std::move(listener));
65 } 62 }
66 63
67 void Session::LockScreen() { 64 void Session::LockScreen() {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 auto connection = connections_.find("mojo:screenlock"); 124 auto connection = connections_.find("mojo:screenlock");
128 DCHECK(connections_.end() != connection); 125 DCHECK(connections_.end() != connection);
129 connections_.erase(connection); 126 connections_.erase(connection);
130 } 127 }
131 128
132 void Session::StartRestartableService( 129 void Session::StartRestartableService(
133 const std::string& url, 130 const std::string& url,
134 const base::Closure& restart_callback) { 131 const base::Closure& restart_callback) {
135 // TODO(beng): This would be the place to insert logic that counted restarts 132 // TODO(beng): This would be the place to insert logic that counted restarts
136 // to avoid infinite crash-restart loops. 133 // to avoid infinite crash-restart loops.
137 std::unique_ptr<shell::Connection> connection = connector_->Connect(url); 134 std::unique_ptr<shell::Connection> connection =
135 connector()->Connect(url);
138 // Note: |connection| may be null if we've lost our connection to the shell. 136 // Note: |connection| may be null if we've lost our connection to the shell.
139 if (connection) { 137 if (connection) {
140 connection->SetConnectionLostClosure( 138 connection->SetConnectionLostClosure(
141 base::Bind(&LogAndCallServiceRestartCallback, url, restart_callback)); 139 base::Bind(&LogAndCallServiceRestartCallback, url, restart_callback));
142 connection->AddInterface<mojom::Session>(this); 140 connection->AddInterface<mojom::Session>(this);
143 connections_[url] = std::move(connection); 141 connections_[url] = std::move(connection);
144 } 142 }
145 } 143 }
146 144
147 } // namespace session 145 } // namespace session
148 } // namespace main 146 } // namespace main
OLDNEW
« no previous file with comments | « mash/session/session.h ('k') | mash/task_viewer/task_viewer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698