| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef CHROME_BROWSER_UI_ASH_SESSION_CONTROLLER_CLIENT_H_ | 5 #ifndef CHROME_BROWSER_UI_ASH_SESSION_CONTROLLER_CLIENT_H_ |
| 6 #define CHROME_BROWSER_UI_ASH_SESSION_CONTROLLER_CLIENT_H_ | 6 #define CHROME_BROWSER_UI_ASH_SESSION_CONTROLLER_CLIENT_H_ |
| 7 | 7 |
| 8 #include "ash/public/interfaces/session_controller.mojom.h" | 8 #include "ash/public/interfaces/session_controller.mojom.h" |
| 9 #include "base/callback_forward.h" | 9 #include "base/callback_forward.h" |
| 10 #include "base/gtest_prod_util.h" |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "chrome/browser/supervised_user/supervised_user_service_observer.h" |
| 11 #include "components/session_manager/core/session_manager_observer.h" | 14 #include "components/session_manager/core/session_manager_observer.h" |
| 12 #include "components/user_manager/user_manager.h" | 15 #include "components/user_manager/user_manager.h" |
| 13 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
| 14 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
| 15 #include "mojo/public/cpp/bindings/binding.h" | 18 #include "mojo/public/cpp/bindings/binding.h" |
| 16 | 19 |
| 20 class Profile; |
| 21 |
| 17 namespace ash { | 22 namespace ash { |
| 18 enum class AddUserSessionPolicy; | 23 enum class AddUserSessionPolicy; |
| 19 } | 24 } |
| 20 | 25 |
| 21 namespace user_manager { | 26 namespace user_manager { |
| 22 class User; | 27 class User; |
| 23 } | 28 } |
| 24 | 29 |
| 25 // Updates session state etc to ash via SessionController interface and handles | 30 // Updates session state etc to ash via SessionController interface and handles |
| 26 // session related calls from ash. | 31 // session related calls from ash. |
| 27 // TODO(xiyuan): Update when UserSessionStateObserver is gone. | 32 // TODO(xiyuan): Update when UserSessionStateObserver is gone. |
| 28 class SessionControllerClient | 33 class SessionControllerClient |
| 29 : public ash::mojom::SessionControllerClient, | 34 : public ash::mojom::SessionControllerClient, |
| 30 public user_manager::UserManager::UserSessionStateObserver, | 35 public user_manager::UserManager::UserSessionStateObserver, |
| 31 public user_manager::UserManager::Observer, | 36 public user_manager::UserManager::Observer, |
| 32 public session_manager::SessionManagerObserver, | 37 public session_manager::SessionManagerObserver, |
| 38 public SupervisedUserServiceObserver, |
| 33 public content::NotificationObserver { | 39 public content::NotificationObserver { |
| 34 public: | 40 public: |
| 35 SessionControllerClient(); | 41 SessionControllerClient(); |
| 36 ~SessionControllerClient() override; | 42 ~SessionControllerClient() override; |
| 37 | 43 |
| 44 void Init(); |
| 45 |
| 38 static SessionControllerClient* Get(); | 46 static SessionControllerClient* Get(); |
| 39 | 47 |
| 40 // Calls SessionController to start locking ash. |callback| will be invoked | 48 // Calls SessionController to start locking ash. |callback| will be invoked |
| 41 // to indicate whether the lock is successful. If |locked| is true, the post | 49 // to indicate whether the lock is successful. If |locked| is true, the post |
| 42 // lock animation is finished and ash is fully locked. Otherwise, the lock | 50 // lock animation is finished and ash is fully locked. Otherwise, the lock |
| 43 // is failed somehow. | 51 // is failed somehow. |
| 44 using StartLockCallback = base::Callback<void(bool locked)>; | 52 using StartLockCallback = base::Callback<void(bool locked)>; |
| 45 void StartLock(StartLockCallback callback); | 53 void StartLock(StartLockCallback callback); |
| 46 | 54 |
| 47 // Calls ash SessionController to run unlock animation. | 55 // Calls ash SessionController to run unlock animation. |
| 48 // |animation_finished_callback| will be invoked when the animation finishes. | 56 // |animation_finished_callback| will be invoked when the animation finishes. |
| 49 void RunUnlockAnimation(base::Closure animation_finished_callback); | 57 void RunUnlockAnimation(base::Closure animation_finished_callback); |
| 50 | 58 |
| 51 // ash::mojom::SessionControllerClient: | 59 // ash::mojom::SessionControllerClient: |
| 52 void RequestLockScreen() override; | 60 void RequestLockScreen() override; |
| 53 void SwitchActiveUser(const AccountId& account_id) override; | 61 void SwitchActiveUser(const AccountId& account_id) override; |
| 54 void CycleActiveUser(ash::CycleUserDirection direction) override; | 62 void CycleActiveUser(ash::CycleUserDirection direction) override; |
| 55 | 63 |
| 56 // user_manager::UserManager::UserSessionStateObserver: | 64 // user_manager::UserManager::UserSessionStateObserver: |
| 57 void ActiveUserChanged(const user_manager::User* active_user) override; | 65 void ActiveUserChanged(const user_manager::User* active_user) override; |
| 58 void UserAddedToSession(const user_manager::User* added_user) override; | 66 void UserAddedToSession(const user_manager::User* added_user) override; |
| 59 void UserChangedChildStatus(user_manager::User* user) override; | 67 void UserChangedChildStatus(user_manager::User* user) override; |
| 60 | 68 |
| 61 // user_manager::UserManager::Observer | 69 // user_manager::UserManager::Observer |
| 62 void OnUserImageChanged(const user_manager::User& user) override; | 70 void OnUserImageChanged(const user_manager::User& user) override; |
| 63 | 71 |
| 64 // session_manager::SessionManagerObserver: | 72 // session_manager::SessionManagerObserver: |
| 65 void OnSessionStateChanged() override; | 73 void OnSessionStateChanged() override; |
| 66 | 74 |
| 75 // SupervisedUserServiceObserver: |
| 76 void OnCustodianInfoChanged() override; |
| 77 |
| 67 // content::NotificationObserver: | 78 // content::NotificationObserver: |
| 68 void Observe(int type, | 79 void Observe(int type, |
| 69 const content::NotificationSource& source, | 80 const content::NotificationSource& source, |
| 70 const content::NotificationDetails& details) override; | 81 const content::NotificationDetails& details) override; |
| 71 | 82 |
| 72 // TODO(xiyuan): Remove after SessionStateDelegateChromeOS is gone. | 83 // TODO(xiyuan): Remove after SessionStateDelegateChromeOS is gone. |
| 73 static bool CanLockScreen(); | 84 static bool CanLockScreen(); |
| 74 static bool ShouldLockScreenAutomatically(); | 85 static bool ShouldLockScreenAutomatically(); |
| 75 static ash::AddUserSessionPolicy GetAddUserSessionPolicy(); | 86 static ash::AddUserSessionPolicy GetAddUserSessionPolicy(); |
| 76 static void DoLockScreen(); | 87 static void DoLockScreen(); |
| 77 static void DoSwitchActiveUser(const AccountId& account_id); | 88 static void DoSwitchActiveUser(const AccountId& account_id); |
| 78 static void DoCycleActiveUser(ash::CycleUserDirection direction); | 89 static void DoCycleActiveUser(ash::CycleUserDirection direction); |
| 79 | 90 |
| 80 // Flushes the mojo pipe to ash. | 91 // Flushes the mojo pipe to ash. |
| 81 static void FlushForTesting(); | 92 static void FlushForTesting(); |
| 82 | 93 |
| 83 private: | 94 private: |
| 84 // Connects or reconnects to the |session_controller_| interface and set | 95 FRIEND_TEST_ALL_PREFIXES(SessionControllerClientTest, SupervisedUser); |
| 85 // this object as its client. | 96 |
| 86 void ConnectToSessionControllerAndSetClient(); | 97 // Called when the login profile is ready. |
| 98 void OnLoginUserProfilePrepared(Profile* profile); |
| 99 |
| 100 // Sends the user session info for a given profile. |
| 101 void SendUserSessionForProfile(Profile* profile); |
| 102 |
| 103 // Connects to the |session_controller_| interface. |
| 104 void ConnectToSessionController(); |
| 87 | 105 |
| 88 // Sends session info to ash. | 106 // Sends session info to ash. |
| 89 void SendSessionInfoIfChanged(); | 107 void SendSessionInfoIfChanged(); |
| 90 | 108 |
| 91 // Sends the user session info. | 109 // Sends the user session info. |
| 92 void SendUserSession(const user_manager::User& user); | 110 void SendUserSession(const user_manager::User& user); |
| 93 | 111 |
| 94 // Sends the order of user sessions to ash. | 112 // Sends the order of user sessions to ash. |
| 95 void SendUserSessionOrder(); | 113 void SendUserSessionOrder(); |
| 96 | 114 |
| 97 // Binds to the client interface. | 115 // Binds to the client interface. |
| 98 mojo::Binding<ash::mojom::SessionControllerClient> binding_; | 116 mojo::Binding<ash::mojom::SessionControllerClient> binding_; |
| 99 | 117 |
| 100 // SessionController interface in ash. | 118 // SessionController interface in ash. |
| 101 ash::mojom::SessionControllerPtr session_controller_; | 119 ash::mojom::SessionControllerPtr session_controller_; |
| 102 | 120 |
| 103 // Whether the primary user session info is sent to ash. | 121 // Whether the primary user session info is sent to ash. |
| 104 bool primary_user_session_sent_ = false; | 122 bool primary_user_session_sent_ = false; |
| 105 | 123 |
| 106 // For observing NOTIFICATION_APP_TERMINATING. | 124 // If the session is for a supervised user, the profile of that user. |
| 125 // Chrome OS only supports a single supervised user in a session. |
| 126 Profile* supervised_user_profile_ = nullptr; |
| 127 |
| 107 content::NotificationRegistrar registrar_; | 128 content::NotificationRegistrar registrar_; |
| 108 | 129 |
| 109 ash::mojom::SessionInfoPtr last_sent_session_info_; | 130 ash::mojom::SessionInfoPtr last_sent_session_info_; |
| 110 | 131 |
| 132 base::WeakPtrFactory<SessionControllerClient> weak_ptr_factory_; |
| 133 |
| 111 DISALLOW_COPY_AND_ASSIGN(SessionControllerClient); | 134 DISALLOW_COPY_AND_ASSIGN(SessionControllerClient); |
| 112 }; | 135 }; |
| 113 | 136 |
| 114 #endif // CHROME_BROWSER_UI_ASH_SESSION_CONTROLLER_CLIENT_H_ | 137 #endif // CHROME_BROWSER_UI_ASH_SESSION_CONTROLLER_CLIENT_H_ |
| OLD | NEW |