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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/lock_screen_apps/state_controller.h
diff --git a/chrome/browser/chromeos/lock_screen_apps/state_controller.h b/chrome/browser/chromeos/lock_screen_apps/state_controller.h
index 1b043346e49e530a13a23cd1bd92b1243cf655e2..36273f883ef6d9d2bb07a31e902263c1bf9f0fc5 100644
--- a/chrome/browser/chromeos/lock_screen_apps/state_controller.h
+++ b/chrome/browser/chromeos/lock_screen_apps/state_controller.h
@@ -5,10 +5,12 @@
#ifndef CHROME_BROWSER_CHROMEOS_LOCK_SCREEN_APPS_STATE_CONTROLLER_H_
#define CHROME_BROWSER_CHROMEOS_LOCK_SCREEN_APPS_STATE_CONTROLLER_H_
-#include "base/lazy_instance.h"
+#include <memory>
+
+#include "ash/public/interfaces/tray_action.mojom.h"
#include "base/observer_list.h"
#include "chrome/browser/chromeos/lock_screen_apps/state_observer.h"
-#include "chrome/browser/chromeos/lock_screen_apps/types.h"
+#include "mojo/public/cpp/bindings/binding.h"
namespace lock_screen_apps {
@@ -17,42 +19,77 @@ class StateObserver;
// Manages state of lock screen action handler apps, and notifies
// interested parties as the state changes.
// Currently assumes single supported action - NEW_NOTE.
-class StateController {
+class StateController : public ash::mojom::TrayActionClient {
public:
+ // Returns whether the StateController is enabled - it is currently guarded by
+ // a feature flag. If not enabled, |Create| methods are not allowed
+ // to be called. |Get| will still work, but will return nullptr.
+ static bool IsEnabled();
+
+ // Returns the global StateController instance. Note that this can return
+ // nullptr when lock screen apps are not enabled (see |IsEnabled|).
static StateController* Get();
+ // Creates and initializes a global instance. It must not be called more than
+ // once, or when lock screen apps are not enabled (see |IsEnabled|).
+ // The global instance (returned by |Get|) will be reset when the returned
+ // 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.
+ static std::unique_ptr<StateController> Create();
+
+ // Creates and initializes a global instance to be used in tests - it must not
+ // be called more than once, or when lock screen apps are not enabled. See
+ // |IsEnabled|.
+ // The global instance (returned by |Get|) will be reset when the returned
+ // object is desctructed.
+ // |tray_action_ptr| - TrayAction interface implementation to be used by the
+ // test instance.
+ static std::unique_ptr<StateController> CreateForTesting(
+ ash::mojom::TrayActionPtr tray_action_ptr);
+
+ ~StateController() override;
+
void AddObserver(StateObserver* observer);
void RemoveObserver(StateObserver* observer);
- // Gets current state assiciated with the action.
- ActionState GetActionState(Action action) const;
+ // Gets current state assiciated with the lock screen note action.
+ ash::mojom::TrayActionState GetLockScreenNoteState() const;
+ // ash::mojom::TrayActionClient:
// Handles an action request - if the action handler is available, this will
// 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.
- bool HandleAction(Action action);
+ void RequestNewLockScreenNote() override;
// If there are any active lock screen action handlers, moved their windows
// to background, to ensure lock screen UI is visible.
void MoveToBackground();
- private:
- friend struct base::LazyInstanceTraitsBase<StateController>;
+ // Sets the current state - to be used in tests. Hopefully, when this class
+ // has more logic implemented, this will not be needed.
+ void SetLockScreenNoteStateForTesting(ash::mojom::TrayActionState state);
+ private:
StateController();
- ~StateController();
- // Requests action state change to |state|.
+ // Initializes mojo bindings for the StateController - it creates binding to
+ // ash's tray action interface and sets this object as the interface's client.
+ void RegisterAsAshTrayActionClient();
+
+ // Requests lock screen note action state change to |state|.
// Returns whether the action state has changed.
- bool UpdateActionState(Action action, ActionState state);
+ bool UpdateLockScreenNoteState(ash::mojom::TrayActionState state);
- // notifies observers that an action state changed.
- void NotifyStateChanged(Action action);
+ // Notifies observers that the lock screen note action state changed.
+ void NotifyLockScreenNoteStateChanged();
- // New note action state.
- ActionState new_note_state_ = ActionState::kNotSupported;
+ // Lock screen note action state.
+ ash::mojom::TrayActionState lock_screen_note_state_ =
+ ash::mojom::TrayActionState::kNotSupported;
base::ObserverList<StateObserver> observers_;
+ mojo::Binding<ash::mojom::TrayActionClient> binding_;
+ ash::mojom::TrayActionPtr tray_action_ptr_;
+
DISALLOW_COPY_AND_ASSIGN(StateController);
};

Powered by Google App Engine
This is Rietveld 408576698