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

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: try again Created 6 years, 9 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 40a439bef6d95950a002cb4bae5600f2bda902bb..6543db0118082ebab9fe776e2ded6b22175c8c0b 100644
--- a/chrome/browser/media/media_capture_devices_dispatcher.cc
+++ b/chrome/browser/media/media_capture_devices_dispatcher.cc
@@ -25,7 +25,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"
@@ -51,6 +51,7 @@
#endif // !defined(OS_ANDROID) && !defined(OS_IOS)
using content::BrowserThread;
+using content::MediaCaptureDevices;
using content::MediaStreamDevices;
namespace {
@@ -247,8 +248,7 @@ MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() {
}
MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher()
- : devices_enumerated_(false),
- is_device_enumeration_disabled_(false),
+ : is_device_enumeration_disabled_(false),
media_stream_capture_indicator_(new MediaStreamCaptureIndicator()) {
// MediaCaptureDevicesDispatcher is a singleton. It should be created on
// UI thread. Otherwise, it will not receive
@@ -288,21 +288,19 @@ void MediaCaptureDevicesDispatcher::RemoveObserver(Observer* 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_;
+ if (is_device_enumeration_disabled_ || !test_audio_devices_.empty())
+ return test_audio_devices_;
+
+ return MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices();
}
const MediaStreamDevices&
MediaCaptureDevicesDispatcher::GetVideoCaptureDevices() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- if (!is_device_enumeration_disabled_ && !devices_enumerated_) {
- content::EnsureMonitorCaptureDevices();
- devices_enumerated_ = true;
- }
- return video_devices_;
+ if (is_device_enumeration_disabled_ || !test_video_devices_.empty())
+ return test_video_devices_;
+
+ return MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices();
}
void MediaCaptureDevicesDispatcher::Observe(
@@ -730,22 +728,22 @@ MediaCaptureDevicesDispatcher::GetDesktopStreamsRegistry() {
return desktop_streams_registry_.get();
}
-void MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged(
- const content::MediaStreamDevices& devices) {
+void MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
- base::Bind(&MediaCaptureDevicesDispatcher::UpdateAudioDevicesOnUIThread,
- base::Unretained(this), devices));
+ base::Bind(
+ &MediaCaptureDevicesDispatcher::NotifyAudioDevicesChangedOnUIThread,
+ base::Unretained(this)));
}
-void MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged(
- const content::MediaStreamDevices& devices) {
+void MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
- base::Bind(&MediaCaptureDevicesDispatcher::UpdateVideoDevicesOnUIThread,
- base::Unretained(this), devices));
+ base::Bind(
+ &MediaCaptureDevicesDispatcher::NotifyVideoDevicesChangedOnUIThread,
+ base::Unretained(this)));
}
void MediaCaptureDevicesDispatcher::OnMediaRequestStateChanged(
@@ -809,22 +807,16 @@ 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;
+void MediaCaptureDevicesDispatcher::NotifyAudioDevicesChangedOnUIThread() {
+ MediaStreamDevices devices = GetAudioCaptureDevices();
FOR_EACH_OBSERVER(Observer, observers_,
- OnUpdateAudioDevices(audio_devices_));
+ OnUpdateAudioDevices(devices));
}
-void MediaCaptureDevicesDispatcher::UpdateVideoDevicesOnUIThread(
- const content::MediaStreamDevices& devices) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- devices_enumerated_ = true;
- video_devices_ = devices;
+void MediaCaptureDevicesDispatcher::NotifyVideoDevicesChangedOnUIThread() {
+ MediaStreamDevices devices = GetVideoCaptureDevices();
FOR_EACH_OBSERVER(Observer, observers_,
- OnUpdateVideoDevices(video_devices_));
+ OnUpdateVideoDevices(devices));
}
void MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread(
@@ -918,3 +910,14 @@ bool MediaCaptureDevicesDispatcher::IsDesktopCaptureInProgress() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
return desktop_capture_sessions_.size() > 0;
}
+
+
+void MediaCaptureDevicesDispatcher::SetTestAudioCaptureDevices(
+ const MediaStreamDevices& devices) {
+ test_audio_devices_ = devices;
+}
+
+void MediaCaptureDevicesDispatcher::SetTestVideoCaptureDevices(
+ const MediaStreamDevices& devices) {
+ test_video_devices_ = devices;
+}
« no previous file with comments | « chrome/browser/media/media_capture_devices_dispatcher.h ('k') | chrome/browser/policy/policy_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698