| OLD | NEW |
| 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" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 bool Session::OnConnect(const shell::Identity& remote_identity, | 38 bool Session::OnConnect(const shell::Identity& remote_identity, |
| 39 shell::InterfaceRegistry* registry) { | 39 shell::InterfaceRegistry* registry) { |
| 40 registry->AddInterface<mojom::Session>(this); | 40 registry->AddInterface<mojom::Session>(this); |
| 41 return true; | 41 return true; |
| 42 } | 42 } |
| 43 | 43 |
| 44 void Session::Logout() { | 44 void Session::Logout() { |
| 45 // TODO(beng): Notify connected listeners that login is happening, potentially | 45 // TODO(beng): Notify connected listeners that login is happening, potentially |
| 46 // give them the option to stop it. | 46 // give them the option to stop it. |
| 47 mash::login::mojom::LoginPtr login; | 47 mash::login::mojom::LoginPtr login; |
| 48 connector()->ConnectToInterface("mojo:login", &login); | 48 connector()->ConnectToInterface("service:login", &login); |
| 49 login->ShowLoginUI(); | 49 login->ShowLoginUI(); |
| 50 // This kills the user environment. | 50 // This kills the user environment. |
| 51 base::MessageLoop::current()->QuitWhenIdle(); | 51 base::MessageLoop::current()->QuitWhenIdle(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void Session::SwitchUser() { | 54 void Session::SwitchUser() { |
| 55 mash::login::mojom::LoginPtr login; | 55 mash::login::mojom::LoginPtr login; |
| 56 connector()->ConnectToInterface("mojo:login", &login); | 56 connector()->ConnectToInterface("service:login", &login); |
| 57 login->SwitchUser(); | 57 login->SwitchUser(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void Session::AddScreenlockStateListener( | 60 void Session::AddScreenlockStateListener( |
| 61 mojom::ScreenlockStateListenerPtr listener) { | 61 mojom::ScreenlockStateListenerPtr listener) { |
| 62 listener->ScreenlockStateChanged(screen_locked_); | 62 listener->ScreenlockStateChanged(screen_locked_); |
| 63 screenlock_listeners_.AddPtr(std::move(listener)); | 63 screenlock_listeners_.AddPtr(std::move(listener)); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void Session::LockScreen() { | 66 void Session::LockScreen() { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 84 StopScreenlock(); | 84 StopScreenlock(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void Session::Create(const shell::Identity& remote_identity, | 87 void Session::Create(const shell::Identity& remote_identity, |
| 88 mojom::SessionRequest request) { | 88 mojom::SessionRequest request) { |
| 89 bindings_.AddBinding(this, std::move(request)); | 89 bindings_.AddBinding(this, std::move(request)); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void Session::StartWindowManager() { | 92 void Session::StartWindowManager() { |
| 93 StartRestartableService( | 93 StartRestartableService( |
| 94 "mojo:ash", | 94 "service:ash", |
| 95 base::Bind(&Session::StartWindowManager, | 95 base::Bind(&Session::StartWindowManager, |
| 96 base::Unretained(this))); | 96 base::Unretained(this))); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void Session::StartAppDriver() { | 99 void Session::StartAppDriver() { |
| 100 StartRestartableService( | 100 StartRestartableService( |
| 101 "mojo:app_driver", | 101 "service:app_driver", |
| 102 base::Bind(&Session::StartAppDriver, base::Unretained(this))); | 102 base::Bind(&Session::StartAppDriver, base::Unretained(this))); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void Session::StartQuickLaunch() { | 105 void Session::StartQuickLaunch() { |
| 106 StartRestartableService( | 106 StartRestartableService( |
| 107 "mojo:quick_launch", | 107 "service:quick_launch", |
| 108 base::Bind(&Session::StartQuickLaunch, | 108 base::Bind(&Session::StartQuickLaunch, |
| 109 base::Unretained(this))); | 109 base::Unretained(this))); |
| 110 } | 110 } |
| 111 | 111 |
| 112 void Session::StartScreenlock() { | 112 void Session::StartScreenlock() { |
| 113 StartRestartableService( | 113 StartRestartableService( |
| 114 "mojo:screenlock", | 114 "service:screenlock", |
| 115 base::Bind(&Session::StartScreenlock, | 115 base::Bind(&Session::StartScreenlock, |
| 116 base::Unretained(this))); | 116 base::Unretained(this))); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void Session::StopScreenlock() { | 119 void Session::StopScreenlock() { |
| 120 auto connection = connections_.find("mojo:screenlock"); | 120 auto connection = connections_.find("service:screenlock"); |
| 121 DCHECK(connections_.end() != connection); | 121 DCHECK(connections_.end() != connection); |
| 122 connections_.erase(connection); | 122 connections_.erase(connection); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void Session::StartRestartableService( | 125 void Session::StartRestartableService( |
| 126 const std::string& url, | 126 const std::string& url, |
| 127 const base::Closure& restart_callback) { | 127 const base::Closure& restart_callback) { |
| 128 // TODO(beng): This would be the place to insert logic that counted restarts | 128 // TODO(beng): This would be the place to insert logic that counted restarts |
| 129 // to avoid infinite crash-restart loops. | 129 // to avoid infinite crash-restart loops. |
| 130 std::unique_ptr<shell::Connection> connection = | 130 std::unique_ptr<shell::Connection> connection = |
| 131 connector()->Connect(url); | 131 connector()->Connect(url); |
| 132 // Note: |connection| may be null if we've lost our connection to the shell. | 132 // Note: |connection| may be null if we've lost our connection to the shell. |
| 133 if (connection) { | 133 if (connection) { |
| 134 connection->SetConnectionLostClosure( | 134 connection->SetConnectionLostClosure( |
| 135 base::Bind(&LogAndCallServiceRestartCallback, url, restart_callback)); | 135 base::Bind(&LogAndCallServiceRestartCallback, url, restart_callback)); |
| 136 connections_[url] = std::move(connection); | 136 connections_[url] = std::move(connection); |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 | 139 |
| 140 } // namespace session | 140 } // namespace session |
| 141 } // namespace main | 141 } // namespace main |
| OLD | NEW |