Commit defada06 authored by Weidong Guo's avatar Weidong Guo Committed by Commit Bot

Fix a crash when apps grid gap is enabled

Background:
A crash occur when a page break item exists in folder. (Not sure why a
page break item gets into folder.)

Changes:
Remove the page break item from folder if it exists.

Bug: 873485
Change-Id: I0cc435ae8d47c056eeec4b04a8afe7f5cc989588
Reviewed-on: https://chromium-review.googlesource.com/1172071
Commit-Queue: Weidong Guo <weidongg@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583125}
parent ec19b70f
......@@ -78,6 +78,10 @@ void UpdateSyncItemFromSync(const sync_pb::AppListSpecifics& specifics,
bool UpdateSyncItemFromAppItem(const ChromeAppListItem* app_item,
AppListSyncableService::SyncItem* sync_item) {
DCHECK_EQ(sync_item->item_id, app_item->id());
// Page breaker should not be added in a folder.
DCHECK(!app_item->is_page_break() || app_item->folder_id().empty());
bool changed = false;
if (sync_item->parent_id != app_item->folder_id()) {
sync_item->parent_id = app_item->folder_id();
......@@ -1201,11 +1205,22 @@ void AppListSyncableService::PruneRedundantPageBreakItems() {
}
}
// Remove the trailing "page break" itme if it exists.
// Remove the trailing "page break" item if it exists.
if (!top_level_sync_items.empty() &&
IsPageBreakItem(*top_level_sync_items.back())) {
DeleteSyncItem(top_level_sync_items.back()->item_id);
}
// Remove all the "page break" items that are in folder. No such item should
// exist in folder. It should be safe to remove them if it do occur.
for (auto iter = sync_items_.begin(); iter != sync_items_.end();) {
const auto* sync_item = (iter++)->second.get();
if (IsTopLevelAppItem(*sync_item) || !IsPageBreakItem(*sync_item))
continue;
LOG(ERROR) << "Delete a page break item in folder: " << sync_item->item_id;
DeleteSyncItem(sync_item->item_id);
}
}
} // namespace app_list
......@@ -260,7 +260,7 @@ class AppListSyncableService : public syncer::SyncableService,
// TODO(http://crbug.com/794724): Remove after M65 goes stable.
void RemoveDriveAppItems();
// Returns a list of sync items sorted by item ordinal.
// Returns a list of top level sync items sorted by item ordinal.
std::vector<SyncItem*> GetSortedTopLevelSyncItems() const;
// Remove leading, trailing and duplicate "page break" items in sorted top
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment