| OLD | NEW |
| 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/display/window_tree_host_manager.h" |
| 13 #include "ash/public/cpp/app_launch_id.h" | |
| 14 #include "ash/public/cpp/shelf_item_delegate.h" | 13 #include "ash/public/cpp/shelf_item_delegate.h" |
| 15 #include "ash/public/cpp/shelf_types.h" | 14 #include "ash/public/cpp/shelf_types.h" |
| 16 #include "ash/public/interfaces/shelf.mojom.h" | 15 #include "ash/public/interfaces/shelf.mojom.h" |
| 17 #include "ash/shelf/shelf_model_observer.h" | 16 #include "ash/shelf/shelf_model_observer.h" |
| 18 #include "base/auto_reset.h" | 17 #include "base/auto_reset.h" |
| 19 #include "base/macros.h" | 18 #include "base/macros.h" |
| 20 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
| 21 #include "chrome/browser/ui/app_icon_loader_delegate.h" | 20 #include "chrome/browser/ui/app_icon_loader_delegate.h" |
| 22 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" | 21 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" |
| 23 #include "chrome/browser/ui/ash/app_sync_ui_state_observer.h" | 22 #include "chrome/browser/ui/ash/app_sync_ui_state_observer.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 96 |
| 98 // Initializes this ChromeLauncherController. | 97 // Initializes this ChromeLauncherController. |
| 99 void Init(); | 98 void Init(); |
| 100 | 99 |
| 101 // Creates a new app item on the shelf for |item_delegate|. | 100 // Creates a new app item on the shelf for |item_delegate|. |
| 102 ash::ShelfID CreateAppLauncherItem( | 101 ash::ShelfID CreateAppLauncherItem( |
| 103 std::unique_ptr<ash::ShelfItemDelegate> item_delegate, | 102 std::unique_ptr<ash::ShelfItemDelegate> item_delegate, |
| 104 ash::ShelfItemStatus status); | 103 ash::ShelfItemStatus status); |
| 105 | 104 |
| 106 // 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. |
| 107 const ash::ShelfItem* GetItem(ash::ShelfID id) const; | 106 const ash::ShelfItem* GetItem(const ash::ShelfID& id) const; |
| 108 | 107 |
| 109 // Updates the type of an item. | 108 // Updates the type of an item. |
| 110 void SetItemType(ash::ShelfID id, ash::ShelfItemType type); | 109 void SetItemType(const ash::ShelfID& id, ash::ShelfItemType type); |
| 111 | 110 |
| 112 // 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 |
| 113 // browsers shelf item if needed. | 112 // browsers shelf item if needed. |
| 114 void SetItemStatus(ash::ShelfID id, ash::ShelfItemStatus status); | 113 void SetItemStatus(const ash::ShelfID& id, ash::ShelfItemStatus status); |
| 115 | 114 |
| 116 // Closes or unpins the shelf item. | 115 // Closes or unpins the shelf item. |
| 117 void CloseLauncherItem(ash::ShelfID id); | 116 void CloseLauncherItem(const ash::ShelfID& id); |
| 118 | 117 |
| 119 // Returns true if the item identified by |id| is pinned. | 118 // Returns true if the item identified by |id| is pinned. |
| 120 bool IsPinned(ash::ShelfID id); | 119 bool IsPinned(const ash::ShelfID& id); |
| 121 | 120 |
| 122 // 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|. |
| 123 // 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. |
| 124 void SetV1AppStatus(const std::string& app_id, ash::ShelfItemStatus status); | 123 void SetV1AppStatus(const std::string& app_id, ash::ShelfItemStatus status); |
| 125 | 124 |
| 126 // 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 |
| 127 // 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 |
| 128 // triggered this command. | 127 // triggered this command. |
| 129 void Launch(ash::ShelfID id, int event_flags); | 128 void Launch(const ash::ShelfID& id, int event_flags); |
| 130 | 129 |
| 131 // Closes the specified item. | 130 // Closes the specified item. |
| 132 void Close(ash::ShelfID id); | 131 void Close(const ash::ShelfID& id); |
| 133 | 132 |
| 134 // Returns true if the specified item is open. | 133 // Returns true if the specified item is open. |
| 135 bool IsOpen(ash::ShelfID id); | 134 bool IsOpen(const ash::ShelfID& id); |
| 136 | 135 |
| 137 // Returns true if the specified item is for a platform app. | 136 // Returns true if the specified item is for a platform app. |
| 138 bool IsPlatformApp(ash::ShelfID id); | 137 bool IsPlatformApp(const ash::ShelfID& id); |
| 139 | 138 |
| 140 // Opens a new instance of the application identified by the AppLaunchId. | 139 // Opens a new instance of the application identified by the ShelfID. |
| 141 // Used by the app-list, and by pinned-app shelf items. | 140 // Used by the app-list, and by pinned-app shelf items. |
| 142 void LaunchApp(ash::AppLaunchId id, | 141 void LaunchApp(const ash::ShelfID& id, |
| 143 ash::ShelfLaunchSource source, | 142 ash::ShelfLaunchSource source, |
| 144 int event_flags); | 143 int event_flags); |
| 145 | 144 |
| 146 // 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, |
| 147 // otherwise launches and activates the app. | 146 // otherwise launches and activates the app. |
| 148 // Used by the app-list, and by pinned-app shelf items. | 147 // Used by the app-list, and by pinned-app shelf items. |
| 149 void ActivateApp(const std::string& app_id, | 148 void ActivateApp(const std::string& app_id, |
| 150 ash::ShelfLaunchSource source, | 149 ash::ShelfLaunchSource source, |
| 151 int event_flags); | 150 int event_flags); |
| 152 | 151 |
| 153 // 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). |
| 154 void SetLauncherItemImage(ash::ShelfID shelf_id, const gfx::ImageSkia& image); | 153 void SetLauncherItemImage(const ash::ShelfID& shelf_id, |
| 154 const gfx::ImageSkia& image); |
| 155 | 155 |
| 156 // Notify the controller that the state of an non platform app's tabs | 156 // Notify the controller that the state of an non platform app's tabs |
| 157 // have changed, | 157 // have changed, |
| 158 void UpdateAppState(content::WebContents* contents, AppState app_state); | 158 void UpdateAppState(content::WebContents* contents, AppState app_state); |
| 159 | 159 |
| 160 // Returns ShelfID for |contents|. If |contents| is not an app or is not | 160 // Returns ShelfID for |contents|. If |contents| is not an app or is not |
| 161 // pinned, returns the id of browser shrotcut. | 161 // pinned, returns the id of browser shrotcut. |
| 162 ash::ShelfID GetShelfIDForWebContents(content::WebContents* contents); | 162 ash::ShelfID GetShelfIDForWebContents(content::WebContents* contents); |
| 163 | 163 |
| 164 // Limits application refocusing to urls that match |url| for |id|. | 164 // Limits application refocusing to urls that match |url| for |id|. |
| 165 void SetRefocusURLPatternForTest(ash::ShelfID id, const GURL& url); | 165 void SetRefocusURLPatternForTest(const ash::ShelfID& id, const GURL& url); |
| 166 | 166 |
| 167 // Activates a |window|. If |allow_minimize| is true and the system allows | 167 // Activates a |window|. If |allow_minimize| is true and the system allows |
| 168 // it, the the window will get minimized instead. | 168 // it, the the window will get minimized instead. |
| 169 // Returns the action performed. Should be one of SHELF_ACTION_NONE, | 169 // Returns the action performed. Should be one of SHELF_ACTION_NONE, |
| 170 // SHELF_ACTION_WINDOW_ACTIVATED, or SHELF_ACTION_WINDOW_MINIMIZED. | 170 // SHELF_ACTION_WINDOW_ACTIVATED, or SHELF_ACTION_WINDOW_MINIMIZED. |
| 171 ash::ShelfAction ActivateWindowOrMinimizeIfActive(ui::BaseWindow* window, | 171 ash::ShelfAction ActivateWindowOrMinimizeIfActive(ui::BaseWindow* window, |
| 172 bool allow_minimize); | 172 bool allow_minimize); |
| 173 | 173 |
| 174 // Called when the active user has changed. | 174 // Called when the active user has changed. |
| 175 void ActiveUserChanged(const std::string& user_email); | 175 void ActiveUserChanged(const std::string& user_email); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 bool ShelfBoundsChangesProbablyWithUser(ash::WmShelf* shelf, | 216 bool ShelfBoundsChangesProbablyWithUser(ash::WmShelf* shelf, |
| 217 const AccountId& account_id) const; | 217 const AccountId& account_id) const; |
| 218 | 218 |
| 219 // Called when the user profile is fully loaded and ready to switch to. | 219 // Called when the user profile is fully loaded and ready to switch to. |
| 220 void OnUserProfileReadyToSwitch(Profile* profile); | 220 void OnUserProfileReadyToSwitch(Profile* profile); |
| 221 | 221 |
| 222 // Controller to launch ARC apps in deferred mode. | 222 // Controller to launch ARC apps in deferred mode. |
| 223 ArcAppDeferredLauncherController* GetArcDeferredLauncher(); | 223 ArcAppDeferredLauncherController* GetArcDeferredLauncher(); |
| 224 | 224 |
| 225 // Get the launch ID for a given shelf ID. | 225 // Get the launch ID for a given shelf ID. |
| 226 const std::string& GetLaunchIDForShelfID(ash::ShelfID id); | 226 const std::string& GetLaunchIDForShelfID(const ash::ShelfID& id); |
| 227 | 227 |
| 228 AppIconLoader* GetAppIconLoaderForApp(const std::string& app_id); | 228 AppIconLoader* GetAppIconLoaderForApp(const std::string& app_id); |
| 229 | 229 |
| 230 // Sets the shelf auto-hide and/or alignment behavior from prefs. | 230 // Sets the shelf auto-hide and/or alignment behavior from prefs. |
| 231 void SetShelfAutoHideBehaviorFromPrefs(); | 231 void SetShelfAutoHideBehaviorFromPrefs(); |
| 232 void SetShelfAlignmentFromPrefs(); | 232 void SetShelfAlignmentFromPrefs(); |
| 233 void SetShelfBehaviorsFromPrefs(); | 233 void SetShelfBehaviorsFromPrefs(); |
| 234 | 234 |
| 235 // Temporarily prevent pinned shelf item changes from updating the sync model. | 235 // Temporarily prevent pinned shelf item changes from updating the sync model. |
| 236 using ScopedPinSyncDisabler = std::unique_ptr<base::AutoReset<bool>>; | 236 using ScopedPinSyncDisabler = std::unique_ptr<base::AutoReset<bool>>; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 252 std::unique_ptr<LauncherControllerHelper> helper); | 252 std::unique_ptr<LauncherControllerHelper> helper); |
| 253 void SetAppIconLoadersForTest( | 253 void SetAppIconLoadersForTest( |
| 254 std::vector<std::unique_ptr<AppIconLoader>>& loaders); | 254 std::vector<std::unique_ptr<AppIconLoader>>& loaders); |
| 255 | 255 |
| 256 void SetProfileForTest(Profile* profile); | 256 void SetProfileForTest(Profile* profile); |
| 257 | 257 |
| 258 // Helpers that call through to corresponding ShelfModel functions. | 258 // Helpers that call through to corresponding ShelfModel functions. |
| 259 ash::ShelfID GetShelfIDForAppID(const std::string& app_id); | 259 ash::ShelfID GetShelfIDForAppID(const std::string& app_id); |
| 260 ash::ShelfID GetShelfIDForAppIDAndLaunchID(const std::string& app_id, | 260 ash::ShelfID GetShelfIDForAppIDAndLaunchID(const std::string& app_id, |
| 261 const std::string& launch_id); | 261 const std::string& launch_id); |
| 262 const std::string& GetAppIDForShelfID(ash::ShelfID id); | 262 const std::string& GetAppIDForShelfID(const ash::ShelfID& id); |
| 263 void PinAppWithID(const std::string& app_id); | 263 void PinAppWithID(const std::string& app_id); |
| 264 bool IsAppPinned(const std::string& app_id); | 264 bool IsAppPinned(const std::string& app_id); |
| 265 void UnpinAppWithID(const std::string& app_id); | 265 void UnpinAppWithID(const std::string& app_id); |
| 266 | 266 |
| 267 // LauncherAppUpdater::Delegate: | 267 // LauncherAppUpdater::Delegate: |
| 268 void OnAppInstalled(content::BrowserContext* browser_context, | 268 void OnAppInstalled(content::BrowserContext* browser_context, |
| 269 const std::string& app_id) override; | 269 const std::string& app_id) override; |
| 270 void OnAppUpdated(content::BrowserContext* browser_context, | 270 void OnAppUpdated(content::BrowserContext* browser_context, |
| 271 const std::string& app_id) override; | 271 const std::string& app_id) override; |
| 272 void OnAppUninstalledPrepared(content::BrowserContext* browser_context, | 272 void OnAppUninstalledPrepared(content::BrowserContext* browser_context, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 283 | 283 |
| 284 private: | 284 private: |
| 285 friend class ChromeLauncherControllerTest; | 285 friend class ChromeLauncherControllerTest; |
| 286 friend class LauncherPlatformAppBrowserTest; | 286 friend class LauncherPlatformAppBrowserTest; |
| 287 friend class ShelfAppBrowserTest; | 287 friend class ShelfAppBrowserTest; |
| 288 friend class TestChromeLauncherController; | 288 friend class TestChromeLauncherController; |
| 289 | 289 |
| 290 using WebContentsToAppIDMap = std::map<content::WebContents*, std::string>; | 290 using WebContentsToAppIDMap = std::map<content::WebContents*, std::string>; |
| 291 | 291 |
| 292 // Creates a new app shortcut item and controller on the shelf at |index|. | 292 // Creates a new app shortcut item and controller on the shelf at |index|. |
| 293 ash::ShelfID CreateAppShortcutLauncherItem( | 293 ash::ShelfID CreateAppShortcutLauncherItem(const ash::ShelfID& shelf_id, |
| 294 const ash::AppLaunchId& app_launch_id, | 294 int index); |
| 295 int index); | |
| 296 | 295 |
| 297 // Remembers / restores list of running applications. | 296 // Remembers / restores list of running applications. |
| 298 // Note that this order will neither be stored in the preference nor will it | 297 // Note that this order will neither be stored in the preference nor will it |
| 299 // remember the order of closed applications since it is only temporary. | 298 // remember the order of closed applications since it is only temporary. |
| 300 void RememberUnpinnedRunningApplicationOrder(); | 299 void RememberUnpinnedRunningApplicationOrder(); |
| 301 void RestoreUnpinnedRunningApplicationOrder(const std::string& user_id); | 300 void RestoreUnpinnedRunningApplicationOrder(const std::string& user_id); |
| 302 | 301 |
| 303 // Invoked when the associated browser or app is closed. | 302 // Invoked when the associated browser or app is closed. |
| 304 void RemoveShelfItem(ash::ShelfID id); | 303 void RemoveShelfItem(const ash::ShelfID& id); |
| 305 | 304 |
| 306 // Internal helpers for pinning and unpinning that handle both | 305 // Internal helpers for pinning and unpinning that handle both |
| 307 // client-triggered and internal pinning operations. | 306 // client-triggered and internal pinning operations. |
| 308 void DoPinAppWithID(const std::string& app_id); | 307 void DoPinAppWithID(const std::string& app_id); |
| 309 void DoUnpinAppWithID(const std::string& app_id, bool update_prefs); | 308 void DoUnpinAppWithID(const std::string& app_id, bool update_prefs); |
| 310 | 309 |
| 311 // Pin a running app with |shelf_id| internally to |index|. | 310 // Pin a running app with |shelf_id| internally to |index|. |
| 312 void PinRunningAppInternal(int index, ash::ShelfID shelf_id); | 311 void PinRunningAppInternal(int index, const ash::ShelfID& shelf_id); |
| 313 | 312 |
| 314 // Unpin a locked application. This is an internal call which converts the | 313 // Unpin a locked application. This is an internal call which converts the |
| 315 // model type of the given app index from a shortcut into an unpinned running | 314 // model type of the given app index from a shortcut into an unpinned running |
| 316 // app. | 315 // app. |
| 317 void UnpinRunningAppInternal(int index); | 316 void UnpinRunningAppInternal(int index); |
| 318 | 317 |
| 319 // Updates pin position for the item specified by |id| in sync model. | 318 // Updates pin position for the item specified by |id| in sync model. |
| 320 void SyncPinPosition(ash::ShelfID id); | 319 void SyncPinPosition(const ash::ShelfID& id); |
| 321 | 320 |
| 322 // Re-syncs shelf model. | 321 // Re-syncs shelf model. |
| 323 void UpdateAppLaunchersFromPref(); | 322 void UpdateAppLaunchersFromPref(); |
| 324 | 323 |
| 325 // Schedules re-sync of shelf model. | 324 // Schedules re-sync of shelf model. |
| 326 void ScheduleUpdateAppLaunchersFromPref(); | 325 void ScheduleUpdateAppLaunchersFromPref(); |
| 327 | 326 |
| 328 // Update the policy-pinned flag for each shelf item. | 327 // Update the policy-pinned flag for each shelf item. |
| 329 void UpdatePolicyPinnedAppsFromPrefs(); | 328 void UpdatePolicyPinnedAppsFromPrefs(); |
| 330 | 329 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 // AppSyncUIStateObserver: | 383 // AppSyncUIStateObserver: |
| 385 void OnAppSyncUIStatusChanged() override; | 384 void OnAppSyncUIStatusChanged() override; |
| 386 | 385 |
| 387 // app_list::AppListSyncableService::Observer: | 386 // app_list::AppListSyncableService::Observer: |
| 388 void OnSyncModelUpdated() override; | 387 void OnSyncModelUpdated() override; |
| 389 | 388 |
| 390 // sync_preferences::PrefServiceSyncableObserver: | 389 // sync_preferences::PrefServiceSyncableObserver: |
| 391 void OnIsSyncingChanged() override; | 390 void OnIsSyncingChanged() override; |
| 392 | 391 |
| 393 // An internal helper to unpin a shelf item; this does not update prefs. | 392 // An internal helper to unpin a shelf item; this does not update prefs. |
| 394 void UnpinShelfItemInternal(ash::ShelfID id); | 393 void UnpinShelfItemInternal(const ash::ShelfID& id); |
| 395 | 394 |
| 396 static ChromeLauncherController* instance_; | 395 static ChromeLauncherController* instance_; |
| 397 | 396 |
| 398 // 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 |
| 399 // 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 |
| 400 // multi-profile use cases this might change over time. | 399 // multi-profile use cases this might change over time. |
| 401 Profile* profile_ = nullptr; | 400 Profile* profile_ = nullptr; |
| 402 | 401 |
| 403 ash::ShelfModel* model_; | 402 ash::ShelfModel* model_; |
| 404 | 403 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 using RunningAppListIds = std::vector<std::string>; | 452 using RunningAppListIds = std::vector<std::string>; |
| 454 using RunningAppListIdMap = std::map<std::string, RunningAppListIds>; | 453 using RunningAppListIdMap = std::map<std::string, RunningAppListIds>; |
| 455 RunningAppListIdMap last_used_running_application_order_; | 454 RunningAppListIdMap last_used_running_application_order_; |
| 456 | 455 |
| 457 base::WeakPtrFactory<ChromeLauncherController> weak_ptr_factory_; | 456 base::WeakPtrFactory<ChromeLauncherController> weak_ptr_factory_; |
| 458 | 457 |
| 459 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController); | 458 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController); |
| 460 }; | 459 }; |
| 461 | 460 |
| 462 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ | 461 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ |
| OLD | NEW |