| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/media/media_web_contents_observer.h" | 5 #include "content/browser/media/media_web_contents_observer.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "content/browser/media/audible_metrics.h" | 10 #include "content/browser/media/audible_metrics.h" |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 } | 206 } |
| 207 | 207 |
| 208 // If there are no more video players, clear the video power save blocker. | 208 // If there are no more video players, clear the video power save blocker. |
| 209 if (active_video_players_.empty()) | 209 if (active_video_players_.empty()) |
| 210 video_power_save_blocker_.reset(); | 210 video_power_save_blocker_.reset(); |
| 211 } | 211 } |
| 212 | 212 |
| 213 void MediaWebContentsObserver::AddMediaPlayerEntry( | 213 void MediaWebContentsObserver::AddMediaPlayerEntry( |
| 214 const MediaPlayerId& id, | 214 const MediaPlayerId& id, |
| 215 ActiveMediaPlayerMap* player_map) { | 215 ActiveMediaPlayerMap* player_map) { |
| 216 DCHECK(std::find((*player_map)[id.first].begin(), | 216 (*player_map)[id.first].insert(id.second); |
| 217 (*player_map)[id.first].end(), | |
| 218 id.second) == (*player_map)[id.first].end()); | |
| 219 (*player_map)[id.first].push_back(id.second); | |
| 220 } | 217 } |
| 221 | 218 |
| 222 bool MediaWebContentsObserver::RemoveMediaPlayerEntry( | 219 bool MediaWebContentsObserver::RemoveMediaPlayerEntry( |
| 223 const MediaPlayerId& id, | 220 const MediaPlayerId& id, |
| 224 ActiveMediaPlayerMap* player_map) { | 221 ActiveMediaPlayerMap* player_map) { |
| 225 auto it = player_map->find(id.first); | 222 auto it = player_map->find(id.first); |
| 226 if (it == player_map->end()) | 223 if (it == player_map->end()) |
| 227 return false; | 224 return false; |
| 228 | 225 |
| 229 // Remove the player. | 226 // Remove the player. |
| 230 auto player_for_removal = | 227 bool did_remove = it->second.erase(id.second) == 1; |
| 231 std::remove(it->second.begin(), it->second.end(), id.second); | 228 if (!did_remove) |
| 232 if (player_for_removal == it->second.end()) | |
| 233 return false; | 229 return false; |
| 234 it->second.erase(player_for_removal); | |
| 235 | 230 |
| 236 // If there are no players left, remove the map entry. | 231 // If there are no players left, remove the map entry. |
| 237 if (it->second.empty()) | 232 if (it->second.empty()) |
| 238 player_map->erase(it); | 233 player_map->erase(it); |
| 239 | 234 |
| 240 return true; | 235 return true; |
| 241 } | 236 } |
| 242 | 237 |
| 243 void MediaWebContentsObserver::RemoveAllMediaPlayerEntries( | 238 void MediaWebContentsObserver::RemoveAllMediaPlayerEntries( |
| 244 RenderFrameHost* render_frame_host, | 239 RenderFrameHost* render_frame_host, |
| 245 ActiveMediaPlayerMap* player_map, | 240 ActiveMediaPlayerMap* player_map, |
| 246 std::set<MediaPlayerId>* removed_players) { | 241 std::set<MediaPlayerId>* removed_players) { |
| 247 auto it = player_map->find(render_frame_host); | 242 auto it = player_map->find(render_frame_host); |
| 248 if (it == player_map->end()) | 243 if (it == player_map->end()) |
| 249 return; | 244 return; |
| 250 | 245 |
| 251 for (int delegate_id : it->second) | 246 for (int delegate_id : it->second) |
| 252 removed_players->insert(MediaPlayerId(render_frame_host, delegate_id)); | 247 removed_players->insert(MediaPlayerId(render_frame_host, delegate_id)); |
| 253 | 248 |
| 254 player_map->erase(it); | 249 player_map->erase(it); |
| 255 } | 250 } |
| 256 | 251 |
| 257 } // namespace content | 252 } // namespace content |
| OLD | NEW |