| 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 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 } | 1114 } |
| 1115 | 1115 |
| 1116 void ChromeLauncherControllerImpl::UnpinAppWithID(const std::string& app_id) { | 1116 void ChromeLauncherControllerImpl::UnpinAppWithID(const std::string& app_id) { |
| 1117 if (GetPinnable(app_id) == AppListControllerDelegate::PIN_EDITABLE) | 1117 if (GetPinnable(app_id) == AppListControllerDelegate::PIN_EDITABLE) |
| 1118 DoUnpinAppWithID(app_id); | 1118 DoUnpinAppWithID(app_id); |
| 1119 else | 1119 else |
| 1120 NOTREACHED(); | 1120 NOTREACHED(); |
| 1121 } | 1121 } |
| 1122 | 1122 |
| 1123 /////////////////////////////////////////////////////////////////////////////// | 1123 /////////////////////////////////////////////////////////////////////////////// |
| 1124 // ash::ShelfItemDelegateManagerObserver: | 1124 // LauncherAppUpdater::Delegate: |
| 1125 | |
| 1126 void ChromeLauncherControllerImpl::OnSetShelfItemDelegate( | |
| 1127 ash::ShelfID id, | |
| 1128 ash::ShelfItemDelegate* item_delegate) { | |
| 1129 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we | |
| 1130 // get into this state in the first place. | |
| 1131 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); | |
| 1132 if (iter == id_to_item_controller_map_.end() || item_delegate == iter->second) | |
| 1133 return; | |
| 1134 LOG(ERROR) << "Unexpected change of shelf item id: " << id; | |
| 1135 id_to_item_controller_map_.erase(iter); | |
| 1136 } | |
| 1137 | |
| 1138 /////////////////////////////////////////////////////////////////////////////// | |
| 1139 // ash::ShelfModelObserver: | |
| 1140 | |
| 1141 void ChromeLauncherControllerImpl::ShelfItemAdded(int index) { | |
| 1142 // The app list launcher can get added to the shelf after we applied the | |
| 1143 // preferences. In that case the item might be at the wrong spot. As such we | |
| 1144 // call the function again. | |
| 1145 if (model_->items()[index].type == ash::TYPE_APP_LIST) | |
| 1146 UpdateAppLaunchersFromPref(); | |
| 1147 } | |
| 1148 | |
| 1149 void ChromeLauncherControllerImpl::ShelfItemRemoved(int index, | |
| 1150 ash::ShelfID id) { | |
| 1151 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we | |
| 1152 // get into this state in the first place. | |
| 1153 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); | |
| 1154 if (iter == id_to_item_controller_map_.end()) | |
| 1155 return; | |
| 1156 | |
| 1157 LOG(ERROR) << "Unexpected change of shelf item id: " << id; | |
| 1158 | |
| 1159 id_to_item_controller_map_.erase(iter); | |
| 1160 } | |
| 1161 | |
| 1162 void ChromeLauncherControllerImpl::ShelfItemMoved(int start_index, | |
| 1163 int target_index) { | |
| 1164 const ash::ShelfItem& item = model_->items()[target_index]; | |
| 1165 // We remember the moved item position if it is either pinnable or | |
| 1166 // it is the app list with the alternate shelf layout. | |
| 1167 if ((HasShelfIDToAppIDMapping(item.id) && IsPinned(item.id)) || | |
| 1168 item.type == ash::TYPE_APP_LIST) | |
| 1169 PersistPinnedState(); | |
| 1170 } | |
| 1171 | |
| 1172 void ChromeLauncherControllerImpl::ShelfItemChanged( | |
| 1173 int index, | |
| 1174 const ash::ShelfItem& old_item) {} | |
| 1175 | |
| 1176 /////////////////////////////////////////////////////////////////////////////// | |
| 1177 // ash::WindowTreeHostManager::Observer: | |
| 1178 | |
| 1179 void ChromeLauncherControllerImpl::OnDisplayConfigurationChanged() { | |
| 1180 SetShelfBehaviorsFromPrefs(); | |
| 1181 } | |
| 1182 | |
| 1183 /////////////////////////////////////////////////////////////////////////////// | |
| 1184 // LauncherAppUpdater: | |
| 1185 | 1125 |
| 1186 void ChromeLauncherControllerImpl::OnAppInstalled( | 1126 void ChromeLauncherControllerImpl::OnAppInstalled( |
| 1187 content::BrowserContext* browser_context, | 1127 content::BrowserContext* browser_context, |
| 1188 const std::string& app_id) { | 1128 const std::string& app_id) { |
| 1189 if (IsAppPinned(app_id)) { | 1129 if (IsAppPinned(app_id)) { |
| 1190 // Clear and re-fetch to ensure icon is up-to-date. | 1130 // Clear and re-fetch to ensure icon is up-to-date. |
| 1191 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); | 1131 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); |
| 1192 if (app_icon_loader) { | 1132 if (app_icon_loader) { |
| 1193 app_icon_loader->ClearImage(app_id); | 1133 app_icon_loader->ClearImage(app_id); |
| 1194 app_icon_loader->FetchImage(app_id); | 1134 app_icon_loader->FetchImage(app_id); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1218 if (IsAppPinned(app_id)) { | 1158 if (IsAppPinned(app_id)) { |
| 1219 if (profile == profile_) | 1159 if (profile == profile_) |
| 1220 DoUnpinAppWithID(app_id); | 1160 DoUnpinAppWithID(app_id); |
| 1221 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); | 1161 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); |
| 1222 if (app_icon_loader) | 1162 if (app_icon_loader) |
| 1223 app_icon_loader->ClearImage(app_id); | 1163 app_icon_loader->ClearImage(app_id); |
| 1224 } | 1164 } |
| 1225 } | 1165 } |
| 1226 | 1166 |
| 1227 /////////////////////////////////////////////////////////////////////////////// | 1167 /////////////////////////////////////////////////////////////////////////////// |
| 1228 // AppSyncUIStateObserver: | |
| 1229 | |
| 1230 void ChromeLauncherControllerImpl::OnAppSyncUIStatusChanged() { | |
| 1231 if (app_sync_ui_state_->status() == AppSyncUIState::STATUS_SYNCING) | |
| 1232 model_->set_status(ash::ShelfModel::STATUS_LOADING); | |
| 1233 else | |
| 1234 model_->set_status(ash::ShelfModel::STATUS_NORMAL); | |
| 1235 } | |
| 1236 | |
| 1237 /////////////////////////////////////////////////////////////////////////////// | |
| 1238 // AppIconLoaderDelegate: | |
| 1239 | |
| 1240 void ChromeLauncherControllerImpl::OnAppImageUpdated( | |
| 1241 const std::string& id, | |
| 1242 const gfx::ImageSkia& image) { | |
| 1243 // TODO: need to get this working for shortcuts. | |
| 1244 for (IDToItemControllerMap::const_iterator i = | |
| 1245 id_to_item_controller_map_.begin(); | |
| 1246 i != id_to_item_controller_map_.end(); ++i) { | |
| 1247 LauncherItemController* controller = i->second; | |
| 1248 if (controller->app_id() != id) | |
| 1249 continue; | |
| 1250 if (controller->image_set_by_controller()) | |
| 1251 continue; | |
| 1252 int index = model_->ItemIndexByID(i->first); | |
| 1253 if (index == -1) | |
| 1254 continue; | |
| 1255 ash::ShelfItem item = model_->items()[index]; | |
| 1256 item.image = image; | |
| 1257 model_->Set(index, item); | |
| 1258 // It's possible we're waiting on more than one item, so don't break. | |
| 1259 } | |
| 1260 } | |
| 1261 | |
| 1262 /////////////////////////////////////////////////////////////////////////////// | |
| 1263 // ChromeLauncherControllerImpl protected: | 1168 // ChromeLauncherControllerImpl protected: |
| 1264 | 1169 |
| 1265 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem( | 1170 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem( |
| 1266 const std::string& app_id, | 1171 const std::string& app_id, |
| 1267 int index) { | 1172 int index) { |
| 1268 return CreateAppShortcutLauncherItemWithType(app_id, index, | 1173 return CreateAppShortcutLauncherItemWithType(app_id, index, |
| 1269 ash::TYPE_APP_SHORTCUT); | 1174 ash::TYPE_APP_SHORTCUT); |
| 1270 } | 1175 } |
| 1271 | 1176 |
| 1272 void ChromeLauncherControllerImpl::SetLauncherControllerHelperForTest( | 1177 void ChromeLauncherControllerImpl::SetLauncherControllerHelperForTest( |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1882 | 1787 |
| 1883 AppIconLoader* ChromeLauncherControllerImpl::GetAppIconLoaderForApp( | 1788 AppIconLoader* ChromeLauncherControllerImpl::GetAppIconLoaderForApp( |
| 1884 const std::string& app_id) { | 1789 const std::string& app_id) { |
| 1885 for (const auto& app_icon_loader : app_icon_loaders_) { | 1790 for (const auto& app_icon_loader : app_icon_loaders_) { |
| 1886 if (app_icon_loader->CanLoadImageForApp(app_id)) | 1791 if (app_icon_loader->CanLoadImageForApp(app_id)) |
| 1887 return app_icon_loader.get(); | 1792 return app_icon_loader.get(); |
| 1888 } | 1793 } |
| 1889 | 1794 |
| 1890 return nullptr; | 1795 return nullptr; |
| 1891 } | 1796 } |
| 1797 |
| 1798 /////////////////////////////////////////////////////////////////////////////// |
| 1799 // ash::ShelfItemDelegateManagerObserver: |
| 1800 |
| 1801 void ChromeLauncherControllerImpl::OnSetShelfItemDelegate( |
| 1802 ash::ShelfID id, |
| 1803 ash::ShelfItemDelegate* item_delegate) { |
| 1804 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we |
| 1805 // get into this state in the first place. |
| 1806 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); |
| 1807 if (iter == id_to_item_controller_map_.end() || item_delegate == iter->second) |
| 1808 return; |
| 1809 LOG(ERROR) << "Unexpected change of shelf item id: " << id; |
| 1810 id_to_item_controller_map_.erase(iter); |
| 1811 } |
| 1812 |
| 1813 /////////////////////////////////////////////////////////////////////////////// |
| 1814 // ash::ShelfModelObserver: |
| 1815 |
| 1816 void ChromeLauncherControllerImpl::ShelfItemAdded(int index) { |
| 1817 // The app list launcher can get added to the shelf after we applied the |
| 1818 // preferences. In that case the item might be at the wrong spot. As such we |
| 1819 // call the function again. |
| 1820 if (model_->items()[index].type == ash::TYPE_APP_LIST) |
| 1821 UpdateAppLaunchersFromPref(); |
| 1822 } |
| 1823 |
| 1824 void ChromeLauncherControllerImpl::ShelfItemRemoved(int index, |
| 1825 ash::ShelfID id) { |
| 1826 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we |
| 1827 // get into this state in the first place. |
| 1828 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); |
| 1829 if (iter == id_to_item_controller_map_.end()) |
| 1830 return; |
| 1831 |
| 1832 LOG(ERROR) << "Unexpected change of shelf item id: " << id; |
| 1833 |
| 1834 id_to_item_controller_map_.erase(iter); |
| 1835 } |
| 1836 |
| 1837 void ChromeLauncherControllerImpl::ShelfItemMoved(int start_index, |
| 1838 int target_index) { |
| 1839 const ash::ShelfItem& item = model_->items()[target_index]; |
| 1840 // We remember the moved item position if it is either pinnable or |
| 1841 // it is the app list with the alternate shelf layout. |
| 1842 if ((HasShelfIDToAppIDMapping(item.id) && IsPinned(item.id)) || |
| 1843 item.type == ash::TYPE_APP_LIST) |
| 1844 PersistPinnedState(); |
| 1845 } |
| 1846 |
| 1847 void ChromeLauncherControllerImpl::ShelfItemChanged( |
| 1848 int index, |
| 1849 const ash::ShelfItem& old_item) {} |
| 1850 |
| 1851 /////////////////////////////////////////////////////////////////////////////// |
| 1852 // ash::WindowTreeHostManager::Observer: |
| 1853 |
| 1854 void ChromeLauncherControllerImpl::OnDisplayConfigurationChanged() { |
| 1855 SetShelfBehaviorsFromPrefs(); |
| 1856 } |
| 1857 |
| 1858 /////////////////////////////////////////////////////////////////////////////// |
| 1859 // AppSyncUIStateObserver: |
| 1860 |
| 1861 void ChromeLauncherControllerImpl::OnAppSyncUIStatusChanged() { |
| 1862 if (app_sync_ui_state_->status() == AppSyncUIState::STATUS_SYNCING) |
| 1863 model_->set_status(ash::ShelfModel::STATUS_LOADING); |
| 1864 else |
| 1865 model_->set_status(ash::ShelfModel::STATUS_NORMAL); |
| 1866 } |
| 1867 |
| 1868 /////////////////////////////////////////////////////////////////////////////// |
| 1869 // AppIconLoaderDelegate: |
| 1870 |
| 1871 void ChromeLauncherControllerImpl::OnAppImageUpdated( |
| 1872 const std::string& id, |
| 1873 const gfx::ImageSkia& image) { |
| 1874 // TODO: need to get this working for shortcuts. |
| 1875 for (IDToItemControllerMap::const_iterator i = |
| 1876 id_to_item_controller_map_.begin(); |
| 1877 i != id_to_item_controller_map_.end(); ++i) { |
| 1878 LauncherItemController* controller = i->second; |
| 1879 if (controller->app_id() != id) |
| 1880 continue; |
| 1881 if (controller->image_set_by_controller()) |
| 1882 continue; |
| 1883 int index = model_->ItemIndexByID(i->first); |
| 1884 if (index == -1) |
| 1885 continue; |
| 1886 ash::ShelfItem item = model_->items()[index]; |
| 1887 item.image = image; |
| 1888 model_->Set(index, item); |
| 1889 // It's possible we're waiting on more than one item, so don't break. |
| 1890 } |
| 1891 } |
| OLD | NEW |