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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 SetVirtualKeyboardBehaviorFromPrefs(); | 290 SetVirtualKeyboardBehaviorFromPrefs(); |
291 | 291 |
292 prefs_observer_ = | 292 prefs_observer_ = |
293 ash::launcher::ChromeLauncherPrefsObserver::CreateIfNecessary(profile()); | 293 ash::launcher::ChromeLauncherPrefsObserver::CreateIfNecessary(profile()); |
294 } | 294 } |
295 | 295 |
296 ash::ShelfID ChromeLauncherControllerImpl::CreateAppLauncherItem( | 296 ash::ShelfID ChromeLauncherControllerImpl::CreateAppLauncherItem( |
297 LauncherItemController* controller, | 297 LauncherItemController* controller, |
298 const std::string& app_id, | 298 const std::string& app_id, |
299 ash::ShelfItemStatus status) { | 299 ash::ShelfItemStatus status) { |
300 CHECK(controller); | 300 return InsertAppLauncherItem(controller, app_id, status, model_->item_count(), |
301 int index = 0; | |
302 // Panels are inserted on the left so as not to push all existing panels over. | |
303 if (controller->GetShelfItemType() != ash::TYPE_APP_PANEL) | |
304 index = model_->item_count(); | |
305 return InsertAppLauncherItem(controller, app_id, status, index, | |
306 controller->GetShelfItemType()); | 301 controller->GetShelfItemType()); |
307 } | 302 } |
308 | 303 |
309 void ChromeLauncherControllerImpl::SetItemStatus(ash::ShelfID id, | 304 void ChromeLauncherControllerImpl::SetItemStatus(ash::ShelfID id, |
310 ash::ShelfItemStatus status) { | 305 ash::ShelfItemStatus status) { |
311 int index = model_->ItemIndexByID(id); | 306 int index = model_->ItemIndexByID(id); |
312 ash::ShelfItemStatus old_status = model_->items()[index].status; | 307 ash::ShelfItemStatus old_status = model_->items()[index].status; |
313 // Since ordinary browser windows are not registered, we might get a negative | 308 // Since ordinary browser windows are not registered, we might get a negative |
314 // index here. | 309 // index here. |
315 if (index >= 0 && old_status != status) { | 310 if (index >= 0 && old_status != status) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 | 419 |
425 void ChromeLauncherControllerImpl::LockV1AppWithID(const std::string& app_id) { | 420 void ChromeLauncherControllerImpl::LockV1AppWithID(const std::string& app_id) { |
426 ash::ShelfID id = GetShelfIDForAppID(app_id); | 421 ash::ShelfID id = GetShelfIDForAppID(app_id); |
427 if (!IsPinned(id) && !IsWindowedAppInLauncher(app_id)) { | 422 if (!IsPinned(id) && !IsWindowedAppInLauncher(app_id)) { |
428 CreateAppShortcutLauncherItemWithType(ash::launcher::AppLauncherId(app_id), | 423 CreateAppShortcutLauncherItemWithType(ash::launcher::AppLauncherId(app_id), |
429 model_->item_count(), | 424 model_->item_count(), |
430 ash::TYPE_WINDOWED_APP); | 425 ash::TYPE_WINDOWED_APP); |
431 id = GetShelfIDForAppID(app_id); | 426 id = GetShelfIDForAppID(app_id); |
432 } | 427 } |
433 CHECK(id); | 428 CHECK(id); |
434 id_to_item_controller_map_[id]->lock(); | 429 GetLauncherItemController(id)->lock(); |
435 } | 430 } |
436 | 431 |
437 void ChromeLauncherControllerImpl::UnlockV1AppWithID( | 432 void ChromeLauncherControllerImpl::UnlockV1AppWithID( |
438 const std::string& app_id) { | 433 const std::string& app_id) { |
439 ash::ShelfID id = GetShelfIDForAppID(app_id); | 434 ash::ShelfID id = GetShelfIDForAppID(app_id); |
440 CHECK(id); | 435 CHECK(id); |
441 CHECK(IsPinned(id) || IsWindowedAppInLauncher(app_id)); | 436 CHECK(IsPinned(id) || IsWindowedAppInLauncher(app_id)); |
442 LauncherItemController* controller = id_to_item_controller_map_[id]; | 437 LauncherItemController* controller = GetLauncherItemController(id); |
443 controller->unlock(); | 438 controller->unlock(); |
444 if (!controller->locked() && !IsPinned(id)) | 439 if (!controller->locked() && !IsPinned(id)) |
445 CloseLauncherItem(id); | 440 CloseLauncherItem(id); |
446 } | 441 } |
447 | 442 |
448 void ChromeLauncherControllerImpl::Launch(ash::ShelfID id, int event_flags) { | 443 void ChromeLauncherControllerImpl::Launch(ash::ShelfID id, int event_flags) { |
449 LauncherItemController* controller = GetLauncherItemController(id); | 444 LauncherItemController* controller = GetLauncherItemController(id); |
450 if (!controller) | 445 if (!controller) |
451 return; // In case invoked from menu and item closed while menu up. | 446 return; // In case invoked from menu and item closed while menu up. |
452 controller->Launch(ash::LAUNCH_FROM_UNKNOWN, event_flags); | 447 controller->Launch(ash::LAUNCH_FROM_UNKNOWN, event_flags); |
453 } | 448 } |
454 | 449 |
455 void ChromeLauncherControllerImpl::Close(ash::ShelfID id) { | 450 void ChromeLauncherControllerImpl::Close(ash::ShelfID id) { |
456 LauncherItemController* controller = GetLauncherItemController(id); | 451 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id); |
457 if (!controller) | 452 if (!delegate) |
458 return; // May happen if menu closed. | 453 return; // May happen if menu closed. |
459 controller->Close(); | 454 delegate->Close(); |
460 } | 455 } |
461 | 456 |
462 bool ChromeLauncherControllerImpl::IsOpen(ash::ShelfID id) { | 457 bool ChromeLauncherControllerImpl::IsOpen(ash::ShelfID id) { |
463 const int index = model_->ItemIndexByID(id); | 458 const int index = model_->ItemIndexByID(id); |
464 return index >= 0 && model_->items()[index].status != ash::STATUS_CLOSED; | 459 return index >= 0 && model_->items()[index].status != ash::STATUS_CLOSED; |
465 } | 460 } |
466 | 461 |
467 bool ChromeLauncherControllerImpl::IsPlatformApp(ash::ShelfID id) { | 462 bool ChromeLauncherControllerImpl::IsPlatformApp(ash::ShelfID id) { |
468 if (!HasShelfIDToAppIDMapping(id)) | 463 if (!HasShelfIDToAppIDMapping(id)) |
469 return false; | 464 return false; |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
796 return static_cast<BrowserShortcutLauncherItemController*>(i->second); | 791 return static_cast<BrowserShortcutLauncherItemController*>(i->second); |
797 } | 792 } |
798 NOTREACHED() | 793 NOTREACHED() |
799 << "There should be always be a BrowserShortcutLauncherItemController."; | 794 << "There should be always be a BrowserShortcutLauncherItemController."; |
800 return nullptr; | 795 return nullptr; |
801 } | 796 } |
802 | 797 |
803 LauncherItemController* ChromeLauncherControllerImpl::GetLauncherItemController( | 798 LauncherItemController* ChromeLauncherControllerImpl::GetLauncherItemController( |
804 const ash::ShelfID id) { | 799 const ash::ShelfID id) { |
805 if (!HasShelfIDToAppIDMapping(id)) | 800 if (!HasShelfIDToAppIDMapping(id)) |
806 return NULL; | 801 return nullptr; |
807 return id_to_item_controller_map_[id]; | 802 return id_to_item_controller_map_[id]; |
808 } | 803 } |
809 | 804 |
810 bool ChromeLauncherControllerImpl::ShelfBoundsChangesProbablyWithUser( | 805 bool ChromeLauncherControllerImpl::ShelfBoundsChangesProbablyWithUser( |
811 ash::WmShelf* shelf, | 806 ash::WmShelf* shelf, |
812 const AccountId& account_id) const { | 807 const AccountId& account_id) const { |
813 Profile* other_profile = multi_user_util::GetProfileFromAccountId(account_id); | 808 Profile* other_profile = multi_user_util::GetProfileFromAccountId(account_id); |
814 if (!other_profile || other_profile == profile()) | 809 if (!other_profile || other_profile == profile()) |
815 return false; | 810 return false; |
816 | 811 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
899 if (app_service) | 894 if (app_service) |
900 app_service->AddObserverAndStart(this); | 895 app_service->AddObserverAndStart(this); |
901 } | 896 } |
902 | 897 |
903 /////////////////////////////////////////////////////////////////////////////// | 898 /////////////////////////////////////////////////////////////////////////////// |
904 // ash::ShelfDelegate: | 899 // ash::ShelfDelegate: |
905 | 900 |
906 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppID( | 901 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppID( |
907 const std::string& app_id) { | 902 const std::string& app_id) { |
908 // Get shelf id for app_id and empty launch_id. | 903 // Get shelf id for app_id and empty launch_id. |
909 return GetShelfIDForAppIDAndLaunchID(app_id, ""); | 904 return GetShelfIDForAppIDAndLaunchID(app_id, std::string()); |
910 } | 905 } |
911 | 906 |
912 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppIDAndLaunchID( | 907 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppIDAndLaunchID( |
913 const std::string& app_id, | 908 const std::string& app_id, |
914 const std::string& launch_id) { | 909 const std::string& launch_id) { |
915 const std::string shelf_app_id = | 910 const std::string shelf_app_id = |
916 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); | 911 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); |
917 for (const auto& id_to_item_controller_pair : id_to_item_controller_map_) { | 912 for (const auto& id_to_item_controller_pair : id_to_item_controller_map_) { |
918 if (id_to_item_controller_pair.second->type() == | |
919 LauncherItemController::TYPE_APP_PANEL) | |
920 continue; // Don't include panels | |
921 if (id_to_item_controller_pair.second->app_id() == shelf_app_id && | 913 if (id_to_item_controller_pair.second->app_id() == shelf_app_id && |
922 id_to_item_controller_pair.second->launch_id() == launch_id) { | 914 id_to_item_controller_pair.second->launch_id() == launch_id) { |
923 return id_to_item_controller_pair.first; | 915 return id_to_item_controller_pair.first; |
924 } | 916 } |
925 } | 917 } |
926 return 0; | 918 return ash::kInvalidShelfID; |
927 } | 919 } |
928 | 920 |
929 bool ChromeLauncherControllerImpl::HasShelfIDToAppIDMapping( | 921 bool ChromeLauncherControllerImpl::HasShelfIDToAppIDMapping( |
930 ash::ShelfID id) const { | 922 ash::ShelfID id) const { |
931 return id_to_item_controller_map_.find(id) != | 923 return id_to_item_controller_map_.find(id) != |
932 id_to_item_controller_map_.end(); | 924 id_to_item_controller_map_.end(); |
933 } | 925 } |
934 | 926 |
935 const std::string& ChromeLauncherControllerImpl::GetAppIDForShelfID( | 927 const std::string& ChromeLauncherControllerImpl::GetAppIDForShelfID( |
936 ash::ShelfID id) { | 928 ash::ShelfID id) { |
937 LauncherItemController* controller = GetLauncherItemController(id); | 929 LauncherItemController* controller = GetLauncherItemController(id); |
938 return controller ? controller->app_id() : base::EmptyString(); | 930 return controller ? controller->app_id() : model_->ItemByID(id)->app_id; |
James Cook
2016/11/10 22:32:46
Is ItemByID() always guaranteed to return a valid
msw
2016/11/10 23:30:52
Ah, this wasn't technically safe (but also isn't c
| |
939 } | 931 } |
940 | 932 |
941 void ChromeLauncherControllerImpl::PinAppWithID(const std::string& app_id) { | 933 void ChromeLauncherControllerImpl::PinAppWithID(const std::string& app_id) { |
942 const std::string shelf_app_id = | 934 const std::string shelf_app_id = |
943 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); | 935 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); |
944 if (GetPinnableForAppID(shelf_app_id, profile()) == | 936 if (GetPinnableForAppID(shelf_app_id, profile()) == |
945 AppListControllerDelegate::PIN_EDITABLE) | 937 AppListControllerDelegate::PIN_EDITABLE) |
946 DoPinAppWithID(shelf_app_id); | 938 DoPinAppWithID(shelf_app_id); |
947 else | 939 else |
948 NOTREACHED(); | 940 NOTREACHED(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1021 /////////////////////////////////////////////////////////////////////////////// | 1013 /////////////////////////////////////////////////////////////////////////////// |
1022 // ChromeLauncherControllerImpl protected: | 1014 // ChromeLauncherControllerImpl protected: |
1023 | 1015 |
1024 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem( | 1016 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem( |
1025 const ash::launcher::AppLauncherId& app_launcher_id, | 1017 const ash::launcher::AppLauncherId& app_launcher_id, |
1026 int index) { | 1018 int index) { |
1027 return CreateAppShortcutLauncherItemWithType(app_launcher_id, index, | 1019 return CreateAppShortcutLauncherItemWithType(app_launcher_id, index, |
1028 ash::TYPE_APP_SHORTCUT); | 1020 ash::TYPE_APP_SHORTCUT); |
1029 } | 1021 } |
1030 | 1022 |
1031 const std::string& ChromeLauncherControllerImpl::GetAppIdFromShelfIdForTest( | |
1032 ash::ShelfID id) { | |
1033 return id_to_item_controller_map_[id]->app_id(); | |
1034 } | |
1035 | |
1036 /////////////////////////////////////////////////////////////////////////////// | 1023 /////////////////////////////////////////////////////////////////////////////// |
1037 // ChromeLauncherControllerImpl private: | 1024 // ChromeLauncherControllerImpl private: |
1038 | 1025 |
1039 void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() { | 1026 void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() { |
1040 RunningAppListIds list; | 1027 RunningAppListIds list; |
1041 for (int i = 0; i < model_->item_count(); i++) { | 1028 for (int i = 0; i < model_->item_count(); i++) { |
1042 ash::ShelfItemType type = model_->items()[i].type; | 1029 ash::ShelfItemType type = model_->items()[i].type; |
1043 if (type == ash::TYPE_WINDOWED_APP || type == ash::TYPE_PLATFORM_APP) | 1030 if (type == ash::TYPE_WINDOWED_APP || type == ash::TYPE_PLATFORM_APP) |
1044 list.push_back(GetAppIDForShelfID(model_->items()[i].id)); | 1031 list.push_back(GetAppIDForShelfID(model_->items()[i].id)); |
1045 } | 1032 } |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1350 | 1337 |
1351 ash::ShelfID ChromeLauncherControllerImpl::InsertAppLauncherItem( | 1338 ash::ShelfID ChromeLauncherControllerImpl::InsertAppLauncherItem( |
1352 LauncherItemController* controller, | 1339 LauncherItemController* controller, |
1353 const std::string& app_id, | 1340 const std::string& app_id, |
1354 ash::ShelfItemStatus status, | 1341 ash::ShelfItemStatus status, |
1355 int index, | 1342 int index, |
1356 ash::ShelfItemType shelf_item_type) { | 1343 ash::ShelfItemType shelf_item_type) { |
1357 ash::ShelfID id = model_->next_id(); | 1344 ash::ShelfID id = model_->next_id(); |
1358 CHECK(!HasShelfIDToAppIDMapping(id)); | 1345 CHECK(!HasShelfIDToAppIDMapping(id)); |
1359 CHECK(controller); | 1346 CHECK(controller); |
1347 // Ash's ShelfWindowWatcher handles app panel windows separately. | |
1348 DCHECK_NE(ash::TYPE_APP_PANEL, controller->GetShelfItemType()); | |
1360 id_to_item_controller_map_[id] = controller; | 1349 id_to_item_controller_map_[id] = controller; |
1361 controller->set_shelf_id(id); | 1350 controller->set_shelf_id(id); |
1362 | 1351 |
1363 ash::ShelfItem item; | 1352 ash::ShelfItem item; |
1364 item.type = shelf_item_type; | 1353 item.type = shelf_item_type; |
1365 item.image = extensions::util::GetDefaultAppIcon(); | 1354 item.image = extensions::util::GetDefaultAppIcon(); |
1366 | 1355 |
1367 ash::ShelfItemStatus new_state = GetAppState(app_id); | 1356 ash::ShelfItemStatus new_state = GetAppState(app_id); |
1368 if (new_state != ash::STATUS_CLOSED) | 1357 if (new_state != ash::STATUS_CLOSED) |
1369 status = new_state; | 1358 status = new_state; |
1370 | 1359 |
1371 item.status = status; | 1360 item.status = status; |
1372 | |
1373 model_->AddAt(index, item); | 1361 model_->AddAt(index, item); |
1374 | 1362 |
1375 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); | 1363 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); |
1376 if (app_icon_loader) { | 1364 if (app_icon_loader) { |
1377 app_icon_loader->FetchImage(app_id); | 1365 app_icon_loader->FetchImage(app_id); |
1378 app_icon_loader->UpdateImage(app_id); | 1366 app_icon_loader->UpdateImage(app_id); |
1379 } | 1367 } |
1380 | 1368 |
1381 SetShelfItemDelegate(id, controller); | 1369 SetShelfItemDelegate(id, controller); |
1382 | 1370 |
1383 return id; | 1371 return id; |
1384 } | 1372 } |
1385 | 1373 |
1386 std::vector<content::WebContents*> | 1374 std::vector<content::WebContents*> |
1387 ChromeLauncherControllerImpl::GetV1ApplicationsFromController( | 1375 ChromeLauncherControllerImpl::GetV1ApplicationsFromController( |
1388 LauncherItemController* controller) { | 1376 LauncherItemController* controller) { |
1389 DCHECK(controller->type() == LauncherItemController::TYPE_SHORTCUT); | 1377 DCHECK(controller->type() == LauncherItemController::TYPE_SHORTCUT); |
1390 AppShortcutLauncherItemController* app_controller = | 1378 AppShortcutLauncherItemController* app_controller = |
1391 static_cast<AppShortcutLauncherItemController*>(controller); | 1379 static_cast<AppShortcutLauncherItemController*>(controller); |
1392 return app_controller->GetRunningApplications(); | 1380 return app_controller->GetRunningApplications(); |
1393 } | 1381 } |
1394 | 1382 |
1395 ash::ShelfID ChromeLauncherControllerImpl::CreateBrowserShortcutLauncherItem() { | 1383 void ChromeLauncherControllerImpl::CreateBrowserShortcutLauncherItem() { |
1396 ash::ShelfItem browser_shortcut; | 1384 ash::ShelfItem browser_shortcut; |
1397 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; | 1385 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; |
1398 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1386 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
1399 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); | 1387 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); |
1400 ash::ShelfID id = model_->next_id(); | 1388 ash::ShelfID id = model_->next_id(); |
1401 model_->AddAt(0, browser_shortcut); | 1389 model_->AddAt(0, browser_shortcut); |
1402 id_to_item_controller_map_[id] = | 1390 id_to_item_controller_map_[id] = |
1403 new BrowserShortcutLauncherItemController(this, model_); | 1391 new BrowserShortcutLauncherItemController(this, model_); |
1404 id_to_item_controller_map_[id]->set_shelf_id(id); | 1392 id_to_item_controller_map_[id]->set_shelf_id(id); |
1405 // ShelfModel owns BrowserShortcutLauncherItemController. | 1393 // ShelfModel owns BrowserShortcutLauncherItemController. |
1406 SetShelfItemDelegate(id, id_to_item_controller_map_[id]); | 1394 SetShelfItemDelegate(id, id_to_item_controller_map_[id]); |
1407 return id; | |
1408 } | 1395 } |
1409 | 1396 |
1410 bool ChromeLauncherControllerImpl::IsIncognito( | 1397 bool ChromeLauncherControllerImpl::IsIncognito( |
1411 const content::WebContents* web_contents) const { | 1398 const content::WebContents* web_contents) const { |
1412 const Profile* profile = | 1399 const Profile* profile = |
1413 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 1400 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
1414 return profile->IsOffTheRecord() && !profile->IsGuestSession() && | 1401 return profile->IsOffTheRecord() && !profile->IsGuestSession() && |
1415 !profile->IsSystemProfile(); | 1402 !profile->IsSystemProfile(); |
1416 } | 1403 } |
1417 | 1404 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1476 | 1463 |
1477 app_list::AppListSyncableService* app_service = | 1464 app_list::AppListSyncableService* app_service = |
1478 app_list::AppListSyncableServiceFactory::GetForProfile(profile()); | 1465 app_list::AppListSyncableServiceFactory::GetForProfile(profile()); |
1479 if (app_service) | 1466 if (app_service) |
1480 app_service->RemoveObserver(this); | 1467 app_service->RemoveObserver(this); |
1481 } | 1468 } |
1482 | 1469 |
1483 /////////////////////////////////////////////////////////////////////////////// | 1470 /////////////////////////////////////////////////////////////////////////////// |
1484 // ash::ShelfModelObserver: | 1471 // ash::ShelfModelObserver: |
1485 | 1472 |
1486 void ChromeLauncherControllerImpl::ShelfItemAdded(int index) { | 1473 void ChromeLauncherControllerImpl::ShelfItemAdded(int index) {} |
1487 } | |
1488 | 1474 |
1489 void ChromeLauncherControllerImpl::ShelfItemRemoved(int index, | 1475 void ChromeLauncherControllerImpl::ShelfItemRemoved(int index, |
1490 ash::ShelfID id) { | 1476 ash::ShelfID id) { |
1491 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we | 1477 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we |
1492 // get into this state in the first place. | 1478 // get into this state in the first place. |
1493 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); | 1479 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); |
1494 if (iter == id_to_item_controller_map_.end()) | 1480 if (iter == id_to_item_controller_map_.end()) |
1495 return; | 1481 return; |
1496 | 1482 |
1497 LOG(ERROR) << "Unexpected change of shelf item id: " << id; | 1483 LOG(ERROR) << "Unexpected removal of shelf item, id: " << id; |
1498 | |
1499 id_to_item_controller_map_.erase(iter); | 1484 id_to_item_controller_map_.erase(iter); |
1500 } | 1485 } |
1501 | 1486 |
1502 void ChromeLauncherControllerImpl::ShelfItemMoved(int start_index, | 1487 void ChromeLauncherControllerImpl::ShelfItemMoved(int start_index, |
1503 int target_index) { | 1488 int target_index) { |
1504 const ash::ShelfItem& item = model_->items()[target_index]; | 1489 const ash::ShelfItem& item = model_->items()[target_index]; |
1505 // We remember the moved item position if it is either pinnable or | 1490 // We remember the moved item position if it is either pinnable or |
1506 // it is the app list with the alternate shelf layout. | 1491 // it is the app list with the alternate shelf layout. |
1507 DCHECK_NE(ash::TYPE_APP_LIST, item.type); | 1492 DCHECK_NE(ash::TYPE_APP_LIST, item.type); |
1508 if (HasShelfIDToAppIDMapping(item.id) && IsPinned(item.id)) | 1493 if (HasShelfIDToAppIDMapping(item.id) && IsPinned(item.id)) |
1509 SyncPinPosition(item.id); | 1494 SyncPinPosition(item.id); |
1510 } | 1495 } |
1511 | 1496 |
1512 void ChromeLauncherControllerImpl::ShelfItemChanged( | 1497 void ChromeLauncherControllerImpl::ShelfItemChanged( |
1513 int index, | 1498 int index, |
1514 const ash::ShelfItem& old_item) {} | 1499 const ash::ShelfItem& old_item) {} |
1515 | 1500 |
1516 void ChromeLauncherControllerImpl::OnSetShelfItemDelegate( | 1501 void ChromeLauncherControllerImpl::OnSetShelfItemDelegate( |
1517 ash::ShelfID id, | 1502 ash::ShelfID id, |
1518 ash::ShelfItemDelegate* item_delegate) { | 1503 ash::ShelfItemDelegate* item_delegate) { |
1519 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we | 1504 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we |
1520 // get into this state in the first place. | 1505 // get into this state in the first place. |
1521 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); | 1506 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); |
1522 if (iter == id_to_item_controller_map_.end() || item_delegate == iter->second) | 1507 if (iter == id_to_item_controller_map_.end() || item_delegate == iter->second) |
1523 return; | 1508 return; |
1524 LOG(ERROR) << "Unexpected change of shelf item id: " << id; | 1509 LOG(ERROR) << "Unexpected change of shelf item delegate, id: " << id; |
1525 id_to_item_controller_map_.erase(iter); | 1510 id_to_item_controller_map_.erase(iter); |
1526 } | 1511 } |
1527 | 1512 |
1528 /////////////////////////////////////////////////////////////////////////////// | 1513 /////////////////////////////////////////////////////////////////////////////// |
1529 // ash::WindowTreeHostManager::Observer: | 1514 // ash::WindowTreeHostManager::Observer: |
1530 | 1515 |
1531 void ChromeLauncherControllerImpl::OnDisplayConfigurationChanged() { | 1516 void ChromeLauncherControllerImpl::OnDisplayConfigurationChanged() { |
1532 // In BOTTOM_LOCKED state, ignore the call of SetShelfBehaviorsFromPrefs. | 1517 // In BOTTOM_LOCKED state, ignore the call of SetShelfBehaviorsFromPrefs. |
1533 // Because it might be called by some operations, like crbug.com/627040 | 1518 // Because it might be called by some operations, like crbug.com/627040 |
1534 // rotating screen. | 1519 // rotating screen. |
(...skipping 13 matching lines...) Expand all Loading... | |
1548 model_->set_status(ash::ShelfModel::STATUS_NORMAL); | 1533 model_->set_status(ash::ShelfModel::STATUS_NORMAL); |
1549 } | 1534 } |
1550 | 1535 |
1551 /////////////////////////////////////////////////////////////////////////////// | 1536 /////////////////////////////////////////////////////////////////////////////// |
1552 // AppIconLoaderDelegate: | 1537 // AppIconLoaderDelegate: |
1553 | 1538 |
1554 void ChromeLauncherControllerImpl::OnAppImageUpdated( | 1539 void ChromeLauncherControllerImpl::OnAppImageUpdated( |
1555 const std::string& id, | 1540 const std::string& id, |
1556 const gfx::ImageSkia& image) { | 1541 const gfx::ImageSkia& image) { |
1557 // TODO: need to get this working for shortcuts. | 1542 // TODO: need to get this working for shortcuts. |
1558 for (IDToItemControllerMap::const_iterator i = | 1543 for (int index = 0; index < model_->item_count(); ++index) { |
1559 id_to_item_controller_map_.begin(); | 1544 ash::ShelfItem item = model_->items()[index]; |
1560 i != id_to_item_controller_map_.end(); ++i) { | 1545 if (GetAppIDForShelfID(item.id) != id) |
1561 LauncherItemController* controller = i->second; | |
1562 if (controller->app_id() != id) | |
1563 continue; | 1546 continue; |
1564 if (controller->image_set_by_controller()) | 1547 LauncherItemController* controller = GetLauncherItemController(item.id); |
1548 if (!controller || controller->image_set_by_controller()) | |
1565 continue; | 1549 continue; |
1566 int index = model_->ItemIndexByID(i->first); | |
1567 if (index == -1) | |
1568 continue; | |
1569 ash::ShelfItem item = model_->items()[index]; | |
1570 item.image = image; | 1550 item.image = image; |
1571 if (arc_deferred_launcher_) | 1551 if (arc_deferred_launcher_) |
1572 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); | 1552 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); |
1573 model_->Set(index, item); | 1553 model_->Set(index, item); |
1574 // It's possible we're waiting on more than one item, so don't break. | 1554 // It's possible we're waiting on more than one item, so don't break. |
1575 } | 1555 } |
1576 } | 1556 } |
OLD | NEW |