Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7834)

Unified Diff: chromecast/media/cdm/browser_cdm_cast.cc

Issue 741823004: Chromecast: extensions to the BrowserCdm interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromecast/media/cdm/browser_cdm_cast.h ('k') | chromecast/media/media.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromecast/media/cdm/browser_cdm_cast.cc
diff --git a/chromecast/media/cdm/browser_cdm_cast.cc b/chromecast/media/cdm/browser_cdm_cast.cc
new file mode 100644
index 0000000000000000000000000000000000000000..33502f2aeb952c1d90fa70fa475ad9e281eff981
--- /dev/null
+++ b/chromecast/media/cdm/browser_cdm_cast.cc
@@ -0,0 +1,57 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromecast/media/cdm/browser_cdm_cast.h"
+
+#include "base/callback.h"
+#include "base/location.h"
+#include "base/message_loop/message_loop_proxy.h"
+#include "base/stl_util.h"
+
+namespace chromecast {
+namespace media {
+
+BrowserCdmCast::BrowserCdmCast()
+ : next_registration_id_(1) {
+}
+
+BrowserCdmCast::~BrowserCdmCast() {
+ // Call unset callbacks synchronously.
+ for (std::map<uint32_t, base::Closure>::const_iterator it =
+ cdm_unset_callbacks_.begin(); it != cdm_unset_callbacks_.end(); ++it) {
+ it->second.Run();
+ }
+
+ new_key_callbacks_.clear();
+ cdm_unset_callbacks_.clear();
+}
+
+int BrowserCdmCast::RegisterPlayer(const base::Closure& new_key_cb,
+ const base::Closure& cdm_unset_cb) {
+ int registration_id = next_registration_id_++;
+ DCHECK(!new_key_cb.is_null());
+ DCHECK(!cdm_unset_cb.is_null());
+ DCHECK(!ContainsKey(new_key_callbacks_, registration_id));
+ DCHECK(!ContainsKey(cdm_unset_callbacks_, registration_id));
+ new_key_callbacks_[registration_id] = new_key_cb;
+ cdm_unset_callbacks_[registration_id] = cdm_unset_cb;
+ return registration_id;
+}
+
+void BrowserCdmCast::UnregisterPlayer(int registration_id) {
+ DCHECK(ContainsKey(new_key_callbacks_, registration_id));
+ DCHECK(ContainsKey(cdm_unset_callbacks_, registration_id));
+ new_key_callbacks_.erase(registration_id);
+ cdm_unset_callbacks_.erase(registration_id);
+}
+
+void BrowserCdmCast::NotifyKeyAdded() const {
+ for (std::map<uint32_t, base::Closure>::const_iterator it =
+ new_key_callbacks_.begin(); it != new_key_callbacks_.end(); ++it) {
+ base::MessageLoopProxy::current()->PostTask(FROM_HERE, it->second);
+ }
+}
+
+} // namespace media
+} // namespace chromecast
« no previous file with comments | « chromecast/media/cdm/browser_cdm_cast.h ('k') | chromecast/media/media.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698