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 #include "components/view_manager/public/cpp/scoped_view_ptr.h"
7 #include "components/view_manager/public/cpp/view.h"
8 #include "components/view_manager/public/cpp/view_observer.h"
9 #include "components/view_manager/public/cpp/view_tree_connection.h"
13 ScopedViewPtr::ScopedViewPtr(View
* view
)
15 view_
->AddObserver(this);
18 ScopedViewPtr::~ScopedViewPtr() {
20 DeleteViewOrViewManager(view_
);
25 void ScopedViewPtr::DeleteViewOrViewManager(View
* view
) {
26 if (view
->connection()->GetRoot() == view
)
27 delete view
->connection();
32 void ScopedViewPtr::DetachFromView() {
36 view_
->RemoveObserver(this);
40 void ScopedViewPtr::OnViewDestroying(View
* view
) {
41 DCHECK_EQ(view_
, view
);