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/app_list/app_list_syncable_service.h" | 5 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/browser/apps/drive/drive_app_provider.h" | 8 #include "chrome/browser/apps/drive/drive_app_provider.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 syncer::StringOrdinal last; | 868 syncer::StringOrdinal last; |
869 for (SyncItemMap::iterator iter = sync_items_.begin(); | 869 for (SyncItemMap::iterator iter = sync_items_.begin(); |
870 iter != sync_items_.end(); ++iter) { | 870 iter != sync_items_.end(); ++iter) { |
871 SyncItem* sync_item = iter->second; | 871 SyncItem* sync_item = iter->second; |
872 if (!last.IsValid() || sync_item->item_ordinal.GreaterThan(last)) | 872 if (!last.IsValid() || sync_item->item_ordinal.GreaterThan(last)) |
873 last = sync_item->item_ordinal; | 873 last = sync_item->item_ordinal; |
874 } | 874 } |
875 return last.CreateAfter(); | 875 return last.CreateAfter(); |
876 } | 876 } |
877 | 877 |
878 // Place the OEM folder just before the last unremovable default item. | 878 // Place the OEM folder just after the web store, which should always be |
879 // Since positions are relative, anywhere else is unstable. TODO(stevenjb): | 879 // followed by a pre-installed app (e.g. Search), so the poosition should be |
880 // consider explicitly setting the OEM folder location along with the name in | 880 // stable. TODO(stevenjb): consider explicitly setting the OEM folder location |
881 // ServicesCustomizationDocument::SetOemFolderName(). | 881 // along with the name in ServicesCustomizationDocument::SetOemFolderName(). |
882 AppListItemList* item_list = model_->top_level_item_list(); | 882 AppListItemList* item_list = model_->top_level_item_list(); |
| 883 if (item_list->item_count() == 0) |
| 884 return syncer::StringOrdinal(); |
| 885 |
883 size_t oem_index = 0; | 886 size_t oem_index = 0; |
884 for (int i = static_cast<int>(item_list->item_count()) - 1; i >= 0; --i) { | 887 for (; oem_index < item_list->item_count() - 1; ++oem_index) { |
885 AppListItem* cur_item = item_list->item_at(i); | 888 AppListItem* cur_item = item_list->item_at(oem_index); |
886 const std::string& id = cur_item->id(); | 889 if (cur_item->id() == extension_misc::kWebStoreAppId) |
887 if (IsUnRemovableDefaultApp(id)) { | |
888 oem_index = i; | |
889 break; | 890 break; |
890 } | |
891 } | 891 } |
892 syncer::StringOrdinal oem_ordinal; | 892 syncer::StringOrdinal oem_ordinal; |
893 AppListItem* next = item_list->item_at(oem_index); | 893 AppListItem* prev = item_list->item_at(oem_index); |
894 if (oem_index > 0) { | 894 if (oem_index + 1 < item_list->item_count()) { |
895 AppListItem* prev = item_list->item_at(oem_index - 1); | 895 AppListItem* next = item_list->item_at(oem_index + 1); |
896 oem_ordinal = prev->position().CreateBetween(next->position()); | 896 oem_ordinal = prev->position().CreateBetween(next->position()); |
897 } else { | 897 } else { |
898 oem_ordinal = next->position().CreateBefore(); | 898 oem_ordinal = prev->position().CreateAfter(); |
899 } | 899 } |
900 DVLOG(1) << "Placing OEM Folder at: " << oem_index | 900 VLOG(1) << "Placing OEM Folder at: " << oem_index |
901 << " position: " << oem_ordinal.ToDebugString(); | 901 << " position: " << oem_ordinal.ToDebugString(); |
902 return oem_ordinal; | 902 return oem_ordinal; |
903 } | 903 } |
904 | 904 |
905 bool AppListSyncableService::AppIsOem(const std::string& id) { | 905 bool AppListSyncableService::AppIsOem(const std::string& id) { |
906 if (!extension_system_->extension_service()) | 906 if (!extension_system_->extension_service()) |
907 return false; | 907 return false; |
908 const extensions::Extension* extension = | 908 const extensions::Extension* extension = |
909 extension_system_->extension_service()->GetExtensionById(id, true); | 909 extension_system_->extension_service()->GetExtensionById(id, true); |
910 return extension && extension->was_installed_by_oem(); | 910 return extension && extension->was_installed_by_oem(); |
911 } | 911 } |
912 | 912 |
913 std::string AppListSyncableService::SyncItem::ToString() const { | 913 std::string AppListSyncableService::SyncItem::ToString() const { |
914 std::string res = item_id.substr(0, 8); | 914 std::string res = item_id.substr(0, 8); |
915 if (item_type == sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) { | 915 if (item_type == sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) { |
916 res += " { RemoveDefault }"; | 916 res += " { RemoveDefault }"; |
917 } else { | 917 } else { |
918 res += " { " + item_name + " }"; | 918 res += " { " + item_name + " }"; |
919 res += " [" + item_ordinal.ToDebugString() + "]"; | 919 res += " [" + item_ordinal.ToDebugString() + "]"; |
920 if (!parent_id.empty()) | 920 if (!parent_id.empty()) |
921 res += " <" + parent_id.substr(0, 8) + ">"; | 921 res += " <" + parent_id.substr(0, 8) + ">"; |
922 } | 922 } |
923 return res; | 923 return res; |
924 } | 924 } |
925 | 925 |
926 } // namespace app_list | 926 } // namespace app_list |
OLD | NEW |