Commit bcbf042f authored by John Rummell's avatar John Rummell Committed by Xiaohan Wang

[eme] Check earlier for errors creating sessions.

In addition to checking earlier for errors creating sessions, don't try to
fulfil a promise twice.

BUG=826068
TEST=EME browser_tests pass

Change-Id: I912297ad3f8578660727638ead086eb28e90cc9c
Reviewed-on: https://chromium-review.googlesource.com/1006229Reviewed-by: default avatarXiaohan Wang <xhwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550006}
parent d3695968
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/stl_util.h"
#include "media/blink/cdm_result_promise_helper.h" #include "media/blink/cdm_result_promise_helper.h"
#include "third_party/blink/public/platform/web_string.h" #include "third_party/blink/public/platform/web_string.h"
...@@ -52,11 +53,13 @@ NewSessionCdmResultPromise::NewSessionCdmResultPromise( ...@@ -52,11 +53,13 @@ NewSessionCdmResultPromise::NewSessionCdmResultPromise(
const blink::WebContentDecryptionModuleResult& result, const blink::WebContentDecryptionModuleResult& result,
const std::string& key_system_uma_prefix, const std::string& key_system_uma_prefix,
const std::string& uma_name, const std::string& uma_name,
const SessionInitializedCB& new_session_created_cb) const SessionInitializedCB& new_session_created_cb,
const std::vector<SessionInitStatus>& expected_statuses)
: web_cdm_result_(result), : web_cdm_result_(result),
key_system_uma_prefix_(key_system_uma_prefix), key_system_uma_prefix_(key_system_uma_prefix),
uma_name_(uma_name), uma_name_(uma_name),
new_session_created_cb_(new_session_created_cb), new_session_created_cb_(new_session_created_cb),
expected_statuses_(expected_statuses),
creation_time_(base::TimeTicks::Now()) {} creation_time_(base::TimeTicks::Now()) {}
NewSessionCdmResultPromise::~NewSessionCdmResultPromise() { NewSessionCdmResultPromise::~NewSessionCdmResultPromise() {
...@@ -70,7 +73,7 @@ void NewSessionCdmResultPromise::resolve(const std::string& session_id) { ...@@ -70,7 +73,7 @@ void NewSessionCdmResultPromise::resolve(const std::string& session_id) {
SessionInitStatus status = SessionInitStatus::UNKNOWN_STATUS; SessionInitStatus status = SessionInitStatus::UNKNOWN_STATUS;
new_session_created_cb_.Run(session_id, &status); new_session_created_cb_.Run(session_id, &status);
if (status == SessionInitStatus::UNKNOWN_STATUS) { if (!base::ContainsValue(expected_statuses_, status)) {
reject(Exception::INVALID_STATE_ERROR, 0, reject(Exception::INVALID_STATE_ERROR, 0,
"Cannot finish session initialization"); "Cannot finish session initialization");
return; return;
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
namespace media { namespace media {
enum class SessionInitStatus { enum class SessionInitStatus {
// Error creating the session. // Unable to determine the status.
UNKNOWN_STATUS, UNKNOWN_STATUS,
// New session has been initialized. // New session has been initialized.
...@@ -39,7 +39,9 @@ typedef base::Callback<void(const std::string& session_id, ...@@ -39,7 +39,9 @@ typedef base::Callback<void(const std::string& session_id,
// Special class for resolving a new session promise. Resolving a new session // Special class for resolving a new session promise. Resolving a new session
// promise returns the session ID (as a string), but the blink promise needs // promise returns the session ID (as a string), but the blink promise needs
// to get passed a SessionStatus. This class converts the session id to a // to get passed a SessionStatus. This class converts the session id to a
// SessionStatus by calling |new_session_created_cb|. // SessionStatus by calling |new_session_created_cb|. The value returned by
// |new_session_created_cb| must be in |expected_statuses| for the promise to
// be resolved. If it's not in the list, the promise will be rejected.
class MEDIA_BLINK_EXPORT NewSessionCdmResultPromise class MEDIA_BLINK_EXPORT NewSessionCdmResultPromise
: public CdmPromiseTemplate<std::string> { : public CdmPromiseTemplate<std::string> {
public: public:
...@@ -47,7 +49,8 @@ class MEDIA_BLINK_EXPORT NewSessionCdmResultPromise ...@@ -47,7 +49,8 @@ class MEDIA_BLINK_EXPORT NewSessionCdmResultPromise
const blink::WebContentDecryptionModuleResult& result, const blink::WebContentDecryptionModuleResult& result,
const std::string& key_system_uma_prefix, const std::string& key_system_uma_prefix,
const std::string& uma_name, const std::string& uma_name,
const SessionInitializedCB& new_session_created_cb); const SessionInitializedCB& new_session_created_cb,
const std::vector<SessionInitStatus>& expected_statuses);
~NewSessionCdmResultPromise() override; ~NewSessionCdmResultPromise() override;
// CdmPromiseTemplate<T> implementation. // CdmPromiseTemplate<T> implementation.
...@@ -64,8 +67,10 @@ class MEDIA_BLINK_EXPORT NewSessionCdmResultPromise ...@@ -64,8 +67,10 @@ class MEDIA_BLINK_EXPORT NewSessionCdmResultPromise
std::string uma_name_; std::string uma_name_;
// Called on resolve() to convert the session ID into a SessionInitStatus to // Called on resolve() to convert the session ID into a SessionInitStatus to
// be reported to blink. // be reported to blink. Returned status must be in |expected_statuses_| or
// else the promise will be rejected.
SessionInitializedCB new_session_created_cb_; SessionInitializedCB new_session_created_cb_;
std::vector<SessionInitStatus> expected_statuses_;
// Time when |this| is created. // Time when |this| is created.
base::TimeTicks creation_time_; base::TimeTicks creation_time_;
......
...@@ -349,7 +349,8 @@ void WebContentDecryptionModuleSessionImpl::InitializeNewSession( ...@@ -349,7 +349,8 @@ void WebContentDecryptionModuleSessionImpl::InitializeNewSession(
result, adapter_->GetKeySystemUMAPrefix(), kGenerateRequestUMAName, result, adapter_->GetKeySystemUMAPrefix(), kGenerateRequestUMAName,
base::Bind( base::Bind(
&WebContentDecryptionModuleSessionImpl::OnSessionInitialized, &WebContentDecryptionModuleSessionImpl::OnSessionInitialized,
weak_ptr_factory_.GetWeakPtr())))); weak_ptr_factory_.GetWeakPtr()),
{SessionInitStatus::NEW_SESSION})));
} }
void WebContentDecryptionModuleSessionImpl::Load( void WebContentDecryptionModuleSessionImpl::Load(
...@@ -384,7 +385,9 @@ void WebContentDecryptionModuleSessionImpl::Load( ...@@ -384,7 +385,9 @@ void WebContentDecryptionModuleSessionImpl::Load(
result, adapter_->GetKeySystemUMAPrefix(), kLoadSessionUMAName, result, adapter_->GetKeySystemUMAPrefix(), kLoadSessionUMAName,
base::Bind( base::Bind(
&WebContentDecryptionModuleSessionImpl::OnSessionInitialized, &WebContentDecryptionModuleSessionImpl::OnSessionInitialized,
weak_ptr_factory_.GetWeakPtr())))); weak_ptr_factory_.GetWeakPtr()),
{SessionInitStatus::NEW_SESSION,
SessionInitStatus::SESSION_NOT_FOUND})));
} }
void WebContentDecryptionModuleSessionImpl::Update( void WebContentDecryptionModuleSessionImpl::Update(
......
...@@ -238,11 +238,7 @@ class NewSessionResultPromise : public ContentDecryptionModuleResultPromise { ...@@ -238,11 +238,7 @@ class NewSessionResultPromise : public ContentDecryptionModuleResultPromise {
if (!IsValidToFulfillPromise()) if (!IsValidToFulfillPromise())
return; return;
if (status != WebContentDecryptionModuleResult::kNewSession) { DCHECK_EQ(status, WebContentDecryptionModuleResult::kNewSession);
NOTREACHED();
Reject(kInvalidStateError, "Unexpected completion.");
}
session_->FinishGenerateRequest(); session_->FinishGenerateRequest();
Resolve(); Resolve();
} }
...@@ -274,23 +270,14 @@ class LoadSessionResultPromise : public ContentDecryptionModuleResultPromise { ...@@ -274,23 +270,14 @@ class LoadSessionResultPromise : public ContentDecryptionModuleResultPromise {
if (!IsValidToFulfillPromise()) if (!IsValidToFulfillPromise())
return; return;
switch (status) { if (status == WebContentDecryptionModuleResult::kSessionNotFound) {
case WebContentDecryptionModuleResult::kNewSession: Resolve(false);
session_->FinishLoad(); return;
Resolve(true);
return;
case WebContentDecryptionModuleResult::kSessionNotFound:
Resolve(false);
return;
case WebContentDecryptionModuleResult::kSessionAlreadyExists:
NOTREACHED();
Reject(kInvalidStateError, "Unexpected completion.");
return;
} }
NOTREACHED(); DCHECK_EQ(status, WebContentDecryptionModuleResult::kNewSession);
session_->FinishLoad();
Resolve(true);
} }
void Trace(blink::Visitor* visitor) override { void Trace(blink::Visitor* visitor) override {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment