summaryrefslogtreecommitdiff
path: root/chromium/media/base/android/android_overlay.cc
blob: e24c39c44e431ce0601125c6c07adb21baadd006 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/base/android/android_overlay.h"

namespace media {

AndroidOverlay::AndroidOverlay() : weak_factory_(this) {}
AndroidOverlay::~AndroidOverlay() {}

void AndroidOverlay::AddSurfaceDestroyedCallback(
    AndroidOverlayConfig::DestroyedCB cb) {
  destruction_cbs_.push_back(std::move(cb));
}

void AndroidOverlay::RunSurfaceDestroyedCallbacks() {
  if (destruction_cbs_.empty())
    return;

  // Move the list, in case it's modified during traversal.
  std::list<AndroidOverlayConfig::DestroyedCB> cbs =
      std::move(destruction_cbs_);

  // Get a wp for |this|, in case it's destroyed during a callback.
  base::WeakPtr<AndroidOverlay> wp = weak_factory_.GetWeakPtr();

  for (auto& cb : cbs) {
    std::move(cb).Run(this);
    // If |this| has been deleted, then stop here.
    if (!wp)
      return;
  }
}

}  // namespace media