1// Copyright 2014 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/compositor/layer_tree_owner.h"
6
7#include "ui/compositor/layer.h"
8
9namespace ui {
10
11namespace {
12
13// Deletes |layer| and all its descendants.
14void DeepDeleteLayers(Layer* layer) {
15  std::vector<Layer*> children = layer->children();
16  for (std::vector<Layer*>::const_iterator it = children.begin();
17       it != children.end();
18       ++it) {
19    Layer* child = *it;
20    DeepDeleteLayers(child);
21  }
22  delete layer;
23}
24
25}  // namespace
26
27LayerTreeOwner::LayerTreeOwner(Layer* root) : root_(root) {}
28
29LayerTreeOwner::~LayerTreeOwner() {
30  if (root_)
31    DeepDeleteLayers(root_);
32}
33
34}  // namespace ui
35