Home | History | Annotate | Download | only in widget
      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 
     11 WidgetDeletionObserver::WidgetDeletionObserver(Widget* widget)
     12     : widget_(widget) {
     13   if (widget_)
     14     widget_->AddObserver(this);
     15 }
     16 
     17 WidgetDeletionObserver::~WidgetDeletionObserver() {
     18   CleanupWidget();
     19 }
     20 
     21 void WidgetDeletionObserver::OnWidgetDestroying(Widget* widget) {
     22   CleanupWidget();
     23 }
     24 
     25 void WidgetDeletionObserver::CleanupWidget() {
     26   if (widget_) {
     27     widget_->RemoveObserver(this);
     28     widget_ = NULL;
     29   }
     30 }
     31 
     32 }  // namespace views
     33