| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/audio/audio_handler.h" | 5 #include "chrome/browser/chromeos/audio/audio_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 // Values used for muted preference. | 41 // Values used for muted preference. |
| 42 const int kPrefMuteOff = 0; | 42 const int kPrefMuteOff = 0; |
| 43 const int kPrefMuteOn = 1; | 43 const int kPrefMuteOn = 1; |
| 44 | 44 |
| 45 static AudioHandler* g_audio_handler = NULL; | 45 static AudioHandler* g_audio_handler = NULL; |
| 46 | 46 |
| 47 } // namespace | 47 } // namespace |
| 48 | 48 |
| 49 // static | 49 // static |
| 50 void AudioHandler::Initialize() { | 50 void AudioHandler::Initialize(const base::Closure& on_connected) { |
| 51 CHECK(!g_audio_handler); | 51 CHECK(!g_audio_handler); |
| 52 #if defined(USE_CRAS) | 52 #if defined(USE_CRAS) |
| 53 g_audio_handler = new AudioHandler(new AudioMixerCras()); | 53 g_audio_handler = new AudioHandler(new AudioMixerCras(), on_connected); |
| 54 #else | 54 #else |
| 55 g_audio_handler = new AudioHandler(new AudioMixerAlsa()); | 55 g_audio_handler = new AudioHandler(new AudioMixerAlsa(), on_connected); |
| 56 #endif | 56 #endif |
| 57 } | 57 } |
| 58 | 58 |
| 59 // static | 59 // static |
| 60 void AudioHandler::Shutdown() { | 60 void AudioHandler::Shutdown() { |
| 61 // We may call Shutdown without calling Initialize, e.g. if we exit early. | 61 // We may call Shutdown without calling Initialize, e.g. if we exit early. |
| 62 if (g_audio_handler) { | 62 if (g_audio_handler) { |
| 63 delete g_audio_handler; | 63 delete g_audio_handler; |
| 64 g_audio_handler = NULL; | 64 g_audio_handler = NULL; |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 // static | 68 // static |
| 69 void AudioHandler::InitializeForTesting(AudioMixer* mixer) { | 69 void AudioHandler::InitializeForTesting(AudioMixer* mixer) { |
| 70 CHECK(!g_audio_handler); | 70 CHECK(!g_audio_handler); |
| 71 g_audio_handler = new AudioHandler(mixer); | 71 g_audio_handler = new AudioHandler(mixer, base::Closure()); |
| 72 } | 72 } |
| 73 | 73 |
| 74 // static | 74 // static |
| 75 AudioHandler* AudioHandler::GetInstance() { | 75 AudioHandler* AudioHandler::GetInstance() { |
| 76 VLOG_IF(1, !g_audio_handler) | 76 VLOG_IF(1, !g_audio_handler) |
| 77 << "AudioHandler::GetInstance() called with NULL global instance."; | 77 << "AudioHandler::GetInstance() called with NULL global instance."; |
| 78 return g_audio_handler; | 78 return g_audio_handler; |
| 79 } | 79 } |
| 80 | 80 |
| 81 // static | 81 // static |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 std::string* pref_name = content::Details<std::string>(details).ptr(); | 168 std::string* pref_name = content::Details<std::string>(details).ptr(); |
| 169 if (*pref_name == prefs::kAudioOutputAllowed || | 169 if (*pref_name == prefs::kAudioOutputAllowed || |
| 170 *pref_name == prefs::kAudioCaptureAllowed) { | 170 *pref_name == prefs::kAudioCaptureAllowed) { |
| 171 ApplyAudioPolicy(); | 171 ApplyAudioPolicy(); |
| 172 } | 172 } |
| 173 } else { | 173 } else { |
| 174 NOTREACHED() << "Unexpected notification type : " << type; | 174 NOTREACHED() << "Unexpected notification type : " << type; |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 | 177 |
| 178 AudioHandler::AudioHandler(AudioMixer* mixer) | 178 AudioHandler::AudioHandler(AudioMixer* mixer, const base::Closure& on_connected) |
| 179 : mixer_(mixer), | 179 : mixer_(mixer), |
| 180 local_state_(g_browser_process->local_state()) { | 180 local_state_(g_browser_process->local_state()) { |
| 181 InitializePrefObservers(); | 181 InitializePrefObservers(); |
| 182 mixer_->Init(); | 182 mixer_->Init(on_connected); |
| 183 ApplyAudioPolicy(); | 183 ApplyAudioPolicy(); |
| 184 SetMuted(local_state_->GetInteger(prefs::kAudioMute) == kPrefMuteOn); | 184 SetMuted(local_state_->GetInteger(prefs::kAudioMute) == kPrefMuteOn); |
| 185 SetVolumePercentInternal(local_state_->GetDouble(prefs::kAudioVolumePercent)); | 185 SetVolumePercentInternal(local_state_->GetDouble(prefs::kAudioVolumePercent)); |
| 186 } | 186 } |
| 187 | 187 |
| 188 AudioHandler::~AudioHandler() { | 188 AudioHandler::~AudioHandler() { |
| 189 mixer_.reset(); | 189 mixer_.reset(); |
| 190 }; | 190 }; |
| 191 | 191 |
| 192 void AudioHandler::InitializePrefObservers() { | 192 void AudioHandler::InitializePrefObservers() { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 208 mixer_->SetCaptureMuteLocked(false); | 208 mixer_->SetCaptureMuteLocked(false); |
| 209 if (local_state_->GetBoolean(prefs::kAudioCaptureAllowed)) { | 209 if (local_state_->GetBoolean(prefs::kAudioCaptureAllowed)) { |
| 210 mixer_->SetCaptureMuted(false); | 210 mixer_->SetCaptureMuted(false); |
| 211 } else { | 211 } else { |
| 212 mixer_->SetCaptureMuted(true); | 212 mixer_->SetCaptureMuted(true); |
| 213 mixer_->SetCaptureMuteLocked(true); | 213 mixer_->SetCaptureMuteLocked(true); |
| 214 } | 214 } |
| 215 } | 215 } |
| 216 | 216 |
| 217 } // namespace chromeos | 217 } // namespace chromeos |
| OLD | NEW |