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

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

Issue 2055553004: arc: Support pinned apps across Arc-enabled and Arc-disabled platforms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup and update 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> 8 #include <list>
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "ash/common/shelf/shelf_item_delegate.h" 14 #include "ash/common/shelf/shelf_item_delegate.h"
15 #include "ash/common/shelf/shelf_item_delegate_manager.h" 15 #include "ash/common/shelf/shelf_item_delegate_manager.h"
16 #include "ash/common/shelf/shelf_item_types.h" 16 #include "ash/common/shelf/shelf_item_types.h"
17 #include "ash/common/shelf/shelf_model_observer.h" 17 #include "ash/common/shelf/shelf_model_observer.h"
18 #include "ash/common/shelf/shelf_types.h" 18 #include "ash/common/shelf/shelf_types.h"
19 #include "ash/display/window_tree_host_manager.h" 19 #include "ash/display/window_tree_host_manager.h"
20 #include "ash/shelf/shelf_delegate.h" 20 #include "ash/shelf/shelf_delegate.h"
21 #include "base/compiler_specific.h" 21 #include "base/compiler_specific.h"
22 #include "base/macros.h" 22 #include "base/macros.h"
23 #include "base/memory/scoped_vector.h" 23 #include "base/memory/scoped_vector.h"
24 #include "build/build_config.h" 24 #include "build/build_config.h"
25 #include "chrome/browser/ui/app_icon_loader.h" 25 #include "chrome/browser/ui/app_icon_loader.h"
26 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" 26 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
27 #include "chrome/browser/ui/app_list/app_list_syncable_service.h"
27 #include "chrome/browser/ui/ash/app_sync_ui_state_observer.h" 28 #include "chrome/browser/ui/ash/app_sync_ui_state_observer.h"
28 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" 29 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h"
29 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h" 30 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h"
30 #include "chrome/browser/ui/ash/launcher/launcher_app_updater.h" 31 #include "chrome/browser/ui/ash/launcher/launcher_app_updater.h"
31 #include "components/prefs/pref_change_registrar.h" 32 #include "components/prefs/pref_change_registrar.h"
32 #include "components/syncable_prefs/pref_service_syncable_observer.h" 33 #include "components/syncable_prefs/pref_service_syncable_observer.h"
33 #include "extensions/common/constants.h" 34 #include "extensions/common/constants.h"
34 #include "ui/aura/window_observer.h" 35 #include "ui/aura/window_observer.h"
35 36
36 class AppSyncUIState; 37 class AppSyncUIState;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 // AppWindowLauncherController. 82 // AppWindowLauncherController.
82 // * Shortcuts have no LauncherItemController. 83 // * Shortcuts have no LauncherItemController.
83 class ChromeLauncherController 84 class ChromeLauncherController
84 : public ash::ShelfDelegate, 85 : public ash::ShelfDelegate,
85 public ash::ShelfModelObserver, 86 public ash::ShelfModelObserver,
86 public ash::WindowTreeHostManager::Observer, 87 public ash::WindowTreeHostManager::Observer,
87 public AppIconLoaderDelegate, 88 public AppIconLoaderDelegate,
88 public syncable_prefs::PrefServiceSyncableObserver, 89 public syncable_prefs::PrefServiceSyncableObserver,
89 public AppSyncUIStateObserver, 90 public AppSyncUIStateObserver,
90 public LauncherAppUpdater::Delegate, 91 public LauncherAppUpdater::Delegate,
91 public ash::ShelfItemDelegateManagerObserver { 92 public ash::ShelfItemDelegateManagerObserver,
93 public app_list::AppListSyncableService::Observer {
92 public: 94 public:
93 // Indicates if a shelf item is incognito or not. 95 // Indicates if a shelf item is incognito or not.
94 enum IncognitoState { 96 enum IncognitoState {
95 STATE_INCOGNITO, 97 STATE_INCOGNITO,
96 STATE_NOT_INCOGNITO, 98 STATE_NOT_INCOGNITO,
97 }; 99 };
98 100
99 // Used to update the state of non plaform apps, as web contents change. 101 // Used to update the state of non plaform apps, as web contents change.
100 enum AppState { 102 enum AppState {
101 APP_STATE_ACTIVE, 103 APP_STATE_ACTIVE,
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 virtual bool IsLoggedInAsGuest(); 207 virtual bool IsLoggedInAsGuest();
206 208
207 // Invoked when user clicks on button in the shelf and there is no last 209 // Invoked when user clicks on button in the shelf and there is no last
208 // used window (or CTRL is held with the click). 210 // used window (or CTRL is held with the click).
209 void CreateNewWindow(); 211 void CreateNewWindow();
210 212
211 // Invoked when the user clicks on button in the shelf to create a new 213 // Invoked when the user clicks on button in the shelf to create a new
212 // incognito window. 214 // incognito window.
213 void CreateNewIncognitoWindow(); 215 void CreateNewIncognitoWindow();
214 216
215 // Updates the pinned pref state. The pinned state consists of a list pref.
216 // Each item of the list is a dictionary. The key |kAppIDPath| gives the
217 // id of the app.
218 void PersistPinnedState();
219
220 // Accessor to the currently loaded profile. Note that in multi profile use 217 // Accessor to the currently loaded profile. Note that in multi profile use
221 // cases this might change over time. 218 // cases this might change over time.
222 Profile* profile(); 219 Profile* profile();
223 220
224 // Notify the controller that the state of an non platform app's tabs 221 // Notify the controller that the state of an non platform app's tabs
225 // have changed, 222 // have changed,
226 void UpdateAppState(content::WebContents* contents, AppState app_state); 223 void UpdateAppState(content::WebContents* contents, AppState app_state);
227 224
228 // Returns ShelfID for |contents|. If |contents| is not an app or is not 225 // Returns ShelfID for |contents|. If |contents| is not an app or is not
229 // pinned, returns the id of browser shrotcut. 226 // pinned, returns the id of browser shrotcut.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 // syncable_prefs::PrefServiceSyncableObserver: 280 // syncable_prefs::PrefServiceSyncableObserver:
284 void OnIsSyncingChanged() override; 281 void OnIsSyncingChanged() override;
285 282
286 // AppSyncUIStateObserver: 283 // AppSyncUIStateObserver:
287 void OnAppSyncUIStatusChanged() override; 284 void OnAppSyncUIStatusChanged() override;
288 285
289 // AppIconLoaderDelegate: 286 // AppIconLoaderDelegate:
290 void OnAppImageUpdated(const std::string& app_id, 287 void OnAppImageUpdated(const std::string& app_id,
291 const gfx::ImageSkia& image) override; 288 const gfx::ImageSkia& image) override;
292 289
290 // app_list::AppListSyncableService::Observer:
291 void OnSyncModelUpdated() override;
292
293 // Called when the active user has changed. 293 // Called when the active user has changed.
294 void ActiveUserChanged(const std::string& user_email); 294 void ActiveUserChanged(const std::string& user_email);
295 295
296 // Called when a user got added to the session. 296 // Called when a user got added to the session.
297 void AdditionalUserAddedToSession(Profile* profile); 297 void AdditionalUserAddedToSession(Profile* profile);
298 298
299 // Get the list of all running incarnations of this item. 299 // Get the list of all running incarnations of this item.
300 // |event_flags| specifies the flags which were set by the event which 300 // |event_flags| specifies the flags which were set by the event which
301 // triggered this menu generation. It can be used to generate different lists. 301 // triggered this menu generation. It can be used to generate different lists.
302 ChromeLauncherAppMenuItems GetApplicationList(const ash::ShelfItem& item, 302 ChromeLauncherAppMenuItems GetApplicationList(const ash::ShelfItem& item,
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 412
413 // Pin a running app with |shelf_id| internally to |index|. It returns 413 // Pin a running app with |shelf_id| internally to |index|. It returns
414 // the index where the item was pinned. 414 // the index where the item was pinned.
415 int PinRunningAppInternal(int index, ash::ShelfID shelf_id); 415 int PinRunningAppInternal(int index, ash::ShelfID shelf_id);
416 416
417 // Unpin a locked application. This is an internal call which converts the 417 // Unpin a locked application. This is an internal call which converts the
418 // model type of the given app index from a shortcut into an unpinned running 418 // model type of the given app index from a shortcut into an unpinned running
419 // app. 419 // app.
420 void UnpinRunningAppInternal(int index); 420 void UnpinRunningAppInternal(int index);
421 421
422 // Re-syncs shelf model with prefs::kPinnedLauncherApps. 422 // Updates pin position for the item specified by |id| in sync model.
423 void SyncPinPosition(ash::ShelfID id);
424
425 // Re-syncs shelf model.
423 void UpdateAppLaunchersFromPref(); 426 void UpdateAppLaunchersFromPref();
424 427
425 // Sets the shelf auto-hide behavior from prefs. 428 // Sets the shelf auto-hide behavior from prefs.
426 void SetShelfAutoHideBehaviorFromPrefs(); 429 void SetShelfAutoHideBehaviorFromPrefs();
427 430
428 // Sets the shelf alignment from prefs. 431 // Sets the shelf alignment from prefs.
429 void SetShelfAlignmentFromPrefs(); 432 void SetShelfAlignmentFromPrefs();
430 433
431 // Sets both of auto-hide behavior and alignment from prefs. 434 // Sets both of auto-hide behavior and alignment from prefs.
432 void SetShelfBehaviorsFromPrefs(); 435 void SetShelfBehaviorsFromPrefs();
(...skipping 18 matching lines...) Expand all
451 // Enumerate all Web contents which match a given shortcut |controller|. 454 // Enumerate all Web contents which match a given shortcut |controller|.
452 std::vector<content::WebContents*> GetV1ApplicationsFromController( 455 std::vector<content::WebContents*> GetV1ApplicationsFromController(
453 LauncherItemController* controller); 456 LauncherItemController* controller);
454 457
455 // Create ShelfItem for Browser Shortcut. 458 // Create ShelfItem for Browser Shortcut.
456 ash::ShelfID CreateBrowserShortcutLauncherItem(); 459 ash::ShelfID CreateBrowserShortcutLauncherItem();
457 460
458 // Check if the given |web_contents| is in incognito mode. 461 // Check if the given |web_contents| is in incognito mode.
459 bool IsIncognito(const content::WebContents* web_contents) const; 462 bool IsIncognito(const content::WebContents* web_contents) const;
460 463
461 // Update browser shortcut's index.
462 void PersistChromeItemIndex(int index);
463
464 // Depending on the provided flags, move either the chrome icon, the app icon
465 // or none to the given |target_index|. The provided |chrome_index| and
466 // |app_list_index| locations will get adjusted within this call to finalize
467 // the action and to make sure that the other item can still be moved
468 // afterwards (index adjustments).
469 void MoveChromeOrApplistToFinalPosition(
470 bool is_chrome,
471 bool is_app_list,
472 int target_index,
473 int* chrome_index,
474 int* app_list_index);
475
476 // Finds the index of where to insert the next item. 464 // Finds the index of where to insert the next item.
477 int FindInsertionPoint(bool is_app_list); 465 int FindInsertionPoint();
478 466
479 // Get the browser shortcut's index in the shelf using the current's systems 467 // Get the browser shortcut's index in the shelf using the current's systems
480 // configuration of pinned and known (but not running) apps. 468 // configuration of pinned and known (but not running) apps.
481 int GetChromeIconIndexForCreation(); 469 int GetChromeIconIndexForCreation();
482 470
483 // Close all windowed V1 applications of a certain extension which was already 471 // Close all windowed V1 applications of a certain extension which was already
484 // deleted. 472 // deleted.
485 void CloseWindowedAppsFromRemovedExtension(const std::string& app_id, 473 void CloseWindowedAppsFromRemovedExtension(const std::string& app_id,
486 const Profile* profile); 474 const Profile* profile);
487 475
488 // Set ShelfItemDelegate |item_delegate| for |id| and take an ownership. 476 // Set ShelfItemDelegate |item_delegate| for |id| and take an ownership.
489 // TODO(simon.hong81): Make this take a scoped_ptr of |item_delegate|. 477 // TODO(simon.hong81): Make this take a scoped_ptr of |item_delegate|.
490 void SetShelfItemDelegate(ash::ShelfID id, 478 void SetShelfItemDelegate(ash::ShelfID id,
491 ash::ShelfItemDelegate* item_delegate); 479 ash::ShelfItemDelegate* item_delegate);
492 480
493 // Attach to a specific profile. 481 // Attach to a specific profile.
494 void AttachProfile(Profile* proifile); 482 void AttachProfile(Profile* proifile);
495 483
496 // Forget the current profile to allow attaching to a new one. 484 // Forget the current profile to allow attaching to a new one.
497 void ReleaseProfile(); 485 void ReleaseProfile();
498 486
499 AppIconLoader* GetAppIconLoaderForApp(const std::string& app_id); 487 AppIconLoader* GetAppIconLoaderForApp(const std::string& app_id);
500 488
501 static ChromeLauncherController* instance_; 489 static ChromeLauncherController* instance_;
502 490
503 ash::ShelfModel* model_; 491 ash::ShelfModel* model_;
504 492
505 ash::ShelfItemDelegateManager* item_delegate_manager_; 493 ash::ShelfItemDelegateManager* item_delegate_manager_ = nullptr;
506 494
507 // Profile used for prefs and loading extensions. This is NOT necessarily the 495 // Profile used for prefs and loading extensions. This is NOT necessarily the
508 // profile new windows are created with. 496 // profile new windows are created with.
509 Profile* profile_; 497 Profile* profile_;
510 498
511 // Controller items in this map are owned by |ShelfItemDelegateManager|. 499 // Controller items in this map are owned by |ShelfItemDelegateManager|.
512 IDToItemControllerMap id_to_item_controller_map_; 500 IDToItemControllerMap id_to_item_controller_map_;
513 501
514 // Direct access to app_id for a web contents. 502 // Direct access to app_id for a web contents.
515 WebContentsToAppIDMap web_contents_to_app_id_; 503 WebContentsToAppIDMap web_contents_to_app_id_;
516 504
517 // Used to track app windows. 505 // Used to track app windows.
518 std::vector<std::unique_ptr<AppWindowLauncherController>> 506 std::vector<std::unique_ptr<AppWindowLauncherController>>
519 app_window_controllers_; 507 app_window_controllers_;
520 508
521 // Used to get app info for tabs. 509 // Used to get app info for tabs.
522 std::unique_ptr<LauncherControllerHelper> launcher_controller_helper_; 510 std::unique_ptr<LauncherControllerHelper> launcher_controller_helper_;
523 511
524 // Used to load the images for app items. 512 // Used to load the images for app items.
525 std::vector<std::unique_ptr<AppIconLoader>> app_icon_loaders_; 513 std::vector<std::unique_ptr<AppIconLoader>> app_icon_loaders_;
526 514
527 // Used to handle app load/unload events. 515 // Used to handle app load/unload events.
528 std::vector<std::unique_ptr<LauncherAppUpdater>> app_updaters_; 516 std::vector<std::unique_ptr<LauncherAppUpdater>> app_updaters_;
529 517
530 PrefChangeRegistrar pref_change_registrar_; 518 PrefChangeRegistrar pref_change_registrar_;
531 519
532 AppSyncUIState* app_sync_ui_state_; 520 AppSyncUIState* app_sync_ui_state_ = nullptr;
533 521
534 // The owned browser status monitor. 522 // The owned browser status monitor.
535 std::unique_ptr<BrowserStatusMonitor> browser_status_monitor_; 523 std::unique_ptr<BrowserStatusMonitor> browser_status_monitor_;
536 524
537 // A special observer class to detect user switches. 525 // A special observer class to detect user switches.
538 std::unique_ptr<ChromeLauncherControllerUserSwitchObserver> 526 std::unique_ptr<ChromeLauncherControllerUserSwitchObserver>
539 user_switch_observer_; 527 user_switch_observer_;
540 528
541 std::unique_ptr<ArcAppDeferredLauncherController> arc_deferred_launcher_; 529 std::unique_ptr<ArcAppDeferredLauncherController> arc_deferred_launcher_;
542 530
543 // If true, incoming pinned state changes should be ignored. 531 // If true, incoming pinned state changes should be ignored.
544 bool ignore_persist_pinned_state_change_; 532 bool ignore_persist_pinned_state_change_ = false;
545 533
546 // The list of running & un-pinned applications for different users on hidden 534 // The list of running & un-pinned applications for different users on hidden
547 // desktops. 535 // desktops.
548 typedef std::vector<std::string> RunningAppListIds; 536 typedef std::vector<std::string> RunningAppListIds;
549 typedef std::map<std::string, RunningAppListIds> RunningAppListIdMap; 537 typedef std::map<std::string, RunningAppListIds> RunningAppListIdMap;
550 RunningAppListIdMap last_used_running_application_order_; 538 RunningAppListIdMap last_used_running_application_order_;
551 539
552 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController); 540 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController);
553 }; 541 };
554 542
555 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ 543 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698