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

Unified Diff: content/renderer/media/cdm_session_id_adapter.cc

Issue 171073002: Move SessionIdAdapter out of WebContentDecryptionModuleImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 months 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
Index: content/renderer/media/cdm_session_id_adapter.cc
diff --git a/content/renderer/media/cdm_session_id_adapter.cc b/content/renderer/media/cdm_session_id_adapter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7df4b14590091d4b9e07325c34640f0dccdaeed4
--- /dev/null
+++ b/content/renderer/media/cdm_session_id_adapter.cc
@@ -0,0 +1,137 @@
+// 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 "content/renderer/media/cdm_session_id_adapter.h"
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "base/memory/weak_ptr.h"
+#include "content/renderer/media/crypto/content_decryption_module_factory.h"
+#include "content/renderer/media/webcontentdecryptionmodulesession_impl.h"
+#include "media/base/media_keys.h"
+#include "url/gurl.h"
+
+namespace content {
+
+const uint32 kStartingSessionId = 1;
+uint32 CdmSessionIdAdapter::next_session_id_ = kStartingSessionId;
+COMPILE_ASSERT(kStartingSessionId > media::MediaKeys::kInvalidSessionId,
+ invalid_starting_value);
+
+CdmSessionIdAdapter::CdmSessionIdAdapter() : weak_ptr_factory_(this) {}
+
+CdmSessionIdAdapter::~CdmSessionIdAdapter() {}
+
+bool CdmSessionIdAdapter::Initialize(const std::string& key_system) {
+ base::WeakPtr<CdmSessionIdAdapter> weak_this = weak_ptr_factory_.GetWeakPtr();
+ media_keys_ =
+ ContentDecryptionModuleFactory::Create(
+ // TODO(ddorwin): Address lower in the stack: http://crbug.com/252065
+ "webkit-" + key_system,
+#if defined(ENABLE_PEPPER_CDMS)
+ // TODO(ddorwin): Support Pepper-based CDMs: http://crbug.com/250049
+ NULL,
+ NULL,
+ base::Closure(),
+#elif defined(OS_ANDROID)
+ // TODO(xhwang): Support Android.
+ NULL,
+ 0,
+ // TODO(ddorwin): Get the URL for the frame containing the MediaKeys.
+ GURL(),
+#endif // defined(ENABLE_PEPPER_CDMS)
+ base::Bind(&CdmSessionIdAdapter::OnSessionCreated, weak_this),
+ base::Bind(&CdmSessionIdAdapter::OnSessionMessage, weak_this),
+ base::Bind(&CdmSessionIdAdapter::OnSessionReady, weak_this),
+ base::Bind(&CdmSessionIdAdapter::OnSessionClosed, weak_this),
+ base::Bind(&CdmSessionIdAdapter::OnSessionError, weak_this));
+ if (!media_keys_)
+ return false;
+
+ return true;
+}
+
+uint32 CdmSessionIdAdapter::GenerateSessionId() {
+ return next_session_id_++;
+}
+
+void CdmSessionIdAdapter::AddSession(
+ uint32 session_id,
+ WebContentDecryptionModuleSessionImpl* session) {
+ DCHECK(sessions_.find(session_id) == sessions_.end());
+ sessions_[session_id] = session;
+}
+
+void CdmSessionIdAdapter::RemoveSession(uint32 session_id) {
+ DCHECK(sessions_.find(session_id) != sessions_.end());
+ sessions_.erase(session_id);
+}
+
+bool CdmSessionIdAdapter::CreateSession(uint32 session_id,
+ const std::string& content_type,
+ const uint8* init_data,
+ int init_data_length) {
+ return media_keys_->CreateSession(
+ session_id, content_type, init_data, init_data_length);
+}
+
+void CdmSessionIdAdapter::UpdateSession(uint32 session_id,
+ const uint8* response,
+ int response_length) {
+ media_keys_->UpdateSession(session_id, response, response_length);
+}
+
+void CdmSessionIdAdapter::ReleaseSession(uint32 session_id) {
+ media_keys_->ReleaseSession(session_id);
+}
+
+media::Decryptor* CdmSessionIdAdapter::GetDecryptor() {
+ return media_keys_->GetDecryptor();
+}
+
+void CdmSessionIdAdapter::OnSessionCreated(uint32 session_id,
+ const std::string& web_session_id) {
+ WebContentDecryptionModuleSessionImpl* session = GetSession(session_id);
+ if (session)
+ session->OnSessionCreated(web_session_id);
+}
+
+void CdmSessionIdAdapter::OnSessionMessage(uint32 session_id,
+ const std::vector<uint8>& message,
+ const std::string& destination_url) {
+ WebContentDecryptionModuleSessionImpl* session = GetSession(session_id);
+ if (session)
+ session->OnSessionMessage(message, destination_url);
+}
+
+void CdmSessionIdAdapter::OnSessionReady(uint32 session_id) {
+ WebContentDecryptionModuleSessionImpl* session = GetSession(session_id);
+ if (session)
+ session->OnSessionReady();
+}
+
+void CdmSessionIdAdapter::OnSessionClosed(uint32 session_id) {
+ WebContentDecryptionModuleSessionImpl* session = GetSession(session_id);
+ if (session)
+ session->OnSessionClosed();
+}
+
+void CdmSessionIdAdapter::OnSessionError(uint32 session_id,
+ media::MediaKeys::KeyError error_code,
+ int system_code) {
+ WebContentDecryptionModuleSessionImpl* session = GetSession(session_id);
+ if (session)
+ session->OnSessionError(error_code, system_code);
+}
+
+WebContentDecryptionModuleSessionImpl* CdmSessionIdAdapter::GetSession(
+ uint32 session_id) {
+ // Since session objects may get garbage collected, it is possible that there
+ // are events coming back from the CDM and the session has been unregistered.
+ // We can not tell if the CDM is firing events at sessions that never existed.
+ SessionMap::iterator session = sessions_.find(session_id);
+ return (session != sessions_.end()) ? session->second : NULL;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698