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

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

Issue 10421010: Revert 138278 - 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 #if defined(USE_CRAS) 43 g_audio_handler = new AudioHandler();
44 g_audio_handler = new AudioHandler(new AudioMixerCras());
45 #else
46 g_audio_handler = new AudioHandler(new AudioMixerAlsa());
47 #endif
48 } 44 }
49 45
50 // static 46 // static
51 void AudioHandler::Shutdown() { 47 void AudioHandler::Shutdown() {
52 // We may call Shutdown without calling Initialize, e.g. if we exit early. 48 // We may call Shutdown without calling Initialize, e.g. if we exit early.
53 if (g_audio_handler) { 49 if (g_audio_handler) {
54 delete g_audio_handler; 50 delete g_audio_handler;
55 g_audio_handler = NULL; 51 g_audio_handler = NULL;
56 } 52 }
57 } 53 }
58 54
59 // static 55 // static
60 void AudioHandler::InitializeForTesting(AudioMixer* mixer) {
61 CHECK(!g_audio_handler);
62 g_audio_handler = new AudioHandler(mixer);
63 }
64
65 // static
66 AudioHandler* AudioHandler::GetInstance() { 56 AudioHandler* AudioHandler::GetInstance() {
67 VLOG_IF(1, !g_audio_handler) 57 VLOG_IF(1, !g_audio_handler)
68 << "AudioHandler::GetInstance() called with NULL global instance."; 58 << "AudioHandler::GetInstance() called with NULL global instance.";
69 return g_audio_handler; 59 return g_audio_handler;
70 } 60 }
71 61
72 // static 62 // static
73 void AudioHandler::RegisterPrefs(PrefService* local_state) { 63 void AudioHandler::RegisterPrefs(PrefService* local_state) {
74 if (!local_state->FindPreference(prefs::kAudioVolumePercent)) 64 if (!local_state->FindPreference(prefs::kAudioVolumePercent))
75 local_state->RegisterDoublePref(prefs::kAudioVolumePercent, 65 local_state->RegisterDoublePref(prefs::kAudioVolumePercent,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 } 108 }
119 109
120 void AudioHandler::AddVolumeObserver(VolumeObserver* observer) { 110 void AudioHandler::AddVolumeObserver(VolumeObserver* observer) {
121 volume_observers_.AddObserver(observer); 111 volume_observers_.AddObserver(observer);
122 } 112 }
123 113
124 void AudioHandler::RemoveVolumeObserver(VolumeObserver* observer) { 114 void AudioHandler::RemoveVolumeObserver(VolumeObserver* observer) {
125 volume_observers_.RemoveObserver(observer); 115 volume_observers_.RemoveObserver(observer);
126 } 116 }
127 117
128 AudioHandler::AudioHandler(AudioMixer* mixer) 118 AudioHandler::AudioHandler()
129 : mixer_(mixer), 119 #if defined(USE_CRAS)
120 : mixer_(new AudioMixerCras()),
121 #else
122 : mixer_(new AudioMixerAlsa()),
123 #endif
130 prefs_(g_browser_process->local_state()) { 124 prefs_(g_browser_process->local_state()) {
131 mixer_->SetVolumePercent(prefs_->GetDouble(prefs::kAudioVolumePercent)); 125 mixer_->SetVolumePercent(prefs_->GetDouble(prefs::kAudioVolumePercent));
132 mixer_->SetMuted(prefs_->GetInteger(prefs::kAudioMute) == kPrefMuteOn); 126 mixer_->SetMuted(prefs_->GetInteger(prefs::kAudioMute) == kPrefMuteOn);
133 mixer_->Init(); 127 mixer_->Init();
134 } 128 }
135 129
136 AudioHandler::~AudioHandler() { 130 AudioHandler::~AudioHandler() {
137 mixer_.reset(); 131 mixer_.reset();
138 }; 132 };
139 133
140 } // namespace chromeos 134 } // 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