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

Side by Side Diff: content/browser/renderer_host/media/video_capture_manager.cc

Issue 248113003: Fix for closing the desktop sharing notification bar when the shared window is closed (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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/renderer_host/media/video_capture_manager.h" 5 #include "content/browser/renderer_host/media/video_capture_manager.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 base::Bind(&VideoCaptureManager::OnOpened, this, 151 base::Bind(&VideoCaptureManager::OnOpened, this,
152 device_info.device.type, capture_session_id)); 152 device_info.device.type, capture_session_id));
153 return capture_session_id; 153 return capture_session_id;
154 } 154 }
155 155
156 void VideoCaptureManager::Close(int capture_session_id) { 156 void VideoCaptureManager::Close(int capture_session_id) {
157 DCHECK_CURRENTLY_ON(BrowserThread::IO); 157 DCHECK_CURRENTLY_ON(BrowserThread::IO);
158 DCHECK(listener_); 158 DCHECK(listener_);
159 DVLOG(1) << "VideoCaptureManager::Close, id " << capture_session_id; 159 DVLOG(1) << "VideoCaptureManager::Close, id " << capture_session_id;
160 160
161 std::map<media::VideoCaptureSessionId, MediaStreamDevice>::iterator 161 SessionMap::iterator session_it = sessions_.find(capture_session_id);
162 session_it = sessions_.find(capture_session_id);
163 if (session_it == sessions_.end()) { 162 if (session_it == sessions_.end()) {
164 NOTREACHED(); 163 NOTREACHED();
165 return; 164 return;
166 } 165 }
167 166
168 DeviceEntry* const existing_device = GetDeviceEntryForMediaStreamDevice( 167 DeviceEntry* const existing_device = GetDeviceEntryForMediaStreamDevice(
169 session_it->second); 168 session_it->second);
170 if (existing_device) { 169 if (existing_device) {
171 // Remove any client that is still using the session. This is safe to call 170 // Remove any client that is still using the session. This is safe to call
172 // even if there are no clients using the session. 171 // even if there are no clients using the session.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 } 281 }
283 // Run the callback first, as AddClient() may trigger OnFrameInfo(). 282 // Run the callback first, as AddClient() may trigger OnFrameInfo().
284 done_cb.Run(entry->video_capture_controller->GetWeakPtr()); 283 done_cb.Run(entry->video_capture_controller->GetWeakPtr());
285 entry->video_capture_controller->AddClient( 284 entry->video_capture_controller->AddClient(
286 client_id, client_handler, client_render_process, session_id, params); 285 client_id, client_handler, client_render_process, session_id, params);
287 } 286 }
288 287
289 void VideoCaptureManager::StopCaptureForClient( 288 void VideoCaptureManager::StopCaptureForClient(
290 VideoCaptureController* controller, 289 VideoCaptureController* controller,
291 VideoCaptureControllerID client_id, 290 VideoCaptureControllerID client_id,
292 VideoCaptureControllerEventHandler* client_handler) { 291 VideoCaptureControllerEventHandler* client_handler,
292 bool aborted_due_to_error) {
293 DCHECK_CURRENTLY_ON(BrowserThread::IO); 293 DCHECK_CURRENTLY_ON(BrowserThread::IO);
294 DCHECK(controller); 294 DCHECK(controller);
295 DCHECK(client_handler); 295 DCHECK(client_handler);
296 296
297 DeviceEntry* entry = GetDeviceEntryForController(controller); 297 DeviceEntry* entry = GetDeviceEntryForController(controller);
298 if (!entry) { 298 if (!entry) {
299 NOTREACHED(); 299 NOTREACHED();
300 return; 300 return;
301 } 301 }
302 if (aborted_due_to_error) {
303 SessionMap::iterator it;
304 for (it = sessions_.begin(); it != sessions_.end(); ++it) {
305 if (it->second.type == entry->stream_type &&
306 it->second.id == entry->id) {
307 listener_->Aborted(it->second.type, it->first);
308 break;
309 }
310 }
311 }
302 312
303 // Detach client from controller. 313 // Detach client from controller.
304 media::VideoCaptureSessionId session_id = 314 media::VideoCaptureSessionId session_id =
305 controller->RemoveClient(client_id, client_handler); 315 controller->RemoveClient(client_id, client_handler);
306 DVLOG(1) << "VideoCaptureManager::StopCaptureForClient, session_id = " 316 DVLOG(1) << "VideoCaptureManager::StopCaptureForClient, session_id = "
307 << session_id; 317 << session_id;
308 318
309 // If controller has no more clients, delete controller and device. 319 // If controller has no more clients, delete controller and device.
310 DestroyDeviceEntryIfNoClients(entry); 320 DestroyDeviceEntryIfNoClients(entry);
311 } 321 }
312 322
313 bool VideoCaptureManager::GetDeviceSupportedFormats( 323 bool VideoCaptureManager::GetDeviceSupportedFormats(
314 media::VideoCaptureSessionId capture_session_id, 324 media::VideoCaptureSessionId capture_session_id,
315 media::VideoCaptureFormats* supported_formats) { 325 media::VideoCaptureFormats* supported_formats) {
316 DCHECK_CURRENTLY_ON(BrowserThread::IO); 326 DCHECK_CURRENTLY_ON(BrowserThread::IO);
317 DCHECK(supported_formats->empty()); 327 DCHECK(supported_formats->empty());
318 328
319 std::map<media::VideoCaptureSessionId, MediaStreamDevice>::iterator it = 329 SessionMap::iterator it = sessions_.find(capture_session_id);
320 sessions_.find(capture_session_id);
321 if (it == sessions_.end()) 330 if (it == sessions_.end())
322 return false; 331 return false;
323 DVLOG(1) << "GetDeviceSupportedFormats for device: " << it->second.name; 332 DVLOG(1) << "GetDeviceSupportedFormats for device: " << it->second.name;
324 333
325 // Return all available formats of the device, regardless its started state. 334 // Return all available formats of the device, regardless its started state.
326 DeviceInfo* existing_device = 335 DeviceInfo* existing_device =
327 FindDeviceInfoById(it->second.id, devices_info_cache_); 336 FindDeviceInfoById(it->second.id, devices_info_cache_);
328 if (existing_device) 337 if (existing_device)
329 *supported_formats = existing_device->supported_formats; 338 *supported_formats = existing_device->supported_formats;
330 return true; 339 return true;
331 } 340 }
332 341
333 bool VideoCaptureManager::GetDeviceFormatsInUse( 342 bool VideoCaptureManager::GetDeviceFormatsInUse(
334 media::VideoCaptureSessionId capture_session_id, 343 media::VideoCaptureSessionId capture_session_id,
335 media::VideoCaptureFormats* formats_in_use) { 344 media::VideoCaptureFormats* formats_in_use) {
336 DCHECK_CURRENTLY_ON(BrowserThread::IO); 345 DCHECK_CURRENTLY_ON(BrowserThread::IO);
337 DCHECK(formats_in_use->empty()); 346 DCHECK(formats_in_use->empty());
338 347
339 std::map<media::VideoCaptureSessionId, MediaStreamDevice>::iterator it = 348 SessionMap::iterator it = sessions_.find(capture_session_id);
340 sessions_.find(capture_session_id);
341 if (it == sessions_.end()) 349 if (it == sessions_.end())
342 return false; 350 return false;
343 DVLOG(1) << "GetDeviceFormatsInUse for device: " << it->second.name; 351 DVLOG(1) << "GetDeviceFormatsInUse for device: " << it->second.name;
344 352
345 // Return the currently in-use format(s) of the device, if it's started. 353 // Return the currently in-use format(s) of the device, if it's started.
346 DeviceEntry* device_in_use = 354 DeviceEntry* device_in_use =
347 GetDeviceEntryForMediaStreamDevice(it->second); 355 GetDeviceEntryForMediaStreamDevice(it->second);
348 if (device_in_use) { 356 if (device_in_use) {
349 // Currently only one format-in-use is supported at the VCC level. 357 // Currently only one format-in-use is supported at the VCC level.
350 formats_in_use->push_back( 358 formats_in_use->push_back(
351 device_in_use->video_capture_controller->GetVideoCaptureFormat()); 359 device_in_use->video_capture_controller->GetVideoCaptureFormat());
352 } 360 }
353 return true; 361 return true;
354 } 362 }
355 363
356 void VideoCaptureManager::SetDesktopCaptureWindowId( 364 void VideoCaptureManager::SetDesktopCaptureWindowId(
357 media::VideoCaptureSessionId session_id, 365 media::VideoCaptureSessionId session_id,
358 gfx::NativeViewId window_id) { 366 gfx::NativeViewId window_id) {
359 DCHECK_CURRENTLY_ON(BrowserThread::IO); 367 DCHECK_CURRENTLY_ON(BrowserThread::IO);
360 std::map<media::VideoCaptureSessionId, MediaStreamDevice>::iterator 368 SessionMap::iterator session_it = sessions_.find(session_id);
361 session_it = sessions_.find(session_id);
362 if (session_it == sessions_.end()) { 369 if (session_it == sessions_.end()) {
363 device_task_runner_->PostTask( 370 device_task_runner_->PostTask(
364 FROM_HERE, 371 FROM_HERE,
365 base::Bind( 372 base::Bind(
366 &VideoCaptureManager::SaveDesktopCaptureWindowIdOnDeviceThread, 373 &VideoCaptureManager::SaveDesktopCaptureWindowIdOnDeviceThread,
367 this, 374 this,
368 session_id, 375 session_id,
369 window_id)); 376 window_id));
370 return; 377 return;
371 } 378 }
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 if (device_info.type == device->stream_type && 520 if (device_info.type == device->stream_type &&
514 device_info.id == device->id) { 521 device_info.id == device->id) {
515 return device; 522 return device;
516 } 523 }
517 } 524 }
518 return NULL; 525 return NULL;
519 } 526 }
520 527
521 VideoCaptureManager::DeviceEntry* 528 VideoCaptureManager::DeviceEntry*
522 VideoCaptureManager::GetDeviceEntryForController( 529 VideoCaptureManager::GetDeviceEntryForController(
523 const VideoCaptureController* controller) { 530 const VideoCaptureController* controller) const {
524 // Look up |controller| in |devices_|. 531 // Look up |controller| in |devices_|.
525 for (DeviceEntries::iterator it = devices_.begin(); 532 for (DeviceEntries::const_iterator it = devices_.begin();
526 it != devices_.end(); ++it) { 533 it != devices_.end(); ++it) {
527 if ((*it)->video_capture_controller.get() == controller) { 534 if ((*it)->video_capture_controller.get() == controller) {
528 return *it; 535 return *it;
529 } 536 }
530 } 537 }
531 return NULL; 538 return NULL;
532 } 539 }
533 540
534 void VideoCaptureManager::DestroyDeviceEntryIfNoClients(DeviceEntry* entry) { 541 void VideoCaptureManager::DestroyDeviceEntryIfNoClients(DeviceEntry* entry) {
535 DCHECK_CURRENTLY_ON(BrowserThread::IO); 542 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 12 matching lines...) Expand all
548 FROM_HERE, 555 FROM_HERE,
549 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this, 556 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this,
550 base::Owned(entry))); 557 base::Owned(entry)));
551 } 558 }
552 } 559 }
553 560
554 VideoCaptureManager::DeviceEntry* VideoCaptureManager::GetOrCreateDeviceEntry( 561 VideoCaptureManager::DeviceEntry* VideoCaptureManager::GetOrCreateDeviceEntry(
555 media::VideoCaptureSessionId capture_session_id) { 562 media::VideoCaptureSessionId capture_session_id) {
556 DCHECK_CURRENTLY_ON(BrowserThread::IO); 563 DCHECK_CURRENTLY_ON(BrowserThread::IO);
557 564
558 std::map<media::VideoCaptureSessionId, MediaStreamDevice>::iterator 565 SessionMap::iterator session_it = sessions_.find(capture_session_id);
559 session_it = sessions_.find(capture_session_id);
560 if (session_it == sessions_.end()) { 566 if (session_it == sessions_.end()) {
561 return NULL; 567 return NULL;
562 } 568 }
563 const MediaStreamDevice& device_info = session_it->second; 569 const MediaStreamDevice& device_info = session_it->second;
564 570
565 // Check if another session has already opened this device. If so, just 571 // Check if another session has already opened this device. If so, just
566 // use that opened device. 572 // use that opened device.
567 DeviceEntry* const existing_device = 573 DeviceEntry* const existing_device =
568 GetDeviceEntryForMediaStreamDevice(device_info); 574 GetDeviceEntryForMediaStreamDevice(device_info);
569 if (existing_device) { 575 if (existing_device) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 void VideoCaptureManager::SaveDesktopCaptureWindowIdOnDeviceThread( 612 void VideoCaptureManager::SaveDesktopCaptureWindowIdOnDeviceThread(
607 media::VideoCaptureSessionId session_id, 613 media::VideoCaptureSessionId session_id,
608 gfx::NativeViewId window_id) { 614 gfx::NativeViewId window_id) {
609 DCHECK(IsOnDeviceThread()); 615 DCHECK(IsOnDeviceThread());
610 DCHECK(notification_window_ids_.find(session_id) == 616 DCHECK(notification_window_ids_.find(session_id) ==
611 notification_window_ids_.end()); 617 notification_window_ids_.end());
612 notification_window_ids_[session_id] = window_id; 618 notification_window_ids_[session_id] = window_id;
613 } 619 }
614 620
615 } // namespace content 621 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698