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

Side by Side Diff: chrome/browser/chromeos/audio/audio_handler.cc

Issue 10411028: Fix the volume controlling behaviors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 22 matching lines...) Expand all
33 const int kPrefMuteOff = 0; 33 const int kPrefMuteOff = 0;
34 const int kPrefMuteOn = 1; 34 const int kPrefMuteOn = 1;
35 35
36 static AudioHandler* g_audio_handler = NULL; 36 static AudioHandler* g_audio_handler = NULL;
37 37
38 } // namespace 38 } // namespace
39 39
40 // static 40 // static
41 void AudioHandler::Initialize() { 41 void AudioHandler::Initialize() {
42 CHECK(!g_audio_handler); 42 CHECK(!g_audio_handler);
43 g_audio_handler = new AudioHandler(); 43 #if defined(USE_CRAS)
44 g_audio_handler = new AudioHandler(new AudioMixerCras());
45 #else
46 g_audio_handler = new AudioHandler(new AudioMixerAlsa());
47 #endif
44 } 48 }
45 49
46 // static 50 // static
47 void AudioHandler::Shutdown() { 51 void AudioHandler::Shutdown() {
48 // We may call Shutdown without calling Initialize, e.g. if we exit early. 52 // We may call Shutdown without calling Initialize, e.g. if we exit early.
49 if (g_audio_handler) { 53 if (g_audio_handler) {
50 delete g_audio_handler; 54 delete g_audio_handler;
51 g_audio_handler = NULL; 55 g_audio_handler = NULL;
52 } 56 }
53 } 57 }
54 58
55 // static 59 // static
60 void AudioHandler::InitializeForTesting(AudioMixer* mixer) {
61 CHECK(!g_audio_handler);
62 g_audio_handler = new AudioHandler(mixer);
63 }
64
65 // static
56 AudioHandler* AudioHandler::GetInstance() { 66 AudioHandler* AudioHandler::GetInstance() {
57 VLOG_IF(1, !g_audio_handler) 67 VLOG_IF(1, !g_audio_handler)
58 << "AudioHandler::GetInstance() called with NULL global instance."; 68 << "AudioHandler::GetInstance() called with NULL global instance.";
59 return g_audio_handler; 69 return g_audio_handler;
60 } 70 }
61 71
62 // static 72 // static
63 void AudioHandler::RegisterPrefs(PrefService* local_state) { 73 void AudioHandler::RegisterPrefs(PrefService* local_state) {
64 if (!local_state->FindPreference(prefs::kAudioVolumePercent)) 74 if (!local_state->FindPreference(prefs::kAudioVolumePercent))
65 local_state->RegisterDoublePref(prefs::kAudioVolumePercent, 75 local_state->RegisterDoublePref(prefs::kAudioVolumePercent,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 116 }
107 117
108 void AudioHandler::AddVolumeObserver(VolumeObserver* observer) { 118 void AudioHandler::AddVolumeObserver(VolumeObserver* observer) {
109 volume_observers_.AddObserver(observer); 119 volume_observers_.AddObserver(observer);
110 } 120 }
111 121
112 void AudioHandler::RemoveVolumeObserver(VolumeObserver* observer) { 122 void AudioHandler::RemoveVolumeObserver(VolumeObserver* observer) {
113 volume_observers_.RemoveObserver(observer); 123 volume_observers_.RemoveObserver(observer);
114 } 124 }
115 125
116 AudioHandler::AudioHandler() 126 AudioHandler::AudioHandler(AudioMixer* mixer)
117 #if defined(USE_CRAS) 127 : mixer_(mixer),
118 : mixer_(new AudioMixerCras()),
119 #else
120 : mixer_(new AudioMixerAlsa()),
121 #endif
122 prefs_(g_browser_process->local_state()) { 128 prefs_(g_browser_process->local_state()) {
123 mixer_->SetVolumePercent(prefs_->GetDouble(prefs::kAudioVolumePercent)); 129 mixer_->SetVolumePercent(prefs_->GetDouble(prefs::kAudioVolumePercent));
124 mixer_->SetMuted(prefs_->GetInteger(prefs::kAudioMute) == kPrefMuteOn); 130 mixer_->SetMuted(prefs_->GetInteger(prefs::kAudioMute) == kPrefMuteOn);
125 mixer_->Init(); 131 mixer_->Init();
126 } 132 }
127 133
128 AudioHandler::~AudioHandler() { 134 AudioHandler::~AudioHandler() {
129 mixer_.reset(); 135 mixer_.reset();
130 }; 136 };
131 137
132 } // namespace chromeos 138 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/audio/audio_handler.h ('k') | chrome/browser/ui/views/ash/volume_controller_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698