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