TabStripModelObserver: clean up on destruction
This change has TabStripModelObserver remember which TabStripModels it
is observing, and unregister from those if necessary on destruction. It
also removes instances of now-unnecessary cleanup code in subclass
destructors.
This change also introduces a new observable event on
TabStripModelObserver: OnTabStripModelDestroyed. This event
notifies observers that the model is being destroyed so
they can do any necessary cleanup. In the future most uses
of TabStripModelObserver::TabStripEmpty() should migrate to
OnTabStripModelDestroyed().
Bug: 991308
Change-Id: Ifed459ec4d88136db4a00e4386dc6c2095048b46
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1739552
Commit-Queue: Elly Fong-Jones <[email protected]>
Auto-Submit: Elly Fong-Jones <[email protected]>
Reviewed-by: Nico Weber <[email protected]>
Cr-Commit-Position: refs/heads/master@{#686075}
diff --git a/chrome/browser/ui/search/instant_controller.cc b/chrome/browser/ui/search/instant_controller.cc
index e146612..b8fc888 100644
--- a/chrome/browser/ui/search/instant_controller.cc
+++ b/chrome/browser/ui/search/instant_controller.cc
@@ -41,8 +41,8 @@
InstantController::InstantController(Profile* profile,
TabStripModel* tab_strip_model)
- : profile_(profile), tab_strip_observer_(this) {
- tab_strip_observer_.Add(tab_strip_model);
+ : profile_(profile) {
+ tab_strip_model->AddObserver(this);
}
InstantController::~InstantController() = default;