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

Side by Side Diff: media/cdm/ppapi/external_clear_key/clear_key_cdm.cc

Issue 604283003: Refactor CdmPromise and related classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + override Created 6 years, 2 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 unified diff | Download patch
« no previous file with comments | « media/cdm/aes_decryptor_unittest.cc ('k') | media/filters/pipeline_integration_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/cdm/ppapi/external_clear_key/clear_key_cdm.h" 5 #include "media/cdm/ppapi/external_clear_key/clear_key_cdm.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstring> 8 #include <cstring>
9 #include <sstream> 9 #include <sstream>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/debug/trace_event.h" 14 #include "base/debug/trace_event.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "media/base/cdm_promise.h" 17 #include "media/base/cdm_callback_promise.h"
18 #include "media/base/decoder_buffer.h" 18 #include "media/base/decoder_buffer.h"
19 #include "media/base/decrypt_config.h" 19 #include "media/base/decrypt_config.h"
20 #include "media/cdm/json_web_key.h" 20 #include "media/cdm/json_web_key.h"
21 #include "media/cdm/ppapi/cdm_file_io_test.h" 21 #include "media/cdm/ppapi/cdm_file_io_test.h"
22 #include "media/cdm/ppapi/external_clear_key/cdm_video_decoder.h" 22 #include "media/cdm/ppapi/external_clear_key/cdm_video_decoder.h"
23 23
24 #if defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) 24 #if defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER)
25 #include "base/basictypes.h" 25 #include "base/basictypes.h"
26 const int64 kNoTimestamp = kint64min; 26 const int64 kNoTimestamp = kint64min;
27 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER 27 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 241
242 void ClearKeyCdm::CreateSession(uint32 promise_id, 242 void ClearKeyCdm::CreateSession(uint32 promise_id,
243 const char* init_data_type, 243 const char* init_data_type,
244 uint32 init_data_type_size, 244 uint32 init_data_type_size,
245 const uint8* init_data, 245 const uint8* init_data,
246 uint32 init_data_size, 246 uint32 init_data_size,
247 cdm::SessionType session_type) { 247 cdm::SessionType session_type) {
248 DVLOG(1) << __FUNCTION__; 248 DVLOG(1) << __FUNCTION__;
249 249
250 scoped_ptr<media::NewSessionCdmPromise> promise( 250 scoped_ptr<media::NewSessionCdmPromise> promise(
251 new media::NewSessionCdmPromise(base::Bind(&ClearKeyCdm::OnSessionCreated, 251 new media::CdmCallbackPromise<std::string>(
252 base::Unretained(this), 252 base::Bind(&ClearKeyCdm::OnSessionCreated,
253 promise_id), 253 base::Unretained(this),
254 base::Bind(&ClearKeyCdm::OnPromiseFailed, 254 promise_id),
255 base::Unretained(this), 255 base::Bind(&ClearKeyCdm::OnPromiseFailed,
256 promise_id))); 256 base::Unretained(this),
257 promise_id)));
257 decryptor_.CreateSession(std::string(init_data_type, init_data_type_size), 258 decryptor_.CreateSession(std::string(init_data_type, init_data_type_size),
258 init_data, 259 init_data,
259 init_data_size, 260 init_data_size,
260 ConvertSessionType(session_type), 261 ConvertSessionType(session_type),
261 promise.Pass()); 262 promise.Pass());
262 263
263 if (key_system_ == kExternalClearKeyFileIOTestKeySystem) 264 if (key_system_ == kExternalClearKeyFileIOTestKeySystem)
264 StartFileIOTest(); 265 StartFileIOTest();
265 } 266 }
266 267
(...skipping 11 matching lines...) Expand all
278 std::string message("Incorrect session id specified for LoadSession()."); 279 std::string message("Incorrect session id specified for LoadSession().");
279 host_->OnRejectPromise(promise_id, 280 host_->OnRejectPromise(promise_id,
280 cdm::kInvalidAccessError, 281 cdm::kInvalidAccessError,
281 0, 282 0,
282 message.data(), 283 message.data(),
283 message.length()); 284 message.length());
284 return; 285 return;
285 } 286 }
286 287
287 scoped_ptr<media::NewSessionCdmPromise> promise( 288 scoped_ptr<media::NewSessionCdmPromise> promise(
288 new media::NewSessionCdmPromise(base::Bind(&ClearKeyCdm::OnSessionLoaded, 289 new media::CdmCallbackPromise<std::string>(
289 base::Unretained(this), 290 base::Bind(&ClearKeyCdm::OnSessionLoaded,
290 promise_id), 291 base::Unretained(this),
291 base::Bind(&ClearKeyCdm::OnPromiseFailed, 292 promise_id),
292 base::Unretained(this), 293 base::Bind(&ClearKeyCdm::OnPromiseFailed,
293 promise_id))); 294 base::Unretained(this),
295 promise_id)));
294 decryptor_.CreateSession(std::string(kLoadableSessionContentType), 296 decryptor_.CreateSession(std::string(kLoadableSessionContentType),
295 NULL, 297 NULL,
296 0, 298 0,
297 MediaKeys::TEMPORARY_SESSION, 299 MediaKeys::TEMPORARY_SESSION,
298 promise.Pass()); 300 promise.Pass());
299 } 301 }
300 302
301 void ClearKeyCdm::UpdateSession(uint32 promise_id, 303 void ClearKeyCdm::UpdateSession(uint32 promise_id,
302 const char* web_session_id, 304 const char* web_session_id,
303 uint32_t web_session_id_length, 305 uint32_t web_session_id_length,
304 const uint8* response, 306 const uint8* response,
305 uint32 response_size) { 307 uint32 response_size) {
306 DVLOG(1) << __FUNCTION__; 308 DVLOG(1) << __FUNCTION__;
307 std::string web_session_str(web_session_id, web_session_id_length); 309 std::string web_session_str(web_session_id, web_session_id_length);
308 310
309 scoped_ptr<media::SimpleCdmPromise> promise(new media::SimpleCdmPromise( 311 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>(
310 base::Bind(&ClearKeyCdm::OnSessionUpdated, 312 base::Bind(&ClearKeyCdm::OnSessionUpdated,
311 base::Unretained(this), 313 base::Unretained(this),
312 promise_id, 314 promise_id,
313 web_session_str), 315 web_session_str),
314 base::Bind( 316 base::Bind(
315 &ClearKeyCdm::OnPromiseFailed, base::Unretained(this), promise_id))); 317 &ClearKeyCdm::OnPromiseFailed, base::Unretained(this), promise_id)));
316 decryptor_.UpdateSession( 318 decryptor_.UpdateSession(
317 web_session_str, response, response_size, promise.Pass()); 319 web_session_str, response, response_size, promise.Pass());
318 320
319 if (!heartbeat_timer_set_) { 321 if (!heartbeat_timer_set_) {
320 ScheduleNextHeartBeat(); 322 ScheduleNextHeartBeat();
321 heartbeat_timer_set_ = true; 323 heartbeat_timer_set_ = true;
322 } 324 }
323 } 325 }
324 326
325 void ClearKeyCdm::CloseSession(uint32 promise_id, 327 void ClearKeyCdm::CloseSession(uint32 promise_id,
326 const char* web_session_id, 328 const char* web_session_id,
327 uint32_t web_session_id_length) { 329 uint32_t web_session_id_length) {
328 DVLOG(1) << __FUNCTION__; 330 DVLOG(1) << __FUNCTION__;
329 std::string web_session_str(web_session_id, web_session_id_length); 331 std::string web_session_str(web_session_id, web_session_id_length);
330 332
331 scoped_ptr<media::SimpleCdmPromise> promise(new media::SimpleCdmPromise( 333 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>(
332 base::Bind( 334 base::Bind(
333 &ClearKeyCdm::OnPromiseResolved, base::Unretained(this), promise_id), 335 &ClearKeyCdm::OnPromiseResolved, base::Unretained(this), promise_id),
334 base::Bind( 336 base::Bind(
335 &ClearKeyCdm::OnPromiseFailed, base::Unretained(this), promise_id))); 337 &ClearKeyCdm::OnPromiseFailed, base::Unretained(this), promise_id)));
336 decryptor_.CloseSession(web_session_str, promise.Pass()); 338 decryptor_.CloseSession(web_session_str, promise.Pass());
337 } 339 }
338 340
339 void ClearKeyCdm::RemoveSession(uint32 promise_id, 341 void ClearKeyCdm::RemoveSession(uint32 promise_id,
340 const char* web_session_id, 342 const char* web_session_id,
341 uint32_t web_session_id_length) { 343 uint32_t web_session_id_length) {
342 DVLOG(1) << __FUNCTION__; 344 DVLOG(1) << __FUNCTION__;
343 // RemoveSession only allowed for persistent sessions. 345 // RemoveSession only allowed for persistent sessions.
344 bool is_persistent_session = 346 bool is_persistent_session =
345 std::string(kLoadableWebSessionId) == 347 std::string(kLoadableWebSessionId) ==
346 std::string(web_session_id, web_session_id_length); 348 std::string(web_session_id, web_session_id_length);
347 if (is_persistent_session) { 349 if (is_persistent_session) {
348 std::string web_session_str(web_session_id, web_session_id_length); 350 std::string web_session_str(web_session_id, web_session_id_length);
349 351
350 scoped_ptr<media::SimpleCdmPromise> promise( 352 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>(
351 new media::SimpleCdmPromise(base::Bind(&ClearKeyCdm::OnPromiseResolved, 353 base::Bind(&ClearKeyCdm::OnPromiseResolved,
352 base::Unretained(this), 354 base::Unretained(this),
353 promise_id), 355 promise_id),
354 base::Bind(&ClearKeyCdm::OnPromiseFailed, 356 base::Bind(&ClearKeyCdm::OnPromiseFailed,
355 base::Unretained(this), 357 base::Unretained(this),
356 promise_id))); 358 promise_id)));
357 decryptor_.RemoveSession(web_session_str, promise.Pass()); 359 decryptor_.RemoveSession(web_session_str, promise.Pass());
358 } else { 360 } else {
359 // TODO(jrummell): This should be a DCHECK once blink does the proper 361 // TODO(jrummell): This should be a DCHECK once blink does the proper
360 // checks. 362 // checks.
361 std::string message("Not supported for non-persistent sessions."); 363 std::string message("Not supported for non-persistent sessions.");
362 host_->OnRejectPromise(promise_id, 364 host_->OnRejectPromise(promise_id,
363 cdm::kInvalidAccessError, 365 cdm::kInvalidAccessError,
364 0, 366 0,
365 message.data(), 367 message.data(),
366 message.length()); 368 message.length());
367 } 369 }
368 } 370 }
369 371
370 void ClearKeyCdm::SetServerCertificate(uint32 promise_id, 372 void ClearKeyCdm::SetServerCertificate(uint32 promise_id,
371 const uint8_t* server_certificate_data, 373 const uint8_t* server_certificate_data,
372 uint32_t server_certificate_data_size) { 374 uint32_t server_certificate_data_size) {
373 // ClearKey doesn't use a server certificate. 375 // ClearKey doesn't use a server certificate.
374 host_->OnResolvePromise(promise_id); 376 host_->OnResolvePromise(promise_id);
375 } 377 }
376 378
377 void ClearKeyCdm::GetUsableKeyIds(uint32_t promise_id, 379 void ClearKeyCdm::GetUsableKeyIds(uint32_t promise_id,
378 const char* web_session_id, 380 const char* web_session_id,
379 uint32_t web_session_id_length) { 381 uint32_t web_session_id_length) {
380 std::string web_session_str(web_session_id, web_session_id_length); 382 std::string web_session_str(web_session_id, web_session_id_length);
381 scoped_ptr<media::KeyIdsPromise> promise(new media::KeyIdsPromise( 383 scoped_ptr<media::KeyIdsPromise> promise(
382 base::Bind(&ClearKeyCdm::OnUsableKeyIdsObtained, 384 new media::CdmCallbackPromise<KeyIdsVector>(
383 base::Unretained(this), 385 base::Bind(&ClearKeyCdm::OnUsableKeyIdsObtained,
384 promise_id), 386 base::Unretained(this),
385 base::Bind( 387 promise_id),
386 &ClearKeyCdm::OnPromiseFailed, base::Unretained(this), promise_id))); 388 base::Bind(&ClearKeyCdm::OnPromiseFailed,
389 base::Unretained(this),
390 promise_id)));
387 decryptor_.GetUsableKeyIds(web_session_str, promise.Pass()); 391 decryptor_.GetUsableKeyIds(web_session_str, promise.Pass());
388 } 392 }
389 393
390 void ClearKeyCdm::TimerExpired(void* context) { 394 void ClearKeyCdm::TimerExpired(void* context) {
391 if (context == &session_id_for_emulated_loadsession_) { 395 if (context == &session_id_for_emulated_loadsession_) {
392 LoadLoadableSession(); 396 LoadLoadableSession();
393 return; 397 return;
394 } 398 }
395 399
396 DCHECK(heartbeat_timer_set_); 400 DCHECK(heartbeat_timer_set_);
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 NOTIMPLEMENTED(); 657 NOTIMPLEMENTED();
654 }; 658 };
655 659
656 void ClearKeyCdm::LoadLoadableSession() { 660 void ClearKeyCdm::LoadLoadableSession() {
657 std::string jwk_set = GenerateJWKSet(kLoadableSessionKey, 661 std::string jwk_set = GenerateJWKSet(kLoadableSessionKey,
658 sizeof(kLoadableSessionKey), 662 sizeof(kLoadableSessionKey),
659 kLoadableSessionKeyId, 663 kLoadableSessionKeyId,
660 sizeof(kLoadableSessionKeyId) - 1); 664 sizeof(kLoadableSessionKeyId) - 1);
661 // TODO(xhwang): This triggers OnSessionUpdated(). For prefixed EME support, 665 // TODO(xhwang): This triggers OnSessionUpdated(). For prefixed EME support,
662 // this is okay. Check WD EME support. 666 // this is okay. Check WD EME support.
663 scoped_ptr<media::SimpleCdmPromise> promise(new media::SimpleCdmPromise( 667 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>(
664 base::Bind(&ClearKeyCdm::OnSessionUpdated, 668 base::Bind(&ClearKeyCdm::OnSessionUpdated,
665 base::Unretained(this), 669 base::Unretained(this),
666 promise_id_for_emulated_loadsession_, 670 promise_id_for_emulated_loadsession_,
667 session_id_for_emulated_loadsession_), 671 session_id_for_emulated_loadsession_),
668 base::Bind(&ClearKeyCdm::OnPromiseFailed, 672 base::Bind(&ClearKeyCdm::OnPromiseFailed,
669 base::Unretained(this), 673 base::Unretained(this),
670 promise_id_for_emulated_loadsession_))); 674 promise_id_for_emulated_loadsession_)));
671 decryptor_.UpdateSession(session_id_for_emulated_loadsession_, 675 decryptor_.UpdateSession(session_id_for_emulated_loadsession_,
672 reinterpret_cast<const uint8*>(jwk_set.data()), 676 reinterpret_cast<const uint8*>(jwk_set.data()),
673 jwk_set.size(), 677 jwk_set.size(),
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 host_->OnSessionMessage(last_session_id_.data(), 852 host_->OnSessionMessage(last_session_id_.data(),
849 last_session_id_.length(), 853 last_session_id_.length(),
850 message.data(), 854 message.data(),
851 message.length(), 855 message.length(),
852 NULL, 856 NULL,
853 0); 857 0);
854 file_io_test_runner_.reset(); 858 file_io_test_runner_.reset();
855 } 859 }
856 860
857 } // namespace media 861 } // namespace media
OLDNEW
« no previous file with comments | « media/cdm/aes_decryptor_unittest.cc ('k') | media/filters/pipeline_integration_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698