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

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

Issue 12153002: Move chrome://media-internals to content. This allows us to hide implementation details from the pu… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 11 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
===================================================================
--- chrome/browser/media/media_capture_devices_dispatcher.cc (revision 179909)
+++ chrome/browser/media/media_capture_devices_dispatcher.cc (working copy)
@@ -4,7 +4,9 @@
#include "chrome/browser/media/media_capture_devices_dispatcher.h"
+#include "chrome/browser/media/media_stream_capture_indicator.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/media_devices_monitor.h"
@@ -13,8 +15,34 @@
using content::BrowserThread;
using content::MediaStreamDevices;
+namespace {
+
+const content::MediaStreamDevice* FindDefaultDeviceWithId(
+ const content::MediaStreamDevices& devices,
+ const std::string& device_id) {
+ if (devices.empty())
+ return NULL;
+
+ content::MediaStreamDevices::const_iterator iter = devices.begin();
+ for (; iter != devices.end(); ++iter) {
+ if (iter->id == device_id) {
+ return &(*iter);
+ }
+ }
+
+ return &(*devices.begin());
+};
+
+} // namespace
+
+
+MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() {
+ return Singleton<MediaCaptureDevicesDispatcher>::get();
+}
+
MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher()
- : devices_enumerated_(false) {}
+ : devices_enumerated_(false),
+ media_stream_capture_indicator_(new MediaStreamCaptureIndicator()) {}
MediaCaptureDevicesDispatcher::~MediaCaptureDevicesDispatcher() {}
@@ -32,26 +60,6 @@
}
}
-void MediaCaptureDevicesDispatcher::AudioCaptureDevicesChanged(
- const MediaStreamDevices& devices) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&MediaCaptureDevicesDispatcher::UpdateAudioDevicesOnUIThread,
- this, devices));
-}
-
-void MediaCaptureDevicesDispatcher::VideoCaptureDevicesChanged(
- const MediaStreamDevices& devices) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&MediaCaptureDevicesDispatcher::UpdateVideoDevicesOnUIThread,
- this, devices));
-}
-
void MediaCaptureDevicesDispatcher::AddObserver(Observer* observer) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!observers_.HasObserver(observer))
@@ -87,6 +95,109 @@
return video_devices_;
}
+void MediaCaptureDevicesDispatcher::GetDefaultDevicesForProfile(
+ Profile* profile,
+ bool audio,
+ bool video,
+ content::MediaStreamDevices* devices) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(audio || video);
+
+ PrefService* prefs = profile->GetPrefs();
+ std::string default_device;
+ if (audio) {
+ default_device = prefs->GetString(prefs::kDefaultAudioCaptureDevice);
+ GetRequestedDevice(default_device, true, false, devices);
+ }
+
+ if (video) {
+ default_device = prefs->GetString(prefs::kDefaultVideoCaptureDevice);
+ GetRequestedDevice(default_device, false, true, devices);
+ }
+}
+
+void MediaCaptureDevicesDispatcher::GetRequestedDevice(
+ const std::string& requested_device_id,
+ bool audio,
+ bool video,
+ content::MediaStreamDevices* devices) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(audio || video);
+
+ if (audio) {
+ const content::MediaStreamDevices& audio_devices = GetAudioCaptureDevices();
+ const content::MediaStreamDevice* const device =
+ FindDefaultDeviceWithId(audio_devices, requested_device_id);
+ if (device)
+ devices->push_back(*device);
+ }
+ if (video) {
+ const content::MediaStreamDevices& video_devices = GetVideoCaptureDevices();
+ const content::MediaStreamDevice* const device =
+ FindDefaultDeviceWithId(video_devices, requested_device_id);
+ if (device)
+ devices->push_back(*device);
+ }
+}
+
+scoped_refptr<MediaStreamCaptureIndicator>
+ MediaCaptureDevicesDispatcher::GetMediaStreamCaptureIndicator() {
+ return media_stream_capture_indicator_;
+}
+
+void MediaCaptureDevicesDispatcher::OnCaptureDevicesOpened(
+ int render_process_id,
+ int render_view_id,
+ const content::MediaStreamDevices& devices) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ media_stream_capture_indicator_->CaptureDevicesOpened(render_process_id,
+ render_view_id,
+ devices);
+}
+
+void MediaCaptureDevicesDispatcher::OnCaptureDevicesClosed(
+ int render_process_id,
+ int render_view_id,
+ const content::MediaStreamDevices& devices) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ media_stream_capture_indicator_->CaptureDevicesClosed(render_process_id,
+ render_view_id,
+ devices);
+}
+
+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,
+ const content::MediaStreamDevice& device,
+ content::MediaRequestState state) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(
+ &MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread,
+ base::Unretained(this), render_process_id, render_view_id, device,
+ state));
+
+}
+
void MediaCaptureDevicesDispatcher::UpdateAudioDevicesOnUIThread(
const content::MediaStreamDevices& devices) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -104,3 +215,15 @@
FOR_EACH_OBSERVER(Observer, observers_,
OnUpdateVideoDevices(video_devices_));
}
+
+void MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread(
+ int render_process_id,
+ int render_view_id,
+ const content::MediaStreamDevice& device,
+ content::MediaRequestState state) {
+ FOR_EACH_OBSERVER(Observer, observers_,
+ OnRequestUpdate(render_process_id,
+ render_view_id,
+ device,
+ state));
+}

Powered by Google App Engine
This is Rietveld 408576698