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

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

Issue 2848813002: Introduce ash mojo interface for lock screen action handlers (Closed)
Patch Set: add ASH_EXPORTS 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 "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, |StateController| instance is not allowed
26 // to be created. |Get| will still work, but it 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 can be accessed using
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::kNotAvailable;
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_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/chrome_browser_main_chromeos.cc ('k') | chrome/browser/chromeos/lock_screen_apps/state_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698