| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/renderer/media/renderer_webmediaplayer_delegate.h" | 5 #include "content/renderer/media/renderer_webmediaplayer_delegate.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 return; | 213 return; |
| 214 } | 214 } |
| 215 | 215 |
| 216 idle_delegate_map_.erase(delegate_id); | 216 idle_delegate_map_.erase(delegate_id); |
| 217 if (idle_delegate_map_.empty()) | 217 if (idle_delegate_map_.empty()) |
| 218 idle_cleanup_timer_.Stop(); | 218 idle_cleanup_timer_.Stop(); |
| 219 } | 219 } |
| 220 | 220 |
| 221 void RendererWebMediaPlayerDelegate::CleanupIdleDelegates( | 221 void RendererWebMediaPlayerDelegate::CleanupIdleDelegates( |
| 222 base::TimeDelta timeout) { | 222 base::TimeDelta timeout) { |
| 223 // Drop reentrant cleanups which can occur during forced suspension when the |
| 224 // number of idle delegates is too high for a given device. |
| 225 if (idle_cleanup_running_) |
| 226 return; |
| 227 |
| 223 // Iterate over the delegates and suspend the idle ones. Note: The call to | 228 // Iterate over the delegates and suspend the idle ones. Note: The call to |
| 224 // OnHidden() can trigger calls into RemoveIdleDelegate(), so for iterator | 229 // OnSuspendRequested() can trigger calls into RemoveIdleDelegate(), so for |
| 225 // validity we set |idle_cleanup_running_| to true and defer deletions. | 230 // iterator validity we set |idle_cleanup_running_| to true and defer |
| 231 // deletions. |
| 232 DCHECK(!idle_cleanup_running_); |
| 226 base::AutoReset<bool> scoper(&idle_cleanup_running_, true); | 233 base::AutoReset<bool> scoper(&idle_cleanup_running_, true); |
| 227 const base::TimeTicks now = tick_clock_->NowTicks(); | 234 const base::TimeTicks now = tick_clock_->NowTicks(); |
| 228 for (auto& idle_delegate_entry : idle_delegate_map_) { | 235 for (auto& idle_delegate_entry : idle_delegate_map_) { |
| 229 if (now - idle_delegate_entry.second > timeout) { | 236 if (now - idle_delegate_entry.second > timeout) { |
| 230 id_map_.Lookup(idle_delegate_entry.first)->OnSuspendRequested(false); | 237 id_map_.Lookup(idle_delegate_entry.first)->OnSuspendRequested(false); |
| 231 | 238 |
| 232 // Whether or not the player accepted the suspension, mark it for removal | 239 // Whether or not the player accepted the suspension, mark it for removal |
| 233 // from future polls to avoid running the timer forever. | 240 // from future polls to avoid running the timer forever. |
| 234 idle_delegate_entry.second = base::TimeTicks(); | 241 idle_delegate_entry.second = base::TimeTicks(); |
| 235 } | 242 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 #endif // OS_ANDROID | 275 #endif // OS_ANDROID |
| 269 | 276 |
| 270 is_playing_background_video_ = is_playing; | 277 is_playing_background_video_ = is_playing; |
| 271 } | 278 } |
| 272 | 279 |
| 273 void RendererWebMediaPlayerDelegate::OnDestruct() { | 280 void RendererWebMediaPlayerDelegate::OnDestruct() { |
| 274 delete this; | 281 delete this; |
| 275 } | 282 } |
| 276 | 283 |
| 277 } // namespace media | 284 } // namespace media |
| OLD | NEW |