Chromium Code Reviews| 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::AddDestructionCallback( | |
| 13 AndroidOverlayConfig::DestroyedCB cb) { | |
| 14 destruction_cbs_.push_back(std::move(cb)); | |
| 15 } | |
| 16 | |
| 17 void AndroidOverlay::RunDestructionCallbacks() { | |
| 18 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.
| |
| 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. We don't want to call back | |
| 31 // 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
| |
| 32 if (!wp) | |
| 33 return; | |
| 34 } | |
| 35 } | |
| 36 | |
| 9 } // namespace media | 37 } // namespace media |
| OLD | NEW |