Chromium Code Reviews| Index: media/base/android/android_overlay.cc |
| diff --git a/media/base/android/android_overlay.cc b/media/base/android/android_overlay.cc |
| index 53fe296681f1ad9d422591c8f72994e3433aefc7..a50adc99a9fc6d7eef3d4361a31d78acacd5fef3 100644 |
| --- a/media/base/android/android_overlay.cc |
| +++ b/media/base/android/android_overlay.cc |
| @@ -6,4 +6,32 @@ |
| namespace media { |
| +AndroidOverlay::AndroidOverlay() : weak_factory_(this) {} |
| +AndroidOverlay::~AndroidOverlay() {} |
| + |
| +void AndroidOverlay::AddDestructionCallback( |
| + AndroidOverlayConfig::DestroyedCB cb) { |
| + destruction_cbs_.push_back(std::move(cb)); |
| +} |
| + |
| +void AndroidOverlay::RunDestructionCallbacks() { |
| + if (!destruction_cbs_.size()) |
|
watk
2017/05/16 19:10:28
nit: More idiomatic to write .empty() I think
liberato (no reviews please)
2017/05/16 20:04:02
Done.
|
| + 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. We don't want to call back |
| + // with an invalid |this| ptr. |
|
watk
2017/05/16 19:10:28
nit: not sure I understand the rationale as writte
liberato (no reviews please)
2017/05/16 20:04:02
if we call with |this| after it's deleted, then it
|
| + if (!wp) |
| + return; |
| + } |
| +} |
| + |
| } // namespace media |