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

Side by Side Diff: content/browser/media/cdm/browser_cdm_manager.cc

Issue 730453004: BrowserCdmManager: gets RenderFrameHost instance on the correct thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 unified diff | Download patch
« no previous file with comments | « content/browser/media/cdm/browser_cdm_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/browser/media/cdm/browser_cdm_manager.h" 5 #include "content/browser/media/cdm/browser_cdm_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/task_runner.h" 10 #include "base/task_runner.h"
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 case CREATE_SESSION_TYPE_MP4: 218 case CREATE_SESSION_TYPE_MP4:
219 mime_type = "video/mp4"; 219 mime_type = "video/mp4";
220 break; 220 break;
221 default: 221 default:
222 NOTREACHED(); 222 NOTREACHED();
223 return; 223 return;
224 } 224 }
225 225
226 #if defined(OS_ANDROID) 226 #if defined(OS_ANDROID)
227 if (CommandLine::ForCurrentProcess() 227 if (CommandLine::ForCurrentProcess()
228 ->HasSwitch(switches::kDisableInfobarForProtectedMediaIdentifier)) { 228 ->HasSwitch(switches::kDisableInfobarForProtectedMediaIdentifier)) {
gunsch 2014/11/17 16:57:33 somewhat related: is there any particular reason t
xhwang 2014/11/17 23:38:17 I guess it's because this flag is only defined on
229 CreateSessionIfPermitted( 229 CreateSessionIfPermitted(
230 render_frame_id, cdm_id, session_id, mime_type, init_data, true); 230 render_frame_id, cdm_id, session_id, mime_type, init_data, true);
231 return; 231 return;
232 } 232 }
233 #endif 233 #endif
234 234
235 BrowserCdm* cdm = GetCdm(render_frame_id, cdm_id); 235 BrowserCdm* cdm = GetCdm(render_frame_id, cdm_id);
236 if (!cdm) { 236 if (!cdm) {
237 DLOG(WARNING) << "No CDM found for: " << render_frame_id << ", " << cdm_id; 237 DLOG(WARNING) << "No CDM found for: " << render_frame_id << ", " << cdm_id;
238 SendSessionError(render_frame_id, cdm_id, session_id); 238 SendSessionError(render_frame_id, cdm_id, session_id);
239 return; 239 return;
240 } 240 }
241 241
242 std::map<uint64, GURL>::const_iterator iter = 242 std::map<uint64, GURL>::const_iterator iter =
243 cdm_security_origin_map_.find(GetId(render_frame_id, cdm_id)); 243 cdm_security_origin_map_.find(GetId(render_frame_id, cdm_id));
244 if (iter == cdm_security_origin_map_.end()) { 244 if (iter == cdm_security_origin_map_.end()) {
245 NOTREACHED(); 245 NOTREACHED();
246 SendSessionError(render_frame_id, cdm_id, session_id); 246 SendSessionError(render_frame_id, cdm_id, session_id);
247 return; 247 return;
248 } 248 }
249 GURL security_origin = iter->second; 249 GURL security_origin = iter->second;
250 250
251 RenderFrameHost* rfh = 251 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
252 RenderFrameHost::FromID(render_process_id_, render_frame_id); 252 BrowserThread::PostTask(
253 WebContents* web_contents = WebContents::FromRenderFrameHost(rfh); 253 BrowserThread::UI,
254 DCHECK(web_contents); 254 FROM_HERE,
255 GetContentClient()->browser()->RequestPermission( 255 base::Bind(&BrowserCdmManager::RequestSessionPermission,
256 content::PERMISSION_PROTECTED_MEDIA, 256 this,
257 web_contents, 257 render_frame_id,
258 0, // bridge id 258 security_origin,
259 security_origin, 259 cdm_id,
260 // Only implemented for Android infobars which do not support 260 session_id,
261 // user gestures. 261 mime_type,
262 true, 262 init_data));
263 base::Bind(&BrowserCdmManager::CreateSessionIfPermitted, 263 return;
264 this, 264 }
265 render_frame_id, 265 RequestSessionPermission(render_frame_id,
266 cdm_id, 266 security_origin,
267 session_id, 267 cdm_id,
268 mime_type, 268 session_id,
269 init_data)); 269 mime_type,
270 init_data);
xhwang 2014/11/17 23:38:17 Can you do the thread check and post within Reques
gunsch 2014/11/19 21:59:01 Done.
270 } 271 }
271 272
272 void BrowserCdmManager::OnUpdateSession( 273 void BrowserCdmManager::OnUpdateSession(
273 int render_frame_id, 274 int render_frame_id,
274 int cdm_id, 275 int cdm_id,
275 uint32 session_id, 276 uint32 session_id,
276 const std::vector<uint8>& response) { 277 const std::vector<uint8>& response) {
277 BrowserCdm* cdm = GetCdm(render_frame_id, cdm_id); 278 BrowserCdm* cdm = GetCdm(render_frame_id, cdm_id);
278 if (!cdm) { 279 if (!cdm) {
279 DLOG(WARNING) << "No CDM found for: " << render_frame_id << ", " << cdm_id; 280 DLOG(WARNING) << "No CDM found for: " << render_frame_id << ", " << cdm_id;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 350 DCHECK(task_runner_->RunsTasksOnCurrentThread());
350 351
351 cdm_map_.erase(id); 352 cdm_map_.erase(id);
352 cdm_security_origin_map_.erase(id); 353 cdm_security_origin_map_.erase(id);
353 if (cdm_cancel_permission_map_.count(id)) { 354 if (cdm_cancel_permission_map_.count(id)) {
354 cdm_cancel_permission_map_[id].Run(); 355 cdm_cancel_permission_map_[id].Run();
355 cdm_cancel_permission_map_.erase(id); 356 cdm_cancel_permission_map_.erase(id);
356 } 357 }
357 } 358 }
358 359
360 void BrowserCdmManager::RequestSessionPermission(
361 int render_frame_id,
362 const GURL& security_origin,
363 int cdm_id,
364 uint32 session_id,
365 const std::string& content_type,
366 const std::vector<uint8>& init_data) {
367 DCHECK_CURRENTLY_ON(BrowserThread::UI);
xhwang 2014/11/17 23:38:17 See comment above. Check thread and post RequestSe
gunsch 2014/11/19 21:59:01 Done.
368 RenderFrameHost* rfh =
369 RenderFrameHost::FromID(render_process_id_, render_frame_id);
370 WebContents* web_contents = WebContents::FromRenderFrameHost(rfh);
371 DCHECK(web_contents);
372 GetContentClient()->browser()->RequestPermission(
373 content::PERMISSION_PROTECTED_MEDIA,
374 web_contents,
375 0, // bridge id
376 security_origin,
377 // Only implemented for Android infobars which do not support
378 // user gestures.
379 true,
380 base::Bind(&BrowserCdmManager::CreateSessionIfPermitted,
381 this,
382 render_frame_id,
383 cdm_id,
384 session_id,
385 content_type,
386 init_data));
387 }
388
359 void BrowserCdmManager::CreateSessionIfPermitted( 389 void BrowserCdmManager::CreateSessionIfPermitted(
360 int render_frame_id, 390 int render_frame_id,
361 int cdm_id, 391 int cdm_id,
362 uint32 session_id, 392 uint32 session_id,
363 const std::string& content_type, 393 const std::string& content_type,
364 const std::vector<uint8>& init_data, 394 const std::vector<uint8>& init_data,
365 bool permitted) { 395 bool permitted) {
366 cdm_cancel_permission_map_.erase(GetId(render_frame_id, cdm_id)); 396 cdm_cancel_permission_map_.erase(GetId(render_frame_id, cdm_id));
367 if (!permitted) { 397 if (!permitted) {
368 SendSessionError(render_frame_id, cdm_id, session_id); 398 SendSessionError(render_frame_id, cdm_id, session_id);
369 return; 399 return;
370 } 400 }
371 401
372 BrowserCdm* cdm = GetCdm(render_frame_id, cdm_id); 402 BrowserCdm* cdm = GetCdm(render_frame_id, cdm_id);
373 if (!cdm) { 403 if (!cdm) {
374 DLOG(WARNING) << "No CDM found for: " << render_frame_id << ", " << cdm_id; 404 DLOG(WARNING) << "No CDM found for: " << render_frame_id << ", " << cdm_id;
375 SendSessionError(render_frame_id, cdm_id, session_id); 405 SendSessionError(render_frame_id, cdm_id, session_id);
376 return; 406 return;
377 } 407 }
378 408
379 // This could fail, in which case a SessionError will be fired. 409 // This could fail, in which case a SessionError will be fired.
380 cdm->CreateSession(session_id, content_type, &init_data[0], init_data.size()); 410 cdm->CreateSession(session_id, content_type, &init_data[0], init_data.size());
381 } 411 }
382 412
383 } // namespace content 413 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/cdm/browser_cdm_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698