| 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 "content/public/common/service_names.mojom.h" |
| 11 #include "mash/login/public/interfaces/constants.mojom.h" |
| 10 #include "mash/login/public/interfaces/login.mojom.h" | 12 #include "mash/login/public/interfaces/login.mojom.h" |
| 13 #include "mash/quick_launch/public/interfaces/constants.mojom.h" |
| 14 #include "mash/screenlock/public/interfaces/constants.mojom.h" |
| 11 #include "services/service_manager/public/cpp/connection.h" | 15 #include "services/service_manager/public/cpp/connection.h" |
| 12 #include "services/service_manager/public/cpp/connector.h" | 16 #include "services/service_manager/public/cpp/connector.h" |
| 13 #include "services/service_manager/public/cpp/interface_registry.h" | 17 #include "services/service_manager/public/cpp/interface_registry.h" |
| 14 #include "services/service_manager/public/cpp/service_context.h" | 18 #include "services/service_manager/public/cpp/service_context.h" |
| 15 | 19 |
| 16 namespace { | 20 namespace { |
| 17 | 21 |
| 18 void LogAndCallServiceRestartCallback(const std::string& url, | 22 void LogAndCallServiceRestartCallback(const std::string& url, |
| 19 const base::Closure& callback) { | 23 const base::Closure& callback) { |
| 20 LOG(ERROR) << "Restarting service: " << url; | 24 LOG(ERROR) << "Restarting service: " << url; |
| 21 callback.Run(); | 25 callback.Run(); |
| 22 } | 26 } |
| 23 | 27 |
| 24 } // namespace | 28 } // namespace |
| 25 | 29 |
| 26 namespace mash { | 30 namespace mash { |
| 27 namespace session { | 31 namespace session { |
| 28 | 32 |
| 29 Session::Session() : screen_locked_(false) {} | 33 Session::Session() : screen_locked_(false) {} |
| 30 Session::~Session() {} | 34 Session::~Session() {} |
| 31 | 35 |
| 32 void Session::OnStart() { | 36 void Session::OnStart() { |
| 33 StartWindowManager(); | 37 StartWindowManager(); |
| 34 StartQuickLaunch(); | 38 StartQuickLaunch(); |
| 35 | 39 |
| 36 // Launch a chrome window for dev convience; don't do this in the long term. | 40 // Launch a chrome window for dev convience; don't do this in the long term. |
| 37 context()->connector()->Connect("content_browser"); | 41 context()->connector()->Connect(content::mojom::kBrowserServiceName); |
| 38 } | 42 } |
| 39 | 43 |
| 40 bool Session::OnConnect(const service_manager::ServiceInfo& remote_info, | 44 bool Session::OnConnect(const service_manager::ServiceInfo& remote_info, |
| 41 service_manager::InterfaceRegistry* registry) { | 45 service_manager::InterfaceRegistry* registry) { |
| 42 registry->AddInterface<mojom::Session>(this); | 46 registry->AddInterface<mojom::Session>(this); |
| 43 return true; | 47 return true; |
| 44 } | 48 } |
| 45 | 49 |
| 46 void Session::Logout() { | 50 void Session::Logout() { |
| 47 // TODO(beng): Notify connected listeners that login is happening, potentially | 51 // TODO(beng): Notify connected listeners that login is happening, potentially |
| 48 // give them the option to stop it. | 52 // give them the option to stop it. |
| 49 mash::login::mojom::LoginPtr login; | 53 mash::login::mojom::LoginPtr login; |
| 50 context()->connector()->ConnectToInterface("login", &login); | 54 context()->connector()->ConnectToInterface(login::mojom::kServiceName, |
| 55 &login); |
| 51 login->ShowLoginUI(); | 56 login->ShowLoginUI(); |
| 52 // This kills the user environment. | 57 // This kills the user environment. |
| 53 base::MessageLoop::current()->QuitWhenIdle(); | 58 base::MessageLoop::current()->QuitWhenIdle(); |
| 54 } | 59 } |
| 55 | 60 |
| 56 void Session::SwitchUser() { | 61 void Session::SwitchUser() { |
| 57 mash::login::mojom::LoginPtr login; | 62 mash::login::mojom::LoginPtr login; |
| 58 context()->connector()->ConnectToInterface("login", &login); | 63 context()->connector()->ConnectToInterface(login::mojom::kServiceName, |
| 64 &login); |
| 59 login->SwitchUser(); | 65 login->SwitchUser(); |
| 60 } | 66 } |
| 61 | 67 |
| 62 void Session::AddScreenlockStateListener( | 68 void Session::AddScreenlockStateListener( |
| 63 mojom::ScreenlockStateListenerPtr listener) { | 69 mojom::ScreenlockStateListenerPtr listener) { |
| 64 listener->ScreenlockStateChanged(screen_locked_); | 70 listener->ScreenlockStateChanged(screen_locked_); |
| 65 screenlock_listeners_.AddPtr(std::move(listener)); | 71 screenlock_listeners_.AddPtr(std::move(listener)); |
| 66 } | 72 } |
| 67 | 73 |
| 68 void Session::LockScreen() { | 74 void Session::LockScreen() { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 93 | 99 |
| 94 void Session::StartWindowManager() { | 100 void Session::StartWindowManager() { |
| 95 StartRestartableService( | 101 StartRestartableService( |
| 96 "ash", | 102 "ash", |
| 97 base::Bind(&Session::StartWindowManager, | 103 base::Bind(&Session::StartWindowManager, |
| 98 base::Unretained(this))); | 104 base::Unretained(this))); |
| 99 } | 105 } |
| 100 | 106 |
| 101 void Session::StartQuickLaunch() { | 107 void Session::StartQuickLaunch() { |
| 102 StartRestartableService( | 108 StartRestartableService( |
| 103 "quick_launch", | 109 quick_launch::mojom::kServiceName, |
| 104 base::Bind(&Session::StartQuickLaunch, | 110 base::Bind(&Session::StartQuickLaunch, |
| 105 base::Unretained(this))); | 111 base::Unretained(this))); |
| 106 } | 112 } |
| 107 | 113 |
| 108 void Session::StartScreenlock() { | 114 void Session::StartScreenlock() { |
| 109 StartRestartableService( | 115 StartRestartableService( |
| 110 "screenlock", | 116 screenlock::mojom::kServiceName, |
| 111 base::Bind(&Session::StartScreenlock, | 117 base::Bind(&Session::StartScreenlock, |
| 112 base::Unretained(this))); | 118 base::Unretained(this))); |
| 113 } | 119 } |
| 114 | 120 |
| 115 void Session::StopScreenlock() { | 121 void Session::StopScreenlock() { |
| 116 auto connection = connections_.find("screenlock"); | 122 auto connection = connections_.find("screenlock"); |
| 117 DCHECK(connections_.end() != connection); | 123 DCHECK(connections_.end() != connection); |
| 118 connections_.erase(connection); | 124 connections_.erase(connection); |
| 119 } | 125 } |
| 120 | 126 |
| 121 void Session::StartRestartableService( | 127 void Session::StartRestartableService( |
| 122 const std::string& url, | 128 const std::string& url, |
| 123 const base::Closure& restart_callback) { | 129 const base::Closure& restart_callback) { |
| 124 // TODO(beng): This would be the place to insert logic that counted restarts | 130 // TODO(beng): This would be the place to insert logic that counted restarts |
| 125 // to avoid infinite crash-restart loops. | 131 // to avoid infinite crash-restart loops. |
| 126 std::unique_ptr<service_manager::Connection> connection = | 132 std::unique_ptr<service_manager::Connection> connection = |
| 127 context()->connector()->Connect(url); | 133 context()->connector()->Connect(url); |
| 128 // Note: |connection| may be null if we've lost our connection to the service | 134 // Note: |connection| may be null if we've lost our connection to the service |
| 129 // manager. | 135 // manager. |
| 130 if (connection) { | 136 if (connection) { |
| 131 connection->SetConnectionLostClosure( | 137 connection->SetConnectionLostClosure( |
| 132 base::Bind(&LogAndCallServiceRestartCallback, url, restart_callback)); | 138 base::Bind(&LogAndCallServiceRestartCallback, url, restart_callback)); |
| 133 connections_[url] = std::move(connection); | 139 connections_[url] = std::move(connection); |
| 134 } | 140 } |
| 135 } | 141 } |
| 136 | 142 |
| 137 } // namespace session | 143 } // namespace session |
| 138 } // namespace main | 144 } // namespace main |
| OLD | NEW |