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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 1125 matching lines...) Loading... | |
1136 GetDriveAppIdFromSyncId(item_id)); | 1136 GetDriveAppIdFromSyncId(item_id)); |
1137 } | 1137 } |
1138 } | 1138 } |
1139 } | 1139 } |
1140 | 1140 |
1141 std::string AppListSyncableService::FindOrCreateOemFolder() { | 1141 std::string AppListSyncableService::FindOrCreateOemFolder() { |
1142 AppListFolderItem* oem_folder = model_->FindFolderItem(kOemFolderId); | 1142 AppListFolderItem* oem_folder = model_->FindFolderItem(kOemFolderId); |
1143 if (!oem_folder) { | 1143 if (!oem_folder) { |
1144 std::unique_ptr<AppListFolderItem> new_folder(new AppListFolderItem( | 1144 std::unique_ptr<AppListFolderItem> new_folder(new AppListFolderItem( |
1145 kOemFolderId, AppListFolderItem::FOLDER_TYPE_OEM)); | 1145 kOemFolderId, AppListFolderItem::FOLDER_TYPE_OEM)); |
1146 oem_folder = | |
1147 static_cast<AppListFolderItem*>(model_->AddItem(std::move(new_folder))); | |
khmel
2017/03/04 02:57:06
It is not safe to add oem_folder to model and then
| |
1148 SyncItem* oem_sync_item = FindSyncItem(kOemFolderId); | 1146 SyncItem* oem_sync_item = FindSyncItem(kOemFolderId); |
1147 syncer::StringOrdinal oem_position; | |
1149 if (oem_sync_item) { | 1148 if (oem_sync_item) { |
1149 DCHECK(oem_sync_item->item_ordinal.IsValid()); | |
1150 VLOG(1) << "Creating OEM folder from existing sync item: " | 1150 VLOG(1) << "Creating OEM folder from existing sync item: " |
1151 << oem_sync_item->item_ordinal.ToDebugString(); | 1151 << oem_sync_item->item_ordinal.ToDebugString(); |
1152 model_->SetItemPosition(oem_folder, oem_sync_item->item_ordinal); | 1152 oem_position = oem_sync_item->item_ordinal; |
1153 } else { | 1153 } else { |
1154 model_->SetItemPosition(oem_folder, GetOemFolderPos()); | 1154 oem_position = GetOemFolderPos(); |
1155 // Do not create a sync item for the OEM folder here, do it in | 1155 // Do not create a sync item for the OEM folder here, do it in |
1156 // ResolveFolderPositions() when the item position is finalized. | 1156 // ResolveFolderPositions() when the item position is finalized. |
1157 } | 1157 } |
1158 oem_folder = | |
1159 static_cast<AppListFolderItem*>(model_->AddItem(std::move(new_folder))); | |
1160 model_->SetItemPosition(oem_folder, oem_position); | |
1158 } | 1161 } |
1159 model_->SetItemName(oem_folder, oem_folder_name_); | 1162 model_->SetItemName(oem_folder, oem_folder_name_); |
1160 return oem_folder->id(); | 1163 return oem_folder->id(); |
1161 } | 1164 } |
1162 | 1165 |
1163 syncer::StringOrdinal AppListSyncableService::GetOemFolderPos() { | 1166 syncer::StringOrdinal AppListSyncableService::GetOemFolderPos() { |
1164 VLOG(1) << "GetOemFolderPos: " << first_app_list_sync_; | 1167 VLOG(1) << "GetOemFolderPos: " << first_app_list_sync_; |
1165 if (!first_app_list_sync_) { | 1168 if (!first_app_list_sync_) { |
1166 VLOG(1) << "Sync items exist, placing OEM folder at end."; | 1169 VLOG(1) << "Sync items exist, placing OEM folder at end."; |
1167 syncer::StringOrdinal last; | 1170 syncer::StringOrdinal last; |
1168 for (const auto& sync_pair : sync_items_) { | 1171 for (const auto& sync_pair : sync_items_) { |
1169 SyncItem* sync_item = sync_pair.second.get(); | 1172 SyncItem* sync_item = sync_pair.second.get(); |
1170 if (sync_item->item_ordinal.IsValid() && | 1173 if (sync_item->item_ordinal.IsValid() && |
1171 (!last.IsValid() || sync_item->item_ordinal.GreaterThan(last))) { | 1174 (!last.IsValid() || sync_item->item_ordinal.GreaterThan(last))) { |
1172 last = sync_item->item_ordinal; | 1175 last = sync_item->item_ordinal; |
1173 } | 1176 } |
1174 } | 1177 } |
1175 if (last.IsValid()) | 1178 if (last.IsValid()) |
1176 return last.CreateAfter(); | 1179 return last.CreateAfter(); |
1177 } | 1180 } |
1178 | 1181 |
1179 // Place the OEM folder just after the web store, which should always be | 1182 // Place the OEM folder just after the web store, which should always be |
1180 // followed by a pre-installed app (e.g. Search), so the poosition should be | 1183 // followed by a pre-installed app (e.g. Search), so the poosition should be |
1181 // stable. TODO(stevenjb): consider explicitly setting the OEM folder location | 1184 // stable. TODO(stevenjb): consider explicitly setting the OEM folder location |
1182 // along with the name in ServicesCustomizationDocument::SetOemFolderName(). | 1185 // along with the name in ServicesCustomizationDocument::SetOemFolderName(). |
1183 AppListItemList* item_list = model_->top_level_item_list(); | 1186 AppListItemList* item_list = model_->top_level_item_list(); |
1184 if (item_list->item_count() == 0) | 1187 if (!item_list->item_count()) { |
1185 return syncer::StringOrdinal(); | 1188 LOG(ERROR) << "No top level item was found. " |
1189 << "Placing OEM folder at the beginning."; | |
1190 return syncer::StringOrdinal::CreateInitialOrdinal(); | |
1191 } | |
1186 | 1192 |
1187 size_t oem_index = 0; | 1193 for (size_t i = 0; i < item_list->item_count(); ++i) { |
1188 for (; oem_index < item_list->item_count() - 1; ++oem_index) { | 1194 const AppListItem* cur_item = item_list->item_at(i); |
1189 AppListItem* cur_item = item_list->item_at(oem_index); | 1195 DCHECK(cur_item->position().IsValid()); |
1190 if (cur_item->id() == extensions::kWebStoreAppId) | 1196 if (cur_item->id() != extensions::kWebStoreAppId) |
1191 break; | 1197 continue; |
stevenjb
2017/03/06 21:35:15
This is confusing to me. If you don't like the pre
khmel
2017/03/06 22:38:15
Thanks for idea! Hopefully |item_list| already has
| |
1198 // Skip items with the same position. | |
1199 for (size_t j = i + 1; j < item_list->item_count(); ++j) { | |
1200 const AppListItem* next_item = item_list->item_at(j); | |
1201 DCHECK(next_item->position().IsValid()); | |
1202 if (!next_item->position().Equals(cur_item->position())) { | |
1203 const syncer::StringOrdinal oem_ordinal = | |
1204 cur_item->position().CreateBetween(next_item->position()); | |
1205 VLOG(1) << "Placing OEM Folder at: " << j | |
1206 << " position: " << oem_ordinal.ToDebugString(); | |
1207 return oem_ordinal; | |
1208 } | |
1209 } | |
1210 | |
1211 const syncer::StringOrdinal oem_ordinal = | |
1212 cur_item->position().CreateAfter(); | |
1213 VLOG(1) << "Placing OEM Folder at: " << item_list->item_count() | |
1214 << " position: " << oem_ordinal.ToDebugString(); | |
1215 return oem_ordinal; | |
1192 } | 1216 } |
1193 syncer::StringOrdinal oem_ordinal; | 1217 |
1194 AppListItem* prev = item_list->item_at(oem_index); | 1218 LOG(ERROR) << "Web store position is not found it top items. " |
1195 if (oem_index + 1 < item_list->item_count()) { | 1219 << "Placing OEM folder at the end."; |
1196 AppListItem* next = item_list->item_at(oem_index + 1); | 1220 return item_list->item_at(item_list->item_count() - 1) |
1197 oem_ordinal = prev->position().CreateBetween(next->position()); | 1221 ->position() |
1198 } else { | 1222 .CreateAfter(); |
1199 oem_ordinal = prev->position().CreateAfter(); | |
1200 } | |
1201 VLOG(1) << "Placing OEM Folder at: " << oem_index | |
1202 << " position: " << oem_ordinal.ToDebugString(); | |
1203 return oem_ordinal; | |
1204 } | 1223 } |
1205 | 1224 |
1206 bool AppListSyncableService::AppIsOem(const std::string& id) { | 1225 bool AppListSyncableService::AppIsOem(const std::string& id) { |
1207 #if defined(OS_CHROMEOS) | 1226 #if defined(OS_CHROMEOS) |
1208 const ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(profile_); | 1227 const ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(profile_); |
1209 if (arc_prefs && arc_prefs->IsOem(id)) | 1228 if (arc_prefs && arc_prefs->IsOem(id)) |
1210 return true; | 1229 return true; |
1211 #endif | 1230 #endif |
1212 | 1231 |
1213 if (!extension_system_->extension_service()) | 1232 if (!extension_system_->extension_service()) |
(...skipping 11 matching lines...) Loading... | |
1225 res += " { " + item_name + " }"; | 1244 res += " { " + item_name + " }"; |
1226 res += " [" + item_ordinal.ToDebugString() + "]"; | 1245 res += " [" + item_ordinal.ToDebugString() + "]"; |
1227 if (!parent_id.empty()) | 1246 if (!parent_id.empty()) |
1228 res += " <" + parent_id.substr(0, 8) + ">"; | 1247 res += " <" + parent_id.substr(0, 8) + ">"; |
1229 res += " [" + item_pin_ordinal.ToDebugString() + "]"; | 1248 res += " [" + item_pin_ordinal.ToDebugString() + "]"; |
1230 } | 1249 } |
1231 return res; | 1250 return res; |
1232 } | 1251 } |
1233 | 1252 |
1234 } // namespace app_list | 1253 } // namespace app_list |
OLD | NEW |