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

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

Issue 2391253004: Use mojo Shelf interfaces for both mash and classic ash. (Closed)
Patch Set: Sync and rebase. Created 4 years, 2 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_IMPL_H_ 5 #ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_IMPL_H_
6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_IMPL_H_ 6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_IMPL_H_
7 7
8 #include <list> 8 #include <list>
9 #include <memory> 9 #include <memory>
10 10
11 #include "ash/common/shelf/shelf_delegate.h" 11 #include "ash/common/shelf/shelf_delegate.h"
12 #include "ash/common/shelf/shelf_model_observer.h" 12 #include "ash/common/shelf/shelf_model_observer.h"
13 #include "ash/display/window_tree_host_manager.h" 13 #include "ash/display/window_tree_host_manager.h"
14 #include "ash/public/cpp/shelf_types.h" 14 #include "ash/public/cpp/shelf_types.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "build/build_config.h" 18 #include "build/build_config.h"
19 #include "chrome/browser/ui/app_icon_loader.h"
20 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" 19 #include "chrome/browser/ui/app_list/app_list_syncable_service.h"
21 #include "chrome/browser/ui/ash/app_sync_ui_state_observer.h" 20 #include "chrome/browser/ui/ash/app_sync_ui_state_observer.h"
22 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 21 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
23 #include "chrome/browser/ui/ash/launcher/launcher_app_updater.h" 22 #include "chrome/browser/ui/ash/launcher/launcher_app_updater.h"
24 #include "components/prefs/pref_change_registrar.h" 23 #include "components/prefs/pref_change_registrar.h"
25 #include "ui/aura/window_observer.h" 24 #include "ui/aura/window_observer.h"
26 25
27 class AppSyncUIState; 26 class AppSyncUIState;
28 class BrowserStatusMonitor; 27 class BrowserStatusMonitor;
29 class LauncherControllerHelper;
30 class Profile; 28 class Profile;
31 class AppWindowLauncherController; 29 class AppWindowLauncherController;
32 class TabContents; 30 class TabContents;
33 31
34 namespace ash { 32 namespace ash {
35 class ShelfModel; 33 class ShelfModel;
36 namespace launcher { 34 namespace launcher {
37 class ChromeLauncherPrefsObserver; 35 class ChromeLauncherPrefsObserver;
38 } 36 }
39 } 37 }
(...skipping 15 matching lines...) Expand all
55 // Implementation of ChromeLauncherController, used for classic Ash. 53 // Implementation of ChromeLauncherController, used for classic Ash.
56 // In addition to implementing ChromeLauncherController, this class performs 54 // In addition to implementing ChromeLauncherController, this class performs
57 // a lot of other responsibilities, such as implementing ash::ShelfDelegate, 55 // a lot of other responsibilities, such as implementing ash::ShelfDelegate,
58 // updating the UI state and the shelf model when apps are uninstalled, etc. 56 // updating the UI state and the shelf model when apps are uninstalled, etc.
59 class ChromeLauncherControllerImpl 57 class ChromeLauncherControllerImpl
60 : public ChromeLauncherController, 58 : public ChromeLauncherController,
61 public ash::ShelfDelegate, 59 public ash::ShelfDelegate,
62 public LauncherAppUpdater::Delegate, 60 public LauncherAppUpdater::Delegate,
63 private ash::ShelfModelObserver, 61 private ash::ShelfModelObserver,
64 private ash::WindowTreeHostManager::Observer, 62 private ash::WindowTreeHostManager::Observer,
65 private AppIconLoaderDelegate,
66 private AppSyncUIStateObserver, 63 private AppSyncUIStateObserver,
67 private app_list::AppListSyncableService::Observer { 64 private app_list::AppListSyncableService::Observer {
68 public: 65 public:
69 ChromeLauncherControllerImpl(Profile* profile, ash::ShelfModel* model); 66 ChromeLauncherControllerImpl(Profile* profile, ash::ShelfModel* model);
70 ~ChromeLauncherControllerImpl() override; 67 ~ChromeLauncherControllerImpl() override;
71 68
72 // Create ChromeLauncherControllerImpl instance and set is as the 69 // Create ChromeLauncherControllerImpl instance and set is as the
73 // ChromeLauncherController singleton. 70 // ChromeLauncherController singleton.
74 static ChromeLauncherControllerImpl* CreateInstance(Profile* profile, 71 static ChromeLauncherControllerImpl* CreateInstance(Profile* profile,
75 ash::ShelfModel* model); 72 ash::ShelfModel* model);
(...skipping 11 matching lines...) Expand all
87 void Unpin(ash::ShelfID id) override; 84 void Unpin(ash::ShelfID id) override;
88 bool IsPinned(ash::ShelfID id) override; 85 bool IsPinned(ash::ShelfID id) override;
89 void TogglePinned(ash::ShelfID id) override; 86 void TogglePinned(ash::ShelfID id) override;
90 bool IsPinnable(ash::ShelfID id) const override; 87 bool IsPinnable(ash::ShelfID id) const override;
91 void LockV1AppWithID(const std::string& app_id) override; 88 void LockV1AppWithID(const std::string& app_id) override;
92 void UnlockV1AppWithID(const std::string& app_id) override; 89 void UnlockV1AppWithID(const std::string& app_id) override;
93 void Launch(ash::ShelfID id, int event_flags) override; 90 void Launch(ash::ShelfID id, int event_flags) override;
94 void Close(ash::ShelfID id) override; 91 void Close(ash::ShelfID id) override;
95 bool IsOpen(ash::ShelfID id) override; 92 bool IsOpen(ash::ShelfID id) override;
96 bool IsPlatformApp(ash::ShelfID id) override; 93 bool IsPlatformApp(ash::ShelfID id) override;
97 void LaunchApp(const std::string& app_id,
98 ash::LaunchSource source,
99 int event_flags) override;
100 void ActivateApp(const std::string& app_id, 94 void ActivateApp(const std::string& app_id,
101 ash::LaunchSource source, 95 ash::LaunchSource source,
102 int event_flags) override; 96 int event_flags) override;
103 extensions::LaunchType GetLaunchType(ash::ShelfID id) override; 97 extensions::LaunchType GetLaunchType(ash::ShelfID id) override;
104 void SetLauncherItemImage(ash::ShelfID shelf_id, 98 void SetLauncherItemImage(ash::ShelfID shelf_id,
105 const gfx::ImageSkia& image) override; 99 const gfx::ImageSkia& image) override;
106 bool IsWindowedAppInLauncher(const std::string& app_id) override; 100 bool IsWindowedAppInLauncher(const std::string& app_id) override;
107 void SetLaunchType(ash::ShelfID id, 101 void SetLaunchType(ash::ShelfID id,
108 extensions::LaunchType launch_type) override; 102 extensions::LaunchType launch_type) override;
109 Profile* GetProfile() override;
110 void UpdateAppState(content::WebContents* contents, 103 void UpdateAppState(content::WebContents* contents,
111 AppState app_state) override; 104 AppState app_state) override;
112 ash::ShelfID GetShelfIDForWebContents( 105 ash::ShelfID GetShelfIDForWebContents(
113 content::WebContents* contents) override; 106 content::WebContents* contents) override;
114 void SetRefocusURLPatternForTest(ash::ShelfID id, const GURL& url) override; 107 void SetRefocusURLPatternForTest(ash::ShelfID id, const GURL& url) override;
115 ash::ShelfItemDelegate::PerformedAction ActivateWindowOrMinimizeIfActive( 108 ash::ShelfItemDelegate::PerformedAction ActivateWindowOrMinimizeIfActive(
116 ui::BaseWindow* window, 109 ui::BaseWindow* window,
117 bool allow_minimize) override; 110 bool allow_minimize) override;
118 void ActiveUserChanged(const std::string& user_email) override; 111 void ActiveUserChanged(const std::string& user_email) override;
119 void AdditionalUserAddedToSession(Profile* profile) override; 112 void AdditionalUserAddedToSession(Profile* profile) override;
(...skipping 11 matching lines...) Expand all
131 content::WebContents* web_contents) const override; 124 content::WebContents* web_contents) const override;
132 BrowserShortcutLauncherItemController* 125 BrowserShortcutLauncherItemController*
133 GetBrowserShortcutLauncherItemController() override; 126 GetBrowserShortcutLauncherItemController() override;
134 LauncherItemController* GetLauncherItemController( 127 LauncherItemController* GetLauncherItemController(
135 const ash::ShelfID id) override; 128 const ash::ShelfID id) override;
136 bool ShelfBoundsChangesProbablyWithUser( 129 bool ShelfBoundsChangesProbablyWithUser(
137 ash::WmShelf* shelf, 130 ash::WmShelf* shelf,
138 const AccountId& account_id) const override; 131 const AccountId& account_id) const override;
139 void OnUserProfileReadyToSwitch(Profile* profile) override; 132 void OnUserProfileReadyToSwitch(Profile* profile) override;
140 ArcAppDeferredLauncherController* GetArcDeferredLauncher() override; 133 ArcAppDeferredLauncherController* GetArcDeferredLauncher() override;
141 134 void AttachProfile(Profile* profile) override;
142 void SetProfileForTest(Profile* profile);
143 135
144 // Access to the BrowserStatusMonitor for tests. 136 // Access to the BrowserStatusMonitor for tests.
145 BrowserStatusMonitor* browser_status_monitor_for_test() { 137 BrowserStatusMonitor* browser_status_monitor_for_test() {
146 return browser_status_monitor_.get(); 138 return browser_status_monitor_.get();
147 } 139 }
148 140
149 // Access to the AppWindowLauncherController list for tests. 141 // Access to the AppWindowLauncherController list for tests.
150 const std::vector<std::unique_ptr<AppWindowLauncherController>>& 142 const std::vector<std::unique_ptr<AppWindowLauncherController>>&
151 app_window_controllers_for_test() { 143 app_window_controllers_for_test() {
152 return app_window_controllers_; 144 return app_window_controllers_;
153 } 145 }
154 146
155 // ash::ShelfDelegate: 147 // ash::ShelfDelegate:
156 void OnShelfCreated(ash::WmShelf* shelf) override;
157 void OnShelfDestroyed(ash::WmShelf* shelf) override;
158 void OnShelfAlignmentChanged(ash::WmShelf* shelf) override;
159 void OnShelfAutoHideBehaviorChanged(ash::WmShelf* shelf) override;
160 void OnShelfAutoHideStateChanged(ash::WmShelf* shelf) override;
161 void OnShelfVisibilityStateChanged(ash::WmShelf* shelf) override;
162 ash::ShelfID GetShelfIDForAppID(const std::string& app_id) override; 148 ash::ShelfID GetShelfIDForAppID(const std::string& app_id) override;
163 ash::ShelfID GetShelfIDForAppIDAndLaunchID( 149 ash::ShelfID GetShelfIDForAppIDAndLaunchID(
164 const std::string& app_id, 150 const std::string& app_id,
165 const std::string& launch_id) override; 151 const std::string& launch_id) override;
166 bool HasShelfIDToAppIDMapping(ash::ShelfID id) const override; 152 bool HasShelfIDToAppIDMapping(ash::ShelfID id) const override;
167 const std::string& GetAppIDForShelfID(ash::ShelfID id) override; 153 const std::string& GetAppIDForShelfID(ash::ShelfID id) override;
168 void PinAppWithID(const std::string& app_id) override; 154 void PinAppWithID(const std::string& app_id) override;
169 bool IsAppPinned(const std::string& app_id) override; 155 bool IsAppPinned(const std::string& app_id) override;
170 void UnpinAppWithID(const std::string& app_id) override; 156 void UnpinAppWithID(const std::string& app_id) override;
171 157
172 // LauncherAppUpdater::Delegate: 158 // LauncherAppUpdater::Delegate:
173 void OnAppInstalled(content::BrowserContext* browser_context, 159 void OnAppInstalled(content::BrowserContext* browser_context,
174 const std::string& app_id) override; 160 const std::string& app_id) override;
175 void OnAppUpdated(content::BrowserContext* browser_context, 161 void OnAppUpdated(content::BrowserContext* browser_context,
176 const std::string& app_id) override; 162 const std::string& app_id) override;
177 void OnAppUninstalledPrepared(content::BrowserContext* browser_context, 163 void OnAppUninstalledPrepared(content::BrowserContext* browser_context,
178 const std::string& app_id) override; 164 const std::string& app_id) override;
179 165
180 protected: 166 protected:
181 // Creates a new app shortcut item and controller on the shelf at |index|. 167 // Creates a new app shortcut item and controller on the shelf at |index|.
182 // Use kInsertItemAtEnd to add a shortcut as the last item. 168 // Use kInsertItemAtEnd to add a shortcut as the last item.
183 ash::ShelfID CreateAppShortcutLauncherItem(const std::string& app_id, 169 ash::ShelfID CreateAppShortcutLauncherItem(const std::string& app_id,
184 int index); 170 int index);
185 171
186 // Sets LauncherControllerHelper/AppIconLoader for test, taking ownership.
187 void SetLauncherControllerHelperForTest(LauncherControllerHelper* helper);
188 void SetAppIconLoadersForTest(
189 std::vector<std::unique_ptr<AppIconLoader>>& loaders);
190 const std::string& GetAppIdFromShelfIdForTest(ash::ShelfID id); 172 const std::string& GetAppIdFromShelfIdForTest(ash::ShelfID id);
191 173
192 private: 174 private:
193 friend class ChromeLauncherControllerImplTest; 175 friend class ChromeLauncherControllerImplTest;
194 friend class ShelfAppBrowserTest; 176 friend class ShelfAppBrowserTest;
195 friend class LauncherPlatformAppBrowserTest; 177 friend class LauncherPlatformAppBrowserTest;
196 FRIEND_TEST_ALL_PREFIXES(ChromeLauncherControllerImplTest, AppPanels); 178 FRIEND_TEST_ALL_PREFIXES(ChromeLauncherControllerImplTest, AppPanels);
197 179
198 typedef std::map<ash::ShelfID, LauncherItemController*> IDToItemControllerMap; 180 typedef std::map<ash::ShelfID, LauncherItemController*> IDToItemControllerMap;
199 typedef std::map<content::WebContents*, std::string> WebContentsToAppIDMap; 181 typedef std::map<content::WebContents*, std::string> WebContentsToAppIDMap;
(...skipping 29 matching lines...) Expand all
229 211
230 // Updates pin position for the item specified by |id| in sync model. 212 // Updates pin position for the item specified by |id| in sync model.
231 void SyncPinPosition(ash::ShelfID id); 213 void SyncPinPosition(ash::ShelfID id);
232 214
233 // Re-syncs shelf model. 215 // Re-syncs shelf model.
234 void UpdateAppLaunchersFromPref(); 216 void UpdateAppLaunchersFromPref();
235 217
236 // Schedules re-sync of shelf model. 218 // Schedules re-sync of shelf model.
237 void ScheduleUpdateAppLaunchersFromPref(); 219 void ScheduleUpdateAppLaunchersFromPref();
238 220
239 // Sets the shelf auto-hide behavior from prefs.
240 void SetShelfAutoHideBehaviorFromPrefs();
241
242 // Sets the shelf alignment from prefs.
243 void SetShelfAlignmentFromPrefs();
244
245 // Sets both of auto-hide behavior and alignment from prefs.
246 void SetShelfBehaviorsFromPrefs();
247
248 // Sets whether the virtual keyboard is enabled from prefs. 221 // Sets whether the virtual keyboard is enabled from prefs.
249 void SetVirtualKeyboardBehaviorFromPrefs(); 222 void SetVirtualKeyboardBehaviorFromPrefs();
250 223
251 // Returns the shelf item status for the given |app_id|, which can be either 224 // Returns the shelf item status for the given |app_id|, which can be either
252 // STATUS_ACTIVE (if the app is active), STATUS_RUNNING (if there is such an 225 // STATUS_ACTIVE (if the app is active), STATUS_RUNNING (if there is such an
253 // app) or STATUS_CLOSED. 226 // app) or STATUS_CLOSED.
254 ash::ShelfItemStatus GetAppState(const std::string& app_id); 227 ash::ShelfItemStatus GetAppState(const std::string& app_id);
255 228
256 // Creates an app launcher to insert at |index|. Note that |index| may be 229 // Creates an app launcher to insert at |index|. Note that |index| may be
257 // adjusted by the model to meet ordering constraints. 230 // adjusted by the model to meet ordering constraints.
(...skipping 20 matching lines...) Expand all
278 // Close all windowed V1 applications of a certain extension which was already 251 // Close all windowed V1 applications of a certain extension which was already
279 // deleted. 252 // deleted.
280 void CloseWindowedAppsFromRemovedExtension(const std::string& app_id, 253 void CloseWindowedAppsFromRemovedExtension(const std::string& app_id,
281 const Profile* profile); 254 const Profile* profile);
282 255
283 // Set ShelfItemDelegate |item_delegate| for |id| and take an ownership. 256 // Set ShelfItemDelegate |item_delegate| for |id| and take an ownership.
284 // TODO(simon.hong81): Make this take a scoped_ptr of |item_delegate|. 257 // TODO(simon.hong81): Make this take a scoped_ptr of |item_delegate|.
285 void SetShelfItemDelegate(ash::ShelfID id, 258 void SetShelfItemDelegate(ash::ShelfID id,
286 ash::ShelfItemDelegate* item_delegate); 259 ash::ShelfItemDelegate* item_delegate);
287 260
288 // Attach to a specific profile.
289 void AttachProfile(Profile* profile);
290
291 // Forget the current profile to allow attaching to a new one. 261 // Forget the current profile to allow attaching to a new one.
292 void ReleaseProfile(); 262 void ReleaseProfile();
293 263
294 AppIconLoader* GetAppIconLoaderForApp(const std::string& app_id);
295
296 // ash::ShelfModelObserver: 264 // ash::ShelfModelObserver:
297 void ShelfItemAdded(int index) override; 265 void ShelfItemAdded(int index) override;
298 void ShelfItemRemoved(int index, ash::ShelfID id) override; 266 void ShelfItemRemoved(int index, ash::ShelfID id) override;
299 void ShelfItemMoved(int start_index, int target_index) override; 267 void ShelfItemMoved(int start_index, int target_index) override;
300 void ShelfItemChanged(int index, const ash::ShelfItem& old_item) override; 268 void ShelfItemChanged(int index, const ash::ShelfItem& old_item) override;
301 void OnSetShelfItemDelegate(ash::ShelfID id, 269 void OnSetShelfItemDelegate(ash::ShelfID id,
302 ash::ShelfItemDelegate* item_delegate) override; 270 ash::ShelfItemDelegate* item_delegate) override;
303 271
304 // ash::WindowTreeHostManager::Observer: 272 // ash::WindowTreeHostManager::Observer:
305 void OnDisplayConfigurationChanged() override; 273 void OnDisplayConfigurationChanged() override;
306 274
307 // AppSyncUIStateObserver: 275 // AppSyncUIStateObserver:
308 void OnAppSyncUIStatusChanged() override; 276 void OnAppSyncUIStatusChanged() override;
309 277
310 // AppIconLoaderDelegate: 278 // AppIconLoaderDelegate:
311 void OnAppImageUpdated(const std::string& app_id, 279 void OnAppImageUpdated(const std::string& app_id,
312 const gfx::ImageSkia& image) override; 280 const gfx::ImageSkia& image) override;
313 281
314 // app_list::AppListSyncableService::Observer: 282 // app_list::AppListSyncableService::Observer:
315 void OnSyncModelUpdated() override; 283 void OnSyncModelUpdated() override;
316 284
317 // Unpins shelf item and optionally updates pin prefs when |update_prefs| is 285 // Unpins shelf item and optionally updates pin prefs when |update_prefs| is
318 // set to true. 286 // set to true.
319 void UnpinAndUpdatePrefs(ash::ShelfID id, bool update_prefs); 287 void UnpinAndUpdatePrefs(ash::ShelfID id, bool update_prefs);
320 288
321 ash::ShelfModel* model_; 289 ash::ShelfModel* model_;
322 290
323 // Profile used for prefs and loading extensions. This is NOT necessarily the
324 // profile new windows are created with.
325 Profile* profile_;
326
327 // Controller items in this map are owned by |ShelfModel|. 291 // Controller items in this map are owned by |ShelfModel|.
328 IDToItemControllerMap id_to_item_controller_map_; 292 IDToItemControllerMap id_to_item_controller_map_;
329 293
330 // Direct access to app_id for a web contents. 294 // Direct access to app_id for a web contents.
331 WebContentsToAppIDMap web_contents_to_app_id_; 295 WebContentsToAppIDMap web_contents_to_app_id_;
332 296
333 // Used to track app windows. 297 // Used to track app windows.
334 std::vector<std::unique_ptr<AppWindowLauncherController>> 298 std::vector<std::unique_ptr<AppWindowLauncherController>>
335 app_window_controllers_; 299 app_window_controllers_;
336 300
337 // Used to get app info for tabs.
338 std::unique_ptr<LauncherControllerHelper> launcher_controller_helper_;
339
340 // Used to load the images for app items.
341 std::vector<std::unique_ptr<AppIconLoader>> app_icon_loaders_;
342
343 // Used to handle app load/unload events. 301 // Used to handle app load/unload events.
344 std::vector<std::unique_ptr<LauncherAppUpdater>> app_updaters_; 302 std::vector<std::unique_ptr<LauncherAppUpdater>> app_updaters_;
345 303
346 PrefChangeRegistrar pref_change_registrar_; 304 PrefChangeRegistrar pref_change_registrar_;
347 305
348 AppSyncUIState* app_sync_ui_state_ = nullptr; 306 AppSyncUIState* app_sync_ui_state_ = nullptr;
349 307
350 // The owned browser status monitor. 308 // The owned browser status monitor.
351 std::unique_ptr<BrowserStatusMonitor> browser_status_monitor_; 309 std::unique_ptr<BrowserStatusMonitor> browser_status_monitor_;
352 310
(...skipping 13 matching lines...) Expand all
366 typedef std::vector<std::string> RunningAppListIds; 324 typedef std::vector<std::string> RunningAppListIds;
367 typedef std::map<std::string, RunningAppListIds> RunningAppListIdMap; 325 typedef std::map<std::string, RunningAppListIds> RunningAppListIdMap;
368 RunningAppListIdMap last_used_running_application_order_; 326 RunningAppListIdMap last_used_running_application_order_;
369 327
370 base::WeakPtrFactory<ChromeLauncherControllerImpl> weak_ptr_factory_; 328 base::WeakPtrFactory<ChromeLauncherControllerImpl> weak_ptr_factory_;
371 329
372 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerImpl); 330 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerImpl);
373 }; 331 };
374 332
375 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_IMPL_H_ 333 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698