Index: content/browser/renderer_host/media/media_capture_devices_impl.cc |
diff --git a/content/browser/renderer_host/media/media_capture_devices_impl.cc b/content/browser/renderer_host/media/media_capture_devices_impl.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..edfa5231d8af42f00855830b88a87c8b2139f788 |
--- /dev/null |
+++ b/content/browser/renderer_host/media/media_capture_devices_impl.cc |
@@ -0,0 +1,123 @@ |
+// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/renderer_host/media/media_capture_devices_impl.h" |
+ |
+#include "content/browser/browser_main_loop.h" |
+#include "content/browser/renderer_host/media/media_stream_manager.h" |
+#include "content/public/browser/browser_thread.h" |
+ |
+namespace content { |
+ |
+namespace { |
+ |
+void EnsureMonitorCaptureDevices() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, FROM_HERE, |
+ base::Bind(&MediaStreamManager::EnsureDeviceMonitorStarted, |
+ base::Unretained( |
+ BrowserMainLoop::GetInstance()->media_stream_manager()))); |
+} |
+ |
+} // namespace |
+ |
+MediaCaptureDevices* MediaCaptureDevices::GetInstance() { |
+ return MediaCaptureDevicesImpl::GetInstance(); |
+} |
+ |
+MediaCaptureDevicesImpl* MediaCaptureDevicesImpl::GetInstance() { |
+ return Singleton<MediaCaptureDevicesImpl>::get(); |
+} |
+ |
+const MediaStreamDevices& |
+MediaCaptureDevicesImpl::GetAudioCaptureDevices() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ if (!is_device_enumeration_disabled_ && !devices_enumerated_) { |
+ EnsureMonitorCaptureDevices(); |
+ devices_enumerated_ = true; |
+ } |
+ return audio_devices_; |
+} |
+ |
+const MediaStreamDevices& |
+MediaCaptureDevicesImpl::GetVideoCaptureDevices() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ if (!is_device_enumeration_disabled_ && !devices_enumerated_) { |
+ EnsureMonitorCaptureDevices(); |
+ devices_enumerated_ = true; |
+ } |
+ return video_devices_; |
+} |
+ |
+void MediaCaptureDevicesImpl::AddObserver(Observer* observer) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ if (!observers_.HasObserver(observer)) |
+ observers_.AddObserver(observer); |
+} |
+ |
+void MediaCaptureDevicesImpl::RemoveObserver(Observer* observer) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ observers_.RemoveObserver(observer); |
+} |
+ |
+void MediaCaptureDevicesImpl::SetAudioCaptureDevices( |
+ const MediaStreamDevices& devices) { |
+ OnAudioCaptureDevicesChanged(devices); |
+} |
+ |
+void MediaCaptureDevicesImpl::SetVideoCaptureDevices( |
+ const MediaStreamDevices& devices) { |
+ OnVideoCaptureDevicesChanged(devices); |
+} |
+ |
+void MediaCaptureDevicesImpl::DisableDeviceEnumerationForTesting() { |
+ is_device_enumeration_disabled_ = true; |
+} |
+ |
+void MediaCaptureDevicesImpl::OnAudioCaptureDevicesChanged( |
+ const MediaStreamDevices& devices) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ BrowserThread::PostTask( |
+ BrowserThread::UI, FROM_HERE, |
+ base::Bind(&MediaCaptureDevicesImpl::UpdateAudioDevicesOnUIThread, |
+ base::Unretained(this), devices)); |
+} |
+ |
+void MediaCaptureDevicesImpl::OnVideoCaptureDevicesChanged( |
+ const MediaStreamDevices& devices) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ BrowserThread::PostTask( |
+ BrowserThread::UI, FROM_HERE, |
+ base::Bind(&MediaCaptureDevicesImpl::UpdateVideoDevicesOnUIThread, |
+ base::Unretained(this), devices)); |
+} |
+ |
+MediaCaptureDevicesImpl::MediaCaptureDevicesImpl() |
+ : devices_enumerated_(false), |
+ is_device_enumeration_disabled_(false) { |
+} |
+ |
+MediaCaptureDevicesImpl::~MediaCaptureDevicesImpl() { |
+} |
+ |
+void MediaCaptureDevicesImpl::UpdateAudioDevicesOnUIThread( |
+ const MediaStreamDevices& devices) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ devices_enumerated_ = true; |
+ audio_devices_ = devices; |
+ FOR_EACH_OBSERVER(Observer, observers_, |
+ OnUpdateAudioDevices(audio_devices_)); |
+} |
+ |
+void MediaCaptureDevicesImpl::UpdateVideoDevicesOnUIThread( |
+ const MediaStreamDevices& devices) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ devices_enumerated_ = true; |
+ video_devices_ = devices; |
+ FOR_EACH_OBSERVER(Observer, observers_, |
+ OnUpdateVideoDevices(video_devices_)); |
+} |
+ |
+} // namespace content |