Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: chrome/browser/chromeos/lock_screen_apps/state_controller.h

Issue 2902293002: Introduce lock screen app manager (Closed)
Patch Set: . Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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,
33 public AppManager::Observer {
23 public: 34 public:
24 // Returns whether the StateController is enabled - it is currently guarded by 35 // Returns whether the StateController is enabled - it is currently guarded by
25 // a feature flag. If not enabled, |StateController| instance is not allowed 36 // a feature flag. If not enabled, |StateController| instance is not allowed
26 // to be created. |Get| will still work, but it will return nullptr. 37 // to be created. |Get| will still work, but it will return nullptr.
27 static bool IsEnabled(); 38 static bool IsEnabled();
28 39
29 // Returns the global StateController instance. Note that this can return 40 // Returns the global StateController instance. Note that this can return
30 // nullptr when lock screen apps are not enabled (see |IsEnabled|). 41 // nullptr when lock screen apps are not enabled (see |IsEnabled|).
31 static StateController* Get(); 42 static StateController* Get();
32 43
33 // Note that only one StateController is allowed per process. Creating a 44 // Note that only one StateController is allowed per process. Creating a
34 // StateController will set global instance ptr that can be accessed using 45 // StateController will set global instance ptr that can be accessed using
35 // |Get|. This pointer will be reset when the StateController is destroyed. 46 // |Get|. This pointer will be reset when the StateController is destroyed.
36 StateController(); 47 StateController();
37 ~StateController() override; 48 ~StateController() override;
38 49
39 // Sets the tray action that should be used by |StateController|. 50 // Sets the tray action that should be used by |StateController|.
40 // Has to be called before |Initialize|. 51 // Has to be called before |Initialize|.
41 void SetTrayActionPtrForTesting(ash::mojom::TrayActionPtr tray_action_ptr); 52 void SetTrayActionPtrForTesting(ash::mojom::TrayActionPtr tray_action_ptr);
42 void FlushTrayActionForTesting(); 53 void FlushTrayActionForTesting();
54 // Sets test AppManager implementation. Should be called before
55 // |SetPrimaryProfile|
56 void SetAppManagerForTesting(std::unique_ptr<AppManager> app_manager);
43 57
44 // Initializes mojo bindings for the StateController - it creates binding to 58 // 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. 59 // ash's tray action interface and sets this object as the interface's client.
46 void Initialize(); 60 void Initialize();
61 void SetPrimaryProfile(Profile* profile);
47 62
48 void AddObserver(StateObserver* observer); 63 void AddObserver(StateObserver* observer);
49 void RemoveObserver(StateObserver* observer); 64 void RemoveObserver(StateObserver* observer);
50 65
51 // Gets current state assiciated with the lock screen note action. 66 // Gets current state assiciated with the lock screen note action.
52 ash::mojom::TrayActionState GetLockScreenNoteState() const; 67 ash::mojom::TrayActionState GetLockScreenNoteState() const;
53 68
54 // ash::mojom::TrayActionClient: 69 // ash::mojom::TrayActionClient:
55 void RequestNewLockScreenNote() override; 70 void RequestNewLockScreenNote() override;
56 71
72 // session_manager::SessionManagerObserver:
73 void OnSessionStateChanged() override;
74
75 // AppManager::Observer:
76 void OnNoteTakingAvailabilityChanged() override;
77
57 // If there are any active lock screen action handlers, moved their windows 78 // If there are any active lock screen action handlers, moved their windows
58 // to background, to ensure lock screen UI is visible. 79 // to background, to ensure lock screen UI is visible.
59 void MoveToBackground(); 80 void MoveToBackground();
60 81
61 // If there are any lock screen action handler in background, moves their 82 // If there are any lock screen action handler in background, moves their
62 // windows back to foreground (i.e. visible over lock screen UI). 83 // windows back to foreground (i.e. visible over lock screen UI).
63 void MoveToForeground(); 84 void MoveToForeground();
64 85
65 // Sets the current state - to be used in tests. Hopefully, when this class 86 // Sets the current state - to be used in tests. Hopefully, when this class
66 // has more logic implemented, this will not be needed. 87 // has more logic implemented, this will not be needed.
67 void SetLockScreenNoteStateForTesting(ash::mojom::TrayActionState state); 88 void SetLockScreenNoteStateForTesting(ash::mojom::TrayActionState state);
68 89
69 private: 90 private:
70 // Requests lock screen note action state change to |state|. 91 // Requests lock screen note action state change to |state|.
71 // Returns whether the action state has changed. 92 // Returns whether the action state has changed.
72 bool UpdateLockScreenNoteState(ash::mojom::TrayActionState state); 93 bool UpdateLockScreenNoteState(ash::mojom::TrayActionState state);
73 94
74 // Notifies observers that the lock screen note action state changed. 95 // Notifies observers that the lock screen note action state changed.
75 void NotifyLockScreenNoteStateChanged(); 96 void NotifyLockScreenNoteStateChanged();
76 97
77 // Lock screen note action state. 98 // Lock screen note action state.
78 ash::mojom::TrayActionState lock_screen_note_state_ = 99 ash::mojom::TrayActionState lock_screen_note_state_ =
79 ash::mojom::TrayActionState::kNotAvailable; 100 ash::mojom::TrayActionState::kNotAvailable;
80 101
81 base::ObserverList<StateObserver> observers_; 102 base::ObserverList<StateObserver> observers_;
82 103
83 mojo::Binding<ash::mojom::TrayActionClient> binding_; 104 mojo::Binding<ash::mojom::TrayActionClient> binding_;
84 ash::mojom::TrayActionPtr tray_action_ptr_; 105 ash::mojom::TrayActionPtr tray_action_ptr_;
85 106
107 std::unique_ptr<AppManager> app_manager_;
108
109 ScopedObserver<session_manager::SessionManager,
110 session_manager::SessionManagerObserver>
111 session_observer_;
112
86 DISALLOW_COPY_AND_ASSIGN(StateController); 113 DISALLOW_COPY_AND_ASSIGN(StateController);
87 }; 114 };
88 115
89 } // namespace lock_screen_apps 116 } // namespace lock_screen_apps
90 117
91 #endif // CHROME_BROWSER_CHROMEOS_LOCK_SCREEN_APPS_STATE_CONTROLLER_H_ 118 #endif // CHROME_BROWSER_CHROMEOS_LOCK_SCREEN_APPS_STATE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698