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

Side by Side Diff: media/mojo/clients/mojo_cdm.cc

Issue 2561263002: [eme] Reject CDM calls after connection error (Closed)
Patch Set: Created 4 years 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "media/mojo/clients/mojo_cdm.h" 5 #include "media/mojo/clients/mojo_cdm.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 // If connection error has happened, fail immediately. 106 // If connection error has happened, fail immediately.
107 if (remote_cdm_.encountered_error()) { 107 if (remote_cdm_.encountered_error()) {
108 LOG(ERROR) << "Remote CDM encountered error."; 108 LOG(ERROR) << "Remote CDM encountered error.";
109 promise->reject(CdmPromise::NOT_SUPPORTED_ERROR, 0, 109 promise->reject(CdmPromise::NOT_SUPPORTED_ERROR, 0,
110 "Mojo CDM creation failed."); 110 "Mojo CDM creation failed.");
111 return; 111 return;
112 } 112 }
113 113
114 // Otherwise, set an error handler to catch the connection error. 114 // Otherwise, set an error handler to catch the connection error.
115 DCHECK(remote_cdm_.is_bound());
115 remote_cdm_.set_connection_error_with_reason_handler( 116 remote_cdm_.set_connection_error_with_reason_handler(
116 base::Bind(&MojoCdm::OnConnectionError, base::Unretained(this))); 117 base::Bind(&MojoCdm::OnConnectionError, base::Unretained(this)));
117 118
118 pending_init_promise_ = std::move(promise); 119 pending_init_promise_ = std::move(promise);
119 120
120 remote_cdm_->Initialize( 121 remote_cdm_->Initialize(
121 key_system, security_origin.spec(), mojom::CdmConfig::From(cdm_config), 122 key_system, security_origin.spec(), mojom::CdmConfig::From(cdm_config),
122 base::Bind(&MojoCdm::OnCdmInitialized, base::Unretained(this))); 123 base::Bind(&MojoCdm::OnCdmInitialized, base::Unretained(this)));
123 } 124 }
124 125
125 // TODO(xhwang): Properly handle CDM calls after connection error.
126 // See http://crbug.com/671362
127 void MojoCdm::OnConnectionError(uint32_t custom_reason, 126 void MojoCdm::OnConnectionError(uint32_t custom_reason,
128 const std::string& description) { 127 const std::string& description) {
129 LOG(ERROR) << "Remote CDM connection error: custom_reason=" << custom_reason 128 LOG(ERROR) << "Remote CDM connection error: custom_reason=" << custom_reason
130 << ", description=\"" << description << "\""; 129 << ", description=\"" << description << "\"";
131 DCHECK(thread_checker_.CalledOnValidThread()); 130 DCHECK(thread_checker_.CalledOnValidThread());
132 131
132 remote_cdm_.reset();
133 DCHECK(!remote_cdm_.is_bound());
134
133 // Handle initial connection error. 135 // Handle initial connection error.
134 if (pending_init_promise_) { 136 if (pending_init_promise_) {
135 DCHECK(!cdm_session_tracker_.HasRemainingSessions()); 137 DCHECK(!cdm_session_tracker_.HasRemainingSessions());
136 pending_init_promise_->reject(CdmPromise::NOT_SUPPORTED_ERROR, 0, 138 pending_init_promise_->reject(CdmPromise::NOT_SUPPORTED_ERROR, 0,
137 "Mojo CDM creation failed."); 139 "Mojo CDM creation failed.");
138 // Dropping the promise could cause |this| to be destructed. 140 // Dropping the promise could cause |this| to be destructed.
139 pending_init_promise_.reset(); 141 pending_init_promise_.reset();
140 return; 142 return;
141 } 143 }
142 144
143 cdm_session_tracker_.CloseRemainingSessions(session_closed_cb_); 145 cdm_session_tracker_.CloseRemainingSessions(session_closed_cb_);
144 } 146 }
145 147
146 void MojoCdm::SetServerCertificate(const std::vector<uint8_t>& certificate, 148 void MojoCdm::SetServerCertificate(const std::vector<uint8_t>& certificate,
147 std::unique_ptr<SimpleCdmPromise> promise) { 149 std::unique_ptr<SimpleCdmPromise> promise) {
148 DVLOG(2) << __func__; 150 DVLOG(2) << __func__;
149 DCHECK(thread_checker_.CalledOnValidThread()); 151 DCHECK(thread_checker_.CalledOnValidThread());
150 152
153 if (!remote_cdm_.is_bound()) {
xhwang 2016/12/09 06:13:30 will this work? if (!remote_cdm_) { ... }
jrummell 2016/12/13 20:57:34 Done.
154 promise->reject(media::CdmPromise::INVALID_STATE_ERROR, 0,
155 "CDM has failed.");
xhwang 2016/12/09 06:13:30 This message will be received by JS app, so it'd b
jrummell 2016/12/13 20:57:34 Done.
156 return;
157 }
158
151 remote_cdm_->SetServerCertificate( 159 remote_cdm_->SetServerCertificate(
152 certificate, base::Bind(&MojoCdm::OnSimpleCdmPromiseResult, 160 certificate, base::Bind(&MojoCdm::OnSimpleCdmPromiseResult,
153 base::Unretained(this), base::Passed(&promise))); 161 base::Unretained(this), base::Passed(&promise)));
154 } 162 }
155 163
156 void MojoCdm::CreateSessionAndGenerateRequest( 164 void MojoCdm::CreateSessionAndGenerateRequest(
157 SessionType session_type, 165 SessionType session_type,
158 EmeInitDataType init_data_type, 166 EmeInitDataType init_data_type,
159 const std::vector<uint8_t>& init_data, 167 const std::vector<uint8_t>& init_data,
160 std::unique_ptr<NewSessionCdmPromise> promise) { 168 std::unique_ptr<NewSessionCdmPromise> promise) {
161 DVLOG(2) << __func__; 169 DVLOG(2) << __func__;
162 DCHECK(thread_checker_.CalledOnValidThread()); 170 DCHECK(thread_checker_.CalledOnValidThread());
163 171
172 if (!remote_cdm_.is_bound()) {
173 promise->reject(media::CdmPromise::INVALID_STATE_ERROR, 0,
174 "CDM has failed.");
175 return;
176 }
177
164 remote_cdm_->CreateSessionAndGenerateRequest( 178 remote_cdm_->CreateSessionAndGenerateRequest(
165 session_type, init_data_type, init_data, 179 session_type, init_data_type, init_data,
166 base::Bind(&MojoCdm::OnNewSessionCdmPromiseResult, base::Unretained(this), 180 base::Bind(&MojoCdm::OnNewSessionCdmPromiseResult, base::Unretained(this),
167 base::Passed(&promise))); 181 base::Passed(&promise)));
168 } 182 }
169 183
170 void MojoCdm::LoadSession(SessionType session_type, 184 void MojoCdm::LoadSession(SessionType session_type,
171 const std::string& session_id, 185 const std::string& session_id,
172 std::unique_ptr<NewSessionCdmPromise> promise) { 186 std::unique_ptr<NewSessionCdmPromise> promise) {
173 DVLOG(2) << __func__; 187 DVLOG(2) << __func__;
174 DCHECK(thread_checker_.CalledOnValidThread()); 188 DCHECK(thread_checker_.CalledOnValidThread());
175 189
190 if (!remote_cdm_.is_bound()) {
191 promise->reject(media::CdmPromise::INVALID_STATE_ERROR, 0,
192 "CDM has failed.");
193 return;
194 }
195
176 remote_cdm_->LoadSession( 196 remote_cdm_->LoadSession(
177 session_type, session_id, 197 session_type, session_id,
178 base::Bind(&MojoCdm::OnNewSessionCdmPromiseResult, base::Unretained(this), 198 base::Bind(&MojoCdm::OnNewSessionCdmPromiseResult, base::Unretained(this),
179 base::Passed(&promise))); 199 base::Passed(&promise)));
180 } 200 }
181 201
182 void MojoCdm::UpdateSession(const std::string& session_id, 202 void MojoCdm::UpdateSession(const std::string& session_id,
183 const std::vector<uint8_t>& response, 203 const std::vector<uint8_t>& response,
184 std::unique_ptr<SimpleCdmPromise> promise) { 204 std::unique_ptr<SimpleCdmPromise> promise) {
185 DVLOG(2) << __func__; 205 DVLOG(2) << __func__;
186 DCHECK(thread_checker_.CalledOnValidThread()); 206 DCHECK(thread_checker_.CalledOnValidThread());
187 207
208 if (!remote_cdm_.is_bound()) {
209 promise->reject(media::CdmPromise::INVALID_STATE_ERROR, 0,
210 "CDM has failed.");
211 return;
212 }
213
188 remote_cdm_->UpdateSession( 214 remote_cdm_->UpdateSession(
189 session_id, response, 215 session_id, response,
190 base::Bind(&MojoCdm::OnSimpleCdmPromiseResult, base::Unretained(this), 216 base::Bind(&MojoCdm::OnSimpleCdmPromiseResult, base::Unretained(this),
191 base::Passed(&promise))); 217 base::Passed(&promise)));
192 } 218 }
193 219
194 void MojoCdm::CloseSession(const std::string& session_id, 220 void MojoCdm::CloseSession(const std::string& session_id,
195 std::unique_ptr<SimpleCdmPromise> promise) { 221 std::unique_ptr<SimpleCdmPromise> promise) {
196 DVLOG(2) << __func__; 222 DVLOG(2) << __func__;
197 DCHECK(thread_checker_.CalledOnValidThread()); 223 DCHECK(thread_checker_.CalledOnValidThread());
198 224
225 if (!remote_cdm_.is_bound()) {
226 promise->reject(media::CdmPromise::INVALID_STATE_ERROR, 0,
227 "CDM has failed.");
228 return;
229 }
230
199 remote_cdm_->CloseSession( 231 remote_cdm_->CloseSession(
200 session_id, base::Bind(&MojoCdm::OnSimpleCdmPromiseResult, 232 session_id, base::Bind(&MojoCdm::OnSimpleCdmPromiseResult,
201 base::Unretained(this), base::Passed(&promise))); 233 base::Unretained(this), base::Passed(&promise)));
202 } 234 }
203 235
204 void MojoCdm::RemoveSession(const std::string& session_id, 236 void MojoCdm::RemoveSession(const std::string& session_id,
205 std::unique_ptr<SimpleCdmPromise> promise) { 237 std::unique_ptr<SimpleCdmPromise> promise) {
206 DVLOG(2) << __func__; 238 DVLOG(2) << __func__;
207 DCHECK(thread_checker_.CalledOnValidThread()); 239 DCHECK(thread_checker_.CalledOnValidThread());
208 240
241 if (!remote_cdm_.is_bound()) {
242 promise->reject(media::CdmPromise::INVALID_STATE_ERROR, 0,
243 "CDM has failed.");
244 return;
245 }
246
209 remote_cdm_->RemoveSession( 247 remote_cdm_->RemoveSession(
210 session_id, base::Bind(&MojoCdm::OnSimpleCdmPromiseResult, 248 session_id, base::Bind(&MojoCdm::OnSimpleCdmPromiseResult,
211 base::Unretained(this), base::Passed(&promise))); 249 base::Unretained(this), base::Passed(&promise)));
212 } 250 }
213 251
214 CdmContext* MojoCdm::GetCdmContext() { 252 CdmContext* MojoCdm::GetCdmContext() {
215 DVLOG(2) << __func__; 253 DVLOG(2) << __func__;
216 return this; 254 return this;
217 } 255 }
218 256
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 mojom::CdmPromiseResultPtr result, 382 mojom::CdmPromiseResultPtr result,
345 const std::string& session_id) { 383 const std::string& session_id) {
346 if (result->success) { 384 if (result->success) {
347 cdm_session_tracker_.AddSession(session_id); 385 cdm_session_tracker_.AddSession(session_id);
348 promise->resolve(session_id); 386 promise->resolve(session_id);
349 } else 387 } else
350 RejectPromise(std::move(promise), std::move(result)); 388 RejectPromise(std::move(promise), std::move(result));
351 } 389 }
352 390
353 } // namespace media 391 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698