Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / components / view_manager / public / cpp / scoped_view_ptr.h
blobb9cba09d603be9111601d990a326d8b2e37475bb
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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_VIEW_MANAGER_PUBLIC_CPP_SCOPED_VIEW_PTR_H_
6 #define COMPONENTS_VIEW_MANAGER_PUBLIC_CPP_SCOPED_VIEW_PTR_H_
8 #include "components/view_manager/public/cpp/view_observer.h"
10 namespace mojo {
12 // Wraps a View, taking overship of the View. Also deals with View being
13 // destroyed while ScopedViewPtr still exists.
14 class ScopedViewPtr : public ViewObserver {
15 public:
16 explicit ScopedViewPtr(View* view);
17 ~ScopedViewPtr() override;
19 // Destroys |view|. If |view| is the root of the ViewManager than the
20 // ViewManager is destroyed (which in turn destroys |view|).
21 static void DeleteViewOrViewManager(View* view);
23 View* view() { return view_; }
24 const View* view() const { return view_; }
26 private:
27 void DetachFromView();
29 void OnViewDestroying(View* view) override;
31 View* view_;
33 DISALLOW_COPY_AND_ASSIGN(ScopedViewPtr);
36 } // namespace mojo
38 #endif // COMPONENTS_VIEW_MANAGER_PUBLIC_CPP_SCOPED_VIEW_PTR_H_