OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/base/android/android_overlay.h" | 5 #include "media/base/android/android_overlay.h" |
6 | 6 |
7 namespace media { | 7 namespace media { |
8 | 8 |
| 9 AndroidOverlay::AndroidOverlay() : weak_factory_(this) {} |
| 10 AndroidOverlay::~AndroidOverlay() {} |
| 11 |
| 12 void AndroidOverlay::AddSurfaceDestroyedCallback( |
| 13 AndroidOverlayConfig::DestroyedCB cb) { |
| 14 destruction_cbs_.push_back(std::move(cb)); |
| 15 } |
| 16 |
| 17 void AndroidOverlay::RunSurfaceDestroyedCallbacks() { |
| 18 if (destruction_cbs_.empty()) |
| 19 return; |
| 20 |
| 21 // Move the list, in case it's modified during traversal. |
| 22 std::list<AndroidOverlayConfig::DestroyedCB> cbs = |
| 23 std::move(destruction_cbs_); |
| 24 |
| 25 // Get a wp for |this|, in case it's destroyed during a callback. |
| 26 base::WeakPtr<AndroidOverlay> wp = weak_factory_.GetWeakPtr(); |
| 27 |
| 28 for (auto& cb : cbs) { |
| 29 std::move(cb).Run(this); |
| 30 // If |this| has been deleted, then stop here. |
| 31 if (!wp) |
| 32 return; |
| 33 } |
| 34 } |
| 35 |
9 } // namespace media | 36 } // namespace media |
OLD | NEW |