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

Unified Diff: chrome/browser/chromeos/audio/audio_handler.cc

Issue 9169033: Support for showing/hiding status area volume controls in desktop devices (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: move IsMixerInitialized Created 8 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/chromeos/audio/audio_handler.cc
===================================================================
--- chrome/browser/chromeos/audio/audio_handler.cc (revision 119229)
+++ chrome/browser/chromeos/audio/audio_handler.cc (working copy)
@@ -10,6 +10,7 @@
#include "base/logging.h"
#include "base/memory/singleton.h"
#include "chrome/browser/chromeos/audio/audio_mixer_alsa.h"
+#include "chrome/browser/chromeos/system/runtime_environment.h"
#include "content/public/browser/browser_thread.h"
using std::max;
@@ -49,8 +50,10 @@
return g_audio_handler;
}
-bool AudioHandler::IsInitialized() {
- return mixer_->IsInitialized();
+// static
+AudioHandler* AudioHandler::GetInstanceIfInitialized() {
+ return g_audio_handler && g_audio_handler->IsMixerInitialized() ?
+ g_audio_handler : NULL;
}
double AudioHandler::GetVolumePercent() {
@@ -60,6 +63,7 @@
void AudioHandler::SetVolumePercent(double volume_percent) {
volume_percent = min(max(volume_percent, 0.0), 100.0);
mixer_->SetVolumeDb(PercentToVolumeDb(volume_percent));
+ FOR_EACH_OBSERVER(VolumeObserver, volume_observers_, OnVolumeChanged());
}
void AudioHandler::AdjustVolumeByPercent(double adjust_by_percent) {
@@ -74,6 +78,7 @@
void AudioHandler::SetMuted(bool mute) {
mixer_->SetMuted(mute);
+ FOR_EACH_OBSERVER(VolumeObserver, volume_observers_, OnVolumeChanged());
}
AudioHandler::AudioHandler()
@@ -85,6 +90,10 @@
mixer_.reset();
};
+bool AudioHandler::IsMixerInitialized() {
+ return mixer_->IsInitialized();
+}
+
// VolumeDbToPercent() and PercentToVolumeDb() conversion functions allow us
// complete control over how the 0 to 100% range is mapped to actual loudness.
//
@@ -113,4 +122,26 @@
(max_volume_db - min_volume_db) + min_volume_db;
}
+void AudioHandler::AddVolumeObserver(VolumeObserver* observer) {
+ volume_observers_.AddObserver(observer);
+}
+
+void AudioHandler::RemoveVolumeObserver(VolumeObserver* observer) {
+ volume_observers_.RemoveObserver(observer);
+}
+
+AudioHandler::VolumeObserver::VolumeObserver() {
+ // AudioHandler should be initialized here if we are on the device, though
+ // the mixer may not have finished initializing yet.
+ DCHECK(AudioHandler::GetInstance() ||
+ !system::runtime_environment::IsRunningOnChromeOS());
+ if (AudioHandler::GetInstance())
Daniel Erat 2012/01/27 18:03:57 remove the if statement; you already have a DCHECK
achuithb 2012/01/27 18:53:44 AudioHandler::GetInstance() is NULL on chrome-chro
stevenjb 2012/01/27 19:45:02 I'm not sure that this is clearer; how about at th
Daniel Erat 2012/01/27 23:06:54 yeah, i'd also prefer: if (system::runtime_envi
achuithb 2012/01/31 00:58:43 Well, I was following the pattern in: http://code.
+ AudioHandler::GetInstance()->AddVolumeObserver(this);
+}
+
+AudioHandler::VolumeObserver::~VolumeObserver() {
+ if (AudioHandler::GetInstance())
+ AudioHandler::GetInstance()->RemoveVolumeObserver(this);
+}
+
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698