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

Unified Diff: media/blink/webcontentdecryptionmodulesession_impl.cc

Issue 2484873002: EME: Make sure sessions are closed before they are destroyed (Closed)
Patch Set: Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/blink/webcontentdecryptionmodulesession_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/blink/webcontentdecryptionmodulesession_impl.cc
diff --git a/media/blink/webcontentdecryptionmodulesession_impl.cc b/media/blink/webcontentdecryptionmodulesession_impl.cc
index ab138e7447d95a9786b94b88895939907fe4ab60..63bd46961538c5c1317e3786e48dee67a5b0f730 100644
--- a/media/blink/webcontentdecryptionmodulesession_impl.cc
+++ b/media/blink/webcontentdecryptionmodulesession_impl.cc
@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/logging.h"
+#include "base/memory/ptr_util.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
@@ -224,16 +225,50 @@ static bool SanitizeResponse(const std::string& key_system,
return true;
}
+// If we need to call close() on destruction, we need a promise that won't
ddorwin 2016/11/07 19:45:30 "call close()" (and similar wording in the descrip
jrummell 2016/11/07 22:51:40 Done.
+// do anything.
+class IgnoreResponsePromise : public SimpleCdmPromise {
+ public:
+ IgnoreResponsePromise() {}
+ ~IgnoreResponsePromise() override {}
+
+ // SimpleCdmPromise implementation.
+ void resolve() final { MarkPromiseSettled(); }
+ void reject(CdmPromise::Exception exception_code,
+ uint32_t system_code,
+ const std::string& error_message) final {
+ MarkPromiseSettled();
+ }
+};
+
WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl(
const scoped_refptr<CdmSessionAdapter>& adapter)
- : adapter_(adapter), is_closed_(false), weak_ptr_factory_(this) {
-}
+ : adapter_(adapter),
+ is_closed_(false),
+ has_close_been_called_(false),
+ weak_ptr_factory_(this) {}
WebContentDecryptionModuleSessionImpl::
~WebContentDecryptionModuleSessionImpl() {
DCHECK(thread_checker_.CalledOnValidThread());
- if (!session_id_.empty())
+
+ if (!session_id_.empty()) {
adapter_->UnregisterSession(session_id_);
+
+ // From http://w3c.github.io/encrypted-media/#mediakeysession-interface
ddorwin 2016/11/07 19:45:30 This text was just updated. (MediaKeySession destr
jrummell 2016/11/07 22:51:40 Done.
+ // "If a MediaKeySession object becomes inaccessible to the page and is not
+ // closed, the User Agent must run the MediaKeySession destroyed algorithm
+ // before User Agent state associated with the session is deleted."
ddorwin 2016/11/07 19:45:31 We don't actually do this last part and can't beca
jrummell 2016/11/07 22:51:40 Acknowledged.
+ //
+ // So if the session is not closed and CloseSession() has not yet been
+ // called, call CloseSession() now. Since this object is being destroyed,
+ // there is no need for the promise to do anything as this session will
+ // be gone.
+ if (!is_closed_ && !has_close_been_called_) {
+ adapter_->CloseSession(session_id_,
+ base::MakeUnique<IgnoreResponsePromise>());
+ }
+ }
}
void WebContentDecryptionModuleSessionImpl::setClientInterface(Client* client) {
@@ -394,6 +429,8 @@ void WebContentDecryptionModuleSessionImpl::close(
blink::WebContentDecryptionModuleResult result) {
DCHECK(!session_id_.empty());
DCHECK(thread_checker_.CalledOnValidThread());
+
+ has_close_been_called_ = true;
adapter_->CloseSession(
session_id_,
std::unique_ptr<SimpleCdmPromise>(new CdmResultPromise<>(
« no previous file with comments | « media/blink/webcontentdecryptionmodulesession_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698