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 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 | 385 |
386 void ChromeLauncherControllerImpl::Unpin(ash::ShelfID id) { | 386 void ChromeLauncherControllerImpl::Unpin(ash::ShelfID id) { |
387 UnpinAndUpdatePrefs(id, true /* update_prefs */); | 387 UnpinAndUpdatePrefs(id, true /* update_prefs */); |
388 } | 388 } |
389 | 389 |
390 void ChromeLauncherControllerImpl::UnpinAndUpdatePrefs(ash::ShelfID id, | 390 void ChromeLauncherControllerImpl::UnpinAndUpdatePrefs(ash::ShelfID id, |
391 bool update_prefs) { | 391 bool update_prefs) { |
392 LauncherItemController* controller = GetLauncherItemController(id); | 392 LauncherItemController* controller = GetLauncherItemController(id); |
393 CHECK(controller); | 393 CHECK(controller); |
394 | 394 |
395 if (update_prefs) | 395 if (update_prefs) { |
396 ash::launcher::RemovePinPosition(profile_, GetAppIDForShelfID(id)); | 396 ash::launcher::RemovePinPosition( |
| 397 profile_, ash::launcher::AppLauncherId(GetAppIDForShelfID(id))); |
| 398 } |
397 | 399 |
398 if (controller->type() == LauncherItemController::TYPE_APP || | 400 if (controller->type() == LauncherItemController::TYPE_APP || |
399 controller->locked()) { | 401 controller->locked()) { |
400 UnpinRunningAppInternal(model_->ItemIndexByID(id)); | 402 UnpinRunningAppInternal(model_->ItemIndexByID(id)); |
401 } else { | 403 } else { |
402 LauncherItemClosed(id); | 404 LauncherItemClosed(id); |
403 } | 405 } |
404 } | 406 } |
405 | 407 |
406 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) { | 408 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) { |
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1170 return; | 1172 return; |
1171 | 1173 |
1172 const int max_index = model_->item_count(); | 1174 const int max_index = model_->item_count(); |
1173 const int index = model_->ItemIndexByID(shelf_id); | 1175 const int index = model_->ItemIndexByID(shelf_id); |
1174 DCHECK_GT(index, 0); | 1176 DCHECK_GT(index, 0); |
1175 | 1177 |
1176 const std::string& app_id = GetAppIDForShelfID(shelf_id); | 1178 const std::string& app_id = GetAppIDForShelfID(shelf_id); |
1177 DCHECK(!app_id.empty()); | 1179 DCHECK(!app_id.empty()); |
1178 | 1180 |
1179 std::string app_id_before; | 1181 std::string app_id_before; |
1180 std::vector<std::string> app_ids_after; | 1182 std::vector<ash::launcher::AppLauncherId> app_launcher_ids_after; |
1181 | 1183 |
1182 for (int i = index - 1; i > 0; --i) { | 1184 for (int i = index - 1; i > 0; --i) { |
1183 const ash::ShelfID shelf_id_before = model_->items()[i].id; | 1185 const ash::ShelfID shelf_id_before = model_->items()[i].id; |
1184 if (IsPinned(shelf_id_before)) { | 1186 if (IsPinned(shelf_id_before)) { |
1185 app_id_before = GetAppIDForShelfID(shelf_id_before); | 1187 app_id_before = GetAppIDForShelfID(shelf_id_before); |
1186 DCHECK(!app_id_before.empty()); | 1188 DCHECK(!app_id_before.empty()); |
1187 break; | 1189 break; |
1188 } | 1190 } |
1189 } | 1191 } |
1190 | 1192 |
1191 for (int i = index + 1; i < max_index; ++i) { | 1193 for (int i = index + 1; i < max_index; ++i) { |
1192 const ash::ShelfID shelf_id_after = model_->items()[i].id; | 1194 const ash::ShelfID shelf_id_after = model_->items()[i].id; |
1193 if (IsPinned(shelf_id_after)) { | 1195 if (IsPinned(shelf_id_after)) { |
1194 const std::string app_id_after = GetAppIDForShelfID(shelf_id_after); | 1196 const std::string app_id_after = GetAppIDForShelfID(shelf_id_after); |
1195 DCHECK(!app_id_after.empty()); | 1197 DCHECK(!app_id_after.empty()); |
1196 app_ids_after.push_back(app_id_after); | 1198 app_launcher_ids_after.push_back( |
| 1199 ash::launcher::AppLauncherId(app_id_after)); |
1197 } | 1200 } |
1198 } | 1201 } |
1199 | 1202 |
1200 ash::launcher::SetPinPosition(profile_, app_id, app_id_before, app_ids_after); | 1203 ash::launcher::SetPinPosition(profile_, ash::launcher::AppLauncherId(app_id), |
| 1204 ash::launcher::AppLauncherId(app_id_before), |
| 1205 app_launcher_ids_after); |
1201 } | 1206 } |
1202 | 1207 |
1203 void ChromeLauncherControllerImpl::OnSyncModelUpdated() { | 1208 void ChromeLauncherControllerImpl::OnSyncModelUpdated() { |
1204 UpdateAppLaunchersFromPref(); | 1209 UpdateAppLaunchersFromPref(); |
1205 } | 1210 } |
1206 | 1211 |
1207 void ChromeLauncherControllerImpl::ScheduleUpdateAppLaunchersFromPref() { | 1212 void ChromeLauncherControllerImpl::ScheduleUpdateAppLaunchersFromPref() { |
1208 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1213 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1209 FROM_HERE, | 1214 FROM_HERE, |
1210 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref, | 1215 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref, |
1211 weak_ptr_factory_.GetWeakPtr())); | 1216 weak_ptr_factory_.GetWeakPtr())); |
1212 } | 1217 } |
1213 | 1218 |
1214 void ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref() { | 1219 void ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref() { |
1215 // There are various functions which will trigger a |SyncPinPosition| call | 1220 // There are various functions which will trigger a |SyncPinPosition| call |
1216 // like a direct call to |DoPinAppWithID|, or an indirect call to the menu | 1221 // like a direct call to |DoPinAppWithID|, or an indirect call to the menu |
1217 // model which will use weights to re-arrange the icons to new positions. | 1222 // model which will use weights to re-arrange the icons to new positions. |
1218 // Since this function is meant to synchronize the "is state" with the | 1223 // Since this function is meant to synchronize the "is state" with the |
1219 // "sync state", it makes no sense to store any changes by this function back | 1224 // "sync state", it makes no sense to store any changes by this function back |
1220 // into the pref state. Therefore we tell |persistPinnedState| to ignore any | 1225 // into the pref state. Therefore we tell |persistPinnedState| to ignore any |
1221 // invocations while we are running. | 1226 // invocations while we are running. |
1222 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true); | 1227 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true); |
1223 const std::vector<std::string> pinned_apps = | 1228 const std::vector<ash::launcher::AppLauncherId> pinned_apps = |
1224 ash::launcher::GetPinnedAppsFromPrefs(profile_->GetPrefs(), | 1229 ash::launcher::GetPinnedAppsFromPrefs(profile_->GetPrefs(), |
1225 launcher_controller_helper_.get()); | 1230 launcher_controller_helper_.get()); |
1226 | 1231 |
1227 int index = 0; | 1232 int index = 0; |
1228 // Skip app list items if it exists. | 1233 // Skip app list items if it exists. |
1229 if (model_->items()[0].type == ash::TYPE_APP_LIST) | 1234 if (model_->items()[0].type == ash::TYPE_APP_LIST) |
1230 ++index; | 1235 ++index; |
1231 | 1236 |
1232 // Apply pins in two steps. At the first step, go through the list of apps to | 1237 // Apply pins in two steps. At the first step, go through the list of apps to |
1233 // pin, move existing pin to current position specified by |index| or create | 1238 // pin, move existing pin to current position specified by |index| or create |
1234 // the new pin at that position. | 1239 // the new pin at that position. |
1235 for (const auto& pref_app_id : pinned_apps) { | 1240 for (const auto& pref_app_launcher_id : pinned_apps) { |
1236 // Filter out apps that may be mapped wrongly. | 1241 // Filter out apps that may be mapped wrongly. |
1237 // TODO(khmel): b/31703859 is to refactore shelf mapping. | 1242 // TODO(khmel): b/31703859 is to refactore shelf mapping. |
| 1243 const std::string launcher_id = pref_app_launcher_id.ToString(); |
1238 const std::string shelf_app_id = | 1244 const std::string shelf_app_id = |
1239 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(pref_app_id); | 1245 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(launcher_id); |
1240 if (shelf_app_id != pref_app_id) | 1246 if (shelf_app_id != launcher_id) |
1241 continue; | 1247 continue; |
1242 | 1248 |
1243 // Update apps icon if applicable. | 1249 // Update apps icon if applicable. |
1244 OnAppUpdated(profile_, pref_app_id); | 1250 OnAppUpdated(profile_, launcher_id); |
1245 | 1251 |
1246 // Find existing pin or app from the right of current |index|. | 1252 // Find existing pin or app from the right of current |index|. |
1247 int app_index = index; | 1253 int app_index = index; |
1248 for (; app_index < model_->item_count(); ++app_index) { | 1254 for (; app_index < model_->item_count(); ++app_index) { |
1249 const ash::ShelfItem& item = model_->items()[app_index]; | 1255 const ash::ShelfItem& item = model_->items()[app_index]; |
1250 const IDToItemControllerMap::iterator it = | 1256 const IDToItemControllerMap::iterator it = |
1251 id_to_item_controller_map_.find(item.id); | 1257 id_to_item_controller_map_.find(item.id); |
1252 if (it != id_to_item_controller_map_.end() && | 1258 if (it != id_to_item_controller_map_.end() && |
1253 it->second->app_id() == pref_app_id) { | 1259 it->second->app_id() == launcher_id) { |
1254 break; | 1260 break; |
1255 } | 1261 } |
1256 } | 1262 } |
1257 if (app_index < model_->item_count()) { | 1263 if (app_index < model_->item_count()) { |
1258 // Found existing pin or running app. | 1264 // Found existing pin or running app. |
1259 const ash::ShelfItem item = model_->items()[app_index]; | 1265 const ash::ShelfItem item = model_->items()[app_index]; |
1260 if (item.type == ash::TYPE_APP_SHORTCUT || | 1266 if (item.type == ash::TYPE_APP_SHORTCUT || |
1261 item.type == ash::TYPE_BROWSER_SHORTCUT) { | 1267 item.type == ash::TYPE_BROWSER_SHORTCUT) { |
1262 // Just move to required position or keep it inplace. | 1268 // Just move to required position or keep it inplace. |
1263 model_->Move(app_index, index); | 1269 model_->Move(app_index, index); |
1264 } else { | 1270 } else { |
1265 PinRunningAppInternal(index, item.id); | 1271 PinRunningAppInternal(index, item.id); |
1266 } | 1272 } |
1267 DCHECK_EQ(model_->ItemIndexByID(item.id), index); | 1273 DCHECK_EQ(model_->ItemIndexByID(item.id), index); |
1268 } else { | 1274 } else { |
1269 // This is fresh pin. Create new one. | 1275 // This is fresh pin. Create new one. |
1270 DCHECK_NE(pref_app_id, extension_misc::kChromeAppId); | 1276 DCHECK_NE(launcher_id, extension_misc::kChromeAppId); |
1271 CreateAppShortcutLauncherItem(pref_app_id, index); | 1277 CreateAppShortcutLauncherItem(launcher_id, index); |
1272 } | 1278 } |
1273 ++index; | 1279 ++index; |
1274 } | 1280 } |
1275 | 1281 |
1276 // At second step remove any pin to the right from the current index. | 1282 // At second step remove any pin to the right from the current index. |
1277 while (index < model_->item_count()) { | 1283 while (index < model_->item_count()) { |
1278 const ash::ShelfItem item = model_->items()[index]; | 1284 const ash::ShelfItem item = model_->items()[index]; |
1279 if (item.type != ash::TYPE_APP_SHORTCUT) { | 1285 if (item.type != ash::TYPE_APP_SHORTCUT) { |
1280 ++index; | 1286 ++index; |
1281 continue; | 1287 continue; |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1679 if (index == -1) | 1685 if (index == -1) |
1680 continue; | 1686 continue; |
1681 ash::ShelfItem item = model_->items()[index]; | 1687 ash::ShelfItem item = model_->items()[index]; |
1682 item.image = image; | 1688 item.image = image; |
1683 if (arc_deferred_launcher_) | 1689 if (arc_deferred_launcher_) |
1684 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); | 1690 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); |
1685 model_->Set(index, item); | 1691 model_->Set(index, item); |
1686 // It's possible we're waiting on more than one item, so don't break. | 1692 // It's possible we're waiting on more than one item, so don't break. |
1687 } | 1693 } |
1688 } | 1694 } |
OLD | NEW |