Commit 5a63f26f authored by Fergus Dall's avatar Fergus Dall Committed by Commit Bot

Remove persistent app list folders when they become empty

In crrev.com/c/1454156 the checks in
AppsGridView::ReparentItemForReorder and
AppsGridView::ReparentItemToAnotherFolder to see if a folder would be
deleted by removing an app was broken for persistent folders. This
would cause the model for the folder to be deleted, while the view
remained in place. Interacting with the empty folder would then cause
a null dereference and crash chrome.

Bug: 1009989
Change-Id: Ief7bc007683b38d536aabb1418d8142e5c0f7702
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1837556Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Fergus Dall <sidereal@google.com>
Cr-Commit-Position: refs/heads/master@{#702884}
parent 496397d7
...@@ -2344,10 +2344,10 @@ void AppsGridView::ReparentItemForReorder(AppListItemView* item_view, ...@@ -2344,10 +2344,10 @@ void AppsGridView::ReparentItemForReorder(AppListItemView* item_view,
int target_model_index = GetTargetModelIndexForMove(item_view, target); int target_model_index = GetTargetModelIndexForMove(item_view, target);
int target_item_index = GetTargetItemIndexForMove(item_view, target); int target_item_index = GetTargetItemIndexForMove(item_view, target);
// If the folder is a candidate for removal, the view needs to be updated // Remove the source folder view if there is only 1 item in it, since the
// accordingly. // source folder will be deleted after its only child item removed from it.
GridIndex target_override = target; GridIndex target_override = target;
if (source_folder->ShouldAutoRemove()) { if (source_folder->ChildItemCount() == 1u) {
const int deleted_folder_index = const int deleted_folder_index =
view_model_.GetIndexOfView(activated_folder_item_view_); view_model_.GetIndexOfView(activated_folder_item_view_);
const GridIndex deleted_folder_grid_index = const GridIndex deleted_folder_grid_index =
...@@ -2415,8 +2415,10 @@ bool AppsGridView::ReparentItemToAnotherFolder(AppListItemView* item_view, ...@@ -2415,8 +2415,10 @@ bool AppsGridView::ReparentItemToAnotherFolder(AppListItemView* item_view,
// Make change to data model. // Make change to data model.
item_list_->RemoveObserver(this); item_list_->RemoveObserver(this);
// Remove the source folder view if the folder is a candidate for removal. // Remove the source folder view if there is only 1 item in it, since the
if (source_folder->ShouldAutoRemove()) { // source folder will be deleted after its only child item merged into the
// target item.
if (source_folder->ChildItemCount() == 1u) {
DeleteItemViewAtIndex( DeleteItemViewAtIndex(
view_model_.GetIndexOfView(activated_folder_item_view()), view_model_.GetIndexOfView(activated_folder_item_view()),
false /* sanitize */); false /* sanitize */);
......
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