| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_MUS_PUBLIC_CPP_SCOPED_VIEW_PTR_H_ | 5 #ifndef COMPONENTS_MUS_PUBLIC_CPP_SCOPED_VIEW_PTR_H_ |
| 6 #define COMPONENTS_MUS_PUBLIC_CPP_SCOPED_VIEW_PTR_H_ | 6 #define COMPONENTS_MUS_PUBLIC_CPP_SCOPED_VIEW_PTR_H_ |
| 7 | 7 |
| 8 #include "components/mus/public/cpp/view_observer.h" | 8 #include "components/mus/public/cpp/view_observer.h" |
| 9 | 9 |
| 10 namespace mus { | 10 namespace mojo { |
| 11 | 11 |
| 12 // Wraps a View, taking overship of the View. Also deals with View being | 12 // Wraps a View, taking overship of the View. Also deals with View being |
| 13 // destroyed while ScopedViewPtr still exists. | 13 // destroyed while ScopedViewPtr still exists. |
| 14 class ScopedViewPtr : public ViewObserver { | 14 class ScopedViewPtr : public ViewObserver { |
| 15 public: | 15 public: |
| 16 explicit ScopedViewPtr(View* view); | 16 explicit ScopedViewPtr(View* view); |
| 17 ~ScopedViewPtr() override; | 17 ~ScopedViewPtr() override; |
| 18 | 18 |
| 19 // Destroys |view|. If |view| is the root of the ViewManager than the | 19 // Destroys |view|. If |view| is the root of the ViewManager than the |
| 20 // ViewManager is destroyed (which in turn destroys |view|). | 20 // ViewManager is destroyed (which in turn destroys |view|). |
| 21 static void DeleteViewOrViewManager(View* view); | 21 static void DeleteViewOrViewManager(View* view); |
| 22 | 22 |
| 23 View* view() { return view_; } | 23 View* view() { return view_; } |
| 24 const View* view() const { return view_; } | 24 const View* view() const { return view_; } |
| 25 | 25 |
| 26 private: | 26 private: |
| 27 void DetachFromView(); | 27 void DetachFromView(); |
| 28 | 28 |
| 29 void OnViewDestroying(View* view) override; | 29 void OnViewDestroying(View* view) override; |
| 30 | 30 |
| 31 View* view_; | 31 View* view_; |
| 32 | 32 |
| 33 DISALLOW_COPY_AND_ASSIGN(ScopedViewPtr); | 33 DISALLOW_COPY_AND_ASSIGN(ScopedViewPtr); |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 } // namespace mus | 36 } // namespace mojo |
| 37 | 37 |
| 38 #endif // COMPONENTS_MUS_PUBLIC_CPP_SCOPED_VIEW_PTR_H_ | 38 #endif // COMPONENTS_MUS_PUBLIC_CPP_SCOPED_VIEW_PTR_H_ |
| OLD | NEW |