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

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller.h

Issue 2839933005: mash: Merge ChromeLauncherController and *Impl subclass. (Closed)
Patch Set: Cleanup 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ 6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "ash/display/window_tree_host_manager.h"
12 #include "ash/public/cpp/app_launch_id.h" 13 #include "ash/public/cpp/app_launch_id.h"
13 #include "ash/public/cpp/shelf_item.h"
14 #include "ash/public/cpp/shelf_item_delegate.h" 14 #include "ash/public/cpp/shelf_item_delegate.h"
15 #include "ash/public/cpp/shelf_types.h"
15 #include "ash/public/interfaces/shelf.mojom.h" 16 #include "ash/public/interfaces/shelf.mojom.h"
17 #include "ash/shelf/shelf_model_observer.h"
16 #include "base/auto_reset.h" 18 #include "base/auto_reset.h"
17 #include "chrome/browser/ui/app_icon_loader.h" 19 #include "base/macros.h"
20 #include "base/memory/weak_ptr.h"
18 #include "chrome/browser/ui/app_icon_loader_delegate.h" 21 #include "chrome/browser/ui/app_icon_loader_delegate.h"
19 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" 22 #include "chrome/browser/ui/app_list/app_list_syncable_service.h"
23 #include "chrome/browser/ui/ash/app_sync_ui_state_observer.h"
24 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
25 #include "chrome/browser/ui/ash/launcher/launcher_app_updater.h"
20 #include "chrome/browser/ui/ash/launcher/settings_window_observer.h" 26 #include "chrome/browser/ui/ash/launcher/settings_window_observer.h"
27 #include "components/prefs/pref_change_registrar.h"
28 #include "components/sync_preferences/pref_service_syncable_observer.h"
21 #include "mojo/public/cpp/bindings/associated_binding.h" 29 #include "mojo/public/cpp/bindings/associated_binding.h"
22 30
23 class AccountId; 31 class AccountId;
32 class AppIconLoader;
33 class AppSyncUIState;
34 class AppWindowLauncherController;
24 class ArcAppDeferredLauncherController; 35 class ArcAppDeferredLauncherController;
25 class BrowserShortcutLauncherItemController; 36 class BrowserShortcutLauncherItemController;
37 class BrowserStatusMonitor;
38 class ChromeLauncherControllerUserSwitchObserver;
26 class GURL; 39 class GURL;
40 class Profile;
27 class LauncherControllerHelper; 41 class LauncherControllerHelper;
28 42
29 namespace ash { 43 namespace ash {
44 struct ShelfItem;
45 class ShelfModel;
30 class WmShelf; 46 class WmShelf;
31 } 47 namespace launcher {
48 class ChromeLauncherPrefsObserver;
49 } // namespace launcher
50 } // namespace ash
32 51
33 namespace content { 52 namespace content {
34 class WebContents; 53 class WebContents;
35 } 54 }
36 55
37 namespace gfx { 56 namespace gfx {
38 class Image; 57 class Image;
39 } 58 }
40 59
41 namespace ui { 60 namespace ui {
42 class BaseWindow; 61 class BaseWindow;
43 } 62 }
44 63
45 // ChromeLauncherController manages the launcher items needed for content 64 // ChromeLauncherController helps manage Ash's shelf for Chrome prefs and apps.
46 // windows. Launcher items have a type, an optional app id, and a controller. 65 // It helps synchronize shelf state with profile preferences and app content.
James Cook 2017/04/26 22:17:13 super nit: Can you add to this comment to explain
msw 2017/04/26 23:20:15 Done.
47 // Implements mojom::ShelfObserver and is a client of mojom::ShelfController. 66 class ChromeLauncherController
48 class ChromeLauncherController : public ash::mojom::ShelfObserver, 67 : public LauncherAppUpdater::Delegate,
49 public AppIconLoaderDelegate { 68 public AppIconLoaderDelegate,
69 private ash::mojom::ShelfObserver,
70 private ash::ShelfModelObserver,
71 private ash::WindowTreeHostManager::Observer,
72 private AppSyncUIStateObserver,
73 private app_list::AppListSyncableService::Observer,
74 private sync_preferences::PrefServiceSyncableObserver {
50 public: 75 public:
51 // Used to update the state of non plaform apps, as web contents change. 76 // Used to update the state of non plaform apps, as web contents change.
52 enum AppState { 77 enum AppState {
53 APP_STATE_ACTIVE, 78 APP_STATE_ACTIVE,
54 APP_STATE_WINDOW_ACTIVE, 79 APP_STATE_WINDOW_ACTIVE,
55 APP_STATE_INACTIVE, 80 APP_STATE_INACTIVE,
56 APP_STATE_REMOVED 81 APP_STATE_REMOVED
57 }; 82 };
58 83
59 // Returns the single ChromeLauncherController instance. 84 // Returns the single ChromeLauncherController instance.
60 static ChromeLauncherController* instance() { return instance_; } 85 static ChromeLauncherController* instance() { return instance_; }
61 // TODO(crbug.com/654622): Remove this when tests are fixed. 86 // TODO(crbug.com/654622): Remove this when tests are fixed.
62 static void set_instance_for_test(ChromeLauncherController* instance) { 87 static void set_instance_for_test(ChromeLauncherController* instance) {
63 instance_ = instance; 88 instance_ = instance;
64 } 89 }
65 90
66 Profile* profile() const { return profile_; } 91 ChromeLauncherController(Profile* profile, ash::ShelfModel* model);
67
68 LauncherControllerHelper* launcher_controller_helper() {
69 return launcher_controller_helper_.get();
70 }
71
72 ~ChromeLauncherController() override; 92 ~ChromeLauncherController() override;
73 93
74 // Initializes this ChromeLauncherController and calls OnInit. 94 Profile* profile() const { return profile_; }
95 ash::ShelfModel* shelf_model() const { return model_; }
96
97 // Initializes this ChromeLauncherController.
75 void Init(); 98 void Init();
76 99
77 // Creates a new app item on the shelf for |item_delegate|. 100 // Creates a new app item on the shelf for |item_delegate|.
78 virtual ash::ShelfID CreateAppLauncherItem( 101 ash::ShelfID CreateAppLauncherItem(
79 std::unique_ptr<ash::ShelfItemDelegate> item_delegate, 102 std::unique_ptr<ash::ShelfItemDelegate> item_delegate,
80 ash::ShelfItemStatus status) = 0; 103 ash::ShelfItemStatus status);
81 104
82 // Returns the shelf item with the given id, or null if |id| isn't found. 105 // Returns the shelf item with the given id, or null if |id| isn't found.
83 virtual const ash::ShelfItem* GetItem(ash::ShelfID id) const = 0; 106 const ash::ShelfItem* GetItem(ash::ShelfID id) const;
84 107
85 // Updates the type of an item. 108 // Updates the type of an item.
86 virtual void SetItemType(ash::ShelfID id, ash::ShelfItemType type) = 0; 109 void SetItemType(ash::ShelfID id, ash::ShelfItemType type);
87 110
88 // Updates the running status of an item. It will also update the status of 111 // Updates the running status of an item. It will also update the status of
89 // browsers shelf item if needed. 112 // browsers shelf item if needed.
90 virtual void SetItemStatus(ash::ShelfID id, ash::ShelfItemStatus status) = 0; 113 void SetItemStatus(ash::ShelfID id, ash::ShelfItemStatus status);
91 114
92 // Closes or unpins the shelf item. 115 // Closes or unpins the shelf item.
93 virtual void CloseLauncherItem(ash::ShelfID id) = 0; 116 void CloseLauncherItem(ash::ShelfID id);
94 117
95 // Returns true if the item identified by |id| is pinned. 118 // Returns true if the item identified by |id| is pinned.
96 virtual bool IsPinned(ash::ShelfID id) = 0; 119 bool IsPinned(ash::ShelfID id);
97 120
98 // Set the shelf item status for the V1 application with the given |app_id|. 121 // Set the shelf item status for the V1 application with the given |app_id|.
99 // Adds or removes an item as needed to respect the running and pinned state. 122 // Adds or removes an item as needed to respect the running and pinned state.
100 virtual void SetV1AppStatus(const std::string& app_id, 123 void SetV1AppStatus(const std::string& app_id, ash::ShelfItemStatus status);
101 ash::ShelfItemStatus status) = 0;
102 124
103 // Requests that the shelf item controller specified by |id| open a new 125 // Requests that the shelf item controller specified by |id| open a new
104 // instance of the app. |event_flags| holds the flags of the event which 126 // instance of the app. |event_flags| holds the flags of the event which
105 // triggered this command. 127 // triggered this command.
106 virtual void Launch(ash::ShelfID id, int event_flags) = 0; 128 void Launch(ash::ShelfID id, int event_flags);
107 129
108 // Closes the specified item. 130 // Closes the specified item.
109 virtual void Close(ash::ShelfID id) = 0; 131 void Close(ash::ShelfID id);
110 132
111 // Returns true if the specified item is open. 133 // Returns true if the specified item is open.
112 virtual bool IsOpen(ash::ShelfID id) = 0; 134 bool IsOpen(ash::ShelfID id);
113 135
114 // Returns true if the specified item is for a platform app. 136 // Returns true if the specified item is for a platform app.
115 virtual bool IsPlatformApp(ash::ShelfID id) = 0; 137 bool IsPlatformApp(ash::ShelfID id);
116 138
117 // Opens a new instance of the application identified by the AppLaunchId. 139 // Opens a new instance of the application identified by the AppLaunchId.
118 // Used by the app-list, and by pinned-app shelf items. 140 // Used by the app-list, and by pinned-app shelf items.
119 void LaunchApp(ash::AppLaunchId id, 141 void LaunchApp(ash::AppLaunchId id,
120 ash::ShelfLaunchSource source, 142 ash::ShelfLaunchSource source,
121 int event_flags); 143 int event_flags);
122 144
123 // If |app_id| is running, reactivates the app's most recently active window, 145 // If |app_id| is running, reactivates the app's most recently active window,
124 // otherwise launches and activates the app. 146 // otherwise launches and activates the app.
125 // Used by the app-list, and by pinned-app shelf items. 147 // Used by the app-list, and by pinned-app shelf items.
126 virtual void ActivateApp(const std::string& app_id, 148 void ActivateApp(const std::string& app_id,
127 ash::ShelfLaunchSource source, 149 ash::ShelfLaunchSource source,
128 int event_flags) = 0; 150 int event_flags);
129 151
130 // Set the image for a specific shelf item (e.g. when set by the app). 152 // Set the image for a specific shelf item (e.g. when set by the app).
131 virtual void SetLauncherItemImage(ash::ShelfID shelf_id, 153 void SetLauncherItemImage(ash::ShelfID shelf_id, const gfx::ImageSkia& image);
132 const gfx::ImageSkia& image) = 0;
133 154
134 // Notify the controller that the state of an non platform app's tabs 155 // Notify the controller that the state of an non platform app's tabs
135 // have changed, 156 // have changed,
136 virtual void UpdateAppState(content::WebContents* contents, 157 void UpdateAppState(content::WebContents* contents, AppState app_state);
137 AppState app_state) = 0;
138 158
139 // Returns ShelfID for |contents|. If |contents| is not an app or is not 159 // Returns ShelfID for |contents|. If |contents| is not an app or is not
140 // pinned, returns the id of browser shrotcut. 160 // pinned, returns the id of browser shrotcut.
141 virtual ash::ShelfID GetShelfIDForWebContents( 161 ash::ShelfID GetShelfIDForWebContents(content::WebContents* contents);
142 content::WebContents* contents) = 0;
143 162
144 // Limits application refocusing to urls that match |url| for |id|. 163 // Limits application refocusing to urls that match |url| for |id|.
145 virtual void SetRefocusURLPatternForTest(ash::ShelfID id, 164 void SetRefocusURLPatternForTest(ash::ShelfID id, const GURL& url);
146 const GURL& url) = 0;
147 165
148 // Activates a |window|. If |allow_minimize| is true and the system allows 166 // Activates a |window|. If |allow_minimize| is true and the system allows
149 // it, the the window will get minimized instead. 167 // it, the the window will get minimized instead.
150 // Returns the action performed. Should be one of SHELF_ACTION_NONE, 168 // Returns the action performed. Should be one of SHELF_ACTION_NONE,
151 // SHELF_ACTION_WINDOW_ACTIVATED, or SHELF_ACTION_WINDOW_MINIMIZED. 169 // SHELF_ACTION_WINDOW_ACTIVATED, or SHELF_ACTION_WINDOW_MINIMIZED.
152 virtual ash::ShelfAction ActivateWindowOrMinimizeIfActive( 170 ash::ShelfAction ActivateWindowOrMinimizeIfActive(ui::BaseWindow* window,
153 ui::BaseWindow* window, 171 bool allow_minimize);
154 bool allow_minimize) = 0;
155 172
156 // Called when the active user has changed. 173 // Called when the active user has changed.
157 virtual void ActiveUserChanged(const std::string& user_email) = 0; 174 void ActiveUserChanged(const std::string& user_email);
158 175
159 // Called when a user got added to the session. 176 // Called when a user got added to the session.
160 virtual void AdditionalUserAddedToSession(Profile* profile) = 0; 177 void AdditionalUserAddedToSession(Profile* profile);
161 178
162 // Get the list of all running incarnations of this item. 179 // Get the list of all running incarnations of this item.
163 virtual ash::MenuItemList GetAppMenuItemsForTesting( 180 ash::MenuItemList GetAppMenuItemsForTesting(const ash::ShelfItem& item);
164 const ash::ShelfItem& item) = 0;
165 181
166 // Get the list of all tabs which belong to a certain application type. 182 // Get the list of all tabs which belong to a certain application type.
167 virtual std::vector<content::WebContents*> GetV1ApplicationsFromAppId( 183 std::vector<content::WebContents*> GetV1ApplicationsFromAppId(
168 const std::string& app_id) = 0; 184 const std::string& app_id);
169 185
170 // Activates a specified shell application by app id and window index. 186 // Activates a specified shell application by app id and window index.
171 virtual void ActivateShellApp(const std::string& app_id, 187 void ActivateShellApp(const std::string& app_id, int window_index);
172 int window_index) = 0;
173 188
174 // Checks if a given |web_contents| is known to be associated with an 189 // Checks if a given |web_contents| is known to be associated with an
175 // application of type |app_id|. 190 // application of type |app_id|.
176 virtual bool IsWebContentHandledByApplication( 191 bool IsWebContentHandledByApplication(content::WebContents* web_contents,
177 content::WebContents* web_contents, 192 const std::string& app_id);
178 const std::string& app_id) = 0;
179 193
180 // Check if the gMail app is loaded and it can handle the given web content. 194 // Check if the gMail app is loaded and it can handle the given web content.
181 // This special treatment is required to address crbug.com/234268. 195 // This special treatment is required to address crbug.com/234268.
182 virtual bool ContentCanBeHandledByGmailApp( 196 bool ContentCanBeHandledByGmailApp(content::WebContents* web_contents);
183 content::WebContents* web_contents) = 0;
184 197
185 // Get the favicon for the application list entry for |web_contents|. 198 // Get the favicon for the application list entry for |web_contents|.
186 // Note that for incognito windows the incognito icon will be returned. 199 // Note that for incognito windows the incognito icon will be returned.
187 // If |web_contents| has not loaded, returns the default favicon. 200 // If |web_contents| has not loaded, returns the default favicon.
188 virtual gfx::Image GetAppListIcon( 201 gfx::Image GetAppListIcon(content::WebContents* web_contents) const;
189 content::WebContents* web_contents) const = 0;
190 202
191 // Get the title for the applicatoin list entry for |web_contents|. 203 // Get the title for the applicatoin list entry for |web_contents|.
192 // If |web_contents| has not loaded, returns "Net Tab". 204 // If |web_contents| has not loaded, returns "Net Tab".
193 virtual base::string16 GetAppListTitle( 205 base::string16 GetAppListTitle(content::WebContents* web_contents) const;
194 content::WebContents* web_contents) const = 0;
195 206
196 // Returns the ash::ShelfItemDelegate of BrowserShortcut. 207 // Returns the ash::ShelfItemDelegate of BrowserShortcut.
197 virtual BrowserShortcutLauncherItemController* 208 BrowserShortcutLauncherItemController*
198 GetBrowserShortcutLauncherItemController() = 0; 209 GetBrowserShortcutLauncherItemController();
199 210
200 // Check if the shelf visibility (location, visibility) will change with a new 211 // Check if the shelf visibility (location, visibility) will change with a new
201 // user profile or not. However, since the full visibility calculation of the 212 // user profile or not. However, since the full visibility calculation of the
202 // shelf cannot be performed here, this is only a probability used for 213 // shelf cannot be performed here, this is only a probability used for
203 // animation predictions. 214 // animation predictions.
204 virtual bool ShelfBoundsChangesProbablyWithUser( 215 bool ShelfBoundsChangesProbablyWithUser(ash::WmShelf* shelf,
205 ash::WmShelf* shelf, 216 const AccountId& account_id) const;
206 const AccountId& account_id) const = 0;
207 217
208 // Called when the user profile is fully loaded and ready to switch to. 218 // Called when the user profile is fully loaded and ready to switch to.
209 virtual void OnUserProfileReadyToSwitch(Profile* profile) = 0; 219 void OnUserProfileReadyToSwitch(Profile* profile);
210 220
211 // Controller to launch ARC apps in deferred mode. 221 // Controller to launch ARC apps in deferred mode.
212 virtual ArcAppDeferredLauncherController* GetArcDeferredLauncher() = 0; 222 ArcAppDeferredLauncherController* GetArcDeferredLauncher();
213 223
214 // Get the launch ID for a given shelf ID. 224 // Get the launch ID for a given shelf ID.
215 virtual const std::string& GetLaunchIDForShelfID(ash::ShelfID id) = 0; 225 const std::string& GetLaunchIDForShelfID(ash::ShelfID id);
216 226
217 AppIconLoader* GetAppIconLoaderForApp(const std::string& app_id); 227 AppIconLoader* GetAppIconLoaderForApp(const std::string& app_id);
218 228
219 // Sets the shelf auto-hide and/or alignment behavior from prefs. 229 // Sets the shelf auto-hide and/or alignment behavior from prefs.
220 void SetShelfAutoHideBehaviorFromPrefs(); 230 void SetShelfAutoHideBehaviorFromPrefs();
221 void SetShelfAlignmentFromPrefs(); 231 void SetShelfAlignmentFromPrefs();
222 void SetShelfBehaviorsFromPrefs(); 232 void SetShelfBehaviorsFromPrefs();
223 233
224 bool should_sync_pin_changes() const { return should_sync_pin_changes_; }
225
226 // Temporarily prevent pinned shelf item changes from updating the sync model. 234 // Temporarily prevent pinned shelf item changes from updating the sync model.
227 using ScopedPinSyncDisabler = std::unique_ptr<base::AutoReset<bool>>; 235 using ScopedPinSyncDisabler = std::unique_ptr<base::AutoReset<bool>>;
228 ScopedPinSyncDisabler GetScopedPinSyncDisabler(); 236 ScopedPinSyncDisabler GetScopedPinSyncDisabler();
229 237
238 // Access to the BrowserStatusMonitor for tests.
239 BrowserStatusMonitor* browser_status_monitor_for_test() {
240 return browser_status_monitor_.get();
241 }
242
243 // Access to the AppWindowLauncherController list for tests.
244 const std::vector<std::unique_ptr<AppWindowLauncherController>>&
245 app_window_controllers_for_test() {
246 return app_window_controllers_;
247 }
248
230 // Sets LauncherControllerHelper or AppIconLoader for test, taking ownership. 249 // Sets LauncherControllerHelper or AppIconLoader for test, taking ownership.
231 void SetLauncherControllerHelperForTest( 250 void SetLauncherControllerHelperForTest(
232 std::unique_ptr<LauncherControllerHelper> helper); 251 std::unique_ptr<LauncherControllerHelper> helper);
233 void SetAppIconLoadersForTest( 252 void SetAppIconLoadersForTest(
234 std::vector<std::unique_ptr<AppIconLoader>>& loaders); 253 std::vector<std::unique_ptr<AppIconLoader>>& loaders);
235 254
236 void SetProfileForTest(Profile* profile); 255 void SetProfileForTest(Profile* profile);
237 256
257 // Helpers that call through to corresponding ShelfModel functions.
258 ash::ShelfID GetShelfIDForAppID(const std::string& app_id);
259 ash::ShelfID GetShelfIDForAppIDAndLaunchID(const std::string& app_id,
260 const std::string& launch_id);
261 const std::string& GetAppIDForShelfID(ash::ShelfID id);
262 void PinAppWithID(const std::string& app_id);
263 bool IsAppPinned(const std::string& app_id);
264 void UnpinAppWithID(const std::string& app_id);
265
266 // LauncherAppUpdater::Delegate:
267 void OnAppInstalled(content::BrowserContext* browser_context,
268 const std::string& app_id) override;
269 void OnAppUpdated(content::BrowserContext* browser_context,
270 const std::string& app_id) override;
271 void OnAppUninstalledPrepared(content::BrowserContext* browser_context,
272 const std::string& app_id) override;
273
274 // AppIconLoaderDelegate:
275 void OnAppImageUpdated(const std::string& app_id,
276 const gfx::ImageSkia& image) override;
277
238 protected: 278 protected:
239 ChromeLauncherController();
240
241 // Called after Init; allows subclasses to perform additional initialization.
242 virtual void OnInit() = 0;
243
244 // Connects or reconnects to the mojom::ShelfController interface in ash. 279 // Connects or reconnects to the mojom::ShelfController interface in ash.
245 // Returns true if connected; virtual for unit tests. 280 // Returns true if connected; virtual for unit tests.
246 virtual bool ConnectToShelfController(); 281 virtual bool ConnectToShelfController();
247 282
248 // Accessor for subclasses to interact with the shelf controller. 283 private:
249 ash::mojom::ShelfControllerPtr& shelf_controller() { 284 friend class ChromeLauncherControllerTest;
250 return shelf_controller_; 285 friend class LauncherPlatformAppBrowserTest;
251 } 286 friend class ShelfAppBrowserTest;
287 friend class TestChromeLauncherController;
288
289 typedef std::map<content::WebContents*, std::string> WebContentsToAppIDMap;
James Cook 2017/04/26 22:17:13 nit: "using"
msw 2017/04/26 23:20:15 Done.
290
291 // Creates a new app shortcut item and controller on the shelf at |index|.
292 ash::ShelfID CreateAppShortcutLauncherItem(
293 const ash::AppLaunchId& app_launch_id,
294 int index);
295
296 // Remembers / restores list of running applications.
297 // Note that this order will neither be stored in the preference nor will it
298 // remember the order of closed applications since it is only temporary.
299 void RememberUnpinnedRunningApplicationOrder();
300 void RestoreUnpinnedRunningApplicationOrder(const std::string& user_id);
301
302 // Invoked when the associated browser or app is closed.
303 void RemoveShelfItem(ash::ShelfID id);
304
305 // Internal helpers for pinning and unpinning that handle both
306 // client-triggered and internal pinning operations.
307 void DoPinAppWithID(const std::string& app_id);
308 void DoUnpinAppWithID(const std::string& app_id, bool update_prefs);
309
310 // Pin a running app with |shelf_id| internally to |index|.
311 void PinRunningAppInternal(int index, ash::ShelfID shelf_id);
312
313 // Unpin a locked application. This is an internal call which converts the
314 // model type of the given app index from a shortcut into an unpinned running
315 // app.
316 void UnpinRunningAppInternal(int index);
317
318 // Updates pin position for the item specified by |id| in sync model.
319 void SyncPinPosition(ash::ShelfID id);
320
321 // Re-syncs shelf model.
322 void UpdateAppLaunchersFromPref();
323
324 // Schedules re-sync of shelf model.
325 void ScheduleUpdateAppLaunchersFromPref();
326
327 // Update the policy-pinned flag for each shelf item.
328 void UpdatePolicyPinnedAppsFromPrefs();
329
330 // Sets whether the virtual keyboard is enabled from prefs.
331 void SetVirtualKeyboardBehaviorFromPrefs();
332
333 // Returns the shelf item status for the given |app_id|, which can be either
334 // STATUS_ACTIVE (if the app is active), STATUS_RUNNING (if there is such an
335 // app) or STATUS_CLOSED.
336 ash::ShelfItemStatus GetAppState(const std::string& app_id);
337
338 // Creates an app launcher to insert at |index|. Note that |index| may be
339 // adjusted by the model to meet ordering constraints.
340 // The |shelf_item_type| will be set into the ShelfModel.
341 ash::ShelfID InsertAppLauncherItem(
342 std::unique_ptr<ash::ShelfItemDelegate> item_delegate,
343 ash::ShelfItemStatus status,
344 int index,
345 ash::ShelfItemType shelf_item_type);
346
347 // Create ShelfItem for Browser Shortcut.
348 void CreateBrowserShortcutLauncherItem();
349
350 // Check if the given |web_contents| is in incognito mode.
351 bool IsIncognito(const content::WebContents* web_contents) const;
352
353 // Finds the index of where to insert the next item.
354 int FindInsertionPoint();
355
356 // Close all windowed V1 applications of a certain extension which was already
357 // deleted.
358 void CloseWindowedAppsFromRemovedExtension(const std::string& app_id,
359 const Profile* profile);
252 360
253 // Attach to a specific profile. 361 // Attach to a specific profile.
254 virtual void AttachProfile(Profile* profile_to_attach); 362 void AttachProfile(Profile* profile_to_attach);
363
364 // Forget the current profile to allow attaching to a new one.
365 void ReleaseProfile();
255 366
256 // ash::mojom::ShelfObserver: 367 // ash::mojom::ShelfObserver:
257 void OnShelfCreated(int64_t display_id) override; 368 void OnShelfCreated(int64_t display_id) override;
258 void OnAlignmentChanged(ash::ShelfAlignment alignment, 369 void OnAlignmentChanged(ash::ShelfAlignment alignment,
259 int64_t display_id) override; 370 int64_t display_id) override;
260 void OnAutoHideBehaviorChanged(ash::ShelfAutoHideBehavior auto_hide, 371 void OnAutoHideBehaviorChanged(ash::ShelfAutoHideBehavior auto_hide,
261 int64_t display_id) override; 372 int64_t display_id) override;
262 373
263 private: 374 // ash::ShelfModelObserver:
264 friend class TestChromeLauncherControllerImpl; 375 void ShelfItemAdded(int index) override;
376 void ShelfItemRemoved(int index, const ash::ShelfItem& old_item) override;
377 void ShelfItemMoved(int start_index, int target_index) override;
378 void ShelfItemChanged(int index, const ash::ShelfItem& old_item) override;
265 379
266 // AppIconLoaderDelegate: 380 // ash::WindowTreeHostManager::Observer:
267 void OnAppImageUpdated(const std::string& app_id, 381 void OnDisplayConfigurationChanged() override;
268 const gfx::ImageSkia& image) override; 382
383 // AppSyncUIStateObserver:
384 void OnAppSyncUIStatusChanged() override;
385
386 // app_list::AppListSyncableService::Observer:
387 void OnSyncModelUpdated() override;
388
389 // sync_preferences::PrefServiceSyncableObserver:
390 void OnIsSyncingChanged() override;
391
392 // An internal helper to unpin a shelf item; this does not update prefs.
393 void UnpinShelfItemInternal(ash::ShelfID id);
269 394
270 static ChromeLauncherController* instance_; 395 static ChromeLauncherController* instance_;
271 396
272 // The currently loaded profile used for prefs and loading extensions. This is 397 // The currently loaded profile used for prefs and loading extensions. This is
273 // NOT necessarily the profile new windows are created with. Note that in 398 // NOT necessarily the profile new windows are created with. Note that in
274 // multi-profile use cases this might change over time. 399 // multi-profile use cases this might change over time.
275 Profile* profile_ = nullptr; 400 Profile* profile_ = nullptr;
276 401
402 ash::ShelfModel* model_;
403
277 // Ash's mojom::ShelfController used to change shelf state. 404 // Ash's mojom::ShelfController used to change shelf state.
278 ash::mojom::ShelfControllerPtr shelf_controller_; 405 ash::mojom::ShelfControllerPtr shelf_controller_;
279 406
280 // The binding this instance uses to implment mojom::ShelfObserver 407 // The binding this instance uses to implment mojom::ShelfObserver
281 mojo::AssociatedBinding<ash::mojom::ShelfObserver> observer_binding_; 408 mojo::AssociatedBinding<ash::mojom::ShelfObserver> observer_binding_;
282 409
283 // True when setting a shelf pref in response to an observer notification. 410 // True when setting a shelf pref in response to an observer notification.
284 bool updating_shelf_pref_from_observer_ = false; 411 bool updating_shelf_pref_from_observer_ = false;
285 412
286 // When true, changes to pinned shelf items should update the sync model. 413 // When true, changes to pinned shelf items should update the sync model.
287 bool should_sync_pin_changes_ = true; 414 bool should_sync_pin_changes_ = true;
288 415
289 // Used to get app info for tabs. 416 // Used to get app info for tabs.
290 std::unique_ptr<LauncherControllerHelper> launcher_controller_helper_; 417 std::unique_ptr<LauncherControllerHelper> launcher_controller_helper_;
291 418
292 // An observer that manages the shelf title and icon for settings windows. 419 // An observer that manages the shelf title and icon for settings windows.
293 SettingsWindowObserver settings_window_observer_; 420 SettingsWindowObserver settings_window_observer_;
294 421
295 // Used to load the images for app items. 422 // Used to load the images for app items.
296 std::vector<std::unique_ptr<AppIconLoader>> app_icon_loaders_; 423 std::vector<std::unique_ptr<AppIconLoader>> app_icon_loaders_;
297 424
425 // Direct access to app_id for a web contents.
426 WebContentsToAppIDMap web_contents_to_app_id_;
427
428 // Used to track app windows.
429 std::vector<std::unique_ptr<AppWindowLauncherController>>
430 app_window_controllers_;
431
432 // Used to handle app load/unload events.
433 std::vector<std::unique_ptr<LauncherAppUpdater>> app_updaters_;
434
435 PrefChangeRegistrar pref_change_registrar_;
436
437 AppSyncUIState* app_sync_ui_state_ = nullptr;
438
439 // The owned browser status monitor.
440 std::unique_ptr<BrowserStatusMonitor> browser_status_monitor_;
441
442 // A special observer class to detect user switches.
443 std::unique_ptr<ChromeLauncherControllerUserSwitchObserver>
444 user_switch_observer_;
445
446 std::unique_ptr<ash::launcher::ChromeLauncherPrefsObserver> prefs_observer_;
447
448 std::unique_ptr<ArcAppDeferredLauncherController> arc_deferred_launcher_;
449
450 // The list of running & un-pinned applications for different users on hidden
451 // desktops.
452 typedef std::vector<std::string> RunningAppListIds;
James Cook 2017/04/26 22:17:13 nit: "using"
msw 2017/04/26 23:20:15 Done.
453 typedef std::map<std::string, RunningAppListIds> RunningAppListIdMap;
James Cook 2017/04/26 22:17:13 ditto
msw 2017/04/26 23:20:15 Done.
454 RunningAppListIdMap last_used_running_application_order_;
455
456 base::WeakPtrFactory<ChromeLauncherController> weak_ptr_factory_;
457
298 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController); 458 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController);
299 }; 459 };
300 460
301 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ 461 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698