| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "content/browser/media/cdm/browser_cdm_manager.h" | 5 #include "content/browser/media/cdm/browser_cdm_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | |
| 9 #include <string> | 8 #include <string> |
| 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/task_runner.h" | 15 #include "base/task_runner.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/content_browser_client.h" | 19 #include "content/public/browser/content_browser_client.h" |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 if (!cdm) { | 419 if (!cdm) { |
| 420 promise->reject(MediaKeys::INVALID_STATE_ERROR, 0, "CDM not found."); | 420 promise->reject(MediaKeys::INVALID_STATE_ERROR, 0, "CDM not found."); |
| 421 return; | 421 return; |
| 422 } | 422 } |
| 423 | 423 |
| 424 if (certificate.empty()) { | 424 if (certificate.empty()) { |
| 425 promise->reject(MediaKeys::INVALID_ACCESS_ERROR, 0, "Empty certificate."); | 425 promise->reject(MediaKeys::INVALID_ACCESS_ERROR, 0, "Empty certificate."); |
| 426 return; | 426 return; |
| 427 } | 427 } |
| 428 | 428 |
| 429 cdm->SetServerCertificate(certificate, promise.Pass()); | 429 cdm->SetServerCertificate(certificate, std::move(promise)); |
| 430 } | 430 } |
| 431 | 431 |
| 432 void BrowserCdmManager::OnCreateSessionAndGenerateRequest( | 432 void BrowserCdmManager::OnCreateSessionAndGenerateRequest( |
| 433 const CdmHostMsg_CreateSessionAndGenerateRequest_Params& params) { | 433 const CdmHostMsg_CreateSessionAndGenerateRequest_Params& params) { |
| 434 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 434 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 435 | 435 |
| 436 int render_frame_id = params.render_frame_id; | 436 int render_frame_id = params.render_frame_id; |
| 437 int cdm_id = params.cdm_id; | 437 int cdm_id = params.cdm_id; |
| 438 const std::vector<uint8_t>& init_data = params.init_data; | 438 const std::vector<uint8_t>& init_data = params.init_data; |
| 439 scoped_ptr<NewSessionPromise> promise( | 439 scoped_ptr<NewSessionPromise> promise( |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 << " is too long: " << response.size(); | 533 << " is too long: " << response.size(); |
| 534 promise->reject(MediaKeys::INVALID_ACCESS_ERROR, 0, "Response too long."); | 534 promise->reject(MediaKeys::INVALID_ACCESS_ERROR, 0, "Response too long."); |
| 535 return; | 535 return; |
| 536 } | 536 } |
| 537 | 537 |
| 538 if (response.empty()) { | 538 if (response.empty()) { |
| 539 promise->reject(MediaKeys::INVALID_ACCESS_ERROR, 0, "Response is empty."); | 539 promise->reject(MediaKeys::INVALID_ACCESS_ERROR, 0, "Response is empty."); |
| 540 return; | 540 return; |
| 541 } | 541 } |
| 542 | 542 |
| 543 cdm->UpdateSession(session_id, response, promise.Pass()); | 543 cdm->UpdateSession(session_id, response, std::move(promise)); |
| 544 } | 544 } |
| 545 | 545 |
| 546 void BrowserCdmManager::OnCloseSession(int render_frame_id, | 546 void BrowserCdmManager::OnCloseSession(int render_frame_id, |
| 547 int cdm_id, | 547 int cdm_id, |
| 548 uint32_t promise_id, | 548 uint32_t promise_id, |
| 549 const std::string& session_id) { | 549 const std::string& session_id) { |
| 550 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 550 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 551 | 551 |
| 552 scoped_ptr<SimplePromise> promise(new SimplePromise( | 552 scoped_ptr<SimplePromise> promise(new SimplePromise( |
| 553 weak_ptr_factory_.GetWeakPtr(), render_frame_id, cdm_id, promise_id)); | 553 weak_ptr_factory_.GetWeakPtr(), render_frame_id, cdm_id, promise_id)); |
| 554 | 554 |
| 555 scoped_refptr<MediaKeys> cdm = GetCdm(render_frame_id, cdm_id); | 555 scoped_refptr<MediaKeys> cdm = GetCdm(render_frame_id, cdm_id); |
| 556 if (!cdm) { | 556 if (!cdm) { |
| 557 promise->reject(MediaKeys::INVALID_STATE_ERROR, 0, "CDM not found."); | 557 promise->reject(MediaKeys::INVALID_STATE_ERROR, 0, "CDM not found."); |
| 558 return; | 558 return; |
| 559 } | 559 } |
| 560 | 560 |
| 561 cdm->CloseSession(session_id, promise.Pass()); | 561 cdm->CloseSession(session_id, std::move(promise)); |
| 562 } | 562 } |
| 563 | 563 |
| 564 void BrowserCdmManager::OnRemoveSession(int render_frame_id, | 564 void BrowserCdmManager::OnRemoveSession(int render_frame_id, |
| 565 int cdm_id, | 565 int cdm_id, |
| 566 uint32_t promise_id, | 566 uint32_t promise_id, |
| 567 const std::string& session_id) { | 567 const std::string& session_id) { |
| 568 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 568 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 569 | 569 |
| 570 scoped_ptr<SimplePromise> promise(new SimplePromise( | 570 scoped_ptr<SimplePromise> promise(new SimplePromise( |
| 571 weak_ptr_factory_.GetWeakPtr(), render_frame_id, cdm_id, promise_id)); | 571 weak_ptr_factory_.GetWeakPtr(), render_frame_id, cdm_id, promise_id)); |
| 572 | 572 |
| 573 scoped_refptr<MediaKeys> cdm = GetCdm(render_frame_id, cdm_id); | 573 scoped_refptr<MediaKeys> cdm = GetCdm(render_frame_id, cdm_id); |
| 574 if (!cdm) { | 574 if (!cdm) { |
| 575 promise->reject(MediaKeys::INVALID_STATE_ERROR, 0, "CDM not found."); | 575 promise->reject(MediaKeys::INVALID_STATE_ERROR, 0, "CDM not found."); |
| 576 return; | 576 return; |
| 577 } | 577 } |
| 578 | 578 |
| 579 cdm->RemoveSession(session_id, promise.Pass()); | 579 cdm->RemoveSession(session_id, std::move(promise)); |
| 580 } | 580 } |
| 581 | 581 |
| 582 void BrowserCdmManager::OnDestroyCdm(int render_frame_id, int cdm_id) { | 582 void BrowserCdmManager::OnDestroyCdm(int render_frame_id, int cdm_id) { |
| 583 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 583 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 584 RemoveCdm(GetId(render_frame_id, cdm_id)); | 584 RemoveCdm(GetId(render_frame_id, cdm_id)); |
| 585 } | 585 } |
| 586 | 586 |
| 587 void BrowserCdmManager::OnCdmCreated( | 587 void BrowserCdmManager::OnCdmCreated( |
| 588 int render_frame_id, | 588 int render_frame_id, |
| 589 int cdm_id, | 589 int cdm_id, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 promise->reject(MediaKeys::NOT_SUPPORTED_ERROR, 0, "Permission denied."); | 693 promise->reject(MediaKeys::NOT_SUPPORTED_ERROR, 0, "Permission denied."); |
| 694 return; | 694 return; |
| 695 } | 695 } |
| 696 | 696 |
| 697 scoped_refptr<MediaKeys> cdm = GetCdm(render_frame_id, cdm_id); | 697 scoped_refptr<MediaKeys> cdm = GetCdm(render_frame_id, cdm_id); |
| 698 if (!cdm) { | 698 if (!cdm) { |
| 699 promise->reject(MediaKeys::INVALID_STATE_ERROR, 0, "CDM not found."); | 699 promise->reject(MediaKeys::INVALID_STATE_ERROR, 0, "CDM not found."); |
| 700 return; | 700 return; |
| 701 } | 701 } |
| 702 | 702 |
| 703 cdm->CreateSessionAndGenerateRequest(session_type, init_data_type, | 703 cdm->CreateSessionAndGenerateRequest(session_type, init_data_type, init_data, |
| 704 init_data, promise.Pass()); | 704 std::move(promise)); |
| 705 } | 705 } |
| 706 | 706 |
| 707 void BrowserCdmManager::LoadSessionIfPermitted( | 707 void BrowserCdmManager::LoadSessionIfPermitted( |
| 708 int render_frame_id, | 708 int render_frame_id, |
| 709 int cdm_id, | 709 int cdm_id, |
| 710 media::MediaKeys::SessionType session_type, | 710 media::MediaKeys::SessionType session_type, |
| 711 const std::string& session_id, | 711 const std::string& session_id, |
| 712 scoped_ptr<media::NewSessionCdmPromise> promise, | 712 scoped_ptr<media::NewSessionCdmPromise> promise, |
| 713 bool permission_was_allowed) { | 713 bool permission_was_allowed) { |
| 714 DCHECK_NE(media::MediaKeys::SessionType::TEMPORARY_SESSION, session_type); | 714 DCHECK_NE(media::MediaKeys::SessionType::TEMPORARY_SESSION, session_type); |
| 715 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 715 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 716 | 716 |
| 717 if (!permission_was_allowed) { | 717 if (!permission_was_allowed) { |
| 718 promise->reject(MediaKeys::NOT_SUPPORTED_ERROR, 0, "Permission denied."); | 718 promise->reject(MediaKeys::NOT_SUPPORTED_ERROR, 0, "Permission denied."); |
| 719 return; | 719 return; |
| 720 } | 720 } |
| 721 | 721 |
| 722 scoped_refptr<MediaKeys> cdm = GetCdm(render_frame_id, cdm_id); | 722 scoped_refptr<MediaKeys> cdm = GetCdm(render_frame_id, cdm_id); |
| 723 if (!cdm) { | 723 if (!cdm) { |
| 724 promise->reject(MediaKeys::INVALID_STATE_ERROR, 0, "CDM not found."); | 724 promise->reject(MediaKeys::INVALID_STATE_ERROR, 0, "CDM not found."); |
| 725 return; | 725 return; |
| 726 } | 726 } |
| 727 | 727 |
| 728 cdm->LoadSession(session_type, session_id, promise.Pass()); | 728 cdm->LoadSession(session_type, session_id, std::move(promise)); |
| 729 } | 729 } |
| 730 | 730 |
| 731 } // namespace content | 731 } // namespace content |
| OLD | NEW |