Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 } | 346 } |
| 347 | 347 |
| 348 void ChromeLauncherControllerImpl::Pin(ash::ShelfID id) { | 348 void ChromeLauncherControllerImpl::Pin(ash::ShelfID id) { |
| 349 DCHECK(HasShelfIDToAppIDMapping(id)); | 349 DCHECK(HasShelfIDToAppIDMapping(id)); |
| 350 | 350 |
| 351 int index = model_->ItemIndexByID(id); | 351 int index = model_->ItemIndexByID(id); |
| 352 DCHECK_GE(index, 0); | 352 DCHECK_GE(index, 0); |
| 353 | 353 |
| 354 ash::ShelfItem item = model_->items()[index]; | 354 ash::ShelfItem item = model_->items()[index]; |
| 355 | 355 |
| 356 if (item.type == ash::TYPE_PLATFORM_APP || | 356 if (item.type == ash::TYPE_APP) { |
| 357 item.type == ash::TYPE_WINDOWED_APP) { | |
| 358 item.type = ash::TYPE_APP_SHORTCUT; | 357 item.type = ash::TYPE_APP_SHORTCUT; |
| 359 model_->Set(index, item); | 358 model_->Set(index, item); |
| 360 } else if (item.type != ash::TYPE_APP_SHORTCUT) { | 359 } else if (item.type != ash::TYPE_APP_SHORTCUT) { |
| 361 return; | 360 return; |
| 362 } | 361 } |
| 363 | 362 |
| 364 SyncPinPosition(id); | 363 SyncPinPosition(id); |
| 365 } | 364 } |
| 366 | 365 |
| 367 void ChromeLauncherControllerImpl::Unpin(ash::ShelfID id) { | 366 void ChromeLauncherControllerImpl::Unpin(ash::ShelfID id) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 Pin(id); | 404 Pin(id); |
| 406 } | 405 } |
| 407 | 406 |
| 408 bool ChromeLauncherControllerImpl::IsPinnable(ash::ShelfID id) const { | 407 bool ChromeLauncherControllerImpl::IsPinnable(ash::ShelfID id) const { |
| 409 int index = model_->ItemIndexByID(id); | 408 int index = model_->ItemIndexByID(id); |
| 410 if (index == -1) | 409 if (index == -1) |
| 411 return false; | 410 return false; |
| 412 | 411 |
| 413 ash::ShelfItemType type = model_->items()[index].type; | 412 ash::ShelfItemType type = model_->items()[index].type; |
| 414 std::string app_id; | 413 std::string app_id; |
| 415 return ((type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_PLATFORM_APP || | 414 return ((type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_APP) && |
| 416 type == ash::TYPE_WINDOWED_APP) && | |
| 417 model_->GetShelfItemDelegate(id)->CanPin()); | 415 model_->GetShelfItemDelegate(id)->CanPin()); |
| 418 } | 416 } |
| 419 | 417 |
| 420 void ChromeLauncherControllerImpl::LockV1AppWithID(const std::string& app_id) { | 418 void ChromeLauncherControllerImpl::LockV1AppWithID(const std::string& app_id) { |
| 421 ash::ShelfID id = GetShelfIDForAppID(app_id); | 419 ash::ShelfID id = GetShelfIDForAppID(app_id); |
| 422 if (!IsPinned(id) && !IsWindowedAppInLauncher(app_id)) { | 420 if (id == ash::kInvalidShelfID) { |
| 423 CreateAppShortcutLauncherItemWithType(ash::launcher::AppLauncherId(app_id), | 421 CreateAppShortcutLauncherItemWithType(ash::launcher::AppLauncherId(app_id), |
| 424 model_->item_count(), | 422 model_->item_count(), ash::TYPE_APP); |
| 425 ash::TYPE_WINDOWED_APP); | |
| 426 id = GetShelfIDForAppID(app_id); | 423 id = GetShelfIDForAppID(app_id); |
| 427 } | 424 } |
| 428 CHECK(id); | 425 CHECK(id); |
| 429 GetLauncherItemController(id)->lock(); | 426 GetLauncherItemController(id)->lock(); |
| 430 } | 427 } |
| 431 | 428 |
| 432 void ChromeLauncherControllerImpl::UnlockV1AppWithID( | 429 void ChromeLauncherControllerImpl::UnlockV1AppWithID( |
| 433 const std::string& app_id) { | 430 const std::string& app_id) { |
| 434 ash::ShelfID id = GetShelfIDForAppID(app_id); | 431 ash::ShelfID id = GetShelfIDForAppID(app_id); |
| 435 CHECK(id); | 432 CHECK_NE(id, ash::kInvalidShelfID); |
| 436 CHECK(IsPinned(id) || IsWindowedAppInLauncher(app_id)); | |
| 437 LauncherItemController* controller = GetLauncherItemController(id); | 433 LauncherItemController* controller = GetLauncherItemController(id); |
| 438 controller->unlock(); | 434 controller->unlock(); |
| 439 if (!controller->locked() && !IsPinned(id)) | 435 if (!controller->locked() && !IsPinned(id)) |
| 440 CloseLauncherItem(id); | 436 CloseLauncherItem(id); |
| 441 } | 437 } |
| 442 | 438 |
| 443 void ChromeLauncherControllerImpl::Launch(ash::ShelfID id, int event_flags) { | 439 void ChromeLauncherControllerImpl::Launch(ash::ShelfID id, int event_flags) { |
| 444 LauncherItemController* controller = GetLauncherItemController(id); | 440 LauncherItemController* controller = GetLauncherItemController(id); |
| 445 if (!controller) | 441 if (!controller) |
| 446 return; // In case invoked from menu and item closed while menu up. | 442 return; // In case invoked from menu and item closed while menu up. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 508 ash::ShelfID shelf_id, | 504 ash::ShelfID shelf_id, |
| 509 const gfx::ImageSkia& image) { | 505 const gfx::ImageSkia& image) { |
| 510 int index = model_->ItemIndexByID(shelf_id); | 506 int index = model_->ItemIndexByID(shelf_id); |
| 511 if (index == -1) | 507 if (index == -1) |
| 512 return; | 508 return; |
| 513 ash::ShelfItem item = model_->items()[index]; | 509 ash::ShelfItem item = model_->items()[index]; |
| 514 item.image = image; | 510 item.image = image; |
| 515 model_->Set(index, item); | 511 model_->Set(index, item); |
| 516 } | 512 } |
| 517 | 513 |
| 518 bool ChromeLauncherControllerImpl::IsWindowedAppInLauncher( | |
| 519 const std::string& app_id) { | |
| 520 int index = model_->ItemIndexByID(GetShelfIDForAppID(app_id)); | |
| 521 if (index < 0) | |
| 522 return false; | |
| 523 | |
| 524 ash::ShelfItemType type = model_->items()[index].type; | |
| 525 return type == ash::TYPE_WINDOWED_APP; | |
| 526 } | |
| 527 | |
| 528 void ChromeLauncherControllerImpl::SetLaunchType( | 514 void ChromeLauncherControllerImpl::SetLaunchType( |
| 529 ash::ShelfID id, | 515 ash::ShelfID id, |
| 530 extensions::LaunchType launch_type) { | 516 extensions::LaunchType launch_type) { |
| 531 LauncherItemController* controller = GetLauncherItemController(id); | 517 LauncherItemController* controller = GetLauncherItemController(id); |
| 532 if (!controller) | 518 if (!controller) |
| 533 return; | 519 return; |
| 534 | 520 |
| 535 extensions::SetLaunchType(profile(), controller->app_id(), launch_type); | 521 extensions::SetLaunchType(profile(), controller->app_id(), launch_type); |
| 536 } | 522 } |
| 537 | 523 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 589 int browser_index = model_->GetItemIndexForType(ash::TYPE_BROWSER_SHORTCUT); | 575 int browser_index = model_->GetItemIndexForType(ash::TYPE_BROWSER_SHORTCUT); |
| 590 return model_->items()[browser_index].id; | 576 return model_->items()[browser_index].id; |
| 591 } | 577 } |
| 592 | 578 |
| 593 return id; | 579 return id; |
| 594 } | 580 } |
| 595 | 581 |
| 596 void ChromeLauncherControllerImpl::SetRefocusURLPatternForTest( | 582 void ChromeLauncherControllerImpl::SetRefocusURLPatternForTest( |
| 597 ash::ShelfID id, | 583 ash::ShelfID id, |
| 598 const GURL& url) { | 584 const GURL& url) { |
| 599 LauncherItemController* controller = GetLauncherItemController(id); | |
| 600 DCHECK(controller); | |
| 601 | |
| 602 int index = model_->ItemIndexByID(id); | 585 int index = model_->ItemIndexByID(id); |
| 603 if (index == -1) { | 586 if (index == -1) { |
| 604 NOTREACHED() << "Invalid launcher id"; | 587 NOTREACHED() << "Invalid launcher id"; |
| 605 return; | 588 return; |
| 606 } | 589 } |
| 607 | 590 |
| 608 ash::ShelfItemType type = model_->items()[index].type; | 591 ash::ShelfItemType type = model_->items()[index].type; |
| 609 if (type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_WINDOWED_APP) { | 592 if ((type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_APP) && |
| 593 !IsPlatformApp(id)) { | |
| 594 LauncherItemController* controller = GetLauncherItemController(id); | |
|
Mr4D (OOO till 08-26)
2016/11/23 23:11:51
You might want to dcheck the controller?
msw
2016/11/24 00:00:55
I don't usually DCHECK immediately before a derefe
Mr4D (OOO till 08-26)
2016/11/24 02:21:33
I'd like that - Thanks!
msw
2016/11/28 20:13:31
Done.
| |
| 610 AppShortcutLauncherItemController* app_controller = | 595 AppShortcutLauncherItemController* app_controller = |
| 611 static_cast<AppShortcutLauncherItemController*>(controller); | 596 static_cast<AppShortcutLauncherItemController*>(controller); |
| 612 app_controller->set_refocus_url(url); | 597 app_controller->set_refocus_url(url); |
| 613 } else { | 598 } else { |
| 614 NOTREACHED() << "Invalid launcher type"; | 599 NOTREACHED() << "Invalid launcher type"; |
| 615 } | 600 } |
| 616 } | 601 } |
| 617 | 602 |
| 618 ash::ShelfItemDelegate::PerformedAction | 603 ash::ShelfItemDelegate::PerformedAction |
| 619 ChromeLauncherControllerImpl::ActivateWindowOrMinimizeIfActive( | 604 ChromeLauncherControllerImpl::ActivateWindowOrMinimizeIfActive( |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1022 return CreateAppShortcutLauncherItemWithType(app_launcher_id, index, | 1007 return CreateAppShortcutLauncherItemWithType(app_launcher_id, index, |
| 1023 ash::TYPE_APP_SHORTCUT); | 1008 ash::TYPE_APP_SHORTCUT); |
| 1024 } | 1009 } |
| 1025 | 1010 |
| 1026 /////////////////////////////////////////////////////////////////////////////// | 1011 /////////////////////////////////////////////////////////////////////////////// |
| 1027 // ChromeLauncherControllerImpl private: | 1012 // ChromeLauncherControllerImpl private: |
| 1028 | 1013 |
| 1029 void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() { | 1014 void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() { |
| 1030 RunningAppListIds list; | 1015 RunningAppListIds list; |
| 1031 for (int i = 0; i < model_->item_count(); i++) { | 1016 for (int i = 0; i < model_->item_count(); i++) { |
| 1032 ash::ShelfItemType type = model_->items()[i].type; | 1017 if (model_->items()[i].type == ash::TYPE_APP) |
| 1033 if (type == ash::TYPE_WINDOWED_APP || type == ash::TYPE_PLATFORM_APP) | |
| 1034 list.push_back(GetAppIDForShelfID(model_->items()[i].id)); | 1018 list.push_back(GetAppIDForShelfID(model_->items()[i].id)); |
| 1035 } | 1019 } |
| 1036 const std::string user_email = | 1020 const std::string user_email = |
| 1037 multi_user_util::GetAccountIdFromProfile(profile()).GetUserEmail(); | 1021 multi_user_util::GetAccountIdFromProfile(profile()).GetUserEmail(); |
| 1038 last_used_running_application_order_[user_email] = list; | 1022 last_used_running_application_order_[user_email] = list; |
| 1039 } | 1023 } |
| 1040 | 1024 |
| 1041 void ChromeLauncherControllerImpl::RestoreUnpinnedRunningApplicationOrder( | 1025 void ChromeLauncherControllerImpl::RestoreUnpinnedRunningApplicationOrder( |
| 1042 const std::string& user_id) { | 1026 const std::string& user_id) { |
| 1043 const RunningAppListIdMap::iterator app_id_list = | 1027 const RunningAppListIdMap::iterator app_id_list = |
| 1044 last_used_running_application_order_.find(user_id); | 1028 last_used_running_application_order_.find(user_id); |
| 1045 if (app_id_list == last_used_running_application_order_.end()) | 1029 if (app_id_list == last_used_running_application_order_.end()) |
| 1046 return; | 1030 return; |
| 1047 | 1031 |
| 1048 // Find the first insertion point for running applications. | 1032 // Find the first insertion point for running applications. |
| 1049 int running_index = model_->FirstRunningAppIndex(); | 1033 int running_index = model_->FirstRunningAppIndex(); |
| 1050 for (RunningAppListIds::iterator app_id = app_id_list->second.begin(); | 1034 for (RunningAppListIds::iterator app_id = app_id_list->second.begin(); |
| 1051 app_id != app_id_list->second.end(); ++app_id) { | 1035 app_id != app_id_list->second.end(); ++app_id) { |
| 1052 ash::ShelfID shelf_id = GetShelfIDForAppID(*app_id); | 1036 ash::ShelfID shelf_id = GetShelfIDForAppID(*app_id); |
| 1053 if (shelf_id) { | 1037 if (shelf_id) { |
| 1054 int app_index = model_->ItemIndexByID(shelf_id); | 1038 int app_index = model_->ItemIndexByID(shelf_id); |
| 1055 DCHECK_GE(app_index, 0); | 1039 DCHECK_GE(app_index, 0); |
| 1056 ash::ShelfItemType type = model_->items()[app_index].type; | 1040 if (model_->items()[app_index].type == ash::TYPE_APP) { |
| 1057 if (type == ash::TYPE_WINDOWED_APP || type == ash::TYPE_PLATFORM_APP) { | |
| 1058 if (running_index != app_index) | 1041 if (running_index != app_index) |
| 1059 model_->Move(running_index, app_index); | 1042 model_->Move(running_index, app_index); |
| 1060 running_index++; | 1043 running_index++; |
| 1061 } | 1044 } |
| 1062 } | 1045 } |
| 1063 } | 1046 } |
| 1064 } | 1047 } |
| 1065 | 1048 |
| 1066 ash::ShelfID | 1049 ash::ShelfID |
| 1067 ChromeLauncherControllerImpl::CreateAppShortcutLauncherItemWithType( | 1050 ChromeLauncherControllerImpl::CreateAppShortcutLauncherItemWithType( |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1115 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id); | 1098 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id); |
| 1116 if (shelf_id && IsPinned(shelf_id)) | 1099 if (shelf_id && IsPinned(shelf_id)) |
| 1117 UnpinAndUpdatePrefs(shelf_id, update_prefs); | 1100 UnpinAndUpdatePrefs(shelf_id, update_prefs); |
| 1118 } | 1101 } |
| 1119 | 1102 |
| 1120 void ChromeLauncherControllerImpl::PinRunningAppInternal( | 1103 void ChromeLauncherControllerImpl::PinRunningAppInternal( |
| 1121 int index, | 1104 int index, |
| 1122 ash::ShelfID shelf_id) { | 1105 ash::ShelfID shelf_id) { |
| 1123 int running_index = model_->ItemIndexByID(shelf_id); | 1106 int running_index = model_->ItemIndexByID(shelf_id); |
| 1124 ash::ShelfItem item = model_->items()[running_index]; | 1107 ash::ShelfItem item = model_->items()[running_index]; |
| 1125 DCHECK(item.type == ash::TYPE_WINDOWED_APP || | 1108 DCHECK_EQ(item.type, ash::TYPE_APP); |
| 1126 item.type == ash::TYPE_PLATFORM_APP); | |
| 1127 item.type = ash::TYPE_APP_SHORTCUT; | 1109 item.type = ash::TYPE_APP_SHORTCUT; |
| 1128 model_->Set(running_index, item); | 1110 model_->Set(running_index, item); |
| 1129 // The |ShelfModel|'s weight system might reposition the item to a | 1111 // The |ShelfModel|'s weight system might reposition the item to a |
| 1130 // new index, so we get the index again. | 1112 // new index, so we get the index again. |
| 1131 running_index = model_->ItemIndexByID(shelf_id); | 1113 running_index = model_->ItemIndexByID(shelf_id); |
| 1132 if (running_index < index) | 1114 if (running_index < index) |
| 1133 --index; | 1115 --index; |
| 1134 if (running_index != index) | 1116 if (running_index != index) |
| 1135 model_->Move(running_index, index); | 1117 model_->Move(running_index, index); |
| 1136 } | 1118 } |
| 1137 | 1119 |
| 1138 void ChromeLauncherControllerImpl::UnpinRunningAppInternal(int index) { | 1120 void ChromeLauncherControllerImpl::UnpinRunningAppInternal(int index) { |
| 1139 DCHECK_GE(index, 0); | 1121 DCHECK_GE(index, 0); |
| 1140 ash::ShelfItem item = model_->items()[index]; | 1122 ash::ShelfItem item = model_->items()[index]; |
| 1141 DCHECK_EQ(item.type, ash::TYPE_APP_SHORTCUT); | 1123 DCHECK_EQ(item.type, ash::TYPE_APP_SHORTCUT); |
| 1142 item.type = ash::TYPE_WINDOWED_APP; | 1124 item.type = ash::TYPE_APP; |
| 1143 // A platform app and a windowed app are sharing TYPE_APP_SHORTCUT. As such | |
| 1144 // we have to check here what this was before it got a shortcut. | |
| 1145 LauncherItemController* controller = GetLauncherItemController(item.id); | |
| 1146 if (controller && controller->type() == LauncherItemController::TYPE_APP) | |
| 1147 item.type = ash::TYPE_PLATFORM_APP; | |
| 1148 model_->Set(index, item); | 1125 model_->Set(index, item); |
| 1149 } | 1126 } |
| 1150 | 1127 |
| 1151 void ChromeLauncherControllerImpl::SyncPinPosition(ash::ShelfID shelf_id) { | 1128 void ChromeLauncherControllerImpl::SyncPinPosition(ash::ShelfID shelf_id) { |
| 1152 DCHECK(shelf_id); | 1129 DCHECK(shelf_id); |
| 1153 if (ignore_persist_pinned_state_change_) | 1130 if (ignore_persist_pinned_state_change_) |
| 1154 return; | 1131 return; |
| 1155 | 1132 |
| 1156 const int max_index = model_->item_count(); | 1133 const int max_index = model_->item_count(); |
| 1157 const int index = model_->ItemIndexByID(shelf_id); | 1134 const int index = model_->ItemIndexByID(shelf_id); |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1550 LauncherItemController* controller = GetLauncherItemController(item.id); | 1527 LauncherItemController* controller = GetLauncherItemController(item.id); |
| 1551 if (!controller || controller->image_set_by_controller()) | 1528 if (!controller || controller->image_set_by_controller()) |
| 1552 continue; | 1529 continue; |
| 1553 item.image = image; | 1530 item.image = image; |
| 1554 if (arc_deferred_launcher_) | 1531 if (arc_deferred_launcher_) |
| 1555 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); | 1532 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); |
| 1556 model_->Set(index, item); | 1533 model_->Set(index, item); |
| 1557 // It's possible we're waiting on more than one item, so don't break. | 1534 // It's possible we're waiting on more than one item, so don't break. |
| 1558 } | 1535 } |
| 1559 } | 1536 } |
| OLD | NEW |