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

Unified Diff: chrome/browser/media/media_capture_devices_dispatcher.cc

Issue 183743021: Implement MediaCaptureDevices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media/media_capture_devices_dispatcher.cc
diff --git a/chrome/browser/media/media_capture_devices_dispatcher.cc b/chrome/browser/media/media_capture_devices_dispatcher.cc
index 690bd1b143f9fcb136cfd170a09e933ce3f69b91..fb38bc29b50aa763f57b69aec3bbed21b6513d9b 100644
--- a/chrome/browser/media/media_capture_devices_dispatcher.cc
+++ b/chrome/browser/media/media_capture_devices_dispatcher.cc
@@ -26,7 +26,7 @@
#include "components/user_prefs/pref_registry_syncable.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/desktop_media_id.h"
-#include "content/public/browser/media_devices_monitor.h"
+#include "content/public/browser/media_capture_devices.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h"
@@ -43,6 +43,7 @@
#endif // defined(OS_CHROMEOS)
using content::BrowserThread;
+using content::MediaCaptureDevices;
using content::MediaStreamDevices;
namespace {
@@ -194,9 +195,7 @@ MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() {
}
MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher()
- : devices_enumerated_(false),
- is_device_enumeration_disabled_(false),
- media_stream_capture_indicator_(new MediaStreamCaptureIndicator()),
+ : media_stream_capture_indicator_(new MediaStreamCaptureIndicator()),
audio_stream_indicator_(new AudioStreamIndicator()) {
// MediaCaptureDevicesDispatcher is a singleton. It should be created on
// UI thread. Otherwise, it will not receive
@@ -233,26 +232,6 @@ void MediaCaptureDevicesDispatcher::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
-const MediaStreamDevices&
-MediaCaptureDevicesDispatcher::GetAudioCaptureDevices() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- if (!is_device_enumeration_disabled_ && !devices_enumerated_) {
- content::EnsureMonitorCaptureDevices();
- devices_enumerated_ = true;
- }
- return audio_devices_;
-}
-
-const MediaStreamDevices&
-MediaCaptureDevicesDispatcher::GetVideoCaptureDevices() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- if (!is_device_enumeration_disabled_ && !devices_enumerated_) {
- content::EnsureMonitorCaptureDevices();
- devices_enumerated_ = true;
- }
- return video_devices_;
-}
-
void MediaCaptureDevicesDispatcher::Observe(
int type,
const content::NotificationSource& source,
@@ -622,7 +601,8 @@ const content::MediaStreamDevice*
MediaCaptureDevicesDispatcher::GetRequestedAudioDevice(
const std::string& requested_audio_device_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- const content::MediaStreamDevices& audio_devices = GetAudioCaptureDevices();
+ const content::MediaStreamDevices& audio_devices =
+ MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices();
const content::MediaStreamDevice* const device =
FindDeviceWithId(audio_devices, requested_audio_device_id);
return device;
@@ -631,7 +611,8 @@ MediaCaptureDevicesDispatcher::GetRequestedAudioDevice(
const content::MediaStreamDevice*
MediaCaptureDevicesDispatcher::GetFirstAvailableAudioDevice() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- const content::MediaStreamDevices& audio_devices = GetAudioCaptureDevices();
+ const content::MediaStreamDevices& audio_devices =
+ MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices();
if (audio_devices.empty())
return NULL;
return &(*audio_devices.begin());
@@ -641,7 +622,8 @@ const content::MediaStreamDevice*
MediaCaptureDevicesDispatcher::GetRequestedVideoDevice(
const std::string& requested_video_device_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- const content::MediaStreamDevices& video_devices = GetVideoCaptureDevices();
+ const content::MediaStreamDevices& video_devices =
+ MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices();
const content::MediaStreamDevice* const device =
FindDeviceWithId(video_devices, requested_video_device_id);
return device;
@@ -650,16 +632,13 @@ MediaCaptureDevicesDispatcher::GetRequestedVideoDevice(
const content::MediaStreamDevice*
MediaCaptureDevicesDispatcher::GetFirstAvailableVideoDevice() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- const content::MediaStreamDevices& video_devices = GetVideoCaptureDevices();
+ const content::MediaStreamDevices& video_devices =
+ MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices();
if (video_devices.empty())
return NULL;
return &(*video_devices.begin());
}
-void MediaCaptureDevicesDispatcher::DisableDeviceEnumerationForTesting() {
- is_device_enumeration_disabled_ = true;
-}
-
scoped_refptr<MediaStreamCaptureIndicator>
MediaCaptureDevicesDispatcher::GetMediaStreamCaptureIndicator() {
return media_stream_capture_indicator_;
@@ -677,24 +656,6 @@ MediaCaptureDevicesDispatcher::GetDesktopStreamsRegistry() {
return desktop_streams_registry_.get();
}
-void MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged(
- const content::MediaStreamDevices& devices) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&MediaCaptureDevicesDispatcher::UpdateAudioDevicesOnUIThread,
- base::Unretained(this), devices));
-}
-
-void MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged(
- const content::MediaStreamDevices& devices) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&MediaCaptureDevicesDispatcher::UpdateVideoDevicesOnUIThread,
- base::Unretained(this), devices));
-}
-
void MediaCaptureDevicesDispatcher::OnMediaRequestStateChanged(
int render_process_id,
int render_view_id,
@@ -730,24 +691,6 @@ void MediaCaptureDevicesDispatcher::OnCreatingAudioStream(
base::Unretained(this), render_process_id, render_frame_id));
}
-void MediaCaptureDevicesDispatcher::UpdateAudioDevicesOnUIThread(
- const content::MediaStreamDevices& devices) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- devices_enumerated_ = true;
- audio_devices_ = devices;
- FOR_EACH_OBSERVER(Observer, observers_,
- OnUpdateAudioDevices(audio_devices_));
-}
-
-void MediaCaptureDevicesDispatcher::UpdateVideoDevicesOnUIThread(
- const content::MediaStreamDevices& devices) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- devices_enumerated_ = true;
- video_devices_ = devices;
- FOR_EACH_OBSERVER(Observer, observers_,
- OnUpdateVideoDevices(video_devices_));
-}
-
void MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread(
int render_process_id,
int render_view_id,

Powered by Google App Engine
This is Rietveld 408576698