1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "ui/views/widget/widget_deletion_observer.h" 6 7 #include "ui/views/widget/widget.h" 8 9 namespace views { 10 WidgetDeletionObserver(Widget * widget)11WidgetDeletionObserver::WidgetDeletionObserver(Widget* widget) 12 : widget_(widget) { 13 if (widget_) 14 widget_->AddObserver(this); 15 } 16 ~WidgetDeletionObserver()17WidgetDeletionObserver::~WidgetDeletionObserver() { 18 CleanupWidget(); 19 CHECK(!IsInObserverList()); 20 } 21 OnWidgetDestroying(Widget * widget)22void WidgetDeletionObserver::OnWidgetDestroying(Widget* widget) { 23 CleanupWidget(); 24 } 25 CleanupWidget()26void WidgetDeletionObserver::CleanupWidget() { 27 if (widget_) { 28 widget_->RemoveObserver(this); 29 widget_ = nullptr; 30 } 31 } 32 33 } // namespace views 34