Chromium Code Reviews| Index: chrome/browser/chromeos/audio/audio_handler.cc |
| =================================================================== |
| --- chrome/browser/chromeos/audio/audio_handler.cc (revision 119043) |
| +++ chrome/browser/chromeos/audio/audio_handler.cc (working copy) |
| @@ -49,10 +49,16 @@ |
| return g_audio_handler; |
| } |
| -bool AudioHandler::IsInitialized() { |
| +bool AudioHandler::IsMixerInitialized() { |
| return mixer_->IsInitialized(); |
| } |
| +// static |
| +AudioHandler* AudioHandler::GetInitialized() { |
| + return g_audio_handler && g_audio_handler->IsMixerInitialized() ? |
| + g_audio_handler : NULL; |
| +} |
| + |
| double AudioHandler::GetVolumePercent() { |
| return VolumeDbToPercent(mixer_->GetVolumeDb()); |
| } |
| @@ -60,6 +66,7 @@ |
| void AudioHandler::SetVolumePercent(double volume_percent) { |
| volume_percent = min(max(volume_percent, 0.0), 100.0); |
| mixer_->SetVolumeDb(PercentToVolumeDb(volume_percent)); |
| + VolumeChanged(); |
|
Daniel Erat
2012/01/26 17:55:21
nit: unless you anticipate adding more code to Vol
xiyuan
2012/01/26 18:07:10
nit: If you want to keep this function, please ren
achuithb
2012/01/27 01:48:05
Done.
|
| } |
| void AudioHandler::AdjustVolumeByPercent(double adjust_by_percent) { |
| @@ -74,6 +81,7 @@ |
| void AudioHandler::SetMuted(bool mute) { |
| mixer_->SetMuted(mute); |
| + VolumeChanged(); |
| } |
| AudioHandler::AudioHandler() |
| @@ -113,4 +121,26 @@ |
| (max_volume_db - min_volume_db) + min_volume_db; |
| } |
| +void AudioHandler::AddVolumeObserver(VolumeObserver* observer) { |
|
Daniel Erat
2012/01/26 17:55:21
please match the order from the header file
achuithb
2012/01/27 01:48:05
Done. These files have been moved to the bottom in
|
| + volume_observers_.AddObserver(observer); |
| +} |
| + |
| +void AudioHandler::RemoveVolumeObserver(VolumeObserver* observer) { |
| + volume_observers_.RemoveObserver(observer); |
| +} |
| + |
| +void AudioHandler::VolumeChanged() { |
| + FOR_EACH_OBSERVER(VolumeObserver, volume_observers_, OnVolumeChanged()); |
| +} |
| + |
| +AudioHandler::VolumeObserver::VolumeObserver() { |
| + if (AudioHandler::GetInstance()) // Mixer may be uninitialized here. |
|
Daniel Erat
2012/01/26 17:55:21
so after instantiating an object derived from Volu
achuithb
2012/01/26 23:19:34
The comment refers to the fact that we are using G
Daniel Erat
2012/01/26 23:53:28
My comment wasn't related to the comment in the co
achuithb
2012/01/27 00:16:54
We create the AudioHandler singleton before the st
|
| + AudioHandler::GetInstance()->AddVolumeObserver(this); |
| +} |
| + |
| +AudioHandler::VolumeObserver::~VolumeObserver() { |
| + if (AudioHandler::GetInstance()) |
| + AudioHandler::GetInstance()->RemoveVolumeObserver(this); |
| +} |
| + |
| } // namespace chromeos |