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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 | 368 |
369 void ChromeLauncherControllerImpl::Unpin(ash::ShelfID id) { | 369 void ChromeLauncherControllerImpl::Unpin(ash::ShelfID id) { |
370 UnpinAndUpdatePrefs(id, true /* update_prefs */); | 370 UnpinAndUpdatePrefs(id, true /* update_prefs */); |
371 } | 371 } |
372 | 372 |
373 void ChromeLauncherControllerImpl::UnpinAndUpdatePrefs(ash::ShelfID id, | 373 void ChromeLauncherControllerImpl::UnpinAndUpdatePrefs(ash::ShelfID id, |
374 bool update_prefs) { | 374 bool update_prefs) { |
375 LauncherItemController* controller = GetLauncherItemController(id); | 375 LauncherItemController* controller = GetLauncherItemController(id); |
376 CHECK(controller); | 376 CHECK(controller); |
377 | 377 |
378 if (update_prefs) | 378 if (update_prefs) { |
379 ash::launcher::RemovePinPosition(profile(), GetAppIDForShelfID(id)); | 379 ash::launcher::RemovePinPosition( |
380 profile(), ash::launcher::AppLauncherId(GetAppIDForShelfID(id))); | |
381 } | |
380 | 382 |
381 if (controller->type() == LauncherItemController::TYPE_APP || | 383 if (controller->type() == LauncherItemController::TYPE_APP || |
382 controller->locked()) { | 384 controller->locked()) { |
383 UnpinRunningAppInternal(model_->ItemIndexByID(id)); | 385 UnpinRunningAppInternal(model_->ItemIndexByID(id)); |
384 } else { | 386 } else { |
385 LauncherItemClosed(id); | 387 LauncherItemClosed(id); |
386 } | 388 } |
387 } | 389 } |
388 | 390 |
389 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) { | 391 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) { |
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1150 return; | 1152 return; |
1151 | 1153 |
1152 const int max_index = model_->item_count(); | 1154 const int max_index = model_->item_count(); |
1153 const int index = model_->ItemIndexByID(shelf_id); | 1155 const int index = model_->ItemIndexByID(shelf_id); |
1154 DCHECK_GT(index, 0); | 1156 DCHECK_GT(index, 0); |
1155 | 1157 |
1156 const std::string& app_id = GetAppIDForShelfID(shelf_id); | 1158 const std::string& app_id = GetAppIDForShelfID(shelf_id); |
1157 DCHECK(!app_id.empty()); | 1159 DCHECK(!app_id.empty()); |
1158 | 1160 |
1159 std::string app_id_before; | 1161 std::string app_id_before; |
1160 std::vector<std::string> app_ids_after; | 1162 std::vector<ash::launcher::AppLauncherId> app_launcher_ids_after; |
1161 | 1163 |
1162 for (int i = index - 1; i > 0; --i) { | 1164 for (int i = index - 1; i > 0; --i) { |
1163 const ash::ShelfID shelf_id_before = model_->items()[i].id; | 1165 const ash::ShelfID shelf_id_before = model_->items()[i].id; |
1164 if (IsPinned(shelf_id_before)) { | 1166 if (IsPinned(shelf_id_before)) { |
1165 app_id_before = GetAppIDForShelfID(shelf_id_before); | 1167 app_id_before = GetAppIDForShelfID(shelf_id_before); |
1166 DCHECK(!app_id_before.empty()); | 1168 DCHECK(!app_id_before.empty()); |
1167 break; | 1169 break; |
1168 } | 1170 } |
1169 } | 1171 } |
1170 | 1172 |
1171 for (int i = index + 1; i < max_index; ++i) { | 1173 for (int i = index + 1; i < max_index; ++i) { |
1172 const ash::ShelfID shelf_id_after = model_->items()[i].id; | 1174 const ash::ShelfID shelf_id_after = model_->items()[i].id; |
1173 if (IsPinned(shelf_id_after)) { | 1175 if (IsPinned(shelf_id_after)) { |
1174 const std::string app_id_after = GetAppIDForShelfID(shelf_id_after); | 1176 const std::string app_id_after = GetAppIDForShelfID(shelf_id_after); |
1175 DCHECK(!app_id_after.empty()); | 1177 DCHECK(!app_id_after.empty()); |
1176 app_ids_after.push_back(app_id_after); | 1178 app_launcher_ids_after.push_back( |
1179 ash::launcher::AppLauncherId(app_id_after)); | |
1177 } | 1180 } |
1178 } | 1181 } |
1179 | 1182 |
1180 ash::launcher::SetPinPosition(profile(), app_id, app_id_before, | 1183 ash::launcher::SetPinPosition(profile(), ash::launcher::AppLauncherId(app_id), |
1181 app_ids_after); | 1184 ash::launcher::AppLauncherId(app_id_before), |
1185 app_launcher_ids_after); | |
1182 } | 1186 } |
1183 | 1187 |
1184 void ChromeLauncherControllerImpl::OnSyncModelUpdated() { | 1188 void ChromeLauncherControllerImpl::OnSyncModelUpdated() { |
1185 UpdateAppLaunchersFromPref(); | 1189 UpdateAppLaunchersFromPref(); |
1186 } | 1190 } |
1187 | 1191 |
1188 void ChromeLauncherControllerImpl::ScheduleUpdateAppLaunchersFromPref() { | 1192 void ChromeLauncherControllerImpl::ScheduleUpdateAppLaunchersFromPref() { |
1189 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1193 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1190 FROM_HERE, | 1194 FROM_HERE, |
1191 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref, | 1195 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref, |
1192 weak_ptr_factory_.GetWeakPtr())); | 1196 weak_ptr_factory_.GetWeakPtr())); |
1193 } | 1197 } |
1194 | 1198 |
1195 void ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref() { | 1199 void ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref() { |
1196 // There are various functions which will trigger a |SyncPinPosition| call | 1200 // There are various functions which will trigger a |SyncPinPosition| call |
1197 // like a direct call to |DoPinAppWithID|, or an indirect call to the menu | 1201 // like a direct call to |DoPinAppWithID|, or an indirect call to the menu |
1198 // model which will use weights to re-arrange the icons to new positions. | 1202 // model which will use weights to re-arrange the icons to new positions. |
1199 // Since this function is meant to synchronize the "is state" with the | 1203 // Since this function is meant to synchronize the "is state" with the |
1200 // "sync state", it makes no sense to store any changes by this function back | 1204 // "sync state", it makes no sense to store any changes by this function back |
1201 // into the pref state. Therefore we tell |persistPinnedState| to ignore any | 1205 // into the pref state. Therefore we tell |persistPinnedState| to ignore any |
1202 // invocations while we are running. | 1206 // invocations while we are running. |
1203 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true); | 1207 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true); |
1204 const std::vector<std::string> pinned_apps = | 1208 const std::vector<ash::launcher::AppLauncherId> pinned_apps = |
1205 ash::launcher::GetPinnedAppsFromPrefs(profile()->GetPrefs(), | 1209 ash::launcher::GetPinnedAppsFromPrefs(profile()->GetPrefs(), |
1206 launcher_controller_helper()); | 1210 launcher_controller_helper()); |
1207 | 1211 |
1208 int index = 0; | 1212 int index = 0; |
1209 // Skip app list items if it exists. | 1213 // Skip app list items if it exists. |
1210 if (model_->items()[0].type == ash::TYPE_APP_LIST) | 1214 if (model_->items()[0].type == ash::TYPE_APP_LIST) |
1211 ++index; | 1215 ++index; |
1212 | 1216 |
1213 // Apply pins in two steps. At the first step, go through the list of apps to | 1217 // Apply pins in two steps. At the first step, go through the list of apps to |
1214 // pin, move existing pin to current position specified by |index| or create | 1218 // pin, move existing pin to current position specified by |index| or create |
1215 // the new pin at that position. | 1219 // the new pin at that position. |
1216 for (const auto& pref_app_id : pinned_apps) { | 1220 for (const auto& pref_app_launcher_id : pinned_apps) { |
1217 // Filter out apps that may be mapped wrongly. | 1221 // Filter out apps that may be mapped wrongly. |
1218 // TODO(khmel): b/31703859 is to refactore shelf mapping. | 1222 // TODO(khmel): b/31703859 is to refactore shelf mapping. |
1223 const std::string launcher_id = pref_app_launcher_id.ToString(); | |
stevenjb
2016/10/13 17:59:15
nit: app_launcher_id_str
Andra Paraschiv
2016/10/14 12:09:17
Done.
| |
1219 const std::string shelf_app_id = | 1224 const std::string shelf_app_id = |
1220 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(pref_app_id); | 1225 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(launcher_id); |
1221 if (shelf_app_id != pref_app_id) | 1226 if (shelf_app_id != launcher_id) |
1222 continue; | 1227 continue; |
1223 | 1228 |
1224 // Update apps icon if applicable. | 1229 // Update apps icon if applicable. |
1225 OnAppUpdated(profile(), pref_app_id); | 1230 OnAppUpdated(profile(), launcher_id); |
1226 | 1231 |
1227 // Find existing pin or app from the right of current |index|. | 1232 // Find existing pin or app from the right of current |index|. |
1228 int app_index = index; | 1233 int app_index = index; |
1229 for (; app_index < model_->item_count(); ++app_index) { | 1234 for (; app_index < model_->item_count(); ++app_index) { |
1230 const ash::ShelfItem& item = model_->items()[app_index]; | 1235 const ash::ShelfItem& item = model_->items()[app_index]; |
1231 const IDToItemControllerMap::iterator it = | 1236 const IDToItemControllerMap::iterator it = |
1232 id_to_item_controller_map_.find(item.id); | 1237 id_to_item_controller_map_.find(item.id); |
1233 if (it != id_to_item_controller_map_.end() && | 1238 if (it != id_to_item_controller_map_.end() && |
1234 it->second->app_id() == pref_app_id) { | 1239 it->second->app_id() == launcher_id) { |
1235 break; | 1240 break; |
1236 } | 1241 } |
1237 } | 1242 } |
1238 if (app_index < model_->item_count()) { | 1243 if (app_index < model_->item_count()) { |
1239 // Found existing pin or running app. | 1244 // Found existing pin or running app. |
1240 const ash::ShelfItem item = model_->items()[app_index]; | 1245 const ash::ShelfItem item = model_->items()[app_index]; |
1241 if (item.type == ash::TYPE_APP_SHORTCUT || | 1246 if (item.type == ash::TYPE_APP_SHORTCUT || |
1242 item.type == ash::TYPE_BROWSER_SHORTCUT) { | 1247 item.type == ash::TYPE_BROWSER_SHORTCUT) { |
1243 // Just move to required position or keep it inplace. | 1248 // Just move to required position or keep it inplace. |
1244 model_->Move(app_index, index); | 1249 model_->Move(app_index, index); |
1245 } else { | 1250 } else { |
1246 PinRunningAppInternal(index, item.id); | 1251 PinRunningAppInternal(index, item.id); |
1247 } | 1252 } |
1248 DCHECK_EQ(model_->ItemIndexByID(item.id), index); | 1253 DCHECK_EQ(model_->ItemIndexByID(item.id), index); |
1249 } else { | 1254 } else { |
1250 // This is fresh pin. Create new one. | 1255 // This is fresh pin. Create new one. |
1251 DCHECK_NE(pref_app_id, extension_misc::kChromeAppId); | 1256 DCHECK_NE(launcher_id, extension_misc::kChromeAppId); |
1252 CreateAppShortcutLauncherItem(pref_app_id, index); | 1257 CreateAppShortcutLauncherItem(launcher_id, index); |
1253 } | 1258 } |
1254 ++index; | 1259 ++index; |
1255 } | 1260 } |
1256 | 1261 |
1257 // At second step remove any pin to the right from the current index. | 1262 // At second step remove any pin to the right from the current index. |
1258 while (index < model_->item_count()) { | 1263 while (index < model_->item_count()) { |
1259 const ash::ShelfItem item = model_->items()[index]; | 1264 const ash::ShelfItem item = model_->items()[index]; |
1260 if (item.type != ash::TYPE_APP_SHORTCUT) { | 1265 if (item.type != ash::TYPE_APP_SHORTCUT) { |
1261 ++index; | 1266 ++index; |
1262 continue; | 1267 continue; |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1540 if (index == -1) | 1545 if (index == -1) |
1541 continue; | 1546 continue; |
1542 ash::ShelfItem item = model_->items()[index]; | 1547 ash::ShelfItem item = model_->items()[index]; |
1543 item.image = image; | 1548 item.image = image; |
1544 if (arc_deferred_launcher_) | 1549 if (arc_deferred_launcher_) |
1545 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); | 1550 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); |
1546 model_->Set(index, item); | 1551 model_->Set(index, item); |
1547 // It's possible we're waiting on more than one item, so don't break. | 1552 // It's possible we're waiting on more than one item, so don't break. |
1548 } | 1553 } |
1549 } | 1554 } |
OLD | NEW |