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

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: split out browsertests 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 Extension;
29 }
30
20 namespace session_manager { 31 namespace session_manager {
21 class SessionManager; 32 class SessionManager;
22 } 33 }
23 34
24 namespace lock_screen_apps { 35 namespace lock_screen_apps {
25 36
37 class AppManager;
26 class StateObserver; 38 class StateObserver;
27 39
28 // Manages state of lock screen action handler apps, and notifies 40 // Manages state of lock screen action handler apps, and notifies
29 // interested parties as the state changes. 41 // interested parties as the state changes.
30 // Currently assumes single supported action - NEW_NOTE. 42 // Currently assumes single supported action - NEW_NOTE.
31 class StateController : public ash::mojom::TrayActionClient, 43 class StateController : public ash::mojom::TrayActionClient,
32 public session_manager::SessionManagerObserver { 44 public session_manager::SessionManagerObserver,
45 public extensions::AppWindowRegistry::Observer {
33 public: 46 public:
34 // Returns whether the StateController is enabled - it is currently guarded by 47 // Returns whether the StateController is enabled - it is currently guarded by
35 // a feature flag. If not enabled, |StateController| instance is not allowed 48 // a feature flag. If not enabled, |StateController| instance is not allowed
36 // to be created. |Get| will still work, but it will return nullptr. 49 // to be created. |Get| will still work, but it will return nullptr.
37 static bool IsEnabled(); 50 static bool IsEnabled();
38 51
39 // Returns the global StateController instance. Note that this can return 52 // Returns the global StateController instance. Note that this can return
40 // nullptr when lock screen apps are not enabled (see |IsEnabled|). 53 // nullptr when lock screen apps are not enabled (see |IsEnabled|).
41 static StateController* Get(); 54 static StateController* Get();
42 55
(...skipping 21 matching lines...) Expand all
64 77
65 // Gets current state assiciated with the lock screen note action. 78 // Gets current state assiciated with the lock screen note action.
66 ash::mojom::TrayActionState GetLockScreenNoteState() const; 79 ash::mojom::TrayActionState GetLockScreenNoteState() const;
67 80
68 // ash::mojom::TrayActionClient: 81 // ash::mojom::TrayActionClient:
69 void RequestNewLockScreenNote() override; 82 void RequestNewLockScreenNote() override;
70 83
71 // session_manager::SessionManagerObserver: 84 // session_manager::SessionManagerObserver:
72 void OnSessionStateChanged() override; 85 void OnSessionStateChanged() override;
73 86
87 // extensions::AppWindowREgistry::Observer:
benwells 2017/06/13 10:30:46 Nit: REgistry
tbarzic 2017/06/13 19:17:59 Done.
88 void OnAppWindowRemoved(extensions::AppWindow* app_window) override;
89
90 // Returns whether an extension should be allowed to create an app window on
91 // the lock screen in order to handle the provided action.
92 bool CanCreateAppWindowForAction(
benwells 2017/06/13 10:30:46 Does this have to be public?
tbarzic 2017/06/13 19:17:59 It's currently used by ChromeAppWindowDelegate
93 content::BrowserContext* context,
94 const extensions::Extension* extension,
95 extensions::api::app_runtime::ActionType action) const;
96
97 // Registers the app window as action handler for the action on Chrome OS lock
98 // screen.
99 // Returns whether the app window was successfully registered.
100 bool RegisterAppWindowForAction(
101 extensions::AppWindow* window,
102 extensions::api::app_runtime::ActionType action);
103
74 // If there are any active lock screen action handlers, moved their windows 104 // If there are any active lock screen action handlers, moved their windows
75 // to background, to ensure lock screen UI is visible. 105 // to background, to ensure lock screen UI is visible.
76 void MoveToBackground(); 106 void MoveToBackground();
77 107
78 // If there are any lock screen action handler in background, moves their 108 // If there are any lock screen action handler in background, moves their
79 // windows back to foreground (i.e. visible over lock screen UI). 109 // windows back to foreground (i.e. visible over lock screen UI).
80 void MoveToForeground(); 110 void MoveToForeground();
81 111
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: 112 private:
87 // Called when app manager reports that note taking availability has changed. 113 // Called when app manager reports that note taking availability has changed.
88 void OnNoteTakingAvailabilityChanged(); 114 void OnNoteTakingAvailabilityChanged();
89 115
116 // If there is an app window registered as a handler for note taking action
117 // on lock screen, unregisters the window, and closes is if |close_window| is
118 // set. It changes the current state to kAvailable or kNotAvailable, depending
119 // on whether lock screen note taking action can still be handled.
120 void ResetNoteTakingWindowAndMoveToNextState(bool close_window);
121
90 // Requests lock screen note action state change to |state|. 122 // Requests lock screen note action state change to |state|.
91 // Returns whether the action state has changed. 123 // Returns whether the action state has changed.
92 bool UpdateLockScreenNoteState(ash::mojom::TrayActionState state); 124 bool UpdateLockScreenNoteState(ash::mojom::TrayActionState state);
93 125
94 // Notifies observers that the lock screen note action state changed. 126 // Notifies observers that the lock screen note action state changed.
95 void NotifyLockScreenNoteStateChanged(); 127 void NotifyLockScreenNoteStateChanged();
96 128
97 // Lock screen note action state. 129 // Lock screen note action state.
98 ash::mojom::TrayActionState lock_screen_note_state_ = 130 ash::mojom::TrayActionState lock_screen_note_state_ =
99 ash::mojom::TrayActionState::kNotAvailable; 131 ash::mojom::TrayActionState::kNotAvailable;
100 132
101 base::ObserverList<StateObserver> observers_; 133 base::ObserverList<StateObserver> observers_;
102 134
103 mojo::Binding<ash::mojom::TrayActionClient> binding_; 135 mojo::Binding<ash::mojom::TrayActionClient> binding_;
104 ash::mojom::TrayActionPtr tray_action_ptr_; 136 ash::mojom::TrayActionPtr tray_action_ptr_;
105 137
106 std::unique_ptr<AppManager> app_manager_; 138 std::unique_ptr<AppManager> app_manager_;
107 139
140 extensions::AppWindow* note_app_window_ = nullptr;
141
142 ScopedObserver<extensions::AppWindowRegistry,
143 extensions::AppWindowRegistry::Observer>
144 app_window_observer_;
108 ScopedObserver<session_manager::SessionManager, 145 ScopedObserver<session_manager::SessionManager,
109 session_manager::SessionManagerObserver> 146 session_manager::SessionManagerObserver>
110 session_observer_; 147 session_observer_;
111 148
112 DISALLOW_COPY_AND_ASSIGN(StateController); 149 DISALLOW_COPY_AND_ASSIGN(StateController);
113 }; 150 };
114 151
115 } // namespace lock_screen_apps 152 } // namespace lock_screen_apps
116 153
117 #endif // CHROME_BROWSER_CHROMEOS_LOCK_SCREEN_APPS_STATE_CONTROLLER_H_ 154 #endif // CHROME_BROWSER_CHROMEOS_LOCK_SCREEN_APPS_STATE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698