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

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller.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_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 <string> 9 #include <string>
9 #include <vector> 10 #include <vector>
10 11
11 #include "ash/common/shelf/shelf_item_delegate.h" 12 #include "ash/common/shelf/shelf_item_delegate.h"
12 #include "ash/common/shelf/shelf_item_types.h" 13 #include "ash/common/shelf/shelf_item_types.h"
14 #include "ash/public/interfaces/shelf.mojom.h"
13 #include "base/memory/scoped_vector.h" 15 #include "base/memory/scoped_vector.h"
16 #include "chrome/browser/ui/app_icon_loader.h"
17 #include "chrome/browser/ui/app_icon_loader_delegate.h"
14 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" 18 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" 19 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h"
16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h" 20 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h"
17 #include "chrome/browser/ui/ash/launcher/settings_window_observer.h" 21 #include "chrome/browser/ui/ash/launcher/settings_window_observer.h"
18 #include "extensions/common/constants.h" 22 #include "extensions/common/constants.h"
23 #include "mojo/public/cpp/bindings/associated_binding.h"
19 24
20 class AccountId; 25 class AccountId;
21 class ArcAppDeferredLauncherController; 26 class ArcAppDeferredLauncherController;
22 class Browser; 27 class Browser;
23 class BrowserShortcutLauncherItemController; 28 class BrowserShortcutLauncherItemController;
24 class GURL; 29 class GURL;
30 class LauncherControllerHelper;
25 class LauncherItemController; 31 class LauncherItemController;
26 32
27 namespace ash { 33 namespace ash {
28 class WmShelf; 34 class WmShelf;
29 } 35 }
30 36
31 namespace content { 37 namespace content {
32 class WebContents; 38 class WebContents;
33 } 39 }
34 40
35 namespace gfx { 41 namespace gfx {
36 class Image; 42 class Image;
37 } 43 }
38 44
39 namespace ui { 45 namespace ui {
40 class BaseWindow; 46 class BaseWindow;
41 } 47 }
42 48
43 // A list of the elements which makes up a simple menu description. 49 // A list of the elements which makes up a simple menu description.
44 typedef ScopedVector<ChromeLauncherAppMenuItem> ChromeLauncherAppMenuItems; 50 typedef ScopedVector<ChromeLauncherAppMenuItem> ChromeLauncherAppMenuItems;
45 51
46 // ChromeLauncherController manages the launcher items needed for content 52 // ChromeLauncherController manages the launcher items needed for content
47 // windows. Launcher items have a type, an optional app id, and a controller. 53 // windows. Launcher items have a type, an optional app id, and a controller.
48 // There are different kinds of launcher item controllers, all extending the 54 // Implements mojom::ShelfObserver and is a client of mojom::ShelfController.
49 // LauncherItemController class. 55 class ChromeLauncherController : public ash::mojom::ShelfObserver,
50 class ChromeLauncherController { 56 private AppIconLoaderDelegate {
sky 2016/10/07 16:10:18 private->public
msw 2016/10/07 22:45:58 Done.
51 public: 57 public:
52 // Used to update the state of non plaform apps, as web contents change. 58 // Used to update the state of non plaform apps, as web contents change.
53 enum AppState { 59 enum AppState {
54 APP_STATE_ACTIVE, 60 APP_STATE_ACTIVE,
55 APP_STATE_WINDOW_ACTIVE, 61 APP_STATE_WINDOW_ACTIVE,
56 APP_STATE_INACTIVE, 62 APP_STATE_INACTIVE,
57 APP_STATE_REMOVED 63 APP_STATE_REMOVED
58 }; 64 };
59 65
60 // Set the ChromeLauncherController singleton. 66 // Set the ChromeLauncherController singleton.
61 static void set_instance(ChromeLauncherController* instance) { 67 static void set_instance(ChromeLauncherController* instance) {
sky 2016/10/07 16:10:18 optional/future: nuke this and set in constructor?
msw 2016/10/07 22:45:58 Done. Also removed the CreateInstance static metho
62 instance_ = instance; 68 instance_ = instance;
63 } 69 }
64 70
65 // Returns the single ChromeLauncherController instance. 71 // Returns the single ChromeLauncherController instance.
66 static ChromeLauncherController* instance() { return instance_; } 72 static ChromeLauncherController* instance() { return instance_; }
67 73
68 virtual ~ChromeLauncherController(); 74 Profile* profile() const { return profile_; }
75
76 LauncherControllerHelper* launcher_controller_helper() {
77 return launcher_controller_helper_.get();
78 }
79
80 ~ChromeLauncherController() override;
69 81
70 // Initializes this ChromeLauncherController. 82 // Initializes this ChromeLauncherController.
71 virtual void Init() = 0; 83 virtual void Init() = 0;
72 84
73 // Creates a new app item on the shelf for |controller|. 85 // Creates a new app item on the shelf for |controller|.
74 virtual ash::ShelfID CreateAppLauncherItem(LauncherItemController* controller, 86 virtual ash::ShelfID CreateAppLauncherItem(LauncherItemController* controller,
75 const std::string& app_id, 87 const std::string& app_id,
76 ash::ShelfItemStatus status) = 0; 88 ash::ShelfItemStatus status) = 0;
77 89
78 // Updates the running status of an item. It will also update the status of 90 // Updates the running status of an item. It will also update the status of
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 virtual void Close(ash::ShelfID id) = 0; 134 virtual void Close(ash::ShelfID id) = 0;
123 135
124 // Returns true if the specified item is open. 136 // Returns true if the specified item is open.
125 virtual bool IsOpen(ash::ShelfID id) = 0; 137 virtual bool IsOpen(ash::ShelfID id) = 0;
126 138
127 // Returns true if the specified item is for a platform app. 139 // Returns true if the specified item is for a platform app.
128 virtual bool IsPlatformApp(ash::ShelfID id) = 0; 140 virtual bool IsPlatformApp(ash::ShelfID id) = 0;
129 141
130 // Opens a new instance of the application identified by |app_id|. 142 // Opens a new instance of the application identified by |app_id|.
131 // Used by the app-list, and by pinned-app shelf items. 143 // Used by the app-list, and by pinned-app shelf items.
132 virtual void LaunchApp(const std::string& app_id, 144 void LaunchApp(const std::string& app_id,
133 ash::LaunchSource source, 145 ash::LaunchSource source,
134 int event_flags) = 0; 146 int event_flags);
135 147
136 // If |app_id| is running, reactivates the app's most recently active window, 148 // If |app_id| is running, reactivates the app's most recently active window,
137 // otherwise launches and activates the app. 149 // otherwise launches and activates the app.
138 // Used by the app-list, and by pinned-app shelf items. 150 // Used by the app-list, and by pinned-app shelf items.
139 virtual void ActivateApp(const std::string& app_id, 151 virtual void ActivateApp(const std::string& app_id,
140 ash::LaunchSource source, 152 ash::LaunchSource source,
141 int event_flags) = 0; 153 int event_flags) = 0;
142 154
143 // Returns the launch type of app for the specified id. 155 // Returns the launch type of app for the specified id.
144 virtual extensions::LaunchType GetLaunchType(ash::ShelfID id) = 0; 156 virtual extensions::LaunchType GetLaunchType(ash::ShelfID id) = 0;
145 157
146 // Set the image for a specific shelf item (e.g. when set by the app). 158 // Set the image for a specific shelf item (e.g. when set by the app).
147 virtual void SetLauncherItemImage(ash::ShelfID shelf_id, 159 virtual void SetLauncherItemImage(ash::ShelfID shelf_id,
148 const gfx::ImageSkia& image) = 0; 160 const gfx::ImageSkia& image) = 0;
149 161
150 // Find out if the given application |id| is a windowed app item and not a 162 // Find out if the given application |id| is a windowed app item and not a
151 // pinned item in the shelf. 163 // pinned item in the shelf.
152 virtual bool IsWindowedAppInLauncher(const std::string& app_id) = 0; 164 virtual bool IsWindowedAppInLauncher(const std::string& app_id) = 0;
153 165
154 // Updates the launch type of the app for the specified id to |launch_type|. 166 // Updates the launch type of the app for the specified id to |launch_type|.
155 virtual void SetLaunchType(ash::ShelfID id, 167 virtual void SetLaunchType(ash::ShelfID id,
156 extensions::LaunchType launch_type) = 0; 168 extensions::LaunchType launch_type) = 0;
157 169
158 // Accessor to the currently loaded profile. Note that in multi profile use
159 // cases this might change over time.
160 virtual Profile* GetProfile() = 0;
161
162 // Notify the controller that the state of an non platform app's tabs 170 // Notify the controller that the state of an non platform app's tabs
163 // have changed, 171 // have changed,
164 virtual void UpdateAppState(content::WebContents* contents, 172 virtual void UpdateAppState(content::WebContents* contents,
165 AppState app_state) = 0; 173 AppState app_state) = 0;
166 174
167 // Returns ShelfID for |contents|. If |contents| is not an app or is not 175 // Returns ShelfID for |contents|. If |contents| is not an app or is not
168 // pinned, returns the id of browser shrotcut. 176 // pinned, returns the id of browser shrotcut.
169 virtual ash::ShelfID GetShelfIDForWebContents( 177 virtual ash::ShelfID GetShelfIDForWebContents(
170 content::WebContents* contents) = 0; 178 content::WebContents* contents) = 0;
171 179
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 virtual bool ShelfBoundsChangesProbablyWithUser( 245 virtual bool ShelfBoundsChangesProbablyWithUser(
238 ash::WmShelf* shelf, 246 ash::WmShelf* shelf,
239 const AccountId& account_id) const = 0; 247 const AccountId& account_id) const = 0;
240 248
241 // Called when the user profile is fully loaded and ready to switch to. 249 // Called when the user profile is fully loaded and ready to switch to.
242 virtual void OnUserProfileReadyToSwitch(Profile* profile) = 0; 250 virtual void OnUserProfileReadyToSwitch(Profile* profile) = 0;
243 251
244 // Controller to launch Arc apps in deferred mode. 252 // Controller to launch Arc apps in deferred mode.
245 virtual ArcAppDeferredLauncherController* GetArcDeferredLauncher() = 0; 253 virtual ArcAppDeferredLauncherController* GetArcDeferredLauncher() = 0;
246 254
255 AppIconLoader* GetAppIconLoaderForApp(const std::string& app_id);
256
257 // Sets the shelf auto-hide and/or alignment behavior from prefs.
258 void SetShelfAutoHideBehaviorFromPrefs();
259 void SetShelfAlignmentFromPrefs();
260 void SetShelfBehaviorsFromPrefs();
261
262 // Sets LauncherControllerHelper or AppIconLoader for test, taking ownership.
263 void SetLauncherControllerHelperForTest(
264 std::unique_ptr<LauncherControllerHelper> helper);
265 void SetAppIconLoadersForTest(
266 std::vector<std::unique_ptr<AppIconLoader>>& loaders);
267
268 void SetProfileForTest(Profile* profile);
269
247 protected: 270 protected:
248 ChromeLauncherController(); 271 ChromeLauncherController();
249 272
273 // Connects or reconnects to the mojom::ShelfController interface in ash.
274 // Returns true if connected and returns false in unit tests.
275 bool ConnectToShelfController();
276
277 // Accessor for subclasses to interact with the shelf controller.
278 ash::mojom::ShelfControllerPtr& shelf_controller() {
279 return shelf_controller_;
280 }
281
282 // Attach to a specific profile.
283 virtual void AttachProfile(Profile* profile);
284
285 // ash::mojom::ShelfObserver:
286 void OnShelfCreated(int64_t display_id) override;
287 void OnAlignmentChanged(ash::ShelfAlignment alignment,
288 int64_t display_id) override;
289 void OnAutoHideBehaviorChanged(ash::ShelfAutoHideBehavior auto_hide,
290 int64_t display_id) override;
291
250 private: 292 private:
293 // AppIconLoaderDelegate:
294 void OnAppImageUpdated(const std::string& app_id,
295 const gfx::ImageSkia& image) override;
296
251 static ChromeLauncherController* instance_; 297 static ChromeLauncherController* instance_;
252 298
299 // The currently loaded profile used for prefs and loading extensions. This is
300 // NOT necessarily the profile new windows are created with. Note that in
301 // multi-profile use cases this might change over time.
302 Profile* profile_;
303
304 // Ash's mojom::ShelfController used to change shelf state.
305 ash::mojom::ShelfControllerPtr shelf_controller_;
306
307 // The binding this instance uses to implment mojom::ShelfObserver
308 mojo::AssociatedBinding<ash::mojom::ShelfObserver> observer_binding_;
309
310 // Used to get app info for tabs.
311 std::unique_ptr<LauncherControllerHelper> launcher_controller_helper_;
312
313 // An observer that manages the shelf title and icon for settings windows.
253 SettingsWindowObserver settings_window_observer_; 314 SettingsWindowObserver settings_window_observer_;
254 315
316 // Used to load the images for app items.
317 std::vector<std::unique_ptr<AppIconLoader>> app_icon_loaders_;
318
255 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController); 319 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController);
256 }; 320 };
257 321
258 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ 322 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698