OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "services/ui/public/cpp/scoped_window_ptr.h" | |
6 | |
7 #include "services/ui/public/cpp/window.h" | |
8 #include "services/ui/public/cpp/window_observer.h" | |
9 #include "services/ui/public/cpp/window_tree_client.h" | |
10 | |
11 namespace ui { | |
12 | |
13 ScopedWindowPtr::ScopedWindowPtr(Window* window) : window_(window) { | |
14 window_->AddObserver(this); | |
15 } | |
16 | |
17 ScopedWindowPtr::~ScopedWindowPtr() { | |
18 if (window_) | |
19 DeleteWindowOrWindowManager(window_); | |
20 DetachFromWindow(); | |
21 } | |
22 | |
23 // static | |
24 void ScopedWindowPtr::DeleteWindowOrWindowManager(Window* window) { | |
25 if (window->window_tree()->GetRoots().count(window) > 0) | |
26 delete window->window_tree(); | |
27 else | |
28 window->Destroy(); | |
29 } | |
30 | |
31 void ScopedWindowPtr::DetachFromWindow() { | |
32 if (!window_) | |
33 return; | |
34 | |
35 window_->RemoveObserver(this); | |
36 window_ = nullptr; | |
37 } | |
38 | |
39 void ScopedWindowPtr::OnWindowDestroying(Window* window) { | |
40 DCHECK_EQ(window_, window); | |
41 DetachFromWindow(); | |
42 } | |
43 | |
44 } // namespace ui | |
OLD | NEW |