| 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 "chromecast/media/cdm/browser_cdm_cast.h" | 5 #include "chromecast/media/cdm/browser_cdm_cast.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | |
| 8 #include "base/location.h" | |
| 9 #include "base/message_loop/message_loop_proxy.h" | |
| 10 #include "base/stl_util.h" | |
| 11 | |
| 12 namespace chromecast { | 7 namespace chromecast { |
| 13 namespace media { | 8 namespace media { |
| 14 | 9 |
| 15 BrowserCdmCast::BrowserCdmCast() | 10 BrowserCdmCast::BrowserCdmCast() { |
| 16 : next_registration_id_(1) { | |
| 17 } | 11 } |
| 18 | 12 |
| 19 BrowserCdmCast::~BrowserCdmCast() { | 13 BrowserCdmCast::~BrowserCdmCast() { |
| 20 // Call unset callbacks synchronously. | 14 player_tracker_.NotifyCdmUnset(); |
| 21 for (std::map<uint32_t, base::Closure>::const_iterator it = | |
| 22 cdm_unset_callbacks_.begin(); it != cdm_unset_callbacks_.end(); ++it) { | |
| 23 it->second.Run(); | |
| 24 } | |
| 25 | |
| 26 new_key_callbacks_.clear(); | |
| 27 cdm_unset_callbacks_.clear(); | |
| 28 } | 15 } |
| 29 | 16 |
| 30 int BrowserCdmCast::RegisterPlayer(const base::Closure& new_key_cb, | 17 int BrowserCdmCast::RegisterPlayer(const base::Closure& new_key_cb, |
| 31 const base::Closure& cdm_unset_cb) { | 18 const base::Closure& cdm_unset_cb) { |
| 32 int registration_id = next_registration_id_++; | 19 return player_tracker_.RegisterPlayer(new_key_cb, cdm_unset_cb); |
| 33 DCHECK(!new_key_cb.is_null()); | |
| 34 DCHECK(!cdm_unset_cb.is_null()); | |
| 35 DCHECK(!ContainsKey(new_key_callbacks_, registration_id)); | |
| 36 DCHECK(!ContainsKey(cdm_unset_callbacks_, registration_id)); | |
| 37 new_key_callbacks_[registration_id] = new_key_cb; | |
| 38 cdm_unset_callbacks_[registration_id] = cdm_unset_cb; | |
| 39 return registration_id; | |
| 40 } | 20 } |
| 41 | 21 |
| 42 void BrowserCdmCast::UnregisterPlayer(int registration_id) { | 22 void BrowserCdmCast::UnregisterPlayer(int registration_id) { |
| 43 DCHECK(ContainsKey(new_key_callbacks_, registration_id)); | 23 player_tracker_.UnregisterPlayer(registration_id); |
| 44 DCHECK(ContainsKey(cdm_unset_callbacks_, registration_id)); | |
| 45 new_key_callbacks_.erase(registration_id); | |
| 46 cdm_unset_callbacks_.erase(registration_id); | |
| 47 } | 24 } |
| 48 | 25 |
| 49 void BrowserCdmCast::NotifyKeyAdded() const { | 26 void BrowserCdmCast::NotifyKeyAdded() { |
| 50 for (std::map<uint32_t, base::Closure>::const_iterator it = | 27 player_tracker_.NotifyNewKey(); |
| 51 new_key_callbacks_.begin(); it != new_key_callbacks_.end(); ++it) { | |
| 52 base::MessageLoopProxy::current()->PostTask(FROM_HERE, it->second); | |
| 53 } | |
| 54 } | 28 } |
| 55 | 29 |
| 56 } // namespace media | 30 } // namespace media |
| 57 } // namespace chromecast | 31 } // namespace chromecast |
| OLD | NEW |