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

Side by Side Diff: content/renderer/media/webcontentdecryptionmodulesession_impl.cc

Issue 265993002: Add Promises for EME (Chromium side) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/renderer/media/webcontentdecryptionmodulesession_impl.h" 5 #include "content/renderer/media/webcontentdecryptionmodulesession_impl.h"
6 6
7 #include "base/bind.h"
7 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
8 #include "base/logging.h" 9 #include "base/logging.h"
9 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
11 #include "content/renderer/media/cdm_session_adapter.h" 12 #include "content/renderer/media/cdm_session_adapter.h"
13 #include "media/base/media_keys.h"
ddorwin 2014/05/05 18:35:42 duplicate with .h
jrummell 2014/05/08 23:37:45 Done.
14 #include "media/base/media_keys_session_promise.h"
12 #include "third_party/WebKit/public/platform/WebURL.h" 15 #include "third_party/WebKit/public/platform/WebURL.h"
13 16
14 namespace content { 17 namespace content {
15 18
16 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl( 19 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl(
17 uint32 session_id,
18 Client* client, 20 Client* client,
19 const scoped_refptr<CdmSessionAdapter>& adapter) 21 const scoped_refptr<CdmSessionAdapter>& adapter)
20 : adapter_(adapter), 22 : adapter_(adapter),
21 client_(client), 23 client_(client),
22 session_id_(session_id) { 24 weak_ptr_factory_(this) {
23 } 25 }
24 26
25 WebContentDecryptionModuleSessionImpl:: 27 WebContentDecryptionModuleSessionImpl::
26 ~WebContentDecryptionModuleSessionImpl() { 28 ~WebContentDecryptionModuleSessionImpl() {
27 adapter_->RemoveSession(session_id_); 29 if (!web_session_id_.empty())
30 adapter_->RemoveSession(web_session_id_);
28 } 31 }
29 32
30 blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const { 33 blink::WebString WebContentDecryptionModuleSessionImpl::sessionId() const {
31 return web_session_id_; 34 return blink::WebString::fromUTF8(web_session_id_);
32 } 35 }
33 36
34 void WebContentDecryptionModuleSessionImpl::initializeNewSession( 37 void WebContentDecryptionModuleSessionImpl::initializeNewSession(
ddorwin 2014/05/05 18:35:42 I wonder if we'll eventually want to move session
35 const blink::WebString& mime_type, 38 const blink::WebString& init_data_type,
ddorwin 2014/05/05 18:35:42 We might want to DLOG(WARNING) if this includes a
jrummell 2014/05/08 23:37:45 Done.
36 const uint8* init_data, size_t init_data_length) { 39 const uint8* init_data,
40 size_t init_data_length) {
37 // TODO(ddorwin): Guard against this in supported types check and remove this. 41 // TODO(ddorwin): Guard against this in supported types check and remove this.
38 // Chromium only supports ASCII MIME types. 42 // Chromium only supports ASCII MIME types.
39 if (!IsStringASCII(mime_type)) { 43 if (!IsStringASCII(init_data_type)) {
40 NOTREACHED(); 44 NOTREACHED();
41 OnSessionError(media::MediaKeys::kUnknownError, 0); 45 OnSessionError("InvalidCharacterError",
ddorwin 2014/05/05 18:35:42 This is a Chromium choice, not a spec issue, so we
jrummell 2014/05/08 23:37:45 Done.
46 0,
47 "init_data_type contains non-ASCII characters.");
42 return; 48 return;
43 } 49 }
44 50
45 adapter_->InitializeNewSession( 51 scoped_ptr<media::MediaKeysSessionPromise> promise(
46 session_id_, base::UTF16ToASCII(mime_type), init_data, init_data_length); 52 new media::MediaKeysSessionPromise(
53 media::PromiseResolvedCB(),
ddorwin 2014/05/05 18:35:42 This is weird. As noted in the promise header, we
jrummell 2014/05/08 23:37:45 Done.
54 base::Bind(&WebContentDecryptionModuleSessionImpl::setSessionId,
ddorwin 2014/05/05 18:35:42 I think we're going to need to do more than set th
jrummell 2014/05/08 23:37:45 Done.
55 weak_ptr_factory_.GetWeakPtr()),
56 base::Bind(&WebContentDecryptionModuleSessionImpl::OnSessionError,
ddorwin 2014/05/05 18:35:42 Even if we rely on the same code in the interim, t
jrummell 2014/05/08 23:37:45 Done.
57 weak_ptr_factory_.GetWeakPtr())));
58 adapter_->InitializeNewSession(base::UTF16ToASCII(init_data_type),
59 init_data,
60 init_data_length,
61 media::MediaKeys::SessionType::kTemporary,
62 promise.Pass());
47 } 63 }
48 64
49 void WebContentDecryptionModuleSessionImpl::update(const uint8* response, 65 void WebContentDecryptionModuleSessionImpl::update(const uint8* response,
50 size_t response_length) { 66 size_t response_length) {
51 DCHECK(response); 67 DCHECK(response);
52 adapter_->UpdateSession(session_id_, response, response_length); 68 scoped_ptr<media::MediaKeysSessionPromise> promise(
ddorwin 2014/05/05 18:35:42 You might consider helper functions for creating t
jrummell 2014/05/08 23:37:45 Done as a macro. If everybody is OK with it, I'll
69 new media::MediaKeysSessionPromise(
70 base::Bind(&WebContentDecryptionModuleSessionImpl::OnSessionReady,
71 weak_ptr_factory_.GetWeakPtr()),
72 media::PromiseResolvedWithSessionCB(),
73 base::Bind(&WebContentDecryptionModuleSessionImpl::OnSessionError,
74 weak_ptr_factory_.GetWeakPtr())));
75 adapter_->UpdateSession(
76 web_session_id_, response, response_length, promise.Pass());
53 } 77 }
54 78
55 void WebContentDecryptionModuleSessionImpl::release() { 79 void WebContentDecryptionModuleSessionImpl::release() {
56 adapter_->ReleaseSession(session_id_); 80 scoped_ptr<media::MediaKeysSessionPromise> promise(
57 } 81 new media::MediaKeysSessionPromise(
58 82 base::Bind(&WebContentDecryptionModuleSessionImpl::OnSessionClosed,
59 void WebContentDecryptionModuleSessionImpl::OnSessionCreated( 83 weak_ptr_factory_.GetWeakPtr()),
60 const std::string& web_session_id) { 84 media::PromiseResolvedWithSessionCB(),
61 // Due to heartbeat messages, OnSessionCreated() can get called multiple 85 base::Bind(&WebContentDecryptionModuleSessionImpl::OnSessionError,
62 // times. 86 weak_ptr_factory_.GetWeakPtr())));
63 // TODO(jrummell): Once all CDMs are updated to support reference ids, 87 adapter_->ReleaseSession(web_session_id_, promise.Pass());
64 // OnSessionCreated() should only be called once, and the second check can be
65 // removed.
66 blink::WebString id = blink::WebString::fromUTF8(web_session_id);
67 DCHECK(web_session_id_.isEmpty() || web_session_id_ == id)
68 << "Session ID may not be changed once set.";
69 web_session_id_ = id;
70 } 88 }
71 89
72 void WebContentDecryptionModuleSessionImpl::OnSessionMessage( 90 void WebContentDecryptionModuleSessionImpl::OnSessionMessage(
73 const std::vector<uint8>& message, 91 const std::vector<uint8>& message,
74 const std::string& destination_url) { 92 const std::string& destination_url) {
75 client_->message(message.empty() ? NULL : &message[0], 93 client_->message(message.empty() ? NULL : &message[0],
76 message.size(), 94 message.size(),
77 GURL(destination_url)); 95 GURL(destination_url));
78 } 96 }
79 97
80 void WebContentDecryptionModuleSessionImpl::OnSessionReady() { 98 void WebContentDecryptionModuleSessionImpl::OnSessionReady() {
81 client_->ready(); 99 client_->ready();
82 } 100 }
83 101
84 void WebContentDecryptionModuleSessionImpl::OnSessionClosed() { 102 void WebContentDecryptionModuleSessionImpl::OnSessionClosed() {
85 client_->close(); 103 client_->close();
86 } 104 }
87 105
88 void WebContentDecryptionModuleSessionImpl::OnSessionError( 106 void WebContentDecryptionModuleSessionImpl::OnSessionError(
89 media::MediaKeys::KeyError error_code, 107 const std::string& error_name,
90 uint32 system_code) { 108 uint32 system_code,
91 client_->error(static_cast<Client::MediaKeyErrorCode>(error_code), 109 const std::string& error_message) {
92 system_code); 110 // Convert |error_name| back to MediaKeyErrorCode if possible.
111 // TODO(jrummell): Remove this conversion when promises flow
112 // back into blink:: (as the code there will handle the names).
ddorwin 2014/05/05 18:35:42 Not if it is "CDM4ClientError"
jrummell 2014/05/08 23:37:45 True. Changes with exception_code.
113 if (error_name == "CDM4ClientError") {
ddorwin 2014/05/05 18:35:42 What about output error?
jrummell 2014/05/08 23:37:45 Client doesn't have a output error. Only unknown a
114 client_->error(Client::MediaKeyErrorCode::MediaKeyErrorCodeClient,
115 system_code);
116 } else {
117 // This will include all other CDM4 errors and any error generated
118 // by CDM5 or later.
119 client_->error(Client::MediaKeyErrorCode::MediaKeyErrorCodeUnknown,
120 system_code);
121 }
122 }
123
124 void WebContentDecryptionModuleSessionImpl::setSessionId(
125 const std::string& web_session_id) {
126 DCHECK(web_session_id_.empty()) << "Session ID may not be changed once set.";
127 web_session_id_ = web_session_id;
128 adapter_->RegisterSession(web_session_id_, weak_ptr_factory_.GetWeakPtr());
93 } 129 }
94 130
95 } // namespace content 131 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698