| 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 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 item.type = ash::TYPE_APP_SHORTCUT; | 388 item.type = ash::TYPE_APP_SHORTCUT; |
| 389 model_->Set(index, item); | 389 model_->Set(index, item); |
| 390 } else if (item.type != ash::TYPE_APP_SHORTCUT) { | 390 } else if (item.type != ash::TYPE_APP_SHORTCUT) { |
| 391 return; | 391 return; |
| 392 } | 392 } |
| 393 | 393 |
| 394 SyncPinPosition(id); | 394 SyncPinPosition(id); |
| 395 } | 395 } |
| 396 | 396 |
| 397 void ChromeLauncherControllerImpl::Unpin(ash::ShelfID id) { | 397 void ChromeLauncherControllerImpl::Unpin(ash::ShelfID id) { |
| 398 UnpinAndUpdatePrefs(id, true /* update_prefs */); |
| 399 } |
| 400 |
| 401 void ChromeLauncherControllerImpl::UnpinAndUpdatePrefs(ash::ShelfID id, |
| 402 bool update_prefs) { |
| 398 LauncherItemController* controller = GetLauncherItemController(id); | 403 LauncherItemController* controller = GetLauncherItemController(id); |
| 399 CHECK(controller); | 404 CHECK(controller); |
| 400 | 405 |
| 401 ash::launcher::RemovePinPosition(profile_, GetAppIDForShelfID(id)); | 406 if (update_prefs) |
| 407 ash::launcher::RemovePinPosition(profile_, GetAppIDForShelfID(id)); |
| 402 | 408 |
| 403 if (controller->type() == LauncherItemController::TYPE_APP || | 409 if (controller->type() == LauncherItemController::TYPE_APP || |
| 404 controller->locked()) { | 410 controller->locked()) { |
| 405 UnpinRunningAppInternal(model_->ItemIndexByID(id)); | 411 UnpinRunningAppInternal(model_->ItemIndexByID(id)); |
| 406 } else { | 412 } else { |
| 407 LauncherItemClosed(id); | 413 LauncherItemClosed(id); |
| 408 } | 414 } |
| 409 } | 415 } |
| 410 | 416 |
| 411 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) { | 417 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) { |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 i != id_to_item_controller_map_.end(); ++i) { | 950 i != id_to_item_controller_map_.end(); ++i) { |
| 945 if (IsPinned(i->first) && i->second->app_id() == app_id) | 951 if (IsPinned(i->first) && i->second->app_id() == app_id) |
| 946 return true; | 952 return true; |
| 947 } | 953 } |
| 948 return false; | 954 return false; |
| 949 } | 955 } |
| 950 | 956 |
| 951 void ChromeLauncherControllerImpl::UnpinAppWithID(const std::string& app_id) { | 957 void ChromeLauncherControllerImpl::UnpinAppWithID(const std::string& app_id) { |
| 952 if (GetPinnableForAppID(app_id, profile_) == | 958 if (GetPinnableForAppID(app_id, profile_) == |
| 953 AppListControllerDelegate::PIN_EDITABLE) | 959 AppListControllerDelegate::PIN_EDITABLE) |
| 954 DoUnpinAppWithID(app_id); | 960 DoUnpinAppWithID(app_id, true /* update_prefs */); |
| 955 else | 961 else |
| 956 NOTREACHED(); | 962 NOTREACHED(); |
| 957 } | 963 } |
| 958 | 964 |
| 959 /////////////////////////////////////////////////////////////////////////////// | 965 /////////////////////////////////////////////////////////////////////////////// |
| 960 // LauncherAppUpdater::Delegate: | 966 // LauncherAppUpdater::Delegate: |
| 961 | 967 |
| 962 void ChromeLauncherControllerImpl::OnAppInstalled( | 968 void ChromeLauncherControllerImpl::OnAppInstalled( |
| 963 content::BrowserContext* browser_context, | 969 content::BrowserContext* browser_context, |
| 964 const std::string& app_id) { | 970 const std::string& app_id) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 985 void ChromeLauncherControllerImpl::OnAppUninstalledPrepared( | 991 void ChromeLauncherControllerImpl::OnAppUninstalledPrepared( |
| 986 content::BrowserContext* browser_context, | 992 content::BrowserContext* browser_context, |
| 987 const std::string& app_id) { | 993 const std::string& app_id) { |
| 988 // Since we might have windowed apps of this type which might have | 994 // Since we might have windowed apps of this type which might have |
| 989 // outstanding locks which needs to be removed. | 995 // outstanding locks which needs to be removed. |
| 990 const Profile* profile = Profile::FromBrowserContext(browser_context); | 996 const Profile* profile = Profile::FromBrowserContext(browser_context); |
| 991 if (GetShelfIDForAppID(app_id)) | 997 if (GetShelfIDForAppID(app_id)) |
| 992 CloseWindowedAppsFromRemovedExtension(app_id, profile); | 998 CloseWindowedAppsFromRemovedExtension(app_id, profile); |
| 993 | 999 |
| 994 if (IsAppPinned(app_id)) { | 1000 if (IsAppPinned(app_id)) { |
| 995 if (profile == profile_) | 1001 if (profile == profile_) { |
| 996 DoUnpinAppWithID(app_id); | 1002 // Some apps may be removed locally. Don't remove pin position from sync |
| 1003 // model. When needed, it is automatically deleted on app list model |
| 1004 // update. |
| 1005 DoUnpinAppWithID(app_id, false /* update_prefs */); |
| 1006 } |
| 997 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); | 1007 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); |
| 998 if (app_icon_loader) | 1008 if (app_icon_loader) |
| 999 app_icon_loader->ClearImage(app_id); | 1009 app_icon_loader->ClearImage(app_id); |
| 1000 } | 1010 } |
| 1001 } | 1011 } |
| 1002 | 1012 |
| 1003 /////////////////////////////////////////////////////////////////////////////// | 1013 /////////////////////////////////////////////////////////////////////////////// |
| 1004 // ChromeLauncherControllerImpl protected: | 1014 // ChromeLauncherControllerImpl protected: |
| 1005 | 1015 |
| 1006 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem( | 1016 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem( |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 if (shelf_id) { | 1125 if (shelf_id) { |
| 1116 // App item exists, pin it | 1126 // App item exists, pin it |
| 1117 Pin(shelf_id); | 1127 Pin(shelf_id); |
| 1118 } else { | 1128 } else { |
| 1119 // Otherwise, create a shortcut item for it. | 1129 // Otherwise, create a shortcut item for it. |
| 1120 shelf_id = CreateAppShortcutLauncherItem(app_id, model_->item_count()); | 1130 shelf_id = CreateAppShortcutLauncherItem(app_id, model_->item_count()); |
| 1121 SyncPinPosition(shelf_id); | 1131 SyncPinPosition(shelf_id); |
| 1122 } | 1132 } |
| 1123 } | 1133 } |
| 1124 | 1134 |
| 1125 void ChromeLauncherControllerImpl::DoUnpinAppWithID(const std::string& app_id) { | 1135 void ChromeLauncherControllerImpl::DoUnpinAppWithID(const std::string& app_id, |
| 1136 bool update_prefs) { |
| 1126 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id); | 1137 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id); |
| 1127 if (shelf_id && IsPinned(shelf_id)) | 1138 if (shelf_id && IsPinned(shelf_id)) |
| 1128 Unpin(shelf_id); | 1139 UnpinAndUpdatePrefs(shelf_id, update_prefs); |
| 1129 } | 1140 } |
| 1130 | 1141 |
| 1131 int ChromeLauncherControllerImpl::PinRunningAppInternal(int index, | 1142 int ChromeLauncherControllerImpl::PinRunningAppInternal(int index, |
| 1132 ash::ShelfID shelf_id) { | 1143 ash::ShelfID shelf_id) { |
| 1133 int running_index = model_->ItemIndexByID(shelf_id); | 1144 int running_index = model_->ItemIndexByID(shelf_id); |
| 1134 ash::ShelfItem item = model_->items()[running_index]; | 1145 ash::ShelfItem item = model_->items()[running_index]; |
| 1135 DCHECK(item.type == ash::TYPE_WINDOWED_APP || | 1146 DCHECK(item.type == ash::TYPE_WINDOWED_APP || |
| 1136 item.type == ash::TYPE_PLATFORM_APP); | 1147 item.type == ash::TYPE_PLATFORM_APP); |
| 1137 item.type = ash::TYPE_APP_SHORTCUT; | 1148 item.type = ash::TYPE_APP_SHORTCUT; |
| 1138 model_->Set(running_index, item); | 1149 model_->Set(running_index, item); |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1701 if (index == -1) | 1712 if (index == -1) |
| 1702 continue; | 1713 continue; |
| 1703 ash::ShelfItem item = model_->items()[index]; | 1714 ash::ShelfItem item = model_->items()[index]; |
| 1704 item.image = image; | 1715 item.image = image; |
| 1705 if (arc_deferred_launcher_) | 1716 if (arc_deferred_launcher_) |
| 1706 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); | 1717 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); |
| 1707 model_->Set(index, item); | 1718 model_->Set(index, item); |
| 1708 // It's possible we're waiting on more than one item, so don't break. | 1719 // It's possible we're waiting on more than one item, so don't break. |
| 1709 } | 1720 } |
| 1710 } | 1721 } |
| OLD | NEW |