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

Unified Diff: media/mojo/services/mojo_cdm_service.cc

Issue 1448303002: media: Add static MojoCdmService::GetCdm(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 | « media/mojo/services/mojo_cdm_service.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/mojo/services/mojo_cdm_service.cc
diff --git a/media/mojo/services/mojo_cdm_service.cc b/media/mojo/services/mojo_cdm_service.cc
index 4a163872305d5572e6c6abd2a1fb8716976c321f..981ec4d485a442a5f03e2b3621484994f21cf3ad 100644
--- a/media/mojo/services/mojo_cdm_service.cc
+++ b/media/mojo/services/mojo_cdm_service.cc
@@ -4,7 +4,10 @@
#include "media/mojo/services/mojo_cdm_service.h"
+#include <map>
+
#include "base/bind.h"
+#include "base/lazy_instance.h"
#include "media/base/cdm_config.h"
#include "media/base/cdm_context.h"
#include "media/base/cdm_factory.h"
@@ -18,12 +21,31 @@
namespace media {
+namespace {
+
+// A static map between the CDM ID and the CDM. Can be accessed on different
+// threads (protected by the |g_cdm_map_lock_|).
+using CdmMap = std::map<int, scoped_refptr<MediaKeys>>;
+
+base::LazyInstance<CdmMap>::Leaky g_cdm_map = LAZY_INSTANCE_INITIALIZER;
DaleCurtis 2015/11/17 23:57:05 Instead of two lazy instances you could put this i
xhwang 2015/11/18 00:52:53 It does make the main impl (MojoCdmService) cleane
+
+base::LazyInstance<base::Lock>::Leaky g_cdm_map_lock =
+ LAZY_INSTANCE_INITIALIZER;
+}
+
using SimpleMojoCdmPromise = MojoCdmPromise<>;
using CdmIdMojoCdmPromise = MojoCdmPromise<int>;
using NewSessionMojoCdmPromise = MojoCdmPromise<std::string>;
int MojoCdmService::next_cdm_id_ = CdmContext::kInvalidCdmId + 1;
+// static
+scoped_refptr<MediaKeys> MojoCdmService::GetCdm(int cdm_id) {
+ DVLOG(1) << __FUNCTION__ << ": " << cdm_id;
+ base::AutoLock lock(g_cdm_map_lock.Get());
+ return g_cdm_map.Get().count(cdm_id) ? g_cdm_map.Get()[cdm_id] : nullptr;
+}
+
MojoCdmService::MojoCdmService(
base::WeakPtr<MojoCdmServiceContext> context,
mojo::ServiceProvider* service_provider,
@@ -40,6 +62,12 @@ MojoCdmService::MojoCdmService(
}
MojoCdmService::~MojoCdmService() {
+ {
+ base::AutoLock lock(g_cdm_map_lock.Get());
+ DCHECK(g_cdm_map.Get().count(cdm_id_));
+ g_cdm_map.Get().erase(cdm_id_);
+ }
+
if (cdm_id_ != CdmContext::kInvalidCdmId && context_)
context_->UnregisterCdm(cdm_id_);
}
@@ -152,6 +180,14 @@ void MojoCdmService::OnCdmCreated(scoped_ptr<CdmIdMojoCdmPromise> promise,
cdm_ = cdm;
cdm_id_ = next_cdm_id_++;
context_->RegisterCdm(cdm_id_, this);
+
+ {
+ base::AutoLock lock(g_cdm_map_lock.Get());
+ DCHECK(!g_cdm_map.Get().count(cdm_id_));
+ g_cdm_map.Get()[cdm_id_] = cdm;
+ }
+
+ DVLOG(1) << __FUNCTION__ << ": CDM successfully created with ID " << cdm_id_;
promise->resolve(cdm_id_);
}
« no previous file with comments | « media/mojo/services/mojo_cdm_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698