OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_CHROMEOS_LOCK_SCREEN_APPS_STATE_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOCK_SCREEN_APPS_STATE_CONTROLLER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOCK_SCREEN_APPS_STATE_CONTROLLER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOCK_SCREEN_APPS_STATE_CONTROLLER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "ash/public/interfaces/tray_action.mojom.h" | 10 #include "ash/public/interfaces/tray_action.mojom.h" |
11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 12 #include "base/scoped_observer.h" |
| 13 #include "chrome/browser/chromeos/lock_screen_apps/app_manager.h" |
12 #include "chrome/browser/chromeos/lock_screen_apps/state_observer.h" | 14 #include "chrome/browser/chromeos/lock_screen_apps/state_observer.h" |
| 15 #include "components/session_manager/core/session_manager_observer.h" |
13 #include "mojo/public/cpp/bindings/binding.h" | 16 #include "mojo/public/cpp/bindings/binding.h" |
14 | 17 |
| 18 class Profile; |
| 19 |
| 20 namespace session_manager { |
| 21 class SessionManager; |
| 22 } |
| 23 |
15 namespace lock_screen_apps { | 24 namespace lock_screen_apps { |
16 | 25 |
17 class StateObserver; | 26 class StateObserver; |
18 | 27 |
19 // Manages state of lock screen action handler apps, and notifies | 28 // Manages state of lock screen action handler apps, and notifies |
20 // interested parties as the state changes. | 29 // interested parties as the state changes. |
21 // Currently assumes single supported action - NEW_NOTE. | 30 // Currently assumes single supported action - NEW_NOTE. |
22 class StateController : public ash::mojom::TrayActionClient { | 31 class StateController : public ash::mojom::TrayActionClient, |
| 32 public session_manager::SessionManagerObserver { |
23 public: | 33 public: |
24 // Returns whether the StateController is enabled - it is currently guarded by | 34 // Returns whether the StateController is enabled - it is currently guarded by |
25 // a feature flag. If not enabled, |StateController| instance is not allowed | 35 // a feature flag. If not enabled, |StateController| instance is not allowed |
26 // to be created. |Get| will still work, but it will return nullptr. | 36 // to be created. |Get| will still work, but it will return nullptr. |
27 static bool IsEnabled(); | 37 static bool IsEnabled(); |
28 | 38 |
29 // Returns the global StateController instance. Note that this can return | 39 // Returns the global StateController instance. Note that this can return |
30 // nullptr when lock screen apps are not enabled (see |IsEnabled|). | 40 // nullptr when lock screen apps are not enabled (see |IsEnabled|). |
31 static StateController* Get(); | 41 static StateController* Get(); |
32 | 42 |
33 // Note that only one StateController is allowed per process. Creating a | 43 // Note that only one StateController is allowed per process. Creating a |
34 // StateController will set global instance ptr that can be accessed using | 44 // StateController will set global instance ptr that can be accessed using |
35 // |Get|. This pointer will be reset when the StateController is destroyed. | 45 // |Get|. This pointer will be reset when the StateController is destroyed. |
36 StateController(); | 46 StateController(); |
37 ~StateController() override; | 47 ~StateController() override; |
38 | 48 |
39 // Sets the tray action that should be used by |StateController|. | 49 // Sets the tray action that should be used by |StateController|. |
40 // Has to be called before |Initialize|. | 50 // Has to be called before |Initialize|. |
41 void SetTrayActionPtrForTesting(ash::mojom::TrayActionPtr tray_action_ptr); | 51 void SetTrayActionPtrForTesting(ash::mojom::TrayActionPtr tray_action_ptr); |
42 void FlushTrayActionForTesting(); | 52 void FlushTrayActionForTesting(); |
| 53 // Sets test AppManager implementation. Should be called before |
| 54 // |SetPrimaryProfile| |
| 55 void SetAppManagerForTesting(std::unique_ptr<AppManager> app_manager); |
43 | 56 |
44 // Initializes mojo bindings for the StateController - it creates binding to | 57 // Initializes mojo bindings for the StateController - it creates binding to |
45 // ash's tray action interface and sets this object as the interface's client. | 58 // ash's tray action interface and sets this object as the interface's client. |
46 void Initialize(); | 59 void Initialize(); |
| 60 void SetPrimaryProfile(Profile* profile); |
47 | 61 |
48 void AddObserver(StateObserver* observer); | 62 void AddObserver(StateObserver* observer); |
49 void RemoveObserver(StateObserver* observer); | 63 void RemoveObserver(StateObserver* observer); |
50 | 64 |
51 // Gets current state assiciated with the lock screen note action. | 65 // Gets current state assiciated with the lock screen note action. |
52 ash::mojom::TrayActionState GetLockScreenNoteState() const; | 66 ash::mojom::TrayActionState GetLockScreenNoteState() const; |
53 | 67 |
54 // ash::mojom::TrayActionClient: | 68 // ash::mojom::TrayActionClient: |
55 void RequestNewLockScreenNote() override; | 69 void RequestNewLockScreenNote() override; |
56 | 70 |
| 71 // session_manager::SessionManagerObserver: |
| 72 void OnSessionStateChanged() override; |
| 73 |
57 // If there are any active lock screen action handlers, moved their windows | 74 // If there are any active lock screen action handlers, moved their windows |
58 // to background, to ensure lock screen UI is visible. | 75 // to background, to ensure lock screen UI is visible. |
59 void MoveToBackground(); | 76 void MoveToBackground(); |
60 | 77 |
61 // If there are any lock screen action handler in background, moves their | 78 // If there are any lock screen action handler in background, moves their |
62 // windows back to foreground (i.e. visible over lock screen UI). | 79 // windows back to foreground (i.e. visible over lock screen UI). |
63 void MoveToForeground(); | 80 void MoveToForeground(); |
64 | 81 |
65 // Sets the current state - to be used in tests. Hopefully, when this class | 82 // Sets the current state - to be used in tests. Hopefully, when this class |
66 // has more logic implemented, this will not be needed. | 83 // has more logic implemented, this will not be needed. |
67 void SetLockScreenNoteStateForTesting(ash::mojom::TrayActionState state); | 84 void SetLockScreenNoteStateForTesting(ash::mojom::TrayActionState state); |
68 | 85 |
69 private: | 86 private: |
| 87 // Called when app manager reports that note taking availability has changed. |
| 88 void OnNoteTakingAvailabilityChanged(); |
| 89 |
70 // Requests lock screen note action state change to |state|. | 90 // Requests lock screen note action state change to |state|. |
71 // Returns whether the action state has changed. | 91 // Returns whether the action state has changed. |
72 bool UpdateLockScreenNoteState(ash::mojom::TrayActionState state); | 92 bool UpdateLockScreenNoteState(ash::mojom::TrayActionState state); |
73 | 93 |
74 // Notifies observers that the lock screen note action state changed. | 94 // Notifies observers that the lock screen note action state changed. |
75 void NotifyLockScreenNoteStateChanged(); | 95 void NotifyLockScreenNoteStateChanged(); |
76 | 96 |
77 // Lock screen note action state. | 97 // Lock screen note action state. |
78 ash::mojom::TrayActionState lock_screen_note_state_ = | 98 ash::mojom::TrayActionState lock_screen_note_state_ = |
79 ash::mojom::TrayActionState::kNotAvailable; | 99 ash::mojom::TrayActionState::kNotAvailable; |
80 | 100 |
81 base::ObserverList<StateObserver> observers_; | 101 base::ObserverList<StateObserver> observers_; |
82 | 102 |
83 mojo::Binding<ash::mojom::TrayActionClient> binding_; | 103 mojo::Binding<ash::mojom::TrayActionClient> binding_; |
84 ash::mojom::TrayActionPtr tray_action_ptr_; | 104 ash::mojom::TrayActionPtr tray_action_ptr_; |
85 | 105 |
| 106 std::unique_ptr<AppManager> app_manager_; |
| 107 |
| 108 ScopedObserver<session_manager::SessionManager, |
| 109 session_manager::SessionManagerObserver> |
| 110 session_observer_; |
| 111 |
86 DISALLOW_COPY_AND_ASSIGN(StateController); | 112 DISALLOW_COPY_AND_ASSIGN(StateController); |
87 }; | 113 }; |
88 | 114 |
89 } // namespace lock_screen_apps | 115 } // namespace lock_screen_apps |
90 | 116 |
91 #endif // CHROME_BROWSER_CHROMEOS_LOCK_SCREEN_APPS_STATE_CONTROLLER_H_ | 117 #endif // CHROME_BROWSER_CHROMEOS_LOCK_SCREEN_APPS_STATE_CONTROLLER_H_ |
OLD | NEW |