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

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: Address comments. 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 public AppIconLoaderDelegate {
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 // Returns the single ChromeLauncherController instance.
61 static void set_instance(ChromeLauncherController* instance) { 67 static ChromeLauncherController* instance() { return instance_; }
68 // TODO(crbug.com/654622): Remove this when tests are fixed.
69 static void set_instance_for_test(ChromeLauncherController* instance) {
62 instance_ = instance; 70 instance_ = instance;
63 } 71 }
64 72
65 // Returns the single ChromeLauncherController instance. 73 Profile* profile() const { return profile_; }
66 static ChromeLauncherController* instance() { return instance_; }
67 74
68 virtual ~ChromeLauncherController(); 75 LauncherControllerHelper* launcher_controller_helper() {
76 return launcher_controller_helper_.get();
77 }
78
79 ~ChromeLauncherController() override;
69 80
70 // Initializes this ChromeLauncherController. 81 // Initializes this ChromeLauncherController.
71 virtual void Init() = 0; 82 virtual void Init() = 0;
72 83
73 // Creates a new app item on the shelf for |controller|. 84 // Creates a new app item on the shelf for |controller|.
74 virtual ash::ShelfID CreateAppLauncherItem(LauncherItemController* controller, 85 virtual ash::ShelfID CreateAppLauncherItem(LauncherItemController* controller,
75 const std::string& app_id, 86 const std::string& app_id,
76 ash::ShelfItemStatus status) = 0; 87 ash::ShelfItemStatus status) = 0;
77 88
78 // Updates the running status of an item. It will also update the status of 89 // 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; 133 virtual void Close(ash::ShelfID id) = 0;
123 134
124 // Returns true if the specified item is open. 135 // Returns true if the specified item is open.
125 virtual bool IsOpen(ash::ShelfID id) = 0; 136 virtual bool IsOpen(ash::ShelfID id) = 0;
126 137
127 // Returns true if the specified item is for a platform app. 138 // Returns true if the specified item is for a platform app.
128 virtual bool IsPlatformApp(ash::ShelfID id) = 0; 139 virtual bool IsPlatformApp(ash::ShelfID id) = 0;
129 140
130 // Opens a new instance of the application identified by |app_id|. 141 // Opens a new instance of the application identified by |app_id|.
131 // Used by the app-list, and by pinned-app shelf items. 142 // Used by the app-list, and by pinned-app shelf items.
132 virtual void LaunchApp(const std::string& app_id, 143 void LaunchApp(const std::string& app_id,
133 ash::LaunchSource source, 144 ash::LaunchSource source,
134 int event_flags) = 0; 145 int event_flags);
135 146
136 // If |app_id| is running, reactivates the app's most recently active window, 147 // If |app_id| is running, reactivates the app's most recently active window,
137 // otherwise launches and activates the app. 148 // otherwise launches and activates the app.
138 // Used by the app-list, and by pinned-app shelf items. 149 // Used by the app-list, and by pinned-app shelf items.
139 virtual void ActivateApp(const std::string& app_id, 150 virtual void ActivateApp(const std::string& app_id,
140 ash::LaunchSource source, 151 ash::LaunchSource source,
141 int event_flags) = 0; 152 int event_flags) = 0;
142 153
143 // Returns the launch type of app for the specified id. 154 // Returns the launch type of app for the specified id.
144 virtual extensions::LaunchType GetLaunchType(ash::ShelfID id) = 0; 155 virtual extensions::LaunchType GetLaunchType(ash::ShelfID id) = 0;
145 156
146 // Set the image for a specific shelf item (e.g. when set by the app). 157 // Set the image for a specific shelf item (e.g. when set by the app).
147 virtual void SetLauncherItemImage(ash::ShelfID shelf_id, 158 virtual void SetLauncherItemImage(ash::ShelfID shelf_id,
148 const gfx::ImageSkia& image) = 0; 159 const gfx::ImageSkia& image) = 0;
149 160
150 // Find out if the given application |id| is a windowed app item and not a 161 // Find out if the given application |id| is a windowed app item and not a
151 // pinned item in the shelf. 162 // pinned item in the shelf.
152 virtual bool IsWindowedAppInLauncher(const std::string& app_id) = 0; 163 virtual bool IsWindowedAppInLauncher(const std::string& app_id) = 0;
153 164
154 // Updates the launch type of the app for the specified id to |launch_type|. 165 // Updates the launch type of the app for the specified id to |launch_type|.
155 virtual void SetLaunchType(ash::ShelfID id, 166 virtual void SetLaunchType(ash::ShelfID id,
156 extensions::LaunchType launch_type) = 0; 167 extensions::LaunchType launch_type) = 0;
157 168
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 169 // Notify the controller that the state of an non platform app's tabs
163 // have changed, 170 // have changed,
164 virtual void UpdateAppState(content::WebContents* contents, 171 virtual void UpdateAppState(content::WebContents* contents,
165 AppState app_state) = 0; 172 AppState app_state) = 0;
166 173
167 // Returns ShelfID for |contents|. If |contents| is not an app or is not 174 // Returns ShelfID for |contents|. If |contents| is not an app or is not
168 // pinned, returns the id of browser shrotcut. 175 // pinned, returns the id of browser shrotcut.
169 virtual ash::ShelfID GetShelfIDForWebContents( 176 virtual ash::ShelfID GetShelfIDForWebContents(
170 content::WebContents* contents) = 0; 177 content::WebContents* contents) = 0;
171 178
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 virtual bool ShelfBoundsChangesProbablyWithUser( 244 virtual bool ShelfBoundsChangesProbablyWithUser(
238 ash::WmShelf* shelf, 245 ash::WmShelf* shelf,
239 const AccountId& account_id) const = 0; 246 const AccountId& account_id) const = 0;
240 247
241 // Called when the user profile is fully loaded and ready to switch to. 248 // Called when the user profile is fully loaded and ready to switch to.
242 virtual void OnUserProfileReadyToSwitch(Profile* profile) = 0; 249 virtual void OnUserProfileReadyToSwitch(Profile* profile) = 0;
243 250
244 // Controller to launch Arc apps in deferred mode. 251 // Controller to launch Arc apps in deferred mode.
245 virtual ArcAppDeferredLauncherController* GetArcDeferredLauncher() = 0; 252 virtual ArcAppDeferredLauncherController* GetArcDeferredLauncher() = 0;
246 253
254 AppIconLoader* GetAppIconLoaderForApp(const std::string& app_id);
255
256 // Sets the shelf auto-hide and/or alignment behavior from prefs.
257 void SetShelfAutoHideBehaviorFromPrefs();
258 void SetShelfAlignmentFromPrefs();
259 void SetShelfBehaviorsFromPrefs();
260
261 // Sets LauncherControllerHelper or AppIconLoader for test, taking ownership.
262 void SetLauncherControllerHelperForTest(
263 std::unique_ptr<LauncherControllerHelper> helper);
264 void SetAppIconLoadersForTest(
265 std::vector<std::unique_ptr<AppIconLoader>>& loaders);
266
267 void SetProfileForTest(Profile* profile);
268
247 protected: 269 protected:
248 ChromeLauncherController(); 270 ChromeLauncherController();
249 271
272 // Connects or reconnects to the mojom::ShelfController interface in ash.
273 // Returns true if connected and returns false in unit tests.
274 bool ConnectToShelfController();
275
276 // Accessor for subclasses to interact with the shelf controller.
277 ash::mojom::ShelfControllerPtr& shelf_controller() {
278 return shelf_controller_;
279 }
280
281 // Attach to a specific profile.
282 virtual void AttachProfile(Profile* profile_to_attach);
283
284 // ash::mojom::ShelfObserver:
285 void OnShelfCreated(int64_t display_id) override;
286 void OnAlignmentChanged(ash::ShelfAlignment alignment,
287 int64_t display_id) override;
288 void OnAutoHideBehaviorChanged(ash::ShelfAutoHideBehavior auto_hide,
289 int64_t display_id) override;
290
250 private: 291 private:
292 // AppIconLoaderDelegate:
293 void OnAppImageUpdated(const std::string& app_id,
294 const gfx::ImageSkia& image) override;
295
251 static ChromeLauncherController* instance_; 296 static ChromeLauncherController* instance_;
252 297
298 // The currently loaded profile used for prefs and loading extensions. This is
299 // NOT necessarily the profile new windows are created with. Note that in
300 // multi-profile use cases this might change over time.
301 Profile* profile_ = nullptr;
302
303 // Ash's mojom::ShelfController used to change shelf state.
304 ash::mojom::ShelfControllerPtr shelf_controller_;
305
306 // The binding this instance uses to implment mojom::ShelfObserver
307 mojo::AssociatedBinding<ash::mojom::ShelfObserver> observer_binding_;
308
309 // Used to get app info for tabs.
310 std::unique_ptr<LauncherControllerHelper> launcher_controller_helper_;
311
312 // An observer that manages the shelf title and icon for settings windows.
253 SettingsWindowObserver settings_window_observer_; 313 SettingsWindowObserver settings_window_observer_;
254 314
315 // Used to load the images for app items.
316 std::vector<std::unique_ptr<AppIconLoader>> app_icon_loaders_;
317
255 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController); 318 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController);
256 }; 319 };
257 320
258 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ 321 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698