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

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: . 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, |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 // Creates and initializes a global instance. It must not be called more than
34 // once, or when lock screen apps are not enabled (see |IsEnabled|).
35 // The global instance (returned by |Get|) will be reset when the returned
36 // object is desctructed.
James Cook 2017/05/05 02:55:45 nit: "destructed" or "destroyed", here and below
tbarzic 2017/05/05 04:46:27 Done.
37 static std::unique_ptr<StateController> Create();
38
39 // Creates and initializes a global instance to be used in tests - it must not
40 // be called more than once, or when lock screen apps are not enabled. See
41 // |IsEnabled|.
42 // The global instance (returned by |Get|) will be reset when the returned
43 // object is desctructed.
44 // |tray_action_ptr| - TrayAction interface implementation to be used by the
45 // test instance.
46 static std::unique_ptr<StateController> CreateForTesting(
47 ash::mojom::TrayActionPtr tray_action_ptr);
48
49 ~StateController() override;
50
24 void AddObserver(StateObserver* observer); 51 void AddObserver(StateObserver* observer);
25 void RemoveObserver(StateObserver* observer); 52 void RemoveObserver(StateObserver* observer);
26 53
27 // Gets current state assiciated with the action. 54 // Gets current state assiciated with the lock screen note action.
28 ActionState GetActionState(Action action) const; 55 ash::mojom::TrayActionState GetLockScreenNoteState() const;
29 56
57 // ash::mojom::TrayActionClient:
30 // Handles an action request - if the action handler is available, this will 58 // Handles an action request - if the action handler is available, this will
31 // show an app window for the specified action. 59 // show an app window for the specified action.
James Cook 2017/05/05 02:55:45 probably don't need this comment (it should be doc
tbarzic 2017/05/05 04:46:27 Done.
32 bool HandleAction(Action action); 60 void RequestNewLockScreenNote() override;
33 61
34 // If there are any active lock screen action handlers, moved their windows 62 // If there are any active lock screen action handlers, moved their windows
35 // to background, to ensure lock screen UI is visible. 63 // to background, to ensure lock screen UI is visible.
36 void MoveToBackground(); 64 void MoveToBackground();
37 65
66 // Sets the current state - to be used in tests. Hopefully, when this class
67 // has more logic implemented, this will not be needed.
68 void SetLockScreenNoteStateForTesting(ash::mojom::TrayActionState state);
69
38 private: 70 private:
39 friend struct base::LazyInstanceTraitsBase<StateController>; 71 StateController();
40 72
41 StateController(); 73 // Initializes mojo bindings for the StateController - it creates binding to
42 ~StateController(); 74 // ash's tray action interface and sets this object as the interface's client.
75 void RegisterAsAshTrayActionClient();
43 76
44 // Requests action state change to |state|. 77 // Requests lock screen note action state change to |state|.
45 // Returns whether the action state has changed. 78 // Returns whether the action state has changed.
46 bool UpdateActionState(Action action, ActionState state); 79 bool UpdateLockScreenNoteState(ash::mojom::TrayActionState state);
47 80
48 // notifies observers that an action state changed. 81 // Notifies observers that the lock screen note action state changed.
49 void NotifyStateChanged(Action action); 82 void NotifyLockScreenNoteStateChanged();
50 83
51 // New note action state. 84 // Lock screen note action state.
52 ActionState new_note_state_ = ActionState::kNotSupported; 85 ash::mojom::TrayActionState lock_screen_note_state_ =
86 ash::mojom::TrayActionState::kNotSupported;
53 87
54 base::ObserverList<StateObserver> observers_; 88 base::ObserverList<StateObserver> observers_;
55 89
90 mojo::Binding<ash::mojom::TrayActionClient> binding_;
91 ash::mojom::TrayActionPtr tray_action_ptr_;
92
56 DISALLOW_COPY_AND_ASSIGN(StateController); 93 DISALLOW_COPY_AND_ASSIGN(StateController);
57 }; 94 };
58 95
59 } // namespace lock_screen_apps 96 } // namespace lock_screen_apps
60 97
61 #endif // CHROME_BROWSER_CHROMEOS_LOCK_SCREEN_APPS_STATE_CONTROLLER_H_ 98 #endif // CHROME_BROWSER_CHROMEOS_LOCK_SCREEN_APPS_STATE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698