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

Unified Diff: content/browser/media/media_internals.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: content/browser/media/media_internals.cc
===================================================================
--- content/browser/media/media_internals.cc (revision 179909)
+++ content/browser/media/media_internals.cc (working copy)
@@ -2,95 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/media/media_internals.h"
+#include "content/browser/media/media_internals.h"
#include "base/memory/scoped_ptr.h"
#include "base/string16.h"
#include "base/stringprintf.h"
-#include "chrome/browser/media/media_capture_devices_dispatcher.h"
-#include "chrome/browser/media/media_internals_observer.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/web_ui.h"
#include "media/base/media_log.h"
#include "media/base/media_log_event.h"
-using content::BrowserThread;
+namespace content {
-namespace media {
-
-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
-
-void 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 GetRequestedDevice(const std::string& requested_device_id,
- bool audio,
- bool video,
- content::MediaStreamDevices* devices) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK(audio || video);
-
- MediaCaptureDevicesDispatcher* dispatcher =
- MediaInternals::GetInstance()->GetMediaCaptureDevicesDispatcher();
- if (audio) {
- const content::MediaStreamDevices& audio_devices =
- dispatcher->GetAudioCaptureDevices();
- const content::MediaStreamDevice* const device =
- media::FindDefaultDeviceWithId(audio_devices, requested_device_id);
- if (device)
- devices->push_back(*device);
- }
- if (video) {
- const content::MediaStreamDevices& video_devices =
- dispatcher->GetVideoCaptureDevices();
- const content::MediaStreamDevice* const device =
- media::FindDefaultDeviceWithId(video_devices, requested_device_id);
- if (device)
- devices->push_back(*device);
- }
-}
-
-} // namespace media
-
MediaInternals* MediaInternals::GetInstance() {
return Singleton<MediaInternals>::get();
}
@@ -139,84 +62,28 @@
SendUpdate("media.onMediaEvent", &dict);
}
-void MediaInternals::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 MediaInternals::AddUpdateCallback(const UpdateCallback& callback) {
+ update_callbacks_.push_back(callback);
}
-void MediaInternals::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 MediaInternals::OnAudioCaptureDevicesChanged(
- const content::MediaStreamDevices& devices) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- media_devices_dispatcher_->AudioCaptureDevicesChanged(devices);
-}
-
-void MediaInternals::OnVideoCaptureDevicesChanged(
- const content::MediaStreamDevices& devices) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- media_devices_dispatcher_->VideoCaptureDevicesChanged(devices);
-}
-
-void MediaInternals::OnMediaRequestStateChanged(
- int render_process_id,
- int render_view_id,
- const content::MediaStreamDevice& device,
- content::MediaRequestState state) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-
- if (observers_.size()) {
- FOR_EACH_OBSERVER(
- MediaInternalsObserver, observers_, OnRequestUpdate(render_process_id,
- render_view_id,
- device,
- state));
+void MediaInternals::RemoveUpdateCallback(const UpdateCallback& callback) {
+ for (size_t i = 0; i < update_callbacks_.size(); ++i) {
+ if (update_callbacks_[i].Equals(callback)) {
+ update_callbacks_.erase(update_callbacks_.begin() + i);
+ return;
+ }
}
+ NOTREACHED();
}
-void MediaInternals::AddObserver(MediaInternalsObserver* observer) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- observers_.AddObserver(observer);
-}
-
-void MediaInternals::RemoveObserver(MediaInternalsObserver* observer) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- observers_.RemoveObserver(observer);
-}
-
void MediaInternals::SendEverything() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
SendUpdate("media.onReceiveEverything", &data_);
}
-scoped_refptr<MediaCaptureDevicesDispatcher>
-MediaInternals::GetMediaCaptureDevicesDispatcher() {
- return media_devices_dispatcher_;
+MediaInternals::MediaInternals() {
}
-scoped_refptr<MediaStreamCaptureIndicator>
-MediaInternals::GetMediaStreamCaptureIndicator() {
- return media_stream_capture_indicator_.get();
-}
-
-MediaInternals::MediaInternals()
- : media_stream_capture_indicator_(new MediaStreamCaptureIndicator()),
- media_devices_dispatcher_(new MediaCaptureDevicesDispatcher()) {
-}
-
void MediaInternals::UpdateAudioStream(
void* host, int stream_id, const std::string& property, Value* value) {
std::string stream = base::StringPrintf("audio_streams.%p:%d",
@@ -245,10 +112,14 @@
void MediaInternals::SendUpdate(const std::string& function, Value* value) {
// Only bother serializing the update to JSON if someone is watching.
- if (observers_.size()) {
- std::vector<const Value*> args;
- args.push_back(value);
- string16 update = content::WebUI::GetJavascriptCall(function, args);
- FOR_EACH_OBSERVER(MediaInternalsObserver, observers_, OnUpdate(update));
- }
+ if (update_callbacks_.empty())
+ return;
+
+ std::vector<const Value*> args;
+ args.push_back(value);
+ string16 update = WebUI::GetJavascriptCall(function, args);
+ for (size_t i = 0; i < update_callbacks_.size(); i++)
+ update_callbacks_[i].Run(update);
}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698