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 11 matching lines...) Expand all Loading... |
22 } | 22 } |
23 | 23 |
24 } // namespace | 24 } // namespace |
25 | 25 |
26 namespace mash { | 26 namespace mash { |
27 namespace session { | 27 namespace session { |
28 | 28 |
29 Session::Session() : screen_locked_(false) {} | 29 Session::Session() : screen_locked_(false) {} |
30 Session::~Session() {} | 30 Session::~Session() {} |
31 | 31 |
32 void Session::OnStart() { | 32 void Session::OnStart(service_manager::ServiceContext* context) { |
| 33 context_ = context; |
| 34 |
33 StartWindowManager(); | 35 StartWindowManager(); |
34 StartQuickLaunch(); | 36 StartQuickLaunch(); |
35 | 37 |
36 // Launch a chrome window for dev convience; don't do this in the long term. | 38 // Launch a chrome window for dev convience; don't do this in the long term. |
37 context()->connector()->Connect("service:content_browser"); | 39 context->connector()->Connect("service:content_browser"); |
38 } | 40 } |
39 | 41 |
40 bool Session::OnConnect(const service_manager::ServiceInfo& remote_info, | 42 bool Session::OnConnect(const service_manager::ServiceInfo& remote_info, |
41 service_manager::InterfaceRegistry* registry) { | 43 service_manager::InterfaceRegistry* registry) { |
42 registry->AddInterface<mojom::Session>(this); | 44 registry->AddInterface<mojom::Session>(this); |
43 return true; | 45 return true; |
44 } | 46 } |
45 | 47 |
46 void Session::Logout() { | 48 void Session::Logout() { |
47 // TODO(beng): Notify connected listeners that login is happening, potentially | 49 // TODO(beng): Notify connected listeners that login is happening, potentially |
48 // give them the option to stop it. | 50 // give them the option to stop it. |
49 mash::login::mojom::LoginPtr login; | 51 mash::login::mojom::LoginPtr login; |
50 context()->connector()->ConnectToInterface("service:login", &login); | 52 context_->connector()->ConnectToInterface("service:login", &login); |
51 login->ShowLoginUI(); | 53 login->ShowLoginUI(); |
52 // This kills the user environment. | 54 // This kills the user environment. |
53 base::MessageLoop::current()->QuitWhenIdle(); | 55 base::MessageLoop::current()->QuitWhenIdle(); |
54 } | 56 } |
55 | 57 |
56 void Session::SwitchUser() { | 58 void Session::SwitchUser() { |
57 mash::login::mojom::LoginPtr login; | 59 mash::login::mojom::LoginPtr login; |
58 context()->connector()->ConnectToInterface("service:login", &login); | 60 context_->connector()->ConnectToInterface("service:login", &login); |
59 login->SwitchUser(); | 61 login->SwitchUser(); |
60 } | 62 } |
61 | 63 |
62 void Session::AddScreenlockStateListener( | 64 void Session::AddScreenlockStateListener( |
63 mojom::ScreenlockStateListenerPtr listener) { | 65 mojom::ScreenlockStateListenerPtr listener) { |
64 listener->ScreenlockStateChanged(screen_locked_); | 66 listener->ScreenlockStateChanged(screen_locked_); |
65 screenlock_listeners_.AddPtr(std::move(listener)); | 67 screenlock_listeners_.AddPtr(std::move(listener)); |
66 } | 68 } |
67 | 69 |
68 void Session::LockScreen() { | 70 void Session::LockScreen() { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 DCHECK(connections_.end() != connection); | 119 DCHECK(connections_.end() != connection); |
118 connections_.erase(connection); | 120 connections_.erase(connection); |
119 } | 121 } |
120 | 122 |
121 void Session::StartRestartableService( | 123 void Session::StartRestartableService( |
122 const std::string& url, | 124 const std::string& url, |
123 const base::Closure& restart_callback) { | 125 const base::Closure& restart_callback) { |
124 // TODO(beng): This would be the place to insert logic that counted restarts | 126 // TODO(beng): This would be the place to insert logic that counted restarts |
125 // to avoid infinite crash-restart loops. | 127 // to avoid infinite crash-restart loops. |
126 std::unique_ptr<service_manager::Connection> connection = | 128 std::unique_ptr<service_manager::Connection> connection = |
127 context()->connector()->Connect(url); | 129 context_->connector()->Connect(url); |
128 // Note: |connection| may be null if we've lost our connection to the service | 130 // Note: |connection| may be null if we've lost our connection to the service |
129 // manager. | 131 // manager. |
130 if (connection) { | 132 if (connection) { |
131 connection->SetConnectionLostClosure( | 133 connection->SetConnectionLostClosure( |
132 base::Bind(&LogAndCallServiceRestartCallback, url, restart_callback)); | 134 base::Bind(&LogAndCallServiceRestartCallback, url, restart_callback)); |
133 connections_[url] = std::move(connection); | 135 connections_[url] = std::move(connection); |
134 } | 136 } |
135 } | 137 } |
136 | 138 |
137 } // namespace session | 139 } // namespace session |
138 } // namespace main | 140 } // namespace main |
OLD | NEW |