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 "media/cdm/player_tracker_impl.h" | 5 #include "media/cdm/player_tracker_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 | 10 |
11 namespace media { | 11 namespace media { |
12 | 12 |
13 PlayerTrackerImpl::PlayerCallbacks::PlayerCallbacks( | 13 PlayerTrackerImpl::PlayerCallbacks::PlayerCallbacks( |
14 base::Closure new_key_cb, | 14 base::Closure new_key_cb, |
15 base::Closure cdm_unset_cb) | 15 base::Closure cdm_unset_cb) |
16 : new_key_cb(new_key_cb), cdm_unset_cb(cdm_unset_cb) { | 16 : new_key_cb(new_key_cb), cdm_unset_cb(cdm_unset_cb) { |
17 } | 17 } |
18 | 18 |
19 PlayerTrackerImpl::PlayerCallbacks::~PlayerCallbacks() { | 19 PlayerTrackerImpl::PlayerCallbacks::~PlayerCallbacks() { |
20 } | 20 } |
21 | 21 |
22 PlayerTrackerImpl::PlayerTrackerImpl() : next_registration_id_(1) {} | 22 PlayerTrackerImpl::PlayerTrackerImpl() : next_registration_id_(1) {} |
23 | 23 |
24 PlayerTrackerImpl::~PlayerTrackerImpl() {} | 24 PlayerTrackerImpl::~PlayerTrackerImpl() {} |
25 | 25 |
26 int PlayerTrackerImpl::RegisterPlayer(const base::Closure& new_key_cb, | 26 int PlayerTrackerImpl::RegisterPlayer(const base::Closure& new_key_cb, |
27 const base::Closure& cdm_unset_cb) { | 27 const base::Closure& cdm_unset_cb) { |
28 DCHECK(thread_checker_.CalledOnValidThread()); | 28 DVLOG(1) << "PlayerTrackerImpl::RegisterPlayer"; |
| 29 |
| 30 base::AutoLock lock(lock_); |
| 31 |
29 int registration_id = next_registration_id_++; | 32 int registration_id = next_registration_id_++; |
30 DCHECK(!ContainsKey(player_callbacks_map_, registration_id)); | 33 DCHECK(!ContainsKey(player_callbacks_map_, registration_id)); |
31 player_callbacks_map_.insert(std::make_pair( | 34 player_callbacks_map_.insert(std::make_pair( |
32 registration_id, PlayerCallbacks(new_key_cb, cdm_unset_cb))); | 35 registration_id, PlayerCallbacks(new_key_cb, cdm_unset_cb))); |
33 return registration_id; | 36 return registration_id; |
34 } | 37 } |
35 | 38 |
36 void PlayerTrackerImpl::UnregisterPlayer(int registration_id) { | 39 void PlayerTrackerImpl::UnregisterPlayer(int registration_id) { |
37 DCHECK(thread_checker_.CalledOnValidThread()); | 40 base::AutoLock lock(lock_); |
| 41 |
38 DCHECK(ContainsKey(player_callbacks_map_, registration_id)) | 42 DCHECK(ContainsKey(player_callbacks_map_, registration_id)) |
39 << registration_id; | 43 << registration_id; |
40 player_callbacks_map_.erase(registration_id); | 44 player_callbacks_map_.erase(registration_id); |
41 } | 45 } |
42 | 46 |
43 void PlayerTrackerImpl::NotifyNewKey() { | 47 void PlayerTrackerImpl::NotifyNewKey() { |
| 48 // Ensure that callbacks are called on the same thread that created this |
| 49 // class. |
44 DCHECK(thread_checker_.CalledOnValidThread()); | 50 DCHECK(thread_checker_.CalledOnValidThread()); |
| 51 |
| 52 base::AutoLock lock(lock_); |
| 53 |
45 std::map<int, PlayerCallbacks>::iterator iter = player_callbacks_map_.begin(); | 54 std::map<int, PlayerCallbacks>::iterator iter = player_callbacks_map_.begin(); |
46 for (; iter != player_callbacks_map_.end(); ++iter) | 55 for (; iter != player_callbacks_map_.end(); ++iter) |
47 iter->second.new_key_cb.Run(); | 56 iter->second.new_key_cb.Run(); |
48 } | 57 } |
49 | 58 |
50 void PlayerTrackerImpl::NotifyCdmUnset() { | 59 void PlayerTrackerImpl::NotifyCdmUnset() { |
| 60 // Ensure that callbacks are called on the same thread that created this |
| 61 // class. |
51 DCHECK(thread_checker_.CalledOnValidThread()); | 62 DCHECK(thread_checker_.CalledOnValidThread()); |
| 63 |
| 64 base::AutoLock lock(lock_); |
| 65 |
52 std::map<int, PlayerCallbacks>::iterator iter = player_callbacks_map_.begin(); | 66 std::map<int, PlayerCallbacks>::iterator iter = player_callbacks_map_.begin(); |
53 for (; iter != player_callbacks_map_.end(); ++iter) | 67 for (; iter != player_callbacks_map_.end(); ++iter) |
54 iter->second.cdm_unset_cb.Run(); | 68 iter->second.cdm_unset_cb.Run(); |
55 } | 69 } |
56 | 70 |
57 } // namespace media | 71 } // namespace media |
OLD | NEW |