| 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.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 6 | 6 |
| 7 #include "ash/multi_profile_uma.h" | 7 #include "ash/multi_profile_uma.h" |
| 8 #include "ash/public/cpp/remote_shelf_item_delegate.h" | 8 #include "ash/public/cpp/remote_shelf_item_delegate.h" |
| 9 #include "ash/public/cpp/shelf_item.h" | 9 #include "ash/public/cpp/shelf_item.h" |
| 10 #include "ash/public/cpp/shelf_model.h" | 10 #include "ash/public/cpp/shelf_model.h" |
| (...skipping 1265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1276 ash::ShelfAutoHideBehavior auto_hide, | 1276 ash::ShelfAutoHideBehavior auto_hide, |
| 1277 int64_t display_id) { | 1277 int64_t display_id) { |
| 1278 DCHECK(!updating_shelf_pref_from_observer_); | 1278 DCHECK(!updating_shelf_pref_from_observer_); |
| 1279 base::AutoReset<bool> updating(&updating_shelf_pref_from_observer_, true); | 1279 base::AutoReset<bool> updating(&updating_shelf_pref_from_observer_, true); |
| 1280 // This will uselessly store a preference value for invalid display ids. | 1280 // This will uselessly store a preference value for invalid display ids. |
| 1281 SetShelfAutoHideBehaviorPref(profile_->GetPrefs(), display_id, auto_hide); | 1281 SetShelfAutoHideBehaviorPref(profile_->GetPrefs(), display_id, auto_hide); |
| 1282 } | 1282 } |
| 1283 | 1283 |
| 1284 void ChromeLauncherController::OnShelfItemAdded(int32_t index, | 1284 void ChromeLauncherController::OnShelfItemAdded(int32_t index, |
| 1285 const ash::ShelfItem& item) { | 1285 const ash::ShelfItem& item) { |
| 1286 DCHECK(ash_util::IsRunningInMash()) << "Unexpected model synchronization"; | 1286 DCHECK(ash_util::IsRunningInMash()) << " Unexpected model synchronization"; |
| 1287 DCHECK(!applying_remote_shelf_model_changes_) << "Unexpected model change"; | 1287 DCHECK(!applying_remote_shelf_model_changes_) << " Unexpected model change"; |
| 1288 | 1288 |
| 1289 // Ignore notifications of adding the AppList item; it should already exist. | 1289 // Ignore notifications of adding the AppList item; it should already exist. |
| 1290 if (item.id.app_id == ash::kAppListId) { | 1290 if (item.id.app_id == ash::kAppListId) { |
| 1291 DCHECK_EQ(0, model_->ItemIndexByID(item.id)); | 1291 DCHECK_EQ(0, model_->ItemIndexByID(item.id)); |
| 1292 return; | 1292 return; |
| 1293 } | 1293 } |
| 1294 | 1294 |
| 1295 DCHECK_LE(index, model_->item_count()) << "Index out of bounds"; | 1295 DCHECK_LE(index, model_->item_count()) << " Index out of bounds"; |
| 1296 DCHECK_GT(index, 0) << "Items can not preceed the AppList"; | 1296 DCHECK_GT(index, 0) << " Items can not preceed the AppList"; |
| 1297 index = std::min(std::max(index, 1), model_->item_count()); | 1297 index = std::min(std::max(index, 1), model_->item_count()); |
| 1298 base::AutoReset<bool> reset(&applying_remote_shelf_model_changes_, true); | 1298 base::AutoReset<bool> reset(&applying_remote_shelf_model_changes_, true); |
| 1299 model_->AddAt(index, item); | 1299 model_->AddAt(index, item); |
| 1300 } | 1300 } |
| 1301 | 1301 |
| 1302 void ChromeLauncherController::OnShelfItemRemoved(const ash::ShelfID& id) { | 1302 void ChromeLauncherController::OnShelfItemRemoved(const ash::ShelfID& id) { |
| 1303 DCHECK(ash_util::IsRunningInMash()) << "Unexpected model synchronization"; | 1303 DCHECK(ash_util::IsRunningInMash()) << " Unexpected model synchronization"; |
| 1304 DCHECK(!applying_remote_shelf_model_changes_) << "Unexpected model change"; | 1304 DCHECK(!applying_remote_shelf_model_changes_) << " Unexpected model change"; |
| 1305 const int index = model_->ItemIndexByID(id); | 1305 const int index = model_->ItemIndexByID(id); |
| 1306 DCHECK_GE(index, 0) << "Item not found"; | 1306 DCHECK_GE(index, 0) << " No item found with the id: " << id; |
| 1307 DCHECK_NE(index, 0) << "The AppList shelf item cannot be removed"; | 1307 DCHECK_NE(index, 0) << " The AppList shelf item cannot be removed"; |
| 1308 if (index <= 0) | 1308 if (index <= 0) |
| 1309 return; | 1309 return; |
| 1310 base::AutoReset<bool> reset(&applying_remote_shelf_model_changes_, true); | 1310 base::AutoReset<bool> reset(&applying_remote_shelf_model_changes_, true); |
| 1311 model_->RemoveItemAt(index); | 1311 model_->RemoveItemAt(index); |
| 1312 } | 1312 } |
| 1313 | 1313 |
| 1314 void ChromeLauncherController::OnShelfItemMoved(const ash::ShelfID& id, | 1314 void ChromeLauncherController::OnShelfItemMoved(const ash::ShelfID& id, |
| 1315 int32_t index) { | 1315 int32_t index) { |
| 1316 DCHECK(ash_util::IsRunningInMash()) << "Unexpected model synchronization"; | 1316 DCHECK(ash_util::IsRunningInMash()) << " Unexpected model synchronization"; |
| 1317 DCHECK(!applying_remote_shelf_model_changes_) << "Unexpected model change"; | 1317 DCHECK(!applying_remote_shelf_model_changes_) << " Unexpected model change"; |
| 1318 const int current_index = model_->ItemIndexByID(id); | 1318 const int current_index = model_->ItemIndexByID(id); |
| 1319 DCHECK_GE(current_index, 0) << "No item found with the given id"; | 1319 DCHECK_GE(current_index, 0) << " No item found with the id: " << id; |
| 1320 DCHECK_NE(current_index, 0) << "The AppList shelf item cannot be moved"; | 1320 DCHECK_NE(current_index, 0) << " The AppList shelf item cannot be moved"; |
| 1321 if (current_index <= 0) | 1321 if (current_index <= 0) |
| 1322 return; | 1322 return; |
| 1323 DCHECK_GT(index, 0) << "Items can not preceed the AppList"; | 1323 DCHECK_GT(index, 0) << " Items can not preceed the AppList"; |
| 1324 DCHECK_LT(index, model_->item_count()) << "Index out of bounds"; | 1324 DCHECK_LT(index, model_->item_count()) << " Index out of bounds"; |
| 1325 index = std::min(std::max(index, 1), model_->item_count() - 1); | 1325 index = std::min(std::max(index, 1), model_->item_count() - 1); |
| 1326 DCHECK_NE(current_index, index) << "The item is already at the given index"; | 1326 DCHECK_NE(current_index, index) << " The item is already at the given index"; |
| 1327 if (current_index == index) | 1327 if (current_index == index) |
| 1328 return; | 1328 return; |
| 1329 base::AutoReset<bool> reset(&applying_remote_shelf_model_changes_, true); | 1329 base::AutoReset<bool> reset(&applying_remote_shelf_model_changes_, true); |
| 1330 model_->Move(current_index, index); | 1330 model_->Move(current_index, index); |
| 1331 } | 1331 } |
| 1332 | 1332 |
| 1333 void ChromeLauncherController::OnShelfItemUpdated(const ash::ShelfItem& item) { | 1333 void ChromeLauncherController::OnShelfItemUpdated(const ash::ShelfItem& item) { |
| 1334 DCHECK(ash_util::IsRunningInMash()) << "Unexpected model synchronization"; | 1334 DCHECK(ash_util::IsRunningInMash()) << " Unexpected model synchronization"; |
| 1335 DCHECK(!applying_remote_shelf_model_changes_) << "Unexpected model change"; | 1335 DCHECK(!applying_remote_shelf_model_changes_) << " Unexpected model change"; |
| 1336 const int index = model_->ItemIndexByID(item.id); | 1336 const int index = model_->ItemIndexByID(item.id); |
| 1337 DCHECK_GE(index, 0) << "No item found with the given id"; | 1337 DCHECK_GE(index, 0) << " No item found with the id: " << item.id; |
| 1338 if (index < 0) | 1338 if (index < 0) |
| 1339 return; | 1339 return; |
| 1340 base::AutoReset<bool> reset(&applying_remote_shelf_model_changes_, true); | 1340 base::AutoReset<bool> reset(&applying_remote_shelf_model_changes_, true); |
| 1341 model_->Set(index, item); | 1341 model_->Set(index, item); |
| 1342 } | 1342 } |
| 1343 | 1343 |
| 1344 void ChromeLauncherController::OnShelfItemDelegateChanged( | 1344 void ChromeLauncherController::OnShelfItemDelegateChanged( |
| 1345 const ash::ShelfID& id, | 1345 const ash::ShelfID& id, |
| 1346 ash::mojom::ShelfItemDelegatePtr delegate) { | 1346 ash::mojom::ShelfItemDelegatePtr delegate) { |
| 1347 DCHECK(ash_util::IsRunningInMash()) << "Unexpected model synchronization"; | 1347 DCHECK(ash_util::IsRunningInMash()) << " Unexpected model synchronization"; |
| 1348 DCHECK(!applying_remote_shelf_model_changes_) << "Unexpected model change"; | 1348 DCHECK(!applying_remote_shelf_model_changes_) << " Unexpected model change"; |
| 1349 base::AutoReset<bool> reset(&applying_remote_shelf_model_changes_, true); | 1349 base::AutoReset<bool> reset(&applying_remote_shelf_model_changes_, true); |
| 1350 if (delegate.is_bound()) { | 1350 if (delegate.is_bound()) { |
| 1351 model_->SetShelfItemDelegate(id, | 1351 model_->SetShelfItemDelegate(id, |
| 1352 base::MakeUnique<ash::RemoteShelfItemDelegate>( | 1352 base::MakeUnique<ash::RemoteShelfItemDelegate>( |
| 1353 id, std::move(delegate))); | 1353 id, std::move(delegate))); |
| 1354 } else { | 1354 } else { |
| 1355 model_->SetShelfItemDelegate(id, nullptr); | 1355 model_->SetShelfItemDelegate(id, nullptr); |
| 1356 } | 1356 } |
| 1357 } | 1357 } |
| 1358 | 1358 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1494 : IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE); | 1494 : IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE); |
| 1495 | 1495 |
| 1496 const int app_list_index = model_->GetItemIndexForType(ash::TYPE_APP_LIST); | 1496 const int app_list_index = model_->GetItemIndexForType(ash::TYPE_APP_LIST); |
| 1497 DCHECK_GE(app_list_index, 0); | 1497 DCHECK_GE(app_list_index, 0); |
| 1498 ash::ShelfItem item = model_->items()[app_list_index]; | 1498 ash::ShelfItem item = model_->items()[app_list_index]; |
| 1499 if (item.title != title) { | 1499 if (item.title != title) { |
| 1500 item.title = title; | 1500 item.title = title; |
| 1501 model_->Set(app_list_index, item); | 1501 model_->Set(app_list_index, item); |
| 1502 } | 1502 } |
| 1503 } | 1503 } |
| OLD | NEW |