| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chrome_launcher_prefs.h" | 5 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 DCHECK(profile); | 659 DCHECK(profile); |
| 660 DCHECK(!app_id.empty()); | 660 DCHECK(!app_id.empty()); |
| 661 app_list::AppListSyncableService* app_service = | 661 app_list::AppListSyncableService* app_service = |
| 662 app_list::AppListSyncableServiceFactory::GetForProfile(profile); | 662 app_list::AppListSyncableServiceFactory::GetForProfile(profile); |
| 663 app_service->SetPinPosition(app_id, syncer::StringOrdinal()); | 663 app_service->SetPinPosition(app_id, syncer::StringOrdinal()); |
| 664 } | 664 } |
| 665 | 665 |
| 666 void SetPinPosition(Profile* profile, | 666 void SetPinPosition(Profile* profile, |
| 667 const std::string& app_id, | 667 const std::string& app_id, |
| 668 const std::string& app_id_before, | 668 const std::string& app_id_before, |
| 669 const std::string& app_id_after) { | 669 const std::vector<std::string>& app_ids_after) { |
| 670 DCHECK(profile); | 670 DCHECK(profile); |
| 671 DCHECK(!app_id.empty()); | 671 DCHECK(!app_id.empty()); |
| 672 DCHECK_NE(app_id, app_id_before); | 672 DCHECK_NE(app_id, app_id_before); |
| 673 DCHECK_NE(app_id, app_id_after); | |
| 674 DCHECK(app_id_before.empty() || app_id_before != app_id_after); | |
| 675 | 673 |
| 676 app_list::AppListSyncableService* app_service = | 674 app_list::AppListSyncableService* app_service = |
| 677 app_list::AppListSyncableServiceFactory::GetForProfile(profile); | 675 app_list::AppListSyncableServiceFactory::GetForProfile(profile); |
| 678 // Some unit tests may not have this service. | 676 // Some unit tests may not have this service. |
| 679 if (!app_service) | 677 if (!app_service) |
| 680 return; | 678 return; |
| 681 | 679 |
| 682 syncer::StringOrdinal position_before = | 680 syncer::StringOrdinal position_before = |
| 683 app_id_before.empty() ? syncer::StringOrdinal() | 681 app_id_before.empty() ? syncer::StringOrdinal() |
| 684 : app_service->GetPinPosition(app_id_before); | 682 : app_service->GetPinPosition(app_id_before); |
| 685 syncer::StringOrdinal position_after = | 683 syncer::StringOrdinal position_after; |
| 686 app_id_after.empty() ? syncer::StringOrdinal() | 684 for (const auto& app_id_after : app_ids_after) { |
| 687 : app_service->GetPinPosition(app_id_after); | 685 DCHECK_NE(app_id_after, app_id); |
| 686 DCHECK_NE(app_id_after, app_id_before); |
| 687 syncer::StringOrdinal position = app_service->GetPinPosition(app_id_after); |
| 688 DCHECK(position.IsValid()); |
| 689 if (!position.IsValid()) { |
| 690 LOG(ERROR) << "Sync pin position was not found for " << app_id_after; |
| 691 continue; |
| 692 } |
| 693 if (!position_before.IsValid() || !position.Equals(position_before)) { |
| 694 position_after = position; |
| 695 break; |
| 696 } |
| 697 } |
| 688 | 698 |
| 689 syncer::StringOrdinal pin_position; | 699 syncer::StringOrdinal pin_position; |
| 690 if (position_before.IsValid() && position_after.IsValid()) | 700 if (position_before.IsValid() && position_after.IsValid()) |
| 691 pin_position = position_before.CreateBetween(position_after); | 701 pin_position = position_before.CreateBetween(position_after); |
| 692 else if (position_before.IsValid()) | 702 else if (position_before.IsValid()) |
| 693 pin_position = position_before.CreateAfter(); | 703 pin_position = position_before.CreateAfter(); |
| 694 else if (position_after.IsValid()) | 704 else if (position_after.IsValid()) |
| 695 pin_position = position_after.CreateBefore(); | 705 pin_position = position_after.CreateBefore(); |
| 696 else | 706 else |
| 697 pin_position = syncer::StringOrdinal::CreateInitialOrdinal(); | 707 pin_position = syncer::StringOrdinal::CreateInitialOrdinal(); |
| 698 app_service->SetPinPosition(app_id, pin_position); | 708 app_service->SetPinPosition(app_id, pin_position); |
| 699 } | 709 } |
| 700 | 710 |
| 701 } // namespace launcher | 711 } // namespace launcher |
| 702 } // namespace ash | 712 } // namespace ash |
| OLD | NEW |