Chromium Code Reviews| 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 25f325547874cab57238fca9e5340410963173b3..9ec8419ec3ca5cf580a017e6be98800abe989160 100644 |
| --- a/media/mojo/services/mojo_cdm_service.cc |
| +++ b/media/mojo/services/mojo_cdm_service.cc |
| @@ -5,11 +5,11 @@ |
| #include "media/mojo/services/mojo_cdm_service.h" |
| #include "base/bind.h" |
| +#include "media/base/cdm_config.h" |
| +#include "media/base/cdm_factory.h" |
| #include "media/base/cdm_key_information.h" |
| #include "media/base/key_systems.h" |
| -#include "media/cdm/aes_decryptor.h" |
| #include "media/mojo/services/media_type_converters.h" |
| -#include "media/mojo/services/mojo_cdm_promise.h" |
| #include "media/mojo/services/mojo_cdm_service_context.h" |
| #include "mojo/common/common_type_converters.h" |
| #include "mojo/common/url_type_converters.h" |
| @@ -17,16 +17,20 @@ |
| namespace media { |
| -typedef MojoCdmPromise<> SimpleMojoCdmPromise; |
| -typedef MojoCdmPromise<std::string> NewSessionMojoCdmPromise; |
| +using NewSessionMojoCdmPromise = MojoCdmPromise<std::string>; |
| +using SimpleMojoCdmPromise = MojoCdmPromise<>; |
| MojoCdmService::MojoCdmService( |
| MojoCdmServiceContext* context, |
| + CdmFactory* cdm_factory, |
| mojo::InterfaceRequest<mojo::ContentDecryptionModule> request) |
| : binding_(this, request.Pass()), |
| context_(context), |
| + cdm_factory_(cdm_factory), |
| cdm_id_(CdmContext::kInvalidCdmId), |
| weak_factory_(this) { |
| + DCHECK(context_); |
| + DCHECK(cdm_factory_); |
| } |
| MojoCdmService::~MojoCdmService() { |
| @@ -47,26 +51,17 @@ void MojoCdmService::Initialize( |
| DCHECK(!cdm_); |
| DCHECK_NE(CdmContext::kInvalidCdmId, cdm_id); |
| - SimpleMojoCdmPromise promise(callback); |
| - |
| - // Only AesDecryptor is supported. |
| - // TODO(xhwang): Use a CdmFactory to create the CDM here. See |
| - // http://crbug.com/495273 |
| - if (CanUseAesDecryptor(key_system)) { |
| - base::WeakPtr<MojoCdmService> weak_this = weak_factory_.GetWeakPtr(); |
| - cdm_.reset(new AesDecryptor( |
| - GURL::EmptyGURL(), |
| - base::Bind(&MojoCdmService::OnSessionMessage, weak_this), |
| - base::Bind(&MojoCdmService::OnSessionClosed, weak_this), |
| - base::Bind(&MojoCdmService::OnSessionKeysChange, weak_this))); |
| - cdm_id_ = cdm_id; |
| - context_->RegisterCdm(cdm_id_, this); |
| - promise.resolve(); |
| - } else { |
| - // TODO(xhwang): This should not happen when KeySystemInfo is properly |
| - // populated. See http://crbug.com/469366 |
| - promise.reject(MediaKeys::NOT_SUPPORTED_ERROR, 0, "Not supported."); |
| - } |
| + base::WeakPtr<MojoCdmService> weak_this = weak_factory_.GetWeakPtr(); |
|
ddorwin
2015/07/09 18:13:03
Totally optional, but I wonder if "auto" makes sen
xhwang
2015/07/09 21:16:31
Done.
|
| + cdm_factory_->Create( |
| + key_system, GURL(security_origin), CdmConfig(), |
|
ddorwin
2015/07/09 18:13:03
TODO: Something about the config?
xhwang
2015/07/09 21:16:31
This will be fixed this week: https://codereview.c
|
| + base::Bind(&MojoCdmService::OnSessionMessage, weak_this), |
| + base::Bind(&MojoCdmService::OnSessionClosed, weak_this), |
| + base::Bind(&MojoCdmService::OnLegacySessionError, weak_this), |
| + base::Bind(&MojoCdmService::OnSessionKeysChange, weak_this), |
| + base::Bind(&MojoCdmService::OnSessionExpirationUpdate, weak_this), |
| + base::Bind( |
| + &MojoCdmService::OnCdmCreated, weak_this, cdm_id, |
| + base::Passed(make_scoped_ptr(new SimpleMojoCdmPromise(callback))))); |
| } |
| // mojo::MediaRenderer implementation. |
| @@ -138,6 +133,23 @@ CdmContext* MojoCdmService::GetCdmContext() { |
| return cdm_->GetCdmContext(); |
| } |
| +void MojoCdmService::OnCdmCreated(int cdm_id, |
| + scoped_ptr<SimpleMojoCdmPromise> promise, |
| + scoped_ptr<MediaKeys> cdm, |
| + const std::string& error_message) { |
| + // TODO(xhwang): This should not happen when KeySystemInfo is properly |
| + // populated. See http://crbug.com/469366 |
| + if (!cdm) { |
| + promise->reject(MediaKeys::NOT_SUPPORTED_ERROR, 0, error_message); |
| + return; |
| + } |
| + |
| + cdm_ = cdm.Pass(); |
| + cdm_id_ = cdm_id; |
| + context_->RegisterCdm(cdm_id_, this); |
| + promise->resolve(); |
| +} |
| + |
| void MojoCdmService::OnSessionMessage(const std::string& session_id, |
| MediaKeys::MessageType message_type, |
| const std::vector<uint8_t>& message, |