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

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: minor 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
« no previous file with comments | « chrome/browser/chromeos/audio/audio_handler.h ('k') | chrome/browser/chromeos/status/volume_menu_button.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,10 +50,16 @@
return g_audio_handler;
}
-bool AudioHandler::IsInitialized() {
+bool AudioHandler::IsMixerInitialized() {
xiyuan 2012/01/27 03:30:29 nit: move this to after AudioHandler::~AudioHandle
achuithb 2012/01/27 10:12:46 Done.
return mixer_->IsInitialized();
}
+// static
+AudioHandler* AudioHandler::GetInstanceIfInitialized() {
+ return g_audio_handler && g_audio_handler->IsMixerInitialized() ?
+ g_audio_handler : NULL;
+}
+
double AudioHandler::GetVolumePercent() {
return VolumeDbToPercent(mixer_->GetVolumeDb());
}
@@ -60,6 +67,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 +82,7 @@
void AudioHandler::SetMuted(bool mute) {
mixer_->SetMuted(mute);
+ FOR_EACH_OBSERVER(VolumeObserver, volume_observers_, OnVolumeChanged());
}
AudioHandler::AudioHandler()
@@ -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())
+ AudioHandler::GetInstance()->AddVolumeObserver(this);
+}
+
+AudioHandler::VolumeObserver::~VolumeObserver() {
+ if (AudioHandler::GetInstance())
+ AudioHandler::GetInstance()->RemoveVolumeObserver(this);
+}
+
} // namespace chromeos
« no previous file with comments | « chrome/browser/chromeos/audio/audio_handler.h ('k') | chrome/browser/chromeos/status/volume_menu_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698