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

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

Issue 2052013002: Adding ChromeLauncherController interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@chrome_launcher_smaller_api
Patch Set: Fix method order Created 4 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 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 <list>
9 #include <map> 8 #include <map>
msw 2016/06/10 22:44:38 nit: not needed?
mfomitchev 2016/06/13 17:29:18 Done.
10 #include <memory>
11 #include <string> 9 #include <string>
12 #include <vector> 10 #include <vector>
13 11
14 #include "ash/common/shelf/shelf_item_delegate.h" 12 #include "ash/common/shelf/shelf_item_delegate.h"
15 #include "ash/common/shelf/shelf_item_delegate_manager.h"
16 #include "ash/common/shelf/shelf_item_types.h" 13 #include "ash/common/shelf/shelf_item_types.h"
17 #include "ash/common/shelf/shelf_model_observer.h"
18 #include "ash/common/shelf/shelf_types.h"
19 #include "ash/display/window_tree_host_manager.h"
20 #include "ash/shelf/shelf_delegate.h"
21 #include "base/compiler_specific.h"
22 #include "base/macros.h"
23 #include "base/memory/scoped_vector.h" 14 #include "base/memory/scoped_vector.h"
24 #include "build/build_config.h"
25 #include "chrome/browser/ui/app_icon_loader.h"
26 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" 15 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
27 #include "chrome/browser/ui/ash/app_sync_ui_state_observer.h"
28 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h"
29 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h" 17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h"
30 #include "chrome/browser/ui/ash/launcher/launcher_app_updater.h"
31 #include "components/prefs/pref_change_registrar.h"
32 #include "extensions/common/constants.h" 18 #include "extensions/common/constants.h"
33 #include "ui/aura/window_observer.h"
34 19
35 class AppSyncUIState;
36 class ArcAppDeferredLauncherController; 20 class ArcAppDeferredLauncherController;
37 class Browser; 21 class Browser;
38 class BrowserShortcutLauncherItemController; 22 class BrowserShortcutLauncherItemController;
39 class BrowserStatusMonitor;
40 class GURL; 23 class GURL;
41 class LauncherControllerHelper;
42 class LauncherItemController; 24 class LauncherItemController;
43 class Profile;
44 class AppWindowLauncherController;
45 class TabContents;
46 25
47 namespace ash { 26 namespace ash {
48 class ChromeLauncherPrefsObserver; 27 class Shelf;
49 class ShelfItemDelegateManager;
50 class ShelfModel;
51 }
52
53 namespace aura {
54 class Window;
55 } 28 }
56 29
57 namespace content { 30 namespace content {
58 class BrowserContext;
59 class WebContents; 31 class WebContents;
60 } 32 }
61 33
62 namespace extensions { 34 namespace gfx {
63 class Extension; 35 class Image;
64 } 36 }
65 37
66 namespace ui { 38 namespace ui {
67 class BaseWindow; 39 class BaseWindow;
68 } 40 }
69 41
70 class ChromeLauncherControllerUserSwitchObserver;
71
72 // A list of the elements which makes up a simple menu description. 42 // A list of the elements which makes up a simple menu description.
73 typedef ScopedVector<ChromeLauncherAppMenuItem> ChromeLauncherAppMenuItems; 43 typedef ScopedVector<ChromeLauncherAppMenuItem> ChromeLauncherAppMenuItems;
74 44
75 // ChromeLauncherController manages the launcher items needed for content 45 // ChromeLauncherController manages the launcher items needed for content
76 // windows. Launcher items have a type, an optional app id, and a controller. 46 // windows. Launcher items have a type, an optional app id, and a controller.
77 // This incarnation groups running tabs/windows in application specific lists. 47 // There are different kinds of launcher item controllers, all extending the
78 // * Browser app windows have BrowserShortcutLauncherItemController, owned by 48 // LauncherItemController class.
79 // the BrowserView instance. 49 class ChromeLauncherController {
80 // * App windows have AppWindowLauncherItemController, owned by
81 // AppWindowLauncherController.
82 // * Shortcuts have no LauncherItemController.
83 class ChromeLauncherController
84 : public ash::ShelfDelegate,
85 public ash::ShelfModelObserver,
86 public ash::WindowTreeHostManager::Observer,
87 public AppIconLoaderDelegate,
88 public AppSyncUIStateObserver,
89 public LauncherAppUpdater::Delegate,
90 public ash::ShelfItemDelegateManagerObserver {
91 public: 50 public:
92 // Used to update the state of non plaform apps, as web contents change. 51 // Used to update the state of non plaform apps, as web contents change.
93 enum AppState { 52 enum AppState {
94 APP_STATE_ACTIVE, 53 APP_STATE_ACTIVE,
95 APP_STATE_WINDOW_ACTIVE, 54 APP_STATE_WINDOW_ACTIVE,
96 APP_STATE_INACTIVE, 55 APP_STATE_INACTIVE,
97 APP_STATE_REMOVED 56 APP_STATE_REMOVED
98 }; 57 };
99 58
100 ChromeLauncherController(Profile* profile, ash::ShelfModel* model); 59 // Set the ChromeLauncherController singleton.
101 ~ChromeLauncherController() override; 60 static void SetInstance(ChromeLauncherController* instance) {
msw 2016/06/10 22:44:38 nit: set_instance for simple accessor
mfomitchev 2016/06/13 17:29:18 Done.
102 61 instance_ = instance;
103 // Initializes this ChromeLauncherController. 62 }
104 void Init();
105
106 // Creates an instance.
107 static ChromeLauncherController* CreateInstance(Profile* profile,
108 ash::ShelfModel* model);
109 63
110 // Returns the single ChromeLauncherController instance. 64 // Returns the single ChromeLauncherController instance.
111 static ChromeLauncherController* instance() { return instance_; } 65 static ChromeLauncherController* instance() { return instance_; }
112 66
67 // ChromeLauncherController();
msw 2016/06/10 22:44:38 nit: Remove
mfomitchev 2016/06/13 17:29:18 Done.
68 virtual ~ChromeLauncherController();
69
70 // Initializes this ChromeLauncherController.
71 virtual void Init() = 0;
72
113 // Creates a new app item on the shelf for |controller|. 73 // Creates a new app item on the shelf for |controller|.
114 ash::ShelfID CreateAppLauncherItem(LauncherItemController* controller, 74 virtual ash::ShelfID CreateAppLauncherItem(LauncherItemController* controller,
msw 2016/06/10 22:44:38 Just a note, eventually we'll probably want to avo
mfomitchev 2016/06/13 17:29:18 Acknowledged.
115 const std::string& app_id, 75 const std::string& app_id,
116 ash::ShelfItemStatus status); 76 ash::ShelfItemStatus status) = 0;
117 77
118 // Updates the running status of an item. It will also update the status of 78 // Updates the running status of an item. It will also update the status of
119 // browsers shelf item if needed. 79 // browsers shelf item if needed.
120 void SetItemStatus(ash::ShelfID id, ash::ShelfItemStatus status); 80 virtual void SetItemStatus(ash::ShelfID id, ash::ShelfItemStatus status) = 0;
121 81
122 // Updates the controller associated with id (which should be a shortcut). 82 // Updates the controller associated with id (which should be a shortcut).
123 // |controller| will be owned by the |ChromeLauncherController| and then 83 // |controller| will be owned by the |ChromeLauncherController| and then
124 // passed on to |ShelfItemDelegateManager|. 84 // passed on to |ShelfItemDelegateManager|.
125 // TODO(skuhne): Pass in scoped_ptr to make ownership clear. 85 // TODO(skuhne): Pass in scoped_ptr to make ownership clear.
126 void SetItemController(ash::ShelfID id, LauncherItemController* controller); 86 virtual void SetItemController(ash::ShelfID id,
87 LauncherItemController* controller) = 0;
127 88
128 // Closes or unpins the shelf item. 89 // Closes or unpins the shelf item.
129 void CloseLauncherItem(ash::ShelfID id); 90 virtual void CloseLauncherItem(ash::ShelfID id) = 0;
130 91
131 // Pins the specified id. Currently only supports platform apps. 92 // Pins the specified id. Currently only supports platform apps.
132 void Pin(ash::ShelfID id); 93 virtual void Pin(ash::ShelfID id) = 0;
133 94
134 // Unpins the specified id, closing if not running. 95 // Unpins the specified id, closing if not running.
135 void Unpin(ash::ShelfID id); 96 virtual void Unpin(ash::ShelfID id) = 0;
136 97
137 // Returns true if the item identified by |id| is pinned. 98 // Returns true if the item identified by |id| is pinned.
138 bool IsPinned(ash::ShelfID id); 99 virtual bool IsPinned(ash::ShelfID id) = 0;
139 100
140 // Pins/unpins the specified id. 101 // Pins/unpins the specified id.
141 void TogglePinned(ash::ShelfID id); 102 virtual void TogglePinned(ash::ShelfID id) = 0;
142 103
143 // Returns true if the specified item can be pinned or unpinned. Only apps can 104 // Returns true if the specified item can be pinned or unpinned. Only apps can
144 // be pinned. 105 // be pinned.
145 bool IsPinnable(ash::ShelfID id) const; 106 virtual bool IsPinnable(ash::ShelfID id) const = 0;
146 107
147 // If there is no shelf item in the shelf for application |app_id|, one 108 // If there is no shelf item in the shelf for application |app_id|, one
148 // gets created. The (existing or created) shelf items get then locked 109 // gets created. The (existing or created) shelf items get then locked
149 // against a users un-pinning removal. 110 // against a users un-pinning removal.
150 void LockV1AppWithID(const std::string& app_id); 111 virtual void LockV1AppWithID(const std::string& app_id) = 0;
151 112
152 // A previously locked shelf item of type |app_id| gets unlocked. If the 113 // A previously locked shelf item of type |app_id| gets unlocked. If the
153 // lock count reaches 0 and the item is not pinned it will go away. 114 // lock count reaches 0 and the item is not pinned it will go away.
154 void UnlockV1AppWithID(const std::string& app_id); 115 virtual void UnlockV1AppWithID(const std::string& app_id) = 0;
155 116
156 // Requests that the shelf item controller specified by |id| open a new 117 // Requests that the shelf item controller specified by |id| open a new
157 // instance of the app. |event_flags| holds the flags of the event which 118 // instance of the app. |event_flags| holds the flags of the event which
158 // triggered this command. 119 // triggered this command.
159 void Launch(ash::ShelfID id, int event_flags); 120 virtual void Launch(ash::ShelfID id, int event_flags) = 0;
160 121
161 // Closes the specified item. 122 // Closes the specified item.
162 void Close(ash::ShelfID id); 123 virtual void Close(ash::ShelfID id) = 0;
163 124
164 // Returns true if the specified item is open. 125 // Returns true if the specified item is open.
165 bool IsOpen(ash::ShelfID id); 126 virtual bool IsOpen(ash::ShelfID id) = 0;
166 127
167 // Returns true if the specified item is for a platform app. 128 // Returns true if the specified item is for a platform app.
168 bool IsPlatformApp(ash::ShelfID id); 129 virtual bool IsPlatformApp(ash::ShelfID id) = 0;
169 130
170 // Opens a new instance of the application identified by |app_id|. 131 // Opens a new instance of the application identified by |app_id|.
171 // Used by the app-list, and by pinned-app shelf items. 132 // Used by the app-list, and by pinned-app shelf items.
172 void LaunchApp(const std::string& app_id, 133 virtual void LaunchApp(const std::string& app_id,
173 ash::LaunchSource source, 134 ash::LaunchSource source,
174 int event_flags); 135 int event_flags) = 0;
175 136
176 // If |app_id| is running, reactivates the app's most recently active window, 137 // If |app_id| is running, reactivates the app's most recently active window,
177 // otherwise launches and activates the app. 138 // otherwise launches and activates the app.
178 // Used by the app-list, and by pinned-app shelf items. 139 // Used by the app-list, and by pinned-app shelf items.
179 void ActivateApp(const std::string& app_id, 140 virtual void ActivateApp(const std::string& app_id,
180 ash::LaunchSource source, 141 ash::LaunchSource source,
181 int event_flags); 142 int event_flags) = 0;
182 143
183 // Returns the launch type of app for the specified id. 144 // Returns the launch type of app for the specified id.
184 extensions::LaunchType GetLaunchType(ash::ShelfID id); 145 virtual extensions::LaunchType GetLaunchType(ash::ShelfID id) = 0;
185 146
186 // Set the image for a specific shelf item (e.g. when set by the app). 147 // Set the image for a specific shelf item (e.g. when set by the app).
187 void SetLauncherItemImage(ash::ShelfID shelf_id, const gfx::ImageSkia& image); 148 virtual void SetLauncherItemImage(ash::ShelfID shelf_id,
149 const gfx::ImageSkia& image) = 0;
188 150
189 // Find out if the given application |id| is a windowed app item and not a 151 // Find out if the given application |id| is a windowed app item and not a
190 // pinned item in the shelf. 152 // pinned item in the shelf.
191 bool IsWindowedAppInLauncher(const std::string& app_id); 153 virtual bool IsWindowedAppInLauncher(const std::string& app_id) = 0;
192 154
193 // Updates the launch type of the app for the specified id to |launch_type|. 155 // Updates the launch type of the app for the specified id to |launch_type|.
194 void SetLaunchType(ash::ShelfID id, extensions::LaunchType launch_type); 156 virtual void SetLaunchType(ash::ShelfID id,
157 extensions::LaunchType launch_type) = 0;
195 158
196 // Updates the pinned pref state. The pinned state consists of a list pref. 159 // Updates the pinned pref state. The pinned state consists of a list pref.
197 // Each item of the list is a dictionary. The key |kAppIDPath| gives the 160 // Each item of the list is a dictionary. The key |kAppIDPath| gives the
198 // id of the app. 161 // id of the app.
199 void PersistPinnedState(); 162 virtual void PersistPinnedState() = 0;
200 163
201 // Accessor to the currently loaded profile. Note that in multi profile use 164 // Accessor to the currently loaded profile. Note that in multi profile use
202 // cases this might change over time. 165 // cases this might change over time.
203 Profile* profile(); 166 virtual Profile* GetProfile() = 0;
204 167
205 // Notify the controller that the state of an non platform app's tabs 168 // Notify the controller that the state of an non platform app's tabs
206 // have changed, 169 // have changed,
207 void UpdateAppState(content::WebContents* contents, AppState app_state); 170 virtual void UpdateAppState(content::WebContents* contents,
171 AppState app_state) = 0;
208 172
209 // Returns ShelfID for |contents|. If |contents| is not an app or is not 173 // Returns ShelfID for |contents|. If |contents| is not an app or is not
210 // pinned, returns the id of browser shrotcut. 174 // pinned, returns the id of browser shrotcut.
211 ash::ShelfID GetShelfIDForWebContents(content::WebContents* contents); 175 virtual ash::ShelfID GetShelfIDForWebContents(
176 content::WebContents* contents) = 0;
212 177
213 // Limits application refocusing to urls that match |url| for |id|. 178 // Limits application refocusing to urls that match |url| for |id|.
214 void SetRefocusURLPatternForTest(ash::ShelfID id, const GURL& url); 179 virtual void SetRefocusURLPatternForTest(ash::ShelfID id,
180 const GURL& url) = 0;
215 181
216 // Returns the extension identified by |app_id|. 182 // Returns the extension identified by |app_id|.
217 const extensions::Extension* GetExtensionForAppID( 183 virtual const extensions::Extension* GetExtensionForAppID(
218 const std::string& app_id) const; 184 const std::string& app_id) const = 0;
219 185
220 // Activates a |window|. If |allow_minimize| is true and the system allows 186 // Activates a |window|. If |allow_minimize| is true and the system allows
221 // it, the the window will get minimized instead. 187 // it, the the window will get minimized instead.
222 // Returns the action performed. Should be one of kNoAction, 188 // Returns the action performed. Should be one of kNoAction,
223 // kExistingWindowActivated, or kExistingWindowMinimized. 189 // kExistingWindowActivated, or kExistingWindowMinimized.
224 ash::ShelfItemDelegate::PerformedAction ActivateWindowOrMinimizeIfActive( 190 virtual ash::ShelfItemDelegate::PerformedAction
225 ui::BaseWindow* window, 191 ActivateWindowOrMinimizeIfActive(ui::BaseWindow* window,
226 bool allow_minimize); 192 bool allow_minimize) = 0;
227
228 // ash::ShelfDelegate:
229 void OnShelfCreated(ash::Shelf* shelf) override;
230 void OnShelfDestroyed(ash::Shelf* shelf) override;
231 void OnShelfAlignmentChanged(ash::Shelf* shelf) override;
232 void OnShelfAutoHideBehaviorChanged(ash::Shelf* shelf) override;
233 void OnShelfAutoHideStateChanged(ash::Shelf* shelf) override;
234 void OnShelfVisibilityStateChanged(ash::Shelf* shelf) override;
235 ash::ShelfID GetShelfIDForAppID(const std::string& app_id) override;
236 bool HasShelfIDToAppIDMapping(ash::ShelfID id) const override;
237 const std::string& GetAppIDForShelfID(ash::ShelfID id) override;
238 bool GetAppIDForShelfIDConst(ash::ShelfID id, std::string* app_id) const;
239 void PinAppWithID(const std::string& app_id) override;
240 bool IsAppPinned(const std::string& app_id) override;
241 void UnpinAppWithID(const std::string& app_id) override;
242
243 // ash::ShelfItemDelegateManagerObserver:
244 void OnSetShelfItemDelegate(ash::ShelfID id,
245 ash::ShelfItemDelegate* item_delegate) override;
246
247 // ash::ShelfModelObserver:
248 void ShelfItemAdded(int index) override;
249 void ShelfItemRemoved(int index, ash::ShelfID id) override;
250 void ShelfItemMoved(int start_index, int target_index) override;
251 void ShelfItemChanged(int index, const ash::ShelfItem& old_item) override;
252
253 // ash::WindowTreeHostManager::Observer:
254 void OnDisplayConfigurationChanged() override;
255
256 // LauncherAppUpdater:
257 void OnAppInstalled(content::BrowserContext* browser_context,
258 const std::string& app_id) override;
259 void OnAppUpdated(content::BrowserContext* browser_context,
260 const std::string& app_id) override;
261 void OnAppUninstalled(content::BrowserContext* browser_context,
262 const std::string& app_id) override;
263
264 // AppSyncUIStateObserver:
265 void OnAppSyncUIStatusChanged() override;
266
267 // AppIconLoaderDelegate:
268 void OnAppImageUpdated(const std::string& app_id,
269 const gfx::ImageSkia& image) override;
270 193
271 // Called when the active user has changed. 194 // Called when the active user has changed.
272 void ActiveUserChanged(const std::string& user_email); 195 virtual void ActiveUserChanged(const std::string& user_email) = 0;
273 196
274 // Called when a user got added to the session. 197 // Called when a user got added to the session.
275 void AdditionalUserAddedToSession(Profile* profile); 198 virtual void AdditionalUserAddedToSession(Profile* profile) = 0;
276 199
277 // Get the list of all running incarnations of this item. 200 // Get the list of all running incarnations of this item.
278 // |event_flags| specifies the flags which were set by the event which 201 // |event_flags| specifies the flags which were set by the event which
279 // triggered this menu generation. It can be used to generate different lists. 202 // triggered this menu generation. It can be used to generate different lists.
280 ChromeLauncherAppMenuItems GetApplicationList(const ash::ShelfItem& item, 203 virtual ChromeLauncherAppMenuItems GetApplicationList(
281 int event_flags); 204 const ash::ShelfItem& item,
205 int event_flags) = 0;
282 206
283 // Get the list of all tabs which belong to a certain application type. 207 // Get the list of all tabs which belong to a certain application type.
284 std::vector<content::WebContents*> GetV1ApplicationsFromAppId( 208 virtual std::vector<content::WebContents*> GetV1ApplicationsFromAppId(
285 const std::string& app_id); 209 const std::string& app_id) = 0;
286 210
287 // Activates a specified shell application. 211 // Activates a specified shell application.
288 void ActivateShellApp(const std::string& app_id, int index); 212 virtual void ActivateShellApp(const std::string& app_id, int index) = 0;
289 213
290 // Checks if a given |web_contents| is known to be associated with an 214 // Checks if a given |web_contents| is known to be associated with an
291 // application of type |app_id|. 215 // application of type |app_id|.
292 bool IsWebContentHandledByApplication(content::WebContents* web_contents, 216 virtual bool IsWebContentHandledByApplication(
293 const std::string& app_id); 217 content::WebContents* web_contents,
218 const std::string& app_id) = 0;
294 219
295 // Check if the gMail app is loaded and it can handle the given web content. 220 // Check if the gMail app is loaded and it can handle the given web content.
296 // This special treatment is required to address crbug.com/234268. 221 // This special treatment is required to address crbug.com/234268.
297 bool ContentCanBeHandledByGmailApp(content::WebContents* web_contents); 222 virtual bool ContentCanBeHandledByGmailApp(
223 content::WebContents* web_contents) = 0;
298 224
299 // Get the favicon for the application list entry for |web_contents|. 225 // Get the favicon for the application list entry for |web_contents|.
300 // Note that for incognito windows the incognito icon will be returned. 226 // Note that for incognito windows the incognito icon will be returned.
301 // If |web_contents| has not loaded, returns the default favicon. 227 // If |web_contents| has not loaded, returns the default favicon.
302 gfx::Image GetAppListIcon(content::WebContents* web_contents) const; 228 virtual gfx::Image GetAppListIcon(
229 content::WebContents* web_contents) const = 0;
303 230
304 // Get the title for the applicatoin list entry for |web_contents|. 231 // Get the title for the applicatoin list entry for |web_contents|.
305 // If |web_contents| has not loaded, returns "Net Tab". 232 // If |web_contents| has not loaded, returns "Net Tab".
306 base::string16 GetAppListTitle(content::WebContents* web_contents) const; 233 virtual base::string16 GetAppListTitle(
234 content::WebContents* web_contents) const = 0;
307 235
308 // Returns the LauncherItemController of BrowserShortcut. 236 // Returns the LauncherItemController of BrowserShortcut.
309 BrowserShortcutLauncherItemController* 237 virtual BrowserShortcutLauncherItemController*
310 GetBrowserShortcutLauncherItemController(); 238 GetBrowserShortcutLauncherItemController() = 0;
311 239
312 LauncherItemController* GetLauncherItemController(const ash::ShelfID id); 240 virtual LauncherItemController* GetLauncherItemController(
241 const ash::ShelfID id) = 0;
313 242
314 // Returns true if |browser| is owned by the active user. 243 // Returns true if |browser| is owned by the active user.
315 bool IsBrowserFromActiveUser(Browser* browser); 244 virtual bool IsBrowserFromActiveUser(Browser* browser) = 0;
316 245
317 // Check if the shelf visibility (location, visibility) will change with a new 246 // Check if the shelf visibility (location, visibility) will change with a new
318 // user profile or not. However, since the full visibility calculation of the 247 // user profile or not. However, since the full visibility calculation of the
319 // shelf cannot be performed here, this is only a probability used for 248 // shelf cannot be performed here, this is only a probability used for
320 // animation predictions. 249 // animation predictions.
321 bool ShelfBoundsChangesProbablyWithUser(ash::Shelf* shelf, 250 virtual bool ShelfBoundsChangesProbablyWithUser(
322 const std::string& user_id) const; 251 ash::Shelf* shelf,
252 const std::string& user_id) const = 0;
323 253
324 // Called when the user profile is fully loaded and ready to switch to. 254 // Called when the user profile is fully loaded and ready to switch to.
325 void OnUserProfileReadyToSwitch(Profile* profile); 255 virtual void OnUserProfileReadyToSwitch(Profile* profile) = 0;
326 256
327 // Access to the BrowserStatusMonitor for tests. 257 // TODO(khmel): Find better home for Pinnable enum.
328 BrowserStatusMonitor* browser_status_monitor_for_test() { 258 virtual AppListControllerDelegate::Pinnable GetPinnable(
329 return browser_status_monitor_.get(); 259 const std::string& app_id) = 0;
330 }
331
332 // Access to the AppWindowLauncherController for tests.
333 AppWindowLauncherController* app_window_controller_for_test() {
334 return app_window_controllers_[0].get();
335 }
336 260
337 // Controller to launch Arc apps in deferred mode. 261 // Controller to launch Arc apps in deferred mode.
338 ArcAppDeferredLauncherController* arc_deferred_launcher() { 262 virtual ArcAppDeferredLauncherController* GetArcDeferredLauncher() = 0;
339 return arc_deferred_launcher_.get();
340 }
341
342 // TODO(khmel): Find better home for Pinnable enum.
343 AppListControllerDelegate::Pinnable GetPinnable(const std::string& app_id);
344 263
345 protected: 264 protected:
346 // Creates a new app shortcut item and controller on the shelf at |index|. 265 ChromeLauncherController();
347 // Use kInsertItemAtEnd to add a shortcut as the last item.
348 ash::ShelfID CreateAppShortcutLauncherItem(const std::string& app_id,
349 int index);
350
351 // Sets LauncherControllerHelper/AppIconLoader for test, taking ownership.
352 void SetLauncherControllerHelperForTest(LauncherControllerHelper* helper);
353 void SetAppIconLoadersForTest(
354 std::vector<std::unique_ptr<AppIconLoader>>& loaders);
355 const std::string& GetAppIdFromShelfIdForTest(ash::ShelfID id);
356
357 // Sets the ash::ShelfItemDelegateManager only for unittests and doesn't
358 // take an ownership of it.
359 void SetShelfItemDelegateManagerForTest(
360 ash::ShelfItemDelegateManager* manager);
361 266
362 private: 267 private:
363 friend class ChromeLauncherControllerTest;
364 friend class ShelfAppBrowserTest;
365 friend class LauncherPlatformAppBrowserTest;
366
367 typedef std::map<ash::ShelfID, LauncherItemController*> IDToItemControllerMap;
368 typedef std::map<content::WebContents*, std::string> WebContentsToAppIDMap;
369
370 // Remembers / restores list of running applications.
371 // Note that this order will neither be stored in the preference nor will it
372 // remember the order of closed applications since it is only temporary.
373 void RememberUnpinnedRunningApplicationOrder();
374 void RestoreUnpinnedRunningApplicationOrder(const std::string& user_id);
375
376 // Creates a new app shortcut item and controller on the shelf at |index|.
377 // Use kInsertItemAtEnd to add a shortcut as the last item.
378 ash::ShelfID CreateAppShortcutLauncherItemWithType(
379 const std::string& app_id,
380 int index,
381 ash::ShelfItemType shelf_item_type);
382
383 // Invoked when the associated browser or app is closed.
384 void LauncherItemClosed(ash::ShelfID id);
385
386 // Internal helpers for pinning and unpinning that handle both
387 // client-triggered and internal pinning operations.
388 void DoPinAppWithID(const std::string& app_id);
389 void DoUnpinAppWithID(const std::string& app_id);
390
391 // Pin a running app with |shelf_id| internally to |index|. It returns
392 // the index where the item was pinned.
393 int PinRunningAppInternal(int index, ash::ShelfID shelf_id);
394
395 // Unpin a locked application. This is an internal call which converts the
396 // model type of the given app index from a shortcut into an unpinned running
397 // app.
398 void UnpinRunningAppInternal(int index);
399
400 // Re-syncs shelf model with prefs::kPinnedLauncherApps.
401 void UpdateAppLaunchersFromPref();
402
403 // Sets the shelf auto-hide behavior from prefs.
404 void SetShelfAutoHideBehaviorFromPrefs();
405
406 // Sets the shelf alignment from prefs.
407 void SetShelfAlignmentFromPrefs();
408
409 // Sets both of auto-hide behavior and alignment from prefs.
410 void SetShelfBehaviorsFromPrefs();
411
412 // Sets whether the virtual keyboard is enabled from prefs.
413 void SetVirtualKeyboardBehaviorFromPrefs();
414
415 // Returns the shelf item status for the given |app_id|, which can be either
416 // STATUS_ACTIVE (if the app is active), STATUS_RUNNING (if there is such an
417 // app) or STATUS_CLOSED.
418 ash::ShelfItemStatus GetAppState(const std::string& app_id);
419
420 // Creates an app launcher to insert at |index|. Note that |index| may be
421 // adjusted by the model to meet ordering constraints.
422 // The |shelf_item_type| will be set into the ShelfModel.
423 ash::ShelfID InsertAppLauncherItem(LauncherItemController* controller,
424 const std::string& app_id,
425 ash::ShelfItemStatus status,
426 int index,
427 ash::ShelfItemType shelf_item_type);
428
429 // Enumerate all Web contents which match a given shortcut |controller|.
430 std::vector<content::WebContents*> GetV1ApplicationsFromController(
431 LauncherItemController* controller);
432
433 // Create ShelfItem for Browser Shortcut.
434 ash::ShelfID CreateBrowserShortcutLauncherItem();
435
436 // Check if the given |web_contents| is in incognito mode.
437 bool IsIncognito(const content::WebContents* web_contents) const;
438
439 // Update browser shortcut's index.
440 void PersistChromeItemIndex(int index);
441
442 // Depending on the provided flags, move either the chrome icon, the app icon
443 // or none to the given |target_index|. The provided |chrome_index| and
444 // |app_list_index| locations will get adjusted within this call to finalize
445 // the action and to make sure that the other item can still be moved
446 // afterwards (index adjustments).
447 void MoveChromeOrApplistToFinalPosition(
448 bool is_chrome,
449 bool is_app_list,
450 int target_index,
451 int* chrome_index,
452 int* app_list_index);
453
454 // Finds the index of where to insert the next item.
455 int FindInsertionPoint(bool is_app_list);
456
457 // Get the browser shortcut's index in the shelf using the current's systems
458 // configuration of pinned and known (but not running) apps.
459 int GetChromeIconIndexForCreation();
460
461 // Close all windowed V1 applications of a certain extension which was already
462 // deleted.
463 void CloseWindowedAppsFromRemovedExtension(const std::string& app_id,
464 const Profile* profile);
465
466 // Set ShelfItemDelegate |item_delegate| for |id| and take an ownership.
467 // TODO(simon.hong81): Make this take a scoped_ptr of |item_delegate|.
468 void SetShelfItemDelegate(ash::ShelfID id,
469 ash::ShelfItemDelegate* item_delegate);
470
471 // Attach to a specific profile.
472 void AttachProfile(Profile* proifile);
473
474 // Forget the current profile to allow attaching to a new one.
475 void ReleaseProfile();
476
477 AppIconLoader* GetAppIconLoaderForApp(const std::string& app_id);
478
479 static ChromeLauncherController* instance_; 268 static ChromeLauncherController* instance_;
480 269
481 ash::ShelfModel* model_;
482
483 ash::ShelfItemDelegateManager* item_delegate_manager_;
484
485 // Profile used for prefs and loading extensions. This is NOT necessarily the
486 // profile new windows are created with.
487 Profile* profile_;
488
489 // Controller items in this map are owned by |ShelfItemDelegateManager|.
490 IDToItemControllerMap id_to_item_controller_map_;
491
492 // Direct access to app_id for a web contents.
493 WebContentsToAppIDMap web_contents_to_app_id_;
494
495 // Used to track app windows.
496 std::vector<std::unique_ptr<AppWindowLauncherController>>
497 app_window_controllers_;
498
499 // Used to get app info for tabs.
500 std::unique_ptr<LauncherControllerHelper> launcher_controller_helper_;
501
502 // Used to load the images for app items.
503 std::vector<std::unique_ptr<AppIconLoader>> app_icon_loaders_;
504
505 // Used to handle app load/unload events.
506 std::vector<std::unique_ptr<LauncherAppUpdater>> app_updaters_;
507
508 PrefChangeRegistrar pref_change_registrar_;
509
510 AppSyncUIState* app_sync_ui_state_;
511
512 // The owned browser status monitor.
513 std::unique_ptr<BrowserStatusMonitor> browser_status_monitor_;
514
515 // A special observer class to detect user switches.
516 std::unique_ptr<ChromeLauncherControllerUserSwitchObserver>
517 user_switch_observer_;
518
519 std::unique_ptr<ash::ChromeLauncherPrefsObserver> prefs_observer_;
520
521 std::unique_ptr<ArcAppDeferredLauncherController> arc_deferred_launcher_;
522
523 // If true, incoming pinned state changes should be ignored.
524 bool ignore_persist_pinned_state_change_;
525
526 // The list of running & un-pinned applications for different users on hidden
527 // desktops.
528 typedef std::vector<std::string> RunningAppListIds;
529 typedef std::map<std::string, RunningAppListIds> RunningAppListIdMap;
530 RunningAppListIdMap last_used_running_application_order_;
531
532 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController); 270 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController);
533 }; 271 };
534 272
535 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ 273 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698