Chromium Code Reviews| Index: content/renderer/media/webcontentdecryptionmodulesession_impl.cc |
| diff --git a/content/renderer/media/webcontentdecryptionmodulesession_impl.cc b/content/renderer/media/webcontentdecryptionmodulesession_impl.cc |
| index 527720f338c60e75342fd91da5ed283985e2a700..b75c914c256b507a5a83abd0a87d54cc0df5b68f 100644 |
| --- a/content/renderer/media/webcontentdecryptionmodulesession_impl.cc |
| +++ b/content/renderer/media/webcontentdecryptionmodulesession_impl.cc |
| @@ -24,55 +24,17 @@ const char kCreateSessionUMAName[] = "CreateSession"; |
| // WebContentDecryptionModuleResult. |
| const uint32 kReservedIndex = 0; |
| -static blink::WebContentDecryptionModuleException ConvertException( |
| - media::MediaKeys::Exception exception_code) { |
| - switch (exception_code) { |
| - case media::MediaKeys::NOT_SUPPORTED_ERROR: |
| - return blink::WebContentDecryptionModuleExceptionNotSupportedError; |
| - case media::MediaKeys::INVALID_STATE_ERROR: |
| - return blink::WebContentDecryptionModuleExceptionInvalidStateError; |
| - case media::MediaKeys::INVALID_ACCESS_ERROR: |
| - return blink::WebContentDecryptionModuleExceptionInvalidAccessError; |
| - case media::MediaKeys::QUOTA_EXCEEDED_ERROR: |
| - return blink::WebContentDecryptionModuleExceptionQuotaExceededError; |
| - case media::MediaKeys::UNKNOWN_ERROR: |
| - return blink::WebContentDecryptionModuleExceptionUnknownError; |
| - case media::MediaKeys::CLIENT_ERROR: |
| - return blink::WebContentDecryptionModuleExceptionClientError; |
| - case media::MediaKeys::OUTPUT_ERROR: |
| - return blink::WebContentDecryptionModuleExceptionOutputError; |
| - default: |
| - NOTREACHED(); |
| - return blink::WebContentDecryptionModuleExceptionUnknownError; |
| - } |
| -} |
| - |
| WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl( |
| const scoped_refptr<CdmSessionAdapter>& adapter) |
| : adapter_(adapter), |
| is_closed_(false), |
| - next_available_result_index_(1), |
| weak_ptr_factory_(this) { |
| } |
| WebContentDecryptionModuleSessionImpl:: |
| ~WebContentDecryptionModuleSessionImpl() { |
| if (!web_session_id_.empty()) |
| - adapter_->RemoveSession(web_session_id_); |
| - |
| - // Release any WebContentDecryptionModuleResult objects that are left. Their |
| - // index will have been passed down via a CdmPromise, but it uses a WeakPtr. |
| - DLOG_IF(WARNING, outstanding_results_.size() > 0) |
| - << "Clearing " << outstanding_results_.size() << " results"; |
| - for (ResultMap::iterator it = outstanding_results_.begin(); |
| - it != outstanding_results_.end(); |
| - ++it) { |
| - it->second.completeWithError( |
| - blink::WebContentDecryptionModuleExceptionInvalidStateError, |
| - 0, |
| - "Outstanding request being cancelled."); |
| - } |
| - outstanding_results_.clear(); |
| + adapter_->UnregisterSession(web_session_id_); |
| } |
| void WebContentDecryptionModuleSessionImpl::setClientInterface(Client* client) { |
| @@ -137,7 +99,7 @@ void WebContentDecryptionModuleSessionImpl::release() { |
| weak_ptr_factory_.GetWeakPtr()), |
| base::Bind(&WebContentDecryptionModuleSessionImpl::OnSessionError, |
| weak_ptr_factory_.GetWeakPtr()))); |
| - adapter_->ReleaseSession(web_session_id_, promise.Pass()); |
| + adapter_->RemoveSession(web_session_id_, promise.Pass()); |
|
ddorwin
2014/09/12 21:46:29
CloseSession() is probably more appropriate, thoug
jrummell
2014/09/15 18:22:39
Blink doesn't call this. So it doesn't matter. Cha
|
| } |
| void WebContentDecryptionModuleSessionImpl::initializeNewSession( |
| @@ -146,7 +108,7 @@ void WebContentDecryptionModuleSessionImpl::initializeNewSession( |
| size_t init_data_length, |
| const blink::WebString& session_type, |
| blink::WebContentDecryptionModuleResult result) { |
| - uint32 result_index = AddResult(result); |
| + uint32 result_index = outstanding_results_.AddResult(result); |
| // TODO(ddorwin): Guard against this in supported types check and remove this. |
| // Chromium only supports ASCII MIME types. |
| @@ -186,7 +148,7 @@ void WebContentDecryptionModuleSessionImpl::update( |
| size_t response_length, |
| blink::WebContentDecryptionModuleResult result) { |
| DCHECK(response); |
| - uint32 result_index = AddResult(result); |
| + uint32 result_index = outstanding_results_.AddResult(result); |
| scoped_ptr<media::SimpleCdmPromise> promise(new media::SimpleCdmPromise( |
| base::Bind( |
| &WebContentDecryptionModuleSessionImpl::SessionUpdatedOrReleased, |
| @@ -199,9 +161,50 @@ void WebContentDecryptionModuleSessionImpl::update( |
| web_session_id_, response, response_length, promise.Pass()); |
| } |
| +void WebContentDecryptionModuleSessionImpl::close( |
| + blink::WebContentDecryptionModuleResult result) { |
| + uint32 result_index = outstanding_results_.AddResult(result); |
|
ddorwin
2014/09/12 21:46:30
This is a lot of boilerplate code. It'd be nice to
jrummell
2014/09/15 18:22:39
Would work well for most of these calls. However,
|
| + scoped_ptr<media::SimpleCdmPromise> promise(new media::SimpleCdmPromise( |
|
ddorwin
2014/09/12 21:46:29
Related to above, can we eliminate outstanding_res
jrummell
2014/09/15 18:22:40
(I assume you mean CdmPromise.) Have a separate CL
ddorwin
2014/09/17 23:54:33
Okay, I think we'll need to wait for that before c
|
| + base::Bind( |
| + &WebContentDecryptionModuleSessionImpl::SessionUpdatedOrReleased, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + result_index), |
| + base::Bind(&WebContentDecryptionModuleSessionImpl::SessionError, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + result_index))); |
| + adapter_->CloseSession(web_session_id_, promise.Pass()); |
| +} |
| + |
| +void WebContentDecryptionModuleSessionImpl::remove( |
| + blink::WebContentDecryptionModuleResult result) { |
| + uint32 result_index = outstanding_results_.AddResult(result); |
| + scoped_ptr<media::SimpleCdmPromise> promise(new media::SimpleCdmPromise( |
| + base::Bind( |
| + &WebContentDecryptionModuleSessionImpl::SessionUpdatedOrReleased, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + result_index), |
| + base::Bind(&WebContentDecryptionModuleSessionImpl::SessionError, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + result_index))); |
| + adapter_->RemoveSession(web_session_id_, promise.Pass()); |
| +} |
| + |
| +void WebContentDecryptionModuleSessionImpl::getUsableKeyIds( |
| + blink::WebContentDecryptionModuleResult result) { |
| + uint32 result_index = outstanding_results_.AddResult(result); |
| + scoped_ptr<media::KeyIdsPromise> promise(new media::KeyIdsPromise( |
| + base::Bind(&WebContentDecryptionModuleSessionImpl::KeyIdsAvailable, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + result_index), |
| + base::Bind(&WebContentDecryptionModuleSessionImpl::SessionError, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + result_index))); |
| + adapter_->GetUsableKeyIds(web_session_id_, promise.Pass()); |
| +} |
| + |
| void WebContentDecryptionModuleSessionImpl::release( |
| blink::WebContentDecryptionModuleResult result) { |
| - uint32 result_index = AddResult(result); |
| + uint32 result_index = outstanding_results_.AddResult(result); |
| scoped_ptr<media::SimpleCdmPromise> promise(new media::SimpleCdmPromise( |
| base::Bind( |
| &WebContentDecryptionModuleSessionImpl::SessionUpdatedOrReleased, |
| @@ -210,7 +213,7 @@ void WebContentDecryptionModuleSessionImpl::release( |
| base::Bind(&WebContentDecryptionModuleSessionImpl::SessionError, |
| weak_ptr_factory_.GetWeakPtr(), |
| result_index))); |
| - adapter_->ReleaseSession(web_session_id_, promise.Pass()); |
| + adapter_->RemoveSession(web_session_id_, promise.Pass()); |
|
ddorwin
2014/09/12 21:46:30
ditto
jrummell
2014/09/15 18:22:40
This one is called. Changed to close().
|
| } |
| void WebContentDecryptionModuleSessionImpl::OnSessionMessage( |
| @@ -221,6 +224,16 @@ void WebContentDecryptionModuleSessionImpl::OnSessionMessage( |
| message.empty() ? NULL : &message[0], message.size(), destination_url); |
| } |
| +void WebContentDecryptionModuleSessionImpl::OnSessionKeysChange( |
| + bool has_additional_usable_key) { |
| + // TODO(jrummell): Update this once Blink client supports this. |
| +} |
| + |
| +void WebContentDecryptionModuleSessionImpl::OnSessionExpirationChange( |
| + double new_expiry_time) { |
| + // TODO(jrummell): Update this once Blink client supports this. |
| +} |
| + |
| void WebContentDecryptionModuleSessionImpl::OnSessionReady() { |
| client_->ready(); |
| } |
| @@ -270,21 +283,18 @@ void WebContentDecryptionModuleSessionImpl::SessionCreated( |
| : blink::WebContentDecryptionModuleResult::SessionAlreadyExists; |
| } |
| - ResultMap::iterator it = outstanding_results_.find(result_index); |
| - if (it != outstanding_results_.end()) { |
| - blink::WebContentDecryptionModuleResult& result = it->second; |
| - result.completeWithSession(status); |
| - outstanding_results_.erase(result_index); |
| - } |
| + outstanding_results_.CompleteWithSession(result_index, status); |
| } |
| void WebContentDecryptionModuleSessionImpl::SessionUpdatedOrReleased( |
|
ddorwin
2014/09/12 21:46:30
This function needs a new name. OnPromiseResolved?
jrummell
2014/09/15 18:22:39
Done.
|
| uint32 result_index) { |
| - ResultMap::iterator it = outstanding_results_.find(result_index); |
| - DCHECK(it != outstanding_results_.end()); |
| - blink::WebContentDecryptionModuleResult& result = it->second; |
| - result.complete(); |
| - outstanding_results_.erase(it); |
| + outstanding_results_.Complete(result_index); |
| +} |
| + |
| +void WebContentDecryptionModuleSessionImpl::KeyIdsAvailable( |
| + uint32 result_index, |
| + const media::KeyIdsVector& key_ids) { |
| + outstanding_results_.CompleteWithKeyIds(result_index, key_ids); |
| } |
| void WebContentDecryptionModuleSessionImpl::SessionError( |
| @@ -292,21 +302,8 @@ void WebContentDecryptionModuleSessionImpl::SessionError( |
| media::MediaKeys::Exception exception_code, |
| uint32 system_code, |
| const std::string& error_message) { |
| - ResultMap::iterator it = outstanding_results_.find(result_index); |
| - DCHECK(it != outstanding_results_.end()); |
| - blink::WebContentDecryptionModuleResult& result = it->second; |
| - result.completeWithError(ConvertException(exception_code), |
| - system_code, |
| - blink::WebString::fromUTF8(error_message)); |
| - outstanding_results_.erase(it); |
| -} |
| - |
| -uint32 WebContentDecryptionModuleSessionImpl::AddResult( |
| - blink::WebContentDecryptionModuleResult result) { |
| - uint32 result_index = next_available_result_index_++; |
| - DCHECK(result_index != kReservedIndex); |
| - outstanding_results_.insert(std::make_pair(result_index, result)); |
| - return result_index; |
| + outstanding_results_.CompleteWithError( |
| + result_index, exception_code, system_code, error_message); |
| } |
| } // namespace content |