Chromium Code Reviews| 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 "base/lazy_instance.h" | 8 #include <memory> |
| 9 | |
| 10 #include "ash/public/interfaces/tray_action.mojom.h" | |
| 9 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 10 #include "chrome/browser/chromeos/lock_screen_apps/state_observer.h" | 12 #include "chrome/browser/chromeos/lock_screen_apps/state_observer.h" |
| 11 #include "chrome/browser/chromeos/lock_screen_apps/types.h" | 13 #include "mojo/public/cpp/bindings/binding.h" |
| 12 | 14 |
| 13 namespace lock_screen_apps { | 15 namespace lock_screen_apps { |
| 14 | 16 |
| 15 class StateObserver; | 17 class StateObserver; |
| 16 | 18 |
| 17 // Manages state of lock screen action handler apps, and notifies | 19 // Manages state of lock screen action handler apps, and notifies |
| 18 // interested parties as the state changes. | 20 // interested parties as the state changes. |
| 19 // Currently assumes single supported action - NEW_NOTE. | 21 // Currently assumes single supported action - NEW_NOTE. |
| 20 class StateController { | 22 class StateController : public ash::mojom::TrayActionClient { |
| 21 public: | 23 public: |
| 24 // Returns whether the StateController is enabled - it is currently guarded by | |
| 25 // a feature flag. If not enabled, |Create| methods are not allowed | |
| 26 // to be called. |Get| will still work, but will return nullptr. | |
| 27 static bool IsEnabled(); | |
| 28 | |
| 29 // Returns the global StateController instance. Note that this can return | |
| 30 // nullptr when lock screen apps are not enabled (see |IsEnabled|). | |
| 22 static StateController* Get(); | 31 static StateController* Get(); |
| 23 | 32 |
| 33 // Note that only one StateController is allowed per process. Creating a | |
| 34 // StateController will set global instance ptr that cen be accessed using | |
|
James Cook
2017/05/05 17:22:47
nit: cen -> can
tbarzic
2017/05/05 17:51:18
Done.
| |
| 35 // |Get|. This pointer will be reset when the StateController is destroyed. | |
| 36 StateController(); | |
| 37 ~StateController() override; | |
| 38 | |
| 39 // Sets the tray action that should be used by |StateController|. | |
| 40 // Has to be called before |Initialize|. | |
| 41 void SetTrayActionPtrForTesting(ash::mojom::TrayActionPtr tray_action_ptr); | |
| 42 void FlushTrayActionForTesting(); | |
| 43 | |
| 44 // 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. | |
| 46 void Initialize(); | |
| 47 | |
| 24 void AddObserver(StateObserver* observer); | 48 void AddObserver(StateObserver* observer); |
| 25 void RemoveObserver(StateObserver* observer); | 49 void RemoveObserver(StateObserver* observer); |
| 26 | 50 |
| 27 // Gets current state assiciated with the action. | 51 // Gets current state assiciated with the lock screen note action. |
| 28 ActionState GetActionState(Action action) const; | 52 ash::mojom::TrayActionState GetLockScreenNoteState() const; |
| 29 | 53 |
| 30 // Handles an action request - if the action handler is available, this will | 54 // ash::mojom::TrayActionClient: |
| 31 // show an app window for the specified action. | 55 void RequestNewLockScreenNote() override; |
| 32 bool HandleAction(Action action); | |
| 33 | 56 |
| 34 // If there are any active lock screen action handlers, moved their windows | 57 // If there are any active lock screen action handlers, moved their windows |
| 35 // to background, to ensure lock screen UI is visible. | 58 // to background, to ensure lock screen UI is visible. |
| 36 void MoveToBackground(); | 59 void MoveToBackground(); |
| 37 | 60 |
| 61 // Sets the current state - to be used in tests. Hopefully, when this class | |
| 62 // has more logic implemented, this will not be needed. | |
| 63 void SetLockScreenNoteStateForTesting(ash::mojom::TrayActionState state); | |
| 64 | |
| 38 private: | 65 private: |
| 39 friend struct base::LazyInstanceTraitsBase<StateController>; | 66 // Requests lock screen note action state change to |state|. |
| 67 // Returns whether the action state has changed. | |
| 68 bool UpdateLockScreenNoteState(ash::mojom::TrayActionState state); | |
| 40 | 69 |
| 41 StateController(); | 70 // Notifies observers that the lock screen note action state changed. |
| 42 ~StateController(); | 71 void NotifyLockScreenNoteStateChanged(); |
| 43 | 72 |
| 44 // Requests action state change to |state|. | 73 // Lock screen note action state. |
| 45 // Returns whether the action state has changed. | 74 ash::mojom::TrayActionState lock_screen_note_state_ = |
| 46 bool UpdateActionState(Action action, ActionState state); | 75 ash::mojom::TrayActionState::kNotSupported; |
| 47 | |
| 48 // notifies observers that an action state changed. | |
| 49 void NotifyStateChanged(Action action); | |
| 50 | |
| 51 // New note action state. | |
| 52 ActionState new_note_state_ = ActionState::kNotSupported; | |
| 53 | 76 |
| 54 base::ObserverList<StateObserver> observers_; | 77 base::ObserverList<StateObserver> observers_; |
| 55 | 78 |
| 79 mojo::Binding<ash::mojom::TrayActionClient> binding_; | |
| 80 ash::mojom::TrayActionPtr tray_action_ptr_; | |
| 81 | |
| 56 DISALLOW_COPY_AND_ASSIGN(StateController); | 82 DISALLOW_COPY_AND_ASSIGN(StateController); |
| 57 }; | 83 }; |
| 58 | 84 |
| 59 } // namespace lock_screen_apps | 85 } // namespace lock_screen_apps |
| 60 | 86 |
| 61 #endif // CHROME_BROWSER_CHROMEOS_LOCK_SCREEN_APPS_STATE_CONTROLLER_H_ | 87 #endif // CHROME_BROWSER_CHROMEOS_LOCK_SCREEN_APPS_STATE_CONTROLLER_H_ |
| OLD | NEW |