Commit d99281fc authored by Julian Watson's avatar Julian Watson Committed by Commit Bot

crostini: explicitly test lifetimes of controller/notification

The CrostiniExportImportNotificationController's lifetime is tied to the
lifetime of the UI notification, not to the lifetime of the controller
stored on the CrostiniExportImport object. This CL changes the existing
tests to explicitly test these lifetimes.

A following CL further decouples the lifetimes of the
UI/controller/export_import object, and builds upon this CL for its
testing.

Bug: 1024693
Change-Id: I2fe6b906532dd49d1808afe88683bf573a393b0e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1991055Reviewed-by: default avatarDavid Munro <davidmunro@google.com>
Commit-Queue: Julian Watson <juwa@google.com>
Auto-Submit: Julian Watson <juwa@google.com>
Cr-Commit-Position: refs/heads/master@{#729625}
parent de99484b
...@@ -616,14 +616,15 @@ bool CrostiniExportImport::GetExportImportOperationStatus() const { ...@@ -616,14 +616,15 @@ bool CrostiniExportImport::GetExportImportOperationStatus() const {
return status_trackers_.find(id) != status_trackers_.end(); return status_trackers_.find(id) != status_trackers_.end();
} }
CrostiniExportImportNotificationController* base::WeakPtr<CrostiniExportImportNotificationController>
CrostiniExportImport::GetNotificationControllerForTesting( CrostiniExportImport::GetNotificationControllerForTesting(
ContainerId container_id) { ContainerId container_id) {
auto it = status_trackers_.find(container_id); auto it = status_trackers_.find(container_id);
if (it == status_trackers_.end()) { if (it == status_trackers_.end()) {
return nullptr; return nullptr;
} }
return static_cast<CrostiniExportImportNotificationController*>(it->second); return static_cast<CrostiniExportImportNotificationController*>(it->second)
->GetWeakPtr();
} }
} // namespace crostini } // namespace crostini
...@@ -117,7 +117,7 @@ class CrostiniExportImport : public KeyedService, ...@@ -117,7 +117,7 @@ class CrostiniExportImport : public KeyedService,
// Whether an export or import is currently in progress. // Whether an export or import is currently in progress.
bool GetExportImportOperationStatus() const; bool GetExportImportOperationStatus() const;
CrostiniExportImportNotificationController* base::WeakPtr<CrostiniExportImportNotificationController>
GetNotificationControllerForTesting(ContainerId container_id); GetNotificationControllerForTesting(ContainerId container_id);
private: private:
......
...@@ -49,6 +49,9 @@ class CrostiniExportImportNotificationController ...@@ -49,6 +49,9 @@ class CrostiniExportImportNotificationController
message_center::Notification* get_notification() { message_center::Notification* get_notification() {
return notification_.get(); return notification_.get();
} }
base::WeakPtr<CrostiniExportImportNotificationController> GetWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
}
// message_center::NotificationObserver: // message_center::NotificationObserver:
void Close(bool by_user) override; void Close(bool by_user) override;
......
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