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

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

Issue 2934513003: Changes in app.window and app.runtime to support lock screen note taking (Closed)
Patch Set: . Created 3 years, 6 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" 12 #include "base/scoped_observer.h"
13 #include "chrome/browser/chromeos/lock_screen_apps/app_manager.h" 13 #include "chrome/browser/chromeos/lock_screen_apps/app_manager.h"
14 #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" 15 #include "components/session_manager/core/session_manager_observer.h"
16 #include "extensions/browser/app_window/app_window_registry.h"
17 #include "extensions/common/api/app_runtime.h"
16 #include "mojo/public/cpp/bindings/binding.h" 18 #include "mojo/public/cpp/bindings/binding.h"
17 19
18 class Profile; 20 class Profile;
19 21
22 namespace content {
23 class BrowserContext;
24 }
25
26 namespace extensions {
27 class AppWindow;
28 class AppDelegate;
29 class Extension;
30 }
31
20 namespace session_manager { 32 namespace session_manager {
21 class SessionManager; 33 class SessionManager;
22 } 34 }
23 35
24 namespace lock_screen_apps { 36 namespace lock_screen_apps {
25 37
38 class AppManager;
26 class StateObserver; 39 class StateObserver;
27 40
28 // Manages state of lock screen action handler apps, and notifies 41 // Manages state of lock screen action handler apps, and notifies
29 // interested parties as the state changes. 42 // interested parties as the state changes.
30 // Currently assumes single supported action - NEW_NOTE. 43 // Currently assumes single supported action - NEW_NOTE.
31 class StateController : public ash::mojom::TrayActionClient, 44 class StateController : public ash::mojom::TrayActionClient,
32 public session_manager::SessionManagerObserver { 45 public session_manager::SessionManagerObserver,
46 public extensions::AppWindowRegistry::Observer {
33 public: 47 public:
34 // Returns whether the StateController is enabled - it is currently guarded by 48 // Returns whether the StateController is enabled - it is currently guarded by
35 // a feature flag. If not enabled, |StateController| instance is not allowed 49 // a feature flag. If not enabled, |StateController| instance is not allowed
36 // to be created. |Get| will still work, but it will return nullptr. 50 // to be created. |Get| will still work, but it will return nullptr.
37 static bool IsEnabled(); 51 static bool IsEnabled();
38 52
39 // Returns the global StateController instance. Note that this can return 53 // Returns the global StateController instance. Note that this can return
40 // nullptr when lock screen apps are not enabled (see |IsEnabled|). 54 // nullptr when lock screen apps are not enabled (see |IsEnabled|).
41 static StateController* Get(); 55 static StateController* Get();
42 56
(...skipping 21 matching lines...) Expand all
64 78
65 // Gets current state assiciated with the lock screen note action. 79 // Gets current state assiciated with the lock screen note action.
66 ash::mojom::TrayActionState GetLockScreenNoteState() const; 80 ash::mojom::TrayActionState GetLockScreenNoteState() const;
67 81
68 // ash::mojom::TrayActionClient: 82 // ash::mojom::TrayActionClient:
69 void RequestNewLockScreenNote() override; 83 void RequestNewLockScreenNote() override;
70 84
71 // session_manager::SessionManagerObserver: 85 // session_manager::SessionManagerObserver:
72 void OnSessionStateChanged() override; 86 void OnSessionStateChanged() override;
73 87
88 // extensions::AppWindowRegistry::Observer:
89 void OnAppWindowRemoved(extensions::AppWindow* app_window) override;
90
91 // Creates and registers an app window as action handler for the action on
92 // Chrome OS lock screen.
93 // If the app is not allowed to create an app window for handling the action
94 // on lock screen (e.g. if the action has not been requested), it will return
95 // nullptr.
96 extensions::AppWindow* CreateAppWindowForLockScreenAction(
97 content::BrowserContext* context,
98 const extensions::Extension* extension,
99 extensions::api::app_runtime::ActionType action,
100 std::unique_ptr<extensions::AppDelegate> app_delegate);
101
74 // If there are any active lock screen action handlers, moved their windows 102 // If there are any active lock screen action handlers, moved their windows
75 // to background, to ensure lock screen UI is visible. 103 // to background, to ensure lock screen UI is visible.
76 void MoveToBackground(); 104 void MoveToBackground();
77 105
78 // If there are any lock screen action handler in background, moves their 106 // If there are any lock screen action handler in background, moves their
79 // windows back to foreground (i.e. visible over lock screen UI). 107 // windows back to foreground (i.e. visible over lock screen UI).
80 void MoveToForeground(); 108 void MoveToForeground();
81 109
82 // Sets the current state - to be used in tests. Hopefully, when this class
83 // has more logic implemented, this will not be needed.
84 void SetLockScreenNoteStateForTesting(ash::mojom::TrayActionState state);
85
86 private: 110 private:
87 // Called when app manager reports that note taking availability has changed. 111 // Called when app manager reports that note taking availability has changed.
88 void OnNoteTakingAvailabilityChanged(); 112 void OnNoteTakingAvailabilityChanged();
89 113
114 // If there is an app window registered as a handler for note taking action
115 // on lock screen, unregisters the window, and closes is if |close_window| is
116 // set. It changes the current state to kAvailable or kNotAvailable, depending
117 // on whether lock screen note taking action can still be handled.
118 void ResetNoteTakingWindowAndMoveToNextState(bool close_window);
119
90 // Requests lock screen note action state change to |state|. 120 // Requests lock screen note action state change to |state|.
91 // Returns whether the action state has changed. 121 // Returns whether the action state has changed.
92 bool UpdateLockScreenNoteState(ash::mojom::TrayActionState state); 122 bool UpdateLockScreenNoteState(ash::mojom::TrayActionState state);
93 123
94 // Notifies observers that the lock screen note action state changed. 124 // Notifies observers that the lock screen note action state changed.
95 void NotifyLockScreenNoteStateChanged(); 125 void NotifyLockScreenNoteStateChanged();
96 126
97 // Lock screen note action state. 127 // Lock screen note action state.
98 ash::mojom::TrayActionState lock_screen_note_state_ = 128 ash::mojom::TrayActionState lock_screen_note_state_ =
99 ash::mojom::TrayActionState::kNotAvailable; 129 ash::mojom::TrayActionState::kNotAvailable;
100 130
101 base::ObserverList<StateObserver> observers_; 131 base::ObserverList<StateObserver> observers_;
102 132
103 mojo::Binding<ash::mojom::TrayActionClient> binding_; 133 mojo::Binding<ash::mojom::TrayActionClient> binding_;
104 ash::mojom::TrayActionPtr tray_action_ptr_; 134 ash::mojom::TrayActionPtr tray_action_ptr_;
105 135
106 std::unique_ptr<AppManager> app_manager_; 136 std::unique_ptr<AppManager> app_manager_;
107 137
138 extensions::AppWindow* note_app_window_ = nullptr;
139
140 ScopedObserver<extensions::AppWindowRegistry,
141 extensions::AppWindowRegistry::Observer>
142 app_window_observer_;
108 ScopedObserver<session_manager::SessionManager, 143 ScopedObserver<session_manager::SessionManager,
109 session_manager::SessionManagerObserver> 144 session_manager::SessionManagerObserver>
110 session_observer_; 145 session_observer_;
111 146
112 DISALLOW_COPY_AND_ASSIGN(StateController); 147 DISALLOW_COPY_AND_ASSIGN(StateController);
113 }; 148 };
114 149
115 } // namespace lock_screen_apps 150 } // namespace lock_screen_apps
116 151
117 #endif // CHROME_BROWSER_CHROMEOS_LOCK_SCREEN_APPS_STATE_CONTROLLER_H_ 152 #endif // CHROME_BROWSER_CHROMEOS_LOCK_SCREEN_APPS_STATE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698