Chromium Code Reviews| Index: content/browser/renderer_host/media/video_capture_manager.cc |
| diff --git a/content/browser/renderer_host/media/video_capture_manager.cc b/content/browser/renderer_host/media/video_capture_manager.cc |
| index e65eb9d2c12c78c5e4603454fbd5f10478c3e070..9a42170cda28f704df49e861f9a14e1accb2be63 100644 |
| --- a/content/browser/renderer_host/media/video_capture_manager.cc |
| +++ b/content/browser/renderer_host/media/video_capture_manager.cc |
| @@ -47,14 +47,11 @@ VideoCaptureManager::VideoCaptureManager() |
| } |
| VideoCaptureManager::~VideoCaptureManager() { |
| - // TODO(mflodman) Remove this temporary solution when shut-down issue is |
| - // resolved, i.e. all code below this comment. |
| - // Temporary solution: close all open devices and delete them, after the |
| - // thread is stopped. |
| - DLOG_IF(ERROR, !devices_.empty()) << "VideoCaptureManager: Open devices!"; |
| + DCHECK(devices_.empty()); |
| + |
| + // TODO(mflodman) Remove this temporary solution when all controllers are |
| + // guaranteed to be deleted before the destructor is called. |
| listener_ = NULL; |
| - // The devices must be stopped on the device thread to avoid threading issues |
| - // in native device code. |
| vc_device_thread_.message_loop()->PostTask( |
|
mflodman_chromium_OOO
2012/02/10 13:24:41
There is a case when |controllers_| won't be empty
|
| FROM_HERE, |
| base::Bind(&VideoCaptureManager::TerminateOnDeviceThread, |
| @@ -199,17 +196,18 @@ void VideoCaptureManager::OnClose(int capture_session_id) { |
| DCHECK(IsOnCaptureDeviceThread()); |
| media::VideoCaptureDevice* video_capture_device = NULL; |
| - VideoCaptureDevices::iterator it = devices_.find(capture_session_id); |
| - if (it != devices_.end()) { |
| - video_capture_device = it->second; |
| - devices_.erase(it); |
| - } |
| - if (video_capture_device && !DeviceInUse(video_capture_device)) { |
| - // Deallocate (if not done already) and delete the device. |
| - video_capture_device->DeAllocate(); |
| - delete video_capture_device; |
| + VideoCaptureDevices::iterator device_it = devices_.find(capture_session_id); |
| + if (device_it != devices_.end()) { |
| + video_capture_device = device_it->second; |
| + devices_.erase(device_it); |
| + if (!DeviceInUse(video_capture_device)) { |
| + // No other users of this device, deallocate (if not done already) and |
| + // delete the device. No need to take care of the controller, that is done |
| + // by |OnStop|. |
| + video_capture_device->DeAllocate(); |
| + delete video_capture_device; |
| + } |
| } |
| - |
| PostOnClosed(capture_session_id); |
| } |
| @@ -506,14 +504,6 @@ media::VideoCaptureDevice* VideoCaptureManager::GetDeviceInternal( |
| void VideoCaptureManager::TerminateOnDeviceThread() { |
| DCHECK(IsOnCaptureDeviceThread()); |
| - |
| - std::set<media::VideoCaptureDevice*> devices_to_delete; |
| - for (VideoCaptureDevices::iterator it = devices_.begin(); |
| - it != devices_.end(); ++it) { |
| - it->second->DeAllocate(); |
| - devices_to_delete.insert(it->second); |
| - } |
| - STLDeleteElements(&devices_to_delete); |
| STLDeleteValues(&controllers_); |
| } |