All instances of addresses as void* are changed to uintptr_t in
[chromium-blink-merge.git] / media / cdm / player_tracker_impl.cc
blob8f102bd724e18ac00a200e2bfb4efd330b040131
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
3 // found in the LICENSE file.
5 #include "media/cdm/player_tracker_impl.h"
7 #include <utility>
9 #include "base/stl_util.h"
11 namespace media {
13 PlayerTrackerImpl::PlayerCallbacks::PlayerCallbacks(
14 base::Closure new_key_cb,
15 base::Closure cdm_unset_cb)
16 : new_key_cb(new_key_cb), cdm_unset_cb(cdm_unset_cb) {
19 PlayerTrackerImpl::PlayerCallbacks::~PlayerCallbacks() {
22 PlayerTrackerImpl::PlayerTrackerImpl() : next_registration_id_(1) {}
24 PlayerTrackerImpl::~PlayerTrackerImpl() {}
26 int PlayerTrackerImpl::RegisterPlayer(const base::Closure& new_key_cb,
27 const base::Closure& cdm_unset_cb) {
28 DCHECK(thread_checker_.CalledOnValidThread());
29 int registration_id = next_registration_id_++;
30 DCHECK(!ContainsKey(player_callbacks_map_, registration_id));
31 player_callbacks_map_.insert(std::make_pair(
32 registration_id, PlayerCallbacks(new_key_cb, cdm_unset_cb)));
33 return registration_id;
36 void PlayerTrackerImpl::UnregisterPlayer(int registration_id) {
37 DCHECK(thread_checker_.CalledOnValidThread());
38 DCHECK(ContainsKey(player_callbacks_map_, registration_id))
39 << registration_id;
40 player_callbacks_map_.erase(registration_id);
43 void PlayerTrackerImpl::NotifyNewKey() {
44 DCHECK(thread_checker_.CalledOnValidThread());
45 std::map<int, PlayerCallbacks>::iterator iter = player_callbacks_map_.begin();
46 for (; iter != player_callbacks_map_.end(); ++iter)
47 iter->second.new_key_cb.Run();
50 void PlayerTrackerImpl::NotifyCdmUnset() {
51 DCHECK(thread_checker_.CalledOnValidThread());
52 std::map<int, PlayerCallbacks>::iterator iter = player_callbacks_map_.begin();
53 for (; iter != player_callbacks_map_.end(); ++iter)
54 iter->second.cdm_unset_cb.Run();
57 } // namespace media