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..ff878941e7160c9551c8f5c9380fa3efb2559096 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) { |
@@ -106,9 +68,10 @@ void WebContentDecryptionModuleSessionImpl::initializeNewSession( |
scoped_ptr<media::NewSessionCdmPromise> promise( |
new media::NewSessionCdmPromise( |
- base::Bind(&WebContentDecryptionModuleSessionImpl::SessionCreated, |
- weak_ptr_factory_.GetWeakPtr(), |
- kReservedIndex), |
+ base::Bind( |
+ &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ kReservedIndex), |
base::Bind(&WebContentDecryptionModuleSessionImpl::OnSessionError, |
weak_ptr_factory_.GetWeakPtr()), |
adapter_->GetKeySystemUMAPrefix() + kCreateSessionUMAName)); |
@@ -137,7 +100,7 @@ void WebContentDecryptionModuleSessionImpl::release() { |
weak_ptr_factory_.GetWeakPtr()), |
base::Bind(&WebContentDecryptionModuleSessionImpl::OnSessionError, |
weak_ptr_factory_.GetWeakPtr()))); |
- adapter_->ReleaseSession(web_session_id_, promise.Pass()); |
+ adapter_->CloseSession(web_session_id_, promise.Pass()); |
ddorwin
2014/09/17 23:54:34
If this is never called, NOTREACHED()?
jrummell
2014/09/23 01:42:48
Updated all 3 old methods to NOTREACHED().
|
} |
void WebContentDecryptionModuleSessionImpl::initializeNewSession( |
@@ -146,17 +109,17 @@ 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. |
if (!base::IsStringASCII(init_data_type)) { |
NOTREACHED(); |
- SessionError(result_index, |
- media::MediaKeys::NOT_SUPPORTED_ERROR, |
- 0, |
- "The initialization data type " + init_data_type.utf8() + |
- " is not supported by the key system."); |
+ OnPromiseRejected(result_index, |
+ media::MediaKeys::NOT_SUPPORTED_ERROR, |
+ 0, |
+ "The initialization data type " + init_data_type.utf8() + |
+ " is not supported by the key system."); |
return; |
} |
@@ -167,10 +130,11 @@ void WebContentDecryptionModuleSessionImpl::initializeNewSession( |
scoped_ptr<media::NewSessionCdmPromise> promise( |
ddorwin
2014/09/17 23:54:34
For consistency (and less code here), does it make
jrummell
2014/09/23 01:42:48
Done.
|
new media::NewSessionCdmPromise( |
- base::Bind(&WebContentDecryptionModuleSessionImpl::SessionCreated, |
- weak_ptr_factory_.GetWeakPtr(), |
- result_index), |
- base::Bind(&WebContentDecryptionModuleSessionImpl::SessionError, |
+ base::Bind( |
+ &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ result_index), |
+ base::Bind(&WebContentDecryptionModuleSessionImpl::OnPromiseRejected, |
weak_ptr_factory_.GetWeakPtr(), |
result_index), |
adapter_->GetKeySystemUMAPrefix() + kCreateSessionUMAName)); |
@@ -186,31 +150,38 @@ void WebContentDecryptionModuleSessionImpl::update( |
size_t response_length, |
blink::WebContentDecryptionModuleResult result) { |
DCHECK(response); |
- uint32 result_index = 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))); |
+ scoped_ptr<media::SimpleCdmPromise> promise = |
+ outstanding_results_.CreateSimpleCdmPromise(result); |
adapter_->UpdateSession( |
web_session_id_, response, response_length, promise.Pass()); |
} |
+void WebContentDecryptionModuleSessionImpl::close( |
+ blink::WebContentDecryptionModuleResult result) { |
+ scoped_ptr<media::SimpleCdmPromise> promise = |
+ outstanding_results_.CreateSimpleCdmPromise(result); |
+ adapter_->CloseSession(web_session_id_, promise.Pass()); |
+} |
+ |
+void WebContentDecryptionModuleSessionImpl::remove( |
+ blink::WebContentDecryptionModuleResult result) { |
+ scoped_ptr<media::SimpleCdmPromise> promise = |
+ outstanding_results_.CreateSimpleCdmPromise(result); |
+ adapter_->RemoveSession(web_session_id_, promise.Pass()); |
+} |
+ |
+void WebContentDecryptionModuleSessionImpl::getUsableKeyIds( |
+ blink::WebContentDecryptionModuleResult result) { |
+ scoped_ptr<media::KeyIdsPromise> promise = |
+ outstanding_results_.CreateKeyIdsPromise(result); |
+ adapter_->GetUsableKeyIds(web_session_id_, promise.Pass()); |
+} |
+ |
void WebContentDecryptionModuleSessionImpl::release( |
blink::WebContentDecryptionModuleResult result) { |
- uint32 result_index = 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_->ReleaseSession(web_session_id_, promise.Pass()); |
+ scoped_ptr<media::SimpleCdmPromise> promise = |
+ outstanding_results_.CreateSimpleCdmPromise(result); |
+ adapter_->CloseSession(web_session_id_, promise.Pass()); |
} |
void WebContentDecryptionModuleSessionImpl::OnSessionMessage( |
@@ -221,6 +192,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(); |
} |
@@ -251,7 +232,7 @@ void WebContentDecryptionModuleSessionImpl::OnSessionError( |
} |
} |
-void WebContentDecryptionModuleSessionImpl::SessionCreated( |
+void WebContentDecryptionModuleSessionImpl::OnSessionInitialized( |
uint32 result_index, |
ddorwin
2014/09/17 23:54:34
This code doesn't care about result_index. This is
jrummell
2014/09/23 01:42:48
Although the status is needed. Done.
|
const std::string& web_session_id) { |
blink::WebContentDecryptionModuleResult::SessionStatus status; |
@@ -270,43 +251,16 @@ 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); |
- } |
-} |
- |
-void WebContentDecryptionModuleSessionImpl::SessionUpdatedOrReleased( |
- 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_.CompleteWithSession(result_index, status); |
} |
-void WebContentDecryptionModuleSessionImpl::SessionError( |
+void WebContentDecryptionModuleSessionImpl::OnPromiseRejected( |
ddorwin
2014/09/17 23:54:34
It would be nice for this to go away as well (rela
jrummell
2014/09/23 01:42:48
Done.
|
uint32 result_index, |
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 |