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

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

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

Powered by Google App Engine
This is Rietveld 408576698