2023-06-14 10:20:02 +02:00
|
|
|
// Copyright 2023 The Chromium Embedded Framework Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be found
|
|
|
|
// in the LICENSE file.
|
|
|
|
|
2024-05-11 17:48:38 +02:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2023-06-14 10:20:02 +02:00
|
|
|
#include "base/scoped_observation.h"
|
|
|
|
#include "ui/views/widget/widget_observer.h"
|
|
|
|
|
|
|
|
// Tracks if a given widget has been destroyed.
|
|
|
|
class WidgetDestructionObserver : public views::WidgetObserver {
|
|
|
|
public:
|
|
|
|
explicit WidgetDestructionObserver(views::Widget* widget) : widget_(widget) {
|
|
|
|
DCHECK(widget);
|
|
|
|
observation_.Observe(widget);
|
|
|
|
}
|
|
|
|
WidgetDestructionObserver(const WidgetDestructionObserver&) = delete;
|
|
|
|
WidgetDestructionObserver& operator=(const WidgetDestructionObserver&) =
|
|
|
|
delete;
|
|
|
|
~WidgetDestructionObserver() override = default;
|
|
|
|
|
|
|
|
// views::WidgetObserver:
|
|
|
|
void OnWidgetDestroyed(views::Widget* widget) override {
|
|
|
|
DCHECK(widget_);
|
|
|
|
widget_ = nullptr;
|
|
|
|
observation_.Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
views::Widget* widget() const { return widget_; }
|
|
|
|
|
|
|
|
private:
|
2024-05-11 17:48:38 +02:00
|
|
|
raw_ptr<views::Widget> widget_;
|
2023-06-14 10:20:02 +02:00
|
|
|
|
|
|
|
base::ScopedObservation<views::Widget, views::WidgetObserver> observation_{
|
|
|
|
this};
|
|
|
|
};
|