Chromium Code Reviews| Index: chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h |
| diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h |
| similarity index 57% |
| copy from chrome/browser/ui/ash/launcher/chrome_launcher_controller.h |
| copy to chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h |
| index 23dca46642d4499bb2fb3d95a31359a1986c6c0c..b64b921eef02b72bedab6636ae26bbc80344caf3 100644 |
| --- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h |
| +++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h |
| @@ -2,44 +2,30 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ |
| -#define CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ |
| +#ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_IMPL_H_ |
| +#define CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_IMPL_H_ |
| #include <list> |
| -#include <map> |
| #include <memory> |
| -#include <string> |
| -#include <vector> |
| -#include "ash/common/shelf/shelf_item_delegate.h" |
| #include "ash/common/shelf/shelf_item_delegate_manager.h" |
| -#include "ash/common/shelf/shelf_item_types.h" |
| #include "ash/common/shelf/shelf_model_observer.h" |
| #include "ash/common/shelf/shelf_types.h" |
| #include "ash/display/window_tree_host_manager.h" |
| #include "ash/shelf/shelf_delegate.h" |
| #include "base/compiler_specific.h" |
| #include "base/macros.h" |
| -#include "base/memory/scoped_vector.h" |
| #include "build/build_config.h" |
| #include "chrome/browser/ui/app_icon_loader.h" |
| -#include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
| #include "chrome/browser/ui/ash/app_sync_ui_state_observer.h" |
| -#include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" |
| -#include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h" |
| +#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| #include "chrome/browser/ui/ash/launcher/launcher_app_updater.h" |
| #include "components/prefs/pref_change_registrar.h" |
| -#include "extensions/common/constants.h" |
| #include "ui/aura/window_observer.h" |
| class AppSyncUIState; |
| -class ArcAppDeferredLauncherController; |
| -class Browser; |
| -class BrowserShortcutLauncherItemController; |
| class BrowserStatusMonitor; |
| -class GURL; |
| class LauncherControllerHelper; |
| -class LauncherItemController; |
| class Profile; |
| class AppWindowLauncherController; |
| class TabContents; |
| @@ -56,32 +42,24 @@ class Window; |
| namespace content { |
| class BrowserContext; |
| -class WebContents; |
| } |
| namespace extensions { |
| class Extension; |
| } |
| -namespace ui { |
| -class BaseWindow; |
| -} |
| - |
| class ChromeLauncherControllerUserSwitchObserver; |
| // A list of the elements which makes up a simple menu description. |
|
msw
2016/06/10 22:44:38
nit: you should be able to remove this and just in
mfomitchev
2016/06/13 17:29:18
Done.
|
| typedef ScopedVector<ChromeLauncherAppMenuItem> ChromeLauncherAppMenuItems; |
| -// ChromeLauncherController manages the launcher items needed for content |
| -// windows. Launcher items have a type, an optional app id, and a controller. |
| -// This incarnation groups running tabs/windows in application specific lists. |
| -// * Browser app windows have BrowserShortcutLauncherItemController, owned by |
| -// the BrowserView instance. |
| -// * App windows have AppWindowLauncherItemController, owned by |
| -// AppWindowLauncherController. |
| -// * Shortcuts have no LauncherItemController. |
| -class ChromeLauncherController |
| - : public ash::ShelfDelegate, |
| +// Implementation of ChromeLauncherController, used for classic Ash. |
| +// In addition to implementing ChromeLauncherController, this class performs |
| +// a lot of other responsibilities, such as implementing ash::ShelfDelegate, |
| +// updating the UI state and the shelf model when apps are uninstalled, etc. |
| +class ChromeLauncherControllerImpl |
| + : public ChromeLauncherController, |
| + public ash::ShelfDelegate, |
| public ash::ShelfModelObserver, |
| public ash::WindowTreeHostManager::Observer, |
| public AppIconLoaderDelegate, |
| @@ -89,141 +67,94 @@ class ChromeLauncherController |
| public LauncherAppUpdater::Delegate, |
| public ash::ShelfItemDelegateManagerObserver { |
| public: |
| - // Used to update the state of non plaform apps, as web contents change. |
| - enum AppState { |
| - APP_STATE_ACTIVE, |
| - APP_STATE_WINDOW_ACTIVE, |
| - APP_STATE_INACTIVE, |
| - APP_STATE_REMOVED |
| - }; |
| - |
| - ChromeLauncherController(Profile* profile, ash::ShelfModel* model); |
| - ~ChromeLauncherController() override; |
| - |
| - // Initializes this ChromeLauncherController. |
| - void Init(); |
| - |
| - // Creates an instance. |
| - static ChromeLauncherController* CreateInstance(Profile* profile, |
| - ash::ShelfModel* model); |
| + ChromeLauncherControllerImpl(Profile* profile, ash::ShelfModel* model); |
| + ~ChromeLauncherControllerImpl() override; |
| - // Returns the single ChromeLauncherController instance. |
| - static ChromeLauncherController* instance() { return instance_; } |
| + // Create ChromeLauncherControllerImpl instance and set is as the |
| + // ChromeLauncherController singleton. |
| + static ChromeLauncherControllerImpl* CreateInstance(Profile* profile, |
| + ash::ShelfModel* model); |
| - // Creates a new app item on the shelf for |controller|. |
| + // ChromeLauncherController: |
| + void Init() override; |
| ash::ShelfID CreateAppLauncherItem(LauncherItemController* controller, |
| const std::string& app_id, |
| - ash::ShelfItemStatus status); |
| - |
| - // Updates the running status of an item. It will also update the status of |
| - // browsers shelf item if needed. |
| - void SetItemStatus(ash::ShelfID id, ash::ShelfItemStatus status); |
| - |
| - // Updates the controller associated with id (which should be a shortcut). |
| - // |controller| will be owned by the |ChromeLauncherController| and then |
| - // passed on to |ShelfItemDelegateManager|. |
| - // TODO(skuhne): Pass in scoped_ptr to make ownership clear. |
| - void SetItemController(ash::ShelfID id, LauncherItemController* controller); |
| - |
| - // Closes or unpins the shelf item. |
| - void CloseLauncherItem(ash::ShelfID id); |
| - |
| - // Pins the specified id. Currently only supports platform apps. |
| - void Pin(ash::ShelfID id); |
| - |
| - // Unpins the specified id, closing if not running. |
| - void Unpin(ash::ShelfID id); |
| - |
| - // Returns true if the item identified by |id| is pinned. |
| - bool IsPinned(ash::ShelfID id); |
| - |
| - // Pins/unpins the specified id. |
| - void TogglePinned(ash::ShelfID id); |
| - |
| - // Returns true if the specified item can be pinned or unpinned. Only apps can |
| - // be pinned. |
| - bool IsPinnable(ash::ShelfID id) const; |
| - |
| - // If there is no shelf item in the shelf for application |app_id|, one |
| - // gets created. The (existing or created) shelf items get then locked |
| - // against a users un-pinning removal. |
| - void LockV1AppWithID(const std::string& app_id); |
| - |
| - // A previously locked shelf item of type |app_id| gets unlocked. If the |
| - // lock count reaches 0 and the item is not pinned it will go away. |
| - void UnlockV1AppWithID(const std::string& app_id); |
| - |
| - // Requests that the shelf item controller specified by |id| open a new |
| - // instance of the app. |event_flags| holds the flags of the event which |
| - // triggered this command. |
| - void Launch(ash::ShelfID id, int event_flags); |
| - |
| - // Closes the specified item. |
| - void Close(ash::ShelfID id); |
| - |
| - // Returns true if the specified item is open. |
| - bool IsOpen(ash::ShelfID id); |
| - |
| - // Returns true if the specified item is for a platform app. |
| - bool IsPlatformApp(ash::ShelfID id); |
| - |
| - // Opens a new instance of the application identified by |app_id|. |
| - // Used by the app-list, and by pinned-app shelf items. |
| + ash::ShelfItemStatus status) override; |
| + void SetItemStatus(ash::ShelfID id, ash::ShelfItemStatus status) override; |
| + void SetItemController(ash::ShelfID id, |
| + LauncherItemController* controller) override; |
| + void CloseLauncherItem(ash::ShelfID id) override; |
| + void Pin(ash::ShelfID id) override; |
| + void Unpin(ash::ShelfID id) override; |
| + bool IsPinned(ash::ShelfID id) override; |
| + void TogglePinned(ash::ShelfID id) override; |
| + bool IsPinnable(ash::ShelfID id) const override; |
| + void LockV1AppWithID(const std::string& app_id) override; |
| + void UnlockV1AppWithID(const std::string& app_id) override; |
| + void Launch(ash::ShelfID id, int event_flags) override; |
| + void Close(ash::ShelfID id) override; |
| + bool IsOpen(ash::ShelfID id) override; |
| + bool IsPlatformApp(ash::ShelfID id) override; |
| void LaunchApp(const std::string& app_id, |
| ash::LaunchSource source, |
| - int event_flags); |
| - |
| - // If |app_id| is running, reactivates the app's most recently active window, |
| - // otherwise launches and activates the app. |
| - // Used by the app-list, and by pinned-app shelf items. |
| + int event_flags) override; |
| void ActivateApp(const std::string& app_id, |
| ash::LaunchSource source, |
| - int event_flags); |
| - |
| - // Returns the launch type of app for the specified id. |
| - extensions::LaunchType GetLaunchType(ash::ShelfID id); |
| - |
| - // Set the image for a specific shelf item (e.g. when set by the app). |
| - void SetLauncherItemImage(ash::ShelfID shelf_id, const gfx::ImageSkia& image); |
| - |
| - // Find out if the given application |id| is a windowed app item and not a |
| - // pinned item in the shelf. |
| - bool IsWindowedAppInLauncher(const std::string& app_id); |
| - |
| - // Updates the launch type of the app for the specified id to |launch_type|. |
| - void SetLaunchType(ash::ShelfID id, extensions::LaunchType launch_type); |
| - |
| - // Updates the pinned pref state. The pinned state consists of a list pref. |
| - // Each item of the list is a dictionary. The key |kAppIDPath| gives the |
| - // id of the app. |
| - void PersistPinnedState(); |
| - |
| - // Accessor to the currently loaded profile. Note that in multi profile use |
| - // cases this might change over time. |
| - Profile* profile(); |
| - |
| - // Notify the controller that the state of an non platform app's tabs |
| - // have changed, |
| - void UpdateAppState(content::WebContents* contents, AppState app_state); |
| - |
| - // Returns ShelfID for |contents|. If |contents| is not an app or is not |
| - // pinned, returns the id of browser shrotcut. |
| - ash::ShelfID GetShelfIDForWebContents(content::WebContents* contents); |
| - |
| - // Limits application refocusing to urls that match |url| for |id|. |
| - void SetRefocusURLPatternForTest(ash::ShelfID id, const GURL& url); |
| - |
| - // Returns the extension identified by |app_id|. |
| + int event_flags) override; |
| + extensions::LaunchType GetLaunchType(ash::ShelfID id) override; |
| + void SetLauncherItemImage(ash::ShelfID shelf_id, |
| + const gfx::ImageSkia& image) override; |
| + bool IsWindowedAppInLauncher(const std::string& app_id) override; |
| + void SetLaunchType(ash::ShelfID id, |
| + extensions::LaunchType launch_type) override; |
| + void PersistPinnedState() override; |
| + Profile* GetProfile() override; |
| + void UpdateAppState(content::WebContents* contents, |
| + AppState app_state) override; |
| + ash::ShelfID GetShelfIDForWebContents( |
| + content::WebContents* contents) override; |
| + void SetRefocusURLPatternForTest(ash::ShelfID id, const GURL& url) override; |
| const extensions::Extension* GetExtensionForAppID( |
| - const std::string& app_id) const; |
| - |
| - // Activates a |window|. If |allow_minimize| is true and the system allows |
| - // it, the the window will get minimized instead. |
| - // Returns the action performed. Should be one of kNoAction, |
| - // kExistingWindowActivated, or kExistingWindowMinimized. |
| + const std::string& app_id) const override; |
| ash::ShelfItemDelegate::PerformedAction ActivateWindowOrMinimizeIfActive( |
| ui::BaseWindow* window, |
| - bool allow_minimize); |
| + bool allow_minimize) override; |
| + void ActiveUserChanged(const std::string& user_email) override; |
| + void AdditionalUserAddedToSession(Profile* profile) override; |
| + ChromeLauncherAppMenuItems GetApplicationList(const ash::ShelfItem& item, |
| + int event_flags) override; |
| + std::vector<content::WebContents*> GetV1ApplicationsFromAppId( |
| + const std::string& app_id) override; |
| + void ActivateShellApp(const std::string& app_id, int index) override; |
| + bool IsWebContentHandledByApplication(content::WebContents* web_contents, |
| + const std::string& app_id) override; |
| + bool ContentCanBeHandledByGmailApp( |
| + content::WebContents* web_contents) override; |
| + gfx::Image GetAppListIcon(content::WebContents* web_contents) const override; |
| + base::string16 GetAppListTitle( |
| + content::WebContents* web_contents) const override; |
| + BrowserShortcutLauncherItemController* |
| + GetBrowserShortcutLauncherItemController() override; |
| + LauncherItemController* GetLauncherItemController( |
| + const ash::ShelfID id) override; |
| + bool IsBrowserFromActiveUser(Browser* browser) override; |
| + bool ShelfBoundsChangesProbablyWithUser( |
| + ash::Shelf* shelf, |
| + const std::string& user_id) const override; |
| + void OnUserProfileReadyToSwitch(Profile* profile) override; |
| + AppListControllerDelegate::Pinnable GetPinnable( |
| + const std::string& app_id) override; |
| + ArcAppDeferredLauncherController* GetArcDeferredLauncher() override; |
| + |
| + // Access to the BrowserStatusMonitor for tests. |
| + BrowserStatusMonitor* browser_status_monitor_for_test() { |
| + return browser_status_monitor_.get(); |
| + } |
| + |
| + // Access to the AppWindowLauncherController for tests. |
| + AppWindowLauncherController* app_window_controller_for_test() { |
| + return app_window_controllers_[0].get(); |
| + } |
| // ash::ShelfDelegate: |
|
msw
2016/06/10 22:44:38
nit: if possible, we should make the base class ov
mfomitchev
2016/06/10 23:29:09
Hmm.. this might be possible for some of them, but
msw
2016/06/10 23:42:51
Acknowledged.
|
| void OnShelfCreated(ash::Shelf* shelf) override; |
| @@ -268,79 +199,7 @@ class ChromeLauncherController |
| void OnAppImageUpdated(const std::string& app_id, |
| const gfx::ImageSkia& image) override; |
| - // Called when the active user has changed. |
| - void ActiveUserChanged(const std::string& user_email); |
| - |
| - // Called when a user got added to the session. |
| - void AdditionalUserAddedToSession(Profile* profile); |
| - |
| - // Get the list of all running incarnations of this item. |
| - // |event_flags| specifies the flags which were set by the event which |
| - // triggered this menu generation. It can be used to generate different lists. |
| - ChromeLauncherAppMenuItems GetApplicationList(const ash::ShelfItem& item, |
| - int event_flags); |
| - |
| - // Get the list of all tabs which belong to a certain application type. |
| - std::vector<content::WebContents*> GetV1ApplicationsFromAppId( |
| - const std::string& app_id); |
| - |
| - // Activates a specified shell application. |
| - void ActivateShellApp(const std::string& app_id, int index); |
| - |
| - // Checks if a given |web_contents| is known to be associated with an |
| - // application of type |app_id|. |
| - bool IsWebContentHandledByApplication(content::WebContents* web_contents, |
| - const std::string& app_id); |
| - |
| - // Check if the gMail app is loaded and it can handle the given web content. |
| - // This special treatment is required to address crbug.com/234268. |
| - bool ContentCanBeHandledByGmailApp(content::WebContents* web_contents); |
| - |
| - // Get the favicon for the application list entry for |web_contents|. |
| - // Note that for incognito windows the incognito icon will be returned. |
| - // If |web_contents| has not loaded, returns the default favicon. |
| - gfx::Image GetAppListIcon(content::WebContents* web_contents) const; |
| - |
| - // Get the title for the applicatoin list entry for |web_contents|. |
| - // If |web_contents| has not loaded, returns "Net Tab". |
| - base::string16 GetAppListTitle(content::WebContents* web_contents) const; |
| - |
| - // Returns the LauncherItemController of BrowserShortcut. |
| - BrowserShortcutLauncherItemController* |
| - GetBrowserShortcutLauncherItemController(); |
| - |
| - LauncherItemController* GetLauncherItemController(const ash::ShelfID id); |
| - |
| - // Returns true if |browser| is owned by the active user. |
| - bool IsBrowserFromActiveUser(Browser* browser); |
| - |
| - // Check if the shelf visibility (location, visibility) will change with a new |
| - // user profile or not. However, since the full visibility calculation of the |
| - // shelf cannot be performed here, this is only a probability used for |
| - // animation predictions. |
| - bool ShelfBoundsChangesProbablyWithUser(ash::Shelf* shelf, |
| - const std::string& user_id) const; |
| - |
| - // Called when the user profile is fully loaded and ready to switch to. |
| - void OnUserProfileReadyToSwitch(Profile* profile); |
| - // Access to the BrowserStatusMonitor for tests. |
| - BrowserStatusMonitor* browser_status_monitor_for_test() { |
| - return browser_status_monitor_.get(); |
| - } |
| - |
| - // Access to the AppWindowLauncherController for tests. |
| - AppWindowLauncherController* app_window_controller_for_test() { |
| - return app_window_controllers_[0].get(); |
| - } |
| - |
| - // Controller to launch Arc apps in deferred mode. |
| - ArcAppDeferredLauncherController* arc_deferred_launcher() { |
| - return arc_deferred_launcher_.get(); |
| - } |
| - |
| - // TODO(khmel): Find better home for Pinnable enum. |
| - AppListControllerDelegate::Pinnable GetPinnable(const std::string& app_id); |
| protected: |
| // Creates a new app shortcut item and controller on the shelf at |index|. |
| @@ -360,7 +219,7 @@ class ChromeLauncherController |
| ash::ShelfItemDelegateManager* manager); |
| private: |
| - friend class ChromeLauncherControllerTest; |
| + friend class ChromeLauncherControllerImplTest; |
| friend class ShelfAppBrowserTest; |
| friend class LauncherPlatformAppBrowserTest; |
| @@ -421,10 +280,10 @@ class ChromeLauncherController |
| // adjusted by the model to meet ordering constraints. |
| // The |shelf_item_type| will be set into the ShelfModel. |
| ash::ShelfID InsertAppLauncherItem(LauncherItemController* controller, |
| - const std::string& app_id, |
| - ash::ShelfItemStatus status, |
| - int index, |
| - ash::ShelfItemType shelf_item_type); |
| + const std::string& app_id, |
| + ash::ShelfItemStatus status, |
| + int index, |
| + ash::ShelfItemType shelf_item_type); |
| // Enumerate all Web contents which match a given shortcut |controller|. |
| std::vector<content::WebContents*> GetV1ApplicationsFromController( |
| @@ -444,12 +303,11 @@ class ChromeLauncherController |
| // |app_list_index| locations will get adjusted within this call to finalize |
| // the action and to make sure that the other item can still be moved |
| // afterwards (index adjustments). |
| - void MoveChromeOrApplistToFinalPosition( |
| - bool is_chrome, |
| - bool is_app_list, |
| - int target_index, |
| - int* chrome_index, |
| - int* app_list_index); |
| + void MoveChromeOrApplistToFinalPosition(bool is_chrome, |
| + bool is_app_list, |
| + int target_index, |
| + int* chrome_index, |
| + int* app_list_index); |
| // Finds the index of where to insert the next item. |
| int FindInsertionPoint(bool is_app_list); |
| @@ -476,8 +334,6 @@ class ChromeLauncherController |
| AppIconLoader* GetAppIconLoaderForApp(const std::string& app_id); |
| - static ChromeLauncherController* instance_; |
| - |
| ash::ShelfModel* model_; |
| ash::ShelfItemDelegateManager* item_delegate_manager_; |
| @@ -529,7 +385,7 @@ class ChromeLauncherController |
| typedef std::map<std::string, RunningAppListIds> RunningAppListIdMap; |
| RunningAppListIdMap last_used_running_application_order_; |
| - DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController); |
| + DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerImpl); |
| }; |
| -#endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ |
| +#endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_IMPL_H_ |