Skip to content

Commit

Permalink
desk_templates: Fix crash when shut down DesksTemplatesPresenter.
Browse files Browse the repository at this point in the history
The DesksClient shuts down before Shell, making the model unusable
during Shell shutdown. This adds a observer to check when the model is
destroying, to give observers a chance to remove themselves.

Fixed: 1258979
Test: manual
Change-Id: Iee5e22485c180c09511ac4da4105f9f8f0e73985
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3218653
Reviewed-by: Colin Blundell <blundell@chromium.org>
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/main@{#931088}
  • Loading branch information
Sammie Quon authored and Chromium LUCI CQ committed Oct 13, 2021
1 parent bfb2489 commit 0768c49
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions ash/wm/desks/templates/desks_templates_presenter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ DesksTemplatesPresenter::DesksTemplatesPresenter(

DesksTemplatesPresenter::~DesksTemplatesPresenter() = default;

void DesksTemplatesPresenter::OnDeskModelDestroying() {
desk_model_observation_.Reset();
}

void DesksTemplatesPresenter::OnGetAllEntries(
desks_storage::DeskModel::GetAllEntriesStatus status,
std::vector<DeskTemplate*> entries) {
Expand Down
1 change: 1 addition & 0 deletions ash/wm/desks/templates/desks_templates_presenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ASH_EXPORT DesksTemplatesPresenter : desks_storage::DeskModelObserver {
// TODO(sammiequon): Implement these once the model starts sending these
// messages.
void DeskModelLoaded() override {}
void OnDeskModelDestroying() override;
void EntriesAddedOrUpdatedRemotely(
const std::vector<const ash::DeskTemplate*>& new_entries) override {}
void EntriesRemovedRemotely(const std::vector<std::string>& uuids) override {}
Expand Down
7 changes: 5 additions & 2 deletions components/desks_storage/core/desk_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ namespace desks_storage {

DeskModel::DeskModel() = default;

DeskModel::~DeskModel() = default;
DeskModel::~DeskModel() {
for (DeskModelObserver& observer : observers_)
observer.OnDeskModelDestroying();
}

void DeskModel::AddObserver(DeskModelObserver* observer) {
DCHECK(observer);
Expand Down Expand Up @@ -42,4 +45,4 @@ void DeskModel::SetPolicyDeskTemplates(const std::string& policyJson) {
}
}

} // namespace desks_storage
} // namespace desks_storage
7 changes: 6 additions & 1 deletion components/desks_storage/core/desk_model_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class DeskModelObserver {
// is unsafe to use the model.
virtual void DeskModelLoaded() = 0;

// Invoked when the model is about to be destroyed. Gives observes which may
// outlive the model a chance to stop observing. Not pure virtual because it
// needs to be called from the destructor.
virtual void OnDeskModelDestroying() {}

// Invoked when desk templates are added/updated, removed remotely via sync.
// This is the mechanism for the sync server to push changes in the state of
// the model to clients.
Expand All @@ -45,4 +50,4 @@ class DeskModelObserver {

} // namespace desks_storage

#endif // COMPONENTS_DESKS_STORAGE_CORE_DESK_MODEL_OBSERVER_H_
#endif // COMPONENTS_DESKS_STORAGE_CORE_DESK_MODEL_OBSERVER_H_
2 changes: 1 addition & 1 deletion components/desks_storage/core/desk_sync_bridge_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -953,4 +953,4 @@ TEST_F(DeskSyncBridgeTest, MergeSyncDataUploadsLocalOnlyEntries) {

} // namespace

} // namespace desks_storage
} // namespace desks_storage

0 comments on commit 0768c49

Please sign in to comment.