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

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

Issue 1919593003: arc: Prevent showing Opt-in UI when it is not expected. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: TODO added Created 4 years, 7 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.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 *app_list_icon_added = true; 215 *app_list_icon_added = true;
216 pinned_apps->push_back(kAppShelfIdPlaceholder); 216 pinned_apps->push_back(kAppShelfIdPlaceholder);
217 } else if (valid_for_current_user) { 217 } else if (valid_for_current_user) {
218 // Note: In multi profile scenarios we only want to show pinnable apps 218 // Note: In multi profile scenarios we only want to show pinnable apps
219 // here which is correct. Running applications from the other users will 219 // here which is correct. Running applications from the other users will
220 // continue to run. So no need for multi profile modifications. 220 // continue to run. So no need for multi profile modifications.
221 pinned_apps->push_back(app_id); 221 pinned_apps->push_back(app_id);
222 } 222 }
223 } 223 }
224 224
225 const char* const kPinProhibitedExtensionIds[] = {
226 #if defined(OS_CHROMEOS)
227 "cnbgggchhmkkdmeppjobngjoejnihlei", // Arc Support
228 #endif
229 };
230
231 const size_t kPinProhibitedExtensionIdsLength =
232 arraysize(kPinProhibitedExtensionIds);
233
225 } // namespace 234 } // namespace
226 235
227 #if defined(OS_CHROMEOS) 236 #if defined(OS_CHROMEOS)
228 // A class to get events from ChromeOS when a user gets changed or added. 237 // A class to get events from ChromeOS when a user gets changed or added.
229 class ChromeLauncherControllerUserSwitchObserver 238 class ChromeLauncherControllerUserSwitchObserver
230 : public user_manager::UserManager::UserSessionStateObserver { 239 : public user_manager::UserManager::UserSessionStateObserver {
231 public: 240 public:
232 ChromeLauncherControllerUserSwitchObserver( 241 ChromeLauncherControllerUserSwitchObserver(
233 ChromeLauncherController* controller) 242 ChromeLauncherController* controller)
234 : controller_(controller) { 243 : controller_(controller) {
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 std::string app_id = iter->second->app_id(); 505 std::string app_id = iter->second->app_id();
497 iter->second = new AppShortcutLauncherItemController(app_id, this); 506 iter->second = new AppShortcutLauncherItemController(app_id, this);
498 iter->second->set_shelf_id(id); 507 iter->second->set_shelf_id(id);
499 // Existing controller is destroyed and replaced by registering again. 508 // Existing controller is destroyed and replaced by registering again.
500 SetShelfItemDelegate(id, iter->second); 509 SetShelfItemDelegate(id, iter->second);
501 } else { 510 } else {
502 LauncherItemClosed(id); 511 LauncherItemClosed(id);
503 } 512 }
504 } 513 }
505 514
506 bool ChromeLauncherController::CanPin(const std::string& app_id) { 515 AppListControllerDelegate::Pinnable ChromeLauncherController::GetPinnable(
516 const std::string& app_id) {
517 for (size_t i = 0; i < kPinProhibitedExtensionIdsLength; ++i) {
518 if (kPinProhibitedExtensionIds[i] == app_id)
519 return AppListControllerDelegate::NO_PIN;
520 }
521
507 const base::ListValue* pref = 522 const base::ListValue* pref =
508 profile_->GetPrefs()->GetList(prefs::kPolicyPinnedLauncherApps); 523 profile_->GetPrefs()->GetList(prefs::kPolicyPinnedLauncherApps);
509 if (!pref) 524 if (!pref)
510 return true; 525 return AppListControllerDelegate::PIN_EDITABLE;
511 for (size_t index = 0; index < pref->GetSize(); ++index) { 526 for (size_t index = 0; index < pref->GetSize(); ++index) {
512 const base::DictionaryValue* app = nullptr; 527 const base::DictionaryValue* app = nullptr;
513 std::string the_app_id; 528 std::string the_app_id;
514 if (pref->GetDictionary(index, &app) && 529 if (pref->GetDictionary(index, &app) &&
515 app->GetString(ash::kPinnedAppsPrefAppIDPath, &the_app_id) && 530 app->GetString(ash::kPinnedAppsPrefAppIDPath, &the_app_id) &&
516 app_id == the_app_id) 531 app_id == the_app_id)
517 return false; 532 return AppListControllerDelegate::PIN_FIXED;
518 } 533 }
519 return true; 534 return AppListControllerDelegate::PIN_EDITABLE;
520 } 535 }
521 536
522 void ChromeLauncherController::Pin(ash::ShelfID id) { 537 void ChromeLauncherController::Pin(ash::ShelfID id) {
523 DCHECK(HasShelfIDToAppIDMapping(id)); 538 DCHECK(HasShelfIDToAppIDMapping(id));
524 539
525 int index = model_->ItemIndexByID(id); 540 int index = model_->ItemIndexByID(id);
526 DCHECK_GE(index, 0); 541 DCHECK_GE(index, 0);
527 542
528 ash::ShelfItem item = model_->items()[index]; 543 ash::ShelfItem item = model_->items()[index];
529 544
530 if (item.type == ash::TYPE_PLATFORM_APP || 545 if (item.type == ash::TYPE_PLATFORM_APP ||
531 item.type == ash::TYPE_WINDOWED_APP) { 546 item.type == ash::TYPE_WINDOWED_APP) {
532 item.type = ash::TYPE_APP_SHORTCUT; 547 item.type = ash::TYPE_APP_SHORTCUT;
533 model_->Set(index, item); 548 model_->Set(index, item);
534 } else if (item.type != ash::TYPE_APP_SHORTCUT) { 549 } else if (item.type != ash::TYPE_APP_SHORTCUT) {
535 return; 550 return;
536 } 551 }
537 552
538 if (GetLauncherItemController(id)->CanPin()) 553 if (GetLauncherItemController(id)->CanPin())
539 PersistPinnedState(); 554 PersistPinnedState();
540 } 555 }
541 556
542 void ChromeLauncherController::Unpin(ash::ShelfID id) { 557 void ChromeLauncherController::Unpin(ash::ShelfID id) {
543 LauncherItemController* controller = GetLauncherItemController(id); 558 LauncherItemController* controller = GetLauncherItemController(id);
544 CHECK(controller); 559 CHECK(controller);
545 bool can_pin = controller->CanPin(); 560 const bool can_pin = controller->CanPin();
546 561
547 if (controller->type() == LauncherItemController::TYPE_APP || 562 if (controller->type() == LauncherItemController::TYPE_APP ||
548 controller->locked()) { 563 controller->locked()) {
549 UnpinRunningAppInternal(model_->ItemIndexByID(id)); 564 UnpinRunningAppInternal(model_->ItemIndexByID(id));
550 } else { 565 } else {
551 LauncherItemClosed(id); 566 LauncherItemClosed(id);
552 } 567 }
553 if (can_pin) 568 if (can_pin)
554 PersistPinnedState(); 569 PersistPinnedState();
555 } 570 }
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 const std::string& app_id) { 799 const std::string& app_id) {
785 int index = model_->ItemIndexByID(GetShelfIDForAppID(app_id)); 800 int index = model_->ItemIndexByID(GetShelfIDForAppID(app_id));
786 if (index < 0) 801 if (index < 0)
787 return false; 802 return false;
788 803
789 ash::ShelfItemType type = model_->items()[index].type; 804 ash::ShelfItemType type = model_->items()[index].type;
790 return type == ash::TYPE_WINDOWED_APP; 805 return type == ash::TYPE_WINDOWED_APP;
791 } 806 }
792 807
793 void ChromeLauncherController::PinAppWithID(const std::string& app_id) { 808 void ChromeLauncherController::PinAppWithID(const std::string& app_id) {
794 if (CanPin(app_id)) 809 if (GetPinnable(app_id) == AppListControllerDelegate::PIN_EDITABLE)
795 DoPinAppWithID(app_id); 810 DoPinAppWithID(app_id);
796 else 811 else
797 NOTREACHED(); 812 NOTREACHED();
798 } 813 }
799 814
800 void ChromeLauncherController::SetLaunchType( 815 void ChromeLauncherController::SetLaunchType(
801 ash::ShelfID id, 816 ash::ShelfID id,
802 extensions::LaunchType launch_type) { 817 extensions::LaunchType launch_type) {
803 LauncherItemController* controller = GetLauncherItemController(id); 818 LauncherItemController* controller = GetLauncherItemController(id);
804 if (!controller) 819 if (!controller)
805 return; 820 return;
806 821
807 extensions::SetLaunchType(profile_, controller->app_id(), launch_type); 822 extensions::SetLaunchType(profile_, controller->app_id(), launch_type);
808 } 823 }
809 824
810 void ChromeLauncherController::UnpinAppWithID(const std::string& app_id) { 825 void ChromeLauncherController::UnpinAppWithID(const std::string& app_id) {
811 if (CanPin(app_id)) 826 if (GetPinnable(app_id) == AppListControllerDelegate::PIN_EDITABLE)
812 DoUnpinAppWithID(app_id); 827 DoUnpinAppWithID(app_id);
813 else 828 else
814 NOTREACHED(); 829 NOTREACHED();
815 } 830 }
816 831
817 void ChromeLauncherController::OnSetShelfItemDelegate( 832 void ChromeLauncherController::OnSetShelfItemDelegate(
818 ash::ShelfID id, 833 ash::ShelfID id,
819 ash::ShelfItemDelegate* item_delegate) { 834 ash::ShelfItemDelegate* item_delegate) {
820 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we 835 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we
821 // get into this state in the first place. 836 // get into this state in the first place.
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 if (IsAppPinned(app_id)) 1460 if (IsAppPinned(app_id))
1446 return; 1461 return;
1447 1462
1448 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id); 1463 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id);
1449 if (shelf_id) { 1464 if (shelf_id) {
1450 // App item exists, pin it 1465 // App item exists, pin it
1451 Pin(shelf_id); 1466 Pin(shelf_id);
1452 } else { 1467 } else {
1453 // Otherwise, create a shortcut item for it. 1468 // Otherwise, create a shortcut item for it.
1454 shelf_id = CreateAppShortcutLauncherItem(app_id, model_->item_count()); 1469 shelf_id = CreateAppShortcutLauncherItem(app_id, model_->item_count());
1455 if (CanPin(app_id)) 1470 if (GetPinnable(app_id) == AppListControllerDelegate::PIN_EDITABLE)
1456 PersistPinnedState(); 1471 PersistPinnedState();
1457 } 1472 }
1458 } 1473 }
1459 1474
1460 void ChromeLauncherController::DoUnpinAppWithID(const std::string& app_id) { 1475 void ChromeLauncherController::DoUnpinAppWithID(const std::string& app_id) {
1461 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id); 1476 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id);
1462 if (shelf_id && IsPinned(shelf_id)) 1477 if (shelf_id && IsPinned(shelf_id))
1463 Unpin(shelf_id); 1478 Unpin(shelf_id);
1464 } 1479 }
1465 1480
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
2063 2078
2064 AppIconLoader* ChromeLauncherController::GetAppIconLoaderForApp( 2079 AppIconLoader* ChromeLauncherController::GetAppIconLoaderForApp(
2065 const std::string& app_id) { 2080 const std::string& app_id) {
2066 for (const auto& app_icon_loader : app_icon_loaders_) { 2081 for (const auto& app_icon_loader : app_icon_loaders_) {
2067 if (app_icon_loader->CanLoadImageForApp(app_id)) 2082 if (app_icon_loader->CanLoadImageForApp(app_id))
2068 return app_icon_loader.get(); 2083 return app_icon_loader.get();
2069 } 2084 }
2070 2085
2071 return nullptr; 2086 return nullptr;
2072 } 2087 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698