Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "media/mojo/services/mojo_cdm.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/bind_helpers.h" | |
| 9 #include "media/base/cdm_promise.h" | |
| 10 #include "mojo/public/cpp/application/connect.h" | |
| 11 #include "mojo/public/cpp/bindings/interface_impl.h" | |
| 12 #include "mojo/public/interfaces/application/service_provider.mojom.h" | |
| 13 #include "url/gurl.h" | |
| 14 | |
| 15 namespace media { | |
| 16 | |
| 17 static mojo::Array<uint8_t> CreateMojoArray(const uint8* data, int length) { | |
| 18 DCHECK(data); | |
| 19 DCHECK_GT(length, 0); | |
| 20 std::vector<uint8> vector(data, data + length); | |
| 21 mojo::Array<uint8_t> array; | |
|
jrummell
2014/12/18 00:02:12
Why the different types in these two definitions?
xhwang
2014/12/18 17:04:59
This is how we construct an mojo::Array now:
https
jrummell
2014/12/18 20:01:14
As discussed offline, my question was around using
jamesr
2014/12/18 20:14:57
In general in chromium you should always use the _
| |
| 22 array.Swap(&vector); | |
| 23 return array.Pass(); | |
| 24 } | |
| 25 | |
| 26 template <typename PromiseType> | |
| 27 static void RejectPromise(scoped_ptr<PromiseType> promise, | |
| 28 mojo::CdmPromiseResultPtr result) { | |
| 29 promise->reject(static_cast<MediaKeys::Exception>(result->exception), | |
|
jrummell
2014/12/18 00:02:12
Is there a need for compile-time checks that the 2
xhwang
2014/12/18 17:04:59
Done.
| |
| 30 result->system_code, result->error_message); | |
| 31 } | |
| 32 | |
| 33 MojoCdm::MojoCdm(mojo::ContentDecryptionModulePtr remote_cdm, | |
| 34 const SessionMessageCB& session_message_cb, | |
| 35 const SessionReadyCB& session_ready_cb, | |
| 36 const SessionClosedCB& session_closed_cb, | |
| 37 const SessionErrorCB& session_error_cb, | |
| 38 const SessionKeysChangeCB& session_keys_change_cb, | |
| 39 const SessionExpirationUpdateCB& session_expiration_update_cb) | |
| 40 : remote_cdm_(remote_cdm.Pass()), | |
| 41 session_message_cb_(session_message_cb), | |
|
jrummell
2014/12/18 00:02:12
Should these cb's be checked for !null (since they
xhwang
2014/12/18 17:04:59
Done.
| |
| 42 session_ready_cb_(session_ready_cb), | |
| 43 session_closed_cb_(session_closed_cb), | |
| 44 session_error_cb_(session_error_cb), | |
| 45 session_keys_change_cb_(session_keys_change_cb), | |
| 46 session_expiration_update_cb_(session_expiration_update_cb), | |
| 47 weak_factory_(this) { | |
| 48 DVLOG(1) << __FUNCTION__; | |
| 49 DCHECK(remote_cdm_); | |
|
jrummell
2014/12/18 00:02:12
Is this necessary given the following line will cr
xhwang
2014/12/18 17:04:59
Done.
| |
| 50 remote_cdm_.set_client(this); | |
| 51 } | |
| 52 | |
| 53 MojoCdm::~MojoCdm() { | |
| 54 DVLOG(1) << __FUNCTION__; | |
| 55 } | |
| 56 | |
| 57 void MojoCdm::SetServerCertificate(const uint8* certificate_data, | |
| 58 int certificate_data_length, | |
| 59 scoped_ptr<SimpleCdmPromise> promise) { | |
| 60 remote_cdm_->SetServerCertificate( | |
| 61 CreateMojoArray(certificate_data, certificate_data_length), | |
| 62 base::Bind(&MojoCdm::OnPromiseResult<>, weak_factory_.GetWeakPtr(), | |
| 63 base::Passed(&promise))); | |
| 64 } | |
| 65 | |
| 66 void MojoCdm::CreateSession(const std::string& init_data_type, | |
| 67 const uint8* init_data, | |
| 68 int init_data_length, | |
| 69 SessionType session_type, | |
| 70 scoped_ptr<NewSessionCdmPromise> promise) { | |
| 71 remote_cdm_->CreateSession( | |
| 72 init_data_type, CreateMojoArray(init_data, init_data_length), | |
| 73 static_cast<mojo::ContentDecryptionModule::SessionType>(session_type), | |
| 74 base::Bind(&MojoCdm::OnPromiseResult<std::string>, | |
| 75 weak_factory_.GetWeakPtr(), base::Passed(&promise))); | |
| 76 } | |
| 77 | |
| 78 void MojoCdm::LoadSession(const std::string& session_id, | |
| 79 scoped_ptr<NewSessionCdmPromise> promise) { | |
| 80 remote_cdm_->LoadSession( | |
| 81 session_id, | |
| 82 base::Bind(&MojoCdm::OnPromiseResult<std::string>, | |
| 83 weak_factory_.GetWeakPtr(), base::Passed(&promise))); | |
| 84 } | |
| 85 | |
| 86 void MojoCdm::UpdateSession(const std::string& session_id, | |
| 87 const uint8* response, | |
| 88 int response_length, | |
| 89 scoped_ptr<SimpleCdmPromise> promise) { | |
| 90 remote_cdm_->UpdateSession( | |
| 91 session_id, CreateMojoArray(response, response_length), | |
| 92 base::Bind(&MojoCdm::OnPromiseResult<>, weak_factory_.GetWeakPtr(), | |
| 93 base::Passed(&promise))); | |
| 94 } | |
| 95 | |
| 96 void MojoCdm::CloseSession(const std::string& session_id, | |
| 97 scoped_ptr<SimpleCdmPromise> promise) { | |
| 98 remote_cdm_->CloseSession(session_id, base::Bind(&MojoCdm::OnPromiseResult<>, | |
| 99 weak_factory_.GetWeakPtr(), | |
| 100 base::Passed(&promise))); | |
| 101 } | |
| 102 | |
| 103 void MojoCdm::RemoveSession(const std::string& session_id, | |
| 104 scoped_ptr<SimpleCdmPromise> promise) { | |
| 105 remote_cdm_->RemoveSession(session_id, base::Bind(&MojoCdm::OnPromiseResult<>, | |
| 106 weak_factory_.GetWeakPtr(), | |
| 107 base::Passed(&promise))); | |
| 108 } | |
| 109 | |
| 110 void MojoCdm::GetUsableKeyIds(const std::string& session_id, | |
| 111 scoped_ptr<KeyIdsPromise> promise) { | |
| 112 remote_cdm_->GetUsableKeyIds( | |
| 113 session_id, | |
| 114 base::Bind(&MojoCdm::OnPromiseResult<KeyIdsVector>, | |
| 115 weak_factory_.GetWeakPtr(), base::Passed(&promise))); | |
| 116 } | |
| 117 | |
| 118 CdmContext* MojoCdm::GetCdmContext() { | |
| 119 NOTIMPLEMENTED(); | |
| 120 return nullptr; | |
| 121 } | |
| 122 | |
| 123 void MojoCdm::OnSessionMessage(const mojo::String& session_id, | |
| 124 mojo::Array<uint8_t> message, | |
| 125 const mojo::String& destination_url) { | |
| 126 GURL verified_gurl = GURL(destination_url); | |
| 127 if (!verified_gurl.is_valid() && !verified_gurl.is_empty()) { | |
| 128 DLOG(WARNING) << "SessionMessage destination_url is invalid : " | |
| 129 << verified_gurl.possibly_invalid_spec(); | |
| 130 verified_gurl = GURL::EmptyGURL(); // Replace invalid destination_url. | |
| 131 } | |
| 132 | |
| 133 session_message_cb_.Run(session_id, message.storage(), verified_gurl); | |
| 134 } | |
| 135 | |
| 136 void MojoCdm::OnSessionReady(const mojo::String& session_id) { | |
| 137 session_ready_cb_.Run(session_id); | |
| 138 } | |
| 139 | |
| 140 void MojoCdm::OnSessionClosed(const mojo::String& session_id) { | |
| 141 session_closed_cb_.Run(session_id); | |
| 142 } | |
| 143 | |
| 144 void MojoCdm::OnSessionError(const mojo::String& session_id, | |
| 145 mojo::CdmException exception, | |
| 146 uint32_t system_code, | |
| 147 const mojo::String& error_message) { | |
| 148 session_error_cb_.Run(session_id, | |
| 149 static_cast<MediaKeys::Exception>(exception), | |
| 150 system_code, error_message); | |
| 151 } | |
| 152 | |
| 153 void MojoCdm::OnSessionKeysChange(const mojo::String& session_id, | |
| 154 bool has_additional_usable_key) { | |
| 155 session_keys_change_cb_.Run(session_id, has_additional_usable_key); | |
| 156 } | |
| 157 | |
| 158 void MojoCdm::OnSessionExpirationUpdate(const mojo::String& session_id, | |
| 159 int64_t new_expiry_time_usec) { | |
| 160 session_expiration_update_cb_.Run( | |
| 161 session_id, base::Time::FromInternalValue(new_expiry_time_usec)); | |
| 162 } | |
| 163 | |
| 164 template <typename... T> | |
| 165 void MojoCdm::OnPromiseResult(scoped_ptr<CdmPromiseTemplate<T...>> promise, | |
| 166 mojo::CdmPromiseResultPtr result, | |
| 167 typename MojoTypeTrait<T>::MojoType... args) { | |
| 168 if (result->success) | |
| 169 promise->resolve(args.template To<T>()...); // See ISO C++03 14.2/4. | |
| 170 else | |
| 171 RejectPromise(promise.Pass(), result.Pass()); | |
| 172 } | |
| 173 | |
| 174 } // namespace media | |
| OLD | NEW |