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

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

Issue 2765563002: Move and rename Chrome's AppLauncherId to ash::AppLaunchId. (Closed)
Patch Set: Add example commment. Created 3 years, 9 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 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "ash/common/multi_profile_uma.h" 11 #include "ash/common/multi_profile_uma.h"
12 #include "ash/common/shelf/shelf_model.h" 12 #include "ash/common/shelf/shelf_model.h"
13 #include "ash/common/shelf/wm_shelf.h" 13 #include "ash/common/shelf/wm_shelf.h"
14 #include "ash/common/system/tray/system_tray_delegate.h" 14 #include "ash/common/system/tray/system_tray_delegate.h"
15 #include "ash/common/wm_shell.h" 15 #include "ash/common/wm_shell.h"
16 #include "ash/common/wm_window.h" 16 #include "ash/common/wm_window.h"
17 #include "ash/public/cpp/app_launch_id.h"
17 #include "ash/resources/grit/ash_resources.h" 18 #include "ash/resources/grit/ash_resources.h"
18 #include "ash/root_window_controller.h" 19 #include "ash/root_window_controller.h"
19 #include "ash/shell.h" 20 #include "ash/shell.h"
20 #include "ash/strings/grit/ash_strings.h" 21 #include "ash/strings/grit/ash_strings.h"
21 #include "ash/wm/window_util.h" 22 #include "ash/wm/window_util.h"
22 #include "base/command_line.h" 23 #include "base/command_line.h"
23 #include "base/macros.h" 24 #include "base/macros.h"
24 #include "base/strings/pattern.h" 25 #include "base/strings/pattern.h"
25 #include "base/strings/string_util.h" 26 #include "base/strings/string_util.h"
26 #include "base/strings/utf_string_conversions.h" 27 #include "base/strings/utf_string_conversions.h"
27 #include "base/threading/thread_task_runner_handle.h" 28 #include "base/threading/thread_task_runner_handle.h"
28 #include "base/values.h" 29 #include "base/values.h"
29 #include "build/build_config.h" 30 #include "build/build_config.h"
30 #include "chrome/browser/browser_process.h" 31 #include "chrome/browser/browser_process.h"
31 #include "chrome/browser/chrome_notification_types.h" 32 #include "chrome/browser/chrome_notification_types.h"
32 #include "chrome/browser/chromeos/arc/arc_util.h" 33 #include "chrome/browser/chromeos/arc/arc_util.h"
33 #include "chrome/browser/defaults.h" 34 #include "chrome/browser/defaults.h"
34 #include "chrome/browser/extensions/extension_util.h" 35 #include "chrome/browser/extensions/extension_util.h"
35 #include "chrome/browser/prefs/incognito_mode_prefs.h" 36 #include "chrome/browser/prefs/incognito_mode_prefs.h"
36 #include "chrome/browser/prefs/pref_service_syncable_util.h" 37 #include "chrome/browser/prefs/pref_service_syncable_util.h"
37 #include "chrome/browser/profiles/profile.h" 38 #include "chrome/browser/profiles/profile.h"
38 #include "chrome/browser/profiles/profile_manager.h" 39 #include "chrome/browser/profiles/profile_manager.h"
39 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" 40 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
40 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" 41 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
41 #include "chrome/browser/ui/ash/app_launcher_id.h"
42 #include "chrome/browser/ui/ash/app_sync_ui_state.h" 42 #include "chrome/browser/ui/ash/app_sync_ui_state.h"
43 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" 43 #include "chrome/browser/ui/ash/chrome_shell_delegate.h"
44 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h " 44 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h "
45 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h" 45 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h"
46 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h" 46 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h"
47 #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h" 47 #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h"
48 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" 48 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h"
49 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h" 49 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h"
50 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" 50 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h"
51 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" 51 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h"
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 } 367 }
368 368
369 void ChromeLauncherControllerImpl::UnpinAndUpdatePrefs(ash::ShelfID id, 369 void ChromeLauncherControllerImpl::UnpinAndUpdatePrefs(ash::ShelfID id,
370 bool update_prefs) { 370 bool update_prefs) {
371 LauncherItemController* controller = GetLauncherItemController(id); 371 LauncherItemController* controller = GetLauncherItemController(id);
372 CHECK(controller); 372 CHECK(controller);
373 373
374 if (update_prefs) { 374 if (update_prefs) {
375 ash::launcher::RemovePinPosition( 375 ash::launcher::RemovePinPosition(
376 profile(), 376 profile(),
377 ash::AppLauncherId(GetAppIDForShelfID(id), GetLaunchIDForShelfID(id))); 377 ash::AppLaunchId(GetAppIDForShelfID(id), GetLaunchIDForShelfID(id)));
378 } 378 }
379 379
380 const ash::ShelfItem* item = GetItem(id); 380 const ash::ShelfItem* item = GetItem(id);
381 if (item && (item->status != ash::STATUS_CLOSED || controller->locked())) 381 if (item && (item->status != ash::STATUS_CLOSED || controller->locked()))
382 UnpinRunningAppInternal(model_->ItemIndexByID(id)); 382 UnpinRunningAppInternal(model_->ItemIndexByID(id));
383 else 383 else
384 LauncherItemClosed(id); 384 LauncherItemClosed(id);
385 } 385 }
386 386
387 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) { 387 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) {
388 const ash::ShelfItem* item = GetItem(id); 388 const ash::ShelfItem* item = GetItem(id);
389 return item && (item->type == ash::TYPE_PINNED_APP || 389 return item && (item->type == ash::TYPE_PINNED_APP ||
390 item->type == ash::TYPE_BROWSER_SHORTCUT); 390 item->type == ash::TYPE_BROWSER_SHORTCUT);
391 } 391 }
392 392
393 void ChromeLauncherControllerImpl::TogglePinned(ash::ShelfID id) { 393 void ChromeLauncherControllerImpl::TogglePinned(ash::ShelfID id) {
394 if (!HasShelfIDToAppIDMapping(id)) 394 if (!HasShelfIDToAppIDMapping(id))
395 return; // May happen if item closed with menu open. 395 return; // May happen if item closed with menu open.
396 396
397 if (IsPinned(id)) 397 if (IsPinned(id))
398 Unpin(id); 398 Unpin(id);
399 else 399 else
400 Pin(id); 400 Pin(id);
401 } 401 }
402 402
403 void ChromeLauncherControllerImpl::LockV1AppWithID(const std::string& app_id) { 403 void ChromeLauncherControllerImpl::LockV1AppWithID(const std::string& app_id) {
404 ash::ShelfID id = GetShelfIDForAppID(app_id); 404 ash::ShelfID id = GetShelfIDForAppID(app_id);
405 if (id == ash::kInvalidShelfID) { 405 if (id == ash::kInvalidShelfID) {
406 CreateAppShortcutLauncherItemWithType(ash::AppLauncherId(app_id), 406 CreateAppShortcutLauncherItemWithType(ash::AppLaunchId(app_id),
407 model_->item_count(), ash::TYPE_APP); 407 model_->item_count(), ash::TYPE_APP);
408 id = GetShelfIDForAppID(app_id); 408 id = GetShelfIDForAppID(app_id);
409 } 409 }
410 CHECK(id); 410 CHECK(id);
411 GetLauncherItemController(id)->lock(); 411 GetLauncherItemController(id)->lock();
412 } 412 }
413 413
414 void ChromeLauncherControllerImpl::UnlockV1AppWithID( 414 void ChromeLauncherControllerImpl::UnlockV1AppWithID(
415 const std::string& app_id) { 415 const std::string& app_id) {
416 ash::ShelfID id = GetShelfIDForAppID(app_id); 416 ash::ShelfID id = GetShelfIDForAppID(app_id);
417 CHECK_NE(id, ash::kInvalidShelfID); 417 CHECK_NE(id, ash::kInvalidShelfID);
418 LauncherItemController* controller = GetLauncherItemController(id); 418 LauncherItemController* controller = GetLauncherItemController(id);
419 controller->unlock(); 419 controller->unlock();
420 if (!controller->locked() && !IsPinned(id)) 420 if (!controller->locked() && !IsPinned(id))
421 CloseLauncherItem(id); 421 CloseLauncherItem(id);
422 } 422 }
423 423
424 void ChromeLauncherControllerImpl::Launch(ash::ShelfID id, int event_flags) { 424 void ChromeLauncherControllerImpl::Launch(ash::ShelfID id, int event_flags) {
425 LauncherItemController* controller = GetLauncherItemController(id); 425 LauncherItemController* controller = GetLauncherItemController(id);
426 if (!controller) 426 if (!controller)
427 return; // In case invoked from menu and item closed while menu up. 427 return; // In case invoked from menu and item closed while menu up.
428 428
429 // Launching some items replaces the associated item controller instance, 429 // Launching some items replaces the associated item controller instance,
430 // which destroys the app and launch id strings; making copies avoid crashes. 430 // which destroys the app and launch id strings; making copies avoid crashes.
431 LaunchApp(ash::AppLauncherId(controller->app_id(), controller->launch_id()), 431 LaunchApp(ash::AppLaunchId(controller->app_id(), controller->launch_id()),
432 ash::LAUNCH_FROM_UNKNOWN, event_flags); 432 ash::LAUNCH_FROM_UNKNOWN, event_flags);
433 } 433 }
434 434
435 void ChromeLauncherControllerImpl::Close(ash::ShelfID id) { 435 void ChromeLauncherControllerImpl::Close(ash::ShelfID id) {
436 ash::mojom::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id); 436 ash::mojom::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id);
437 if (!delegate) 437 if (!delegate)
438 return; // May happen if menu closed. 438 return; // May happen if menu closed.
439 delegate->Close(); 439 delegate->Close();
440 } 440 }
441 441
(...skipping 23 matching lines...) Expand all
465 return; 465 return;
466 } 466 }
467 467
468 // Create a temporary application launcher item and use it to see if there are 468 // Create a temporary application launcher item and use it to see if there are
469 // running instances. 469 // running instances.
470 std::unique_ptr<AppShortcutLauncherItemController> controller( 470 std::unique_ptr<AppShortcutLauncherItemController> controller(
471 AppShortcutLauncherItemController::Create(app_id, std::string(), this)); 471 AppShortcutLauncherItemController::Create(app_id, std::string(), this));
472 if (!controller->GetRunningApplications().empty()) 472 if (!controller->GetRunningApplications().empty())
473 SelectItemWithSource(controller.get(), source); 473 SelectItemWithSource(controller.get(), source);
474 else 474 else
475 LaunchApp(ash::AppLauncherId(app_id), source, event_flags); 475 LaunchApp(ash::AppLaunchId(app_id), source, event_flags);
476 } 476 }
477 477
478 void ChromeLauncherControllerImpl::SetLauncherItemImage( 478 void ChromeLauncherControllerImpl::SetLauncherItemImage(
479 ash::ShelfID shelf_id, 479 ash::ShelfID shelf_id,
480 const gfx::ImageSkia& image) { 480 const gfx::ImageSkia& image) {
481 const ash::ShelfItem* item = GetItem(shelf_id); 481 const ash::ShelfItem* item = GetItem(shelf_id);
482 if (item) { 482 if (item) {
483 ash::ShelfItem new_item = *item; 483 ash::ShelfItem new_item = *item;
484 new_item.image = image; 484 new_item.image = image;
485 model_->Set(model_->ItemIndexByID(shelf_id), new_item); 485 model_->Set(model_->ItemIndexByID(shelf_id), new_item);
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 956
957 // TODO(sky): update unit test so that this test isn't necessary. 957 // TODO(sky): update unit test so that this test isn't necessary.
958 if (ash::Shell::HasInstance()) 958 if (ash::Shell::HasInstance())
959 SetVirtualKeyboardBehaviorFromPrefs(); 959 SetVirtualKeyboardBehaviorFromPrefs();
960 960
961 prefs_observer_ = 961 prefs_observer_ =
962 ash::launcher::ChromeLauncherPrefsObserver::CreateIfNecessary(profile()); 962 ash::launcher::ChromeLauncherPrefsObserver::CreateIfNecessary(profile());
963 } 963 }
964 964
965 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem( 965 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem(
966 const ash::AppLauncherId& app_launcher_id, 966 const ash::AppLaunchId& app_launch_id,
967 int index) { 967 int index) {
968 return CreateAppShortcutLauncherItemWithType(app_launcher_id, index, 968 return CreateAppShortcutLauncherItemWithType(app_launch_id, index,
969 ash::TYPE_PINNED_APP); 969 ash::TYPE_PINNED_APP);
970 } 970 }
971 971
972 /////////////////////////////////////////////////////////////////////////////// 972 ///////////////////////////////////////////////////////////////////////////////
973 // ChromeLauncherControllerImpl private: 973 // ChromeLauncherControllerImpl private:
974 974
975 void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() { 975 void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() {
976 RunningAppListIds list; 976 RunningAppListIds list;
977 for (int i = 0; i < model_->item_count(); i++) { 977 for (int i = 0; i < model_->item_count(); i++) {
978 if (model_->items()[i].type == ash::TYPE_APP) 978 if (model_->items()[i].type == ash::TYPE_APP)
(...skipping 20 matching lines...) Expand all
999 DCHECK_GE(app_index, 0); 999 DCHECK_GE(app_index, 0);
1000 if (running_index != app_index) 1000 if (running_index != app_index)
1001 model_->Move(running_index, app_index); 1001 model_->Move(running_index, app_index);
1002 running_index++; 1002 running_index++;
1003 } 1003 }
1004 } 1004 }
1005 } 1005 }
1006 1006
1007 ash::ShelfID 1007 ash::ShelfID
1008 ChromeLauncherControllerImpl::CreateAppShortcutLauncherItemWithType( 1008 ChromeLauncherControllerImpl::CreateAppShortcutLauncherItemWithType(
1009 const ash::AppLauncherId& app_launcher_id, 1009 const ash::AppLaunchId& app_launch_id,
1010 int index, 1010 int index,
1011 ash::ShelfItemType shelf_item_type) { 1011 ash::ShelfItemType shelf_item_type) {
1012 AppShortcutLauncherItemController* controller = 1012 AppShortcutLauncherItemController* controller =
1013 AppShortcutLauncherItemController::Create( 1013 AppShortcutLauncherItemController::Create(
1014 app_launcher_id.app_id(), app_launcher_id.launch_id(), this); 1014 app_launch_id.app_id(), app_launch_id.launch_id(), this);
1015 ash::ShelfID shelf_id = 1015 ash::ShelfID shelf_id =
1016 InsertAppLauncherItem(controller, app_launcher_id.app_id(), 1016 InsertAppLauncherItem(controller, app_launch_id.app_id(),
1017 ash::STATUS_CLOSED, index, shelf_item_type); 1017 ash::STATUS_CLOSED, index, shelf_item_type);
1018 return shelf_id; 1018 return shelf_id;
1019 } 1019 }
1020 1020
1021 void ChromeLauncherControllerImpl::LauncherItemClosed(ash::ShelfID id) { 1021 void ChromeLauncherControllerImpl::LauncherItemClosed(ash::ShelfID id) {
1022 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 1022 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
1023 CHECK(iter != id_to_item_controller_map_.end()); 1023 CHECK(iter != id_to_item_controller_map_.end());
1024 CHECK(iter->second); 1024 CHECK(iter->second);
1025 const std::string& app_id = iter->second->app_id(); 1025 const std::string& app_id = iter->second->app_id();
1026 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); 1026 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id);
(...skipping 11 matching lines...) Expand all
1038 // If there is an item, do nothing and return. 1038 // If there is an item, do nothing and return.
1039 if (IsAppPinned(app_id)) 1039 if (IsAppPinned(app_id))
1040 return; 1040 return;
1041 1041
1042 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id); 1042 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id);
1043 if (shelf_id) { 1043 if (shelf_id) {
1044 // App item exists, pin it 1044 // App item exists, pin it
1045 Pin(shelf_id); 1045 Pin(shelf_id);
1046 } else { 1046 } else {
1047 // Otherwise, create a shortcut item for it. 1047 // Otherwise, create a shortcut item for it.
1048 shelf_id = CreateAppShortcutLauncherItem(ash::AppLauncherId(app_id), 1048 shelf_id = CreateAppShortcutLauncherItem(ash::AppLaunchId(app_id),
1049 model_->item_count()); 1049 model_->item_count());
1050 SyncPinPosition(shelf_id); 1050 SyncPinPosition(shelf_id);
1051 } 1051 }
1052 } 1052 }
1053 1053
1054 void ChromeLauncherControllerImpl::DoUnpinAppWithID(const std::string& app_id, 1054 void ChromeLauncherControllerImpl::DoUnpinAppWithID(const std::string& app_id,
1055 bool update_prefs) { 1055 bool update_prefs) {
1056 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id); 1056 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id);
1057 if (shelf_id && IsPinned(shelf_id)) 1057 if (shelf_id && IsPinned(shelf_id))
1058 UnpinAndUpdatePrefs(shelf_id, update_prefs); 1058 UnpinAndUpdatePrefs(shelf_id, update_prefs);
(...skipping 26 matching lines...) Expand all
1085 const int max_index = model_->item_count(); 1085 const int max_index = model_->item_count();
1086 const int index = model_->ItemIndexByID(shelf_id); 1086 const int index = model_->ItemIndexByID(shelf_id);
1087 DCHECK_GT(index, 0); 1087 DCHECK_GT(index, 0);
1088 1088
1089 const std::string& app_id = GetAppIDForShelfID(shelf_id); 1089 const std::string& app_id = GetAppIDForShelfID(shelf_id);
1090 DCHECK(!app_id.empty()); 1090 DCHECK(!app_id.empty());
1091 const std::string& launch_id = GetLaunchIDForShelfID(shelf_id); 1091 const std::string& launch_id = GetLaunchIDForShelfID(shelf_id);
1092 1092
1093 std::string app_id_before; 1093 std::string app_id_before;
1094 std::string launch_id_before; 1094 std::string launch_id_before;
1095 std::vector<ash::AppLauncherId> app_launcher_ids_after; 1095 std::vector<ash::AppLaunchId> app_launch_ids_after;
1096 1096
1097 for (int i = index - 1; i > 0; --i) { 1097 for (int i = index - 1; i > 0; --i) {
1098 const ash::ShelfID shelf_id_before = model_->items()[i].id; 1098 const ash::ShelfID shelf_id_before = model_->items()[i].id;
1099 if (IsPinned(shelf_id_before)) { 1099 if (IsPinned(shelf_id_before)) {
1100 app_id_before = GetAppIDForShelfID(shelf_id_before); 1100 app_id_before = GetAppIDForShelfID(shelf_id_before);
1101 DCHECK(!app_id_before.empty()); 1101 DCHECK(!app_id_before.empty());
1102 launch_id_before = GetLaunchIDForShelfID(shelf_id_before); 1102 launch_id_before = GetLaunchIDForShelfID(shelf_id_before);
1103 break; 1103 break;
1104 } 1104 }
1105 } 1105 }
1106 1106
1107 for (int i = index + 1; i < max_index; ++i) { 1107 for (int i = index + 1; i < max_index; ++i) {
1108 const ash::ShelfID shelf_id_after = model_->items()[i].id; 1108 const ash::ShelfID shelf_id_after = model_->items()[i].id;
1109 if (IsPinned(shelf_id_after)) { 1109 if (IsPinned(shelf_id_after)) {
1110 const std::string app_id_after = GetAppIDForShelfID(shelf_id_after); 1110 const std::string app_id_after = GetAppIDForShelfID(shelf_id_after);
1111 DCHECK(!app_id_after.empty()); 1111 DCHECK(!app_id_after.empty());
1112 const std::string launch_id_after = GetLaunchIDForShelfID(shelf_id_after); 1112 const std::string launch_id_after = GetLaunchIDForShelfID(shelf_id_after);
1113 app_launcher_ids_after.push_back( 1113 app_launch_ids_after.push_back(
1114 ash::AppLauncherId(app_id_after, launch_id_after)); 1114 ash::AppLaunchId(app_id_after, launch_id_after));
1115 } 1115 }
1116 } 1116 }
1117 1117
1118 ash::AppLauncherId app_launcher_id_before = 1118 ash::AppLaunchId app_launch_id_before =
1119 app_id_before.empty() 1119 app_id_before.empty() ? ash::AppLaunchId()
1120 ? ash::AppLauncherId() 1120 : ash::AppLaunchId(app_id_before, launch_id_before);
1121 : ash::AppLauncherId(app_id_before, launch_id_before);
1122 1121
1123 ash::launcher::SetPinPosition(profile(), 1122 ash::launcher::SetPinPosition(profile(), ash::AppLaunchId(app_id, launch_id),
1124 ash::AppLauncherId(app_id, launch_id), 1123 app_launch_id_before, app_launch_ids_after);
1125 app_launcher_id_before, app_launcher_ids_after);
1126 } 1124 }
1127 1125
1128 void ChromeLauncherControllerImpl::OnSyncModelUpdated() { 1126 void ChromeLauncherControllerImpl::OnSyncModelUpdated() {
1129 UpdateAppLaunchersFromPref(); 1127 UpdateAppLaunchersFromPref();
1130 } 1128 }
1131 1129
1132 void ChromeLauncherControllerImpl::OnIsSyncingChanged() { 1130 void ChromeLauncherControllerImpl::OnIsSyncingChanged() {
1133 UpdateAppLaunchersFromPref(); 1131 UpdateAppLaunchersFromPref();
1134 } 1132 }
1135 1133
1136 void ChromeLauncherControllerImpl::ScheduleUpdateAppLaunchersFromPref() { 1134 void ChromeLauncherControllerImpl::ScheduleUpdateAppLaunchersFromPref() {
1137 base::ThreadTaskRunnerHandle::Get()->PostTask( 1135 base::ThreadTaskRunnerHandle::Get()->PostTask(
1138 FROM_HERE, 1136 FROM_HERE,
1139 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref, 1137 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref,
1140 weak_ptr_factory_.GetWeakPtr())); 1138 weak_ptr_factory_.GetWeakPtr()));
1141 } 1139 }
1142 1140
1143 void ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref() { 1141 void ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref() {
1144 // There are various functions which will trigger a |SyncPinPosition| call 1142 // There are various functions which will trigger a |SyncPinPosition| call
1145 // like a direct call to |DoPinAppWithID|, or an indirect call to the menu 1143 // like a direct call to |DoPinAppWithID|, or an indirect call to the menu
1146 // model which will use weights to re-arrange the icons to new positions. 1144 // model which will use weights to re-arrange the icons to new positions.
1147 // Since this function is meant to synchronize the "is state" with the 1145 // Since this function is meant to synchronize the "is state" with the
1148 // "sync state", it makes no sense to store any changes by this function back 1146 // "sync state", it makes no sense to store any changes by this function back
1149 // into the pref state. Therefore we tell |persistPinnedState| to ignore any 1147 // into the pref state. Therefore we tell |persistPinnedState| to ignore any
1150 // invocations while we are running. 1148 // invocations while we are running.
1151 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true); 1149 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true);
1152 const std::vector<ash::AppLauncherId> pinned_apps = 1150 const std::vector<ash::AppLaunchId> pinned_apps =
1153 ash::launcher::GetPinnedAppsFromPrefs(profile()->GetPrefs(), 1151 ash::launcher::GetPinnedAppsFromPrefs(profile()->GetPrefs(),
1154 launcher_controller_helper()); 1152 launcher_controller_helper());
1155 1153
1156 int index = 0; 1154 int index = 0;
1157 // Skip app list items if it exists. 1155 // Skip app list items if it exists.
1158 if (model_->items()[0].type == ash::TYPE_APP_LIST) 1156 if (model_->items()[0].type == ash::TYPE_APP_LIST)
1159 ++index; 1157 ++index;
1160 1158
1161 // Apply pins in two steps. At the first step, go through the list of apps to 1159 // Apply pins in two steps. At the first step, go through the list of apps to
1162 // pin, move existing pin to current position specified by |index| or create 1160 // pin, move existing pin to current position specified by |index| or create
1163 // the new pin at that position. 1161 // the new pin at that position.
1164 for (const auto& pref_app_launcher_id : pinned_apps) { 1162 for (const auto& pref_app_launch_id : pinned_apps) {
1165 // Filter out apps that may be mapped wrongly. 1163 // Filter out apps that may be mapped wrongly.
1166 // TODO(khmel): b/31703859 is to refactore shelf mapping. 1164 // TODO(khmel): b/31703859 is to refactore shelf mapping.
1167 const std::string app_id = pref_app_launcher_id.app_id(); 1165 const std::string app_id = pref_app_launch_id.app_id();
1168 const std::string shelf_app_id = 1166 const std::string shelf_app_id =
1169 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); 1167 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id);
1170 if (shelf_app_id != app_id) 1168 if (shelf_app_id != app_id)
1171 continue; 1169 continue;
1172 1170
1173 // Update apps icon if applicable. 1171 // Update apps icon if applicable.
1174 OnAppUpdated(profile(), app_id); 1172 OnAppUpdated(profile(), app_id);
1175 1173
1176 // Find existing pin or app from the right of current |index|. 1174 // Find existing pin or app from the right of current |index|.
1177 int app_index = index; 1175 int app_index = index;
1178 for (; app_index < model_->item_count(); ++app_index) { 1176 for (; app_index < model_->item_count(); ++app_index) {
1179 const ash::ShelfItem& item = model_->items()[app_index]; 1177 const ash::ShelfItem& item = model_->items()[app_index];
1180 const IDToItemControllerMap::iterator it = 1178 const IDToItemControllerMap::iterator it =
1181 id_to_item_controller_map_.find(item.id); 1179 id_to_item_controller_map_.find(item.id);
1182 if (it != id_to_item_controller_map_.end() && 1180 if (it != id_to_item_controller_map_.end() &&
1183 it->second->app_id() == app_id && 1181 it->second->app_id() == app_id &&
1184 it->second->launch_id() == pref_app_launcher_id.launch_id()) { 1182 it->second->launch_id() == pref_app_launch_id.launch_id()) {
1185 break; 1183 break;
1186 } 1184 }
1187 } 1185 }
1188 if (app_index < model_->item_count()) { 1186 if (app_index < model_->item_count()) {
1189 // Found existing pin or running app. 1187 // Found existing pin or running app.
1190 const ash::ShelfItem item = model_->items()[app_index]; 1188 const ash::ShelfItem item = model_->items()[app_index];
1191 if (item.type == ash::TYPE_PINNED_APP || 1189 if (item.type == ash::TYPE_PINNED_APP ||
1192 item.type == ash::TYPE_BROWSER_SHORTCUT) { 1190 item.type == ash::TYPE_BROWSER_SHORTCUT) {
1193 // Just move to required position or keep it inplace. 1191 // Just move to required position or keep it inplace.
1194 model_->Move(app_index, index); 1192 model_->Move(app_index, index);
1195 } else { 1193 } else {
1196 PinRunningAppInternal(index, item.id); 1194 PinRunningAppInternal(index, item.id);
1197 } 1195 }
1198 DCHECK_EQ(model_->ItemIndexByID(item.id), index); 1196 DCHECK_EQ(model_->ItemIndexByID(item.id), index);
1199 } else { 1197 } else {
1200 // This is fresh pin. Create new one. 1198 // This is fresh pin. Create new one.
1201 DCHECK_NE(app_id, extension_misc::kChromeAppId); 1199 DCHECK_NE(app_id, extension_misc::kChromeAppId);
1202 CreateAppShortcutLauncherItem(pref_app_launcher_id, index); 1200 CreateAppShortcutLauncherItem(pref_app_launch_id, index);
1203 } 1201 }
1204 ++index; 1202 ++index;
1205 } 1203 }
1206 1204
1207 // At second step remove any pin to the right from the current index. 1205 // At second step remove any pin to the right from the current index.
1208 while (index < model_->item_count()) { 1206 while (index < model_->item_count()) {
1209 const ash::ShelfItem item = model_->items()[index]; 1207 const ash::ShelfItem item = model_->items()[index];
1210 if (item.type != ash::TYPE_PINNED_APP) { 1208 if (item.type != ash::TYPE_PINNED_APP) {
1211 ++index; 1209 ++index;
1212 continue; 1210 continue;
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 LauncherItemController* controller = GetLauncherItemController(item.id); 1497 LauncherItemController* controller = GetLauncherItemController(item.id);
1500 if (!controller || controller->image_set_by_controller()) 1498 if (!controller || controller->image_set_by_controller())
1501 continue; 1499 continue;
1502 item.image = image; 1500 item.image = image;
1503 if (arc_deferred_launcher_) 1501 if (arc_deferred_launcher_)
1504 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); 1502 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image);
1505 model_->Set(index, item); 1503 model_->Set(index, item);
1506 // It's possible we're waiting on more than one item, so don't break. 1504 // It's possible we're waiting on more than one item, so don't break.
1507 } 1505 }
1508 } 1506 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698