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

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

Issue 11345008: Remove content::NotificationObserver dependency from most Prefs code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head for commit Created 8 years, 1 month 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"
11 #include "base/memory/singleton.h" 11 #include "base/memory/singleton.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #if defined(USE_CRAS) 13 #if defined(USE_CRAS)
14 #include "chrome/browser/chromeos/audio/audio_mixer_cras.h" 14 #include "chrome/browser/chromeos/audio/audio_mixer_cras.h"
15 #else 15 #else
16 #include "chrome/browser/chromeos/audio/audio_mixer_alsa.h" 16 #include "chrome/browser/chromeos/audio/audio_mixer_alsa.h"
17 #endif 17 #endif
18 #include "chrome/browser/prefs/pref_service.h" 18 #include "chrome/browser/prefs/pref_service.h"
19 #include "chrome/common/chrome_notification_types.h" 19 #include "chrome/common/chrome_notification_types.h"
20 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
21 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/notification_service.h"
23 22
24 using std::max; 23 using std::max;
25 using std::min; 24 using std::min;
26 25
27 namespace chromeos { 26 namespace chromeos {
28 27
29 namespace { 28 namespace {
30 29
31 // Default value for the volume pref, as a percent in the range [0.0, 100.0]. 30 // Default value for the volume pref, as a percent in the range [0.0, 100.0].
32 const double kDefaultVolumePercent = 75.0; 31 const double kDefaultVolumePercent = 75.0;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } 153 }
155 154
156 void AudioHandler::AddVolumeObserver(VolumeObserver* observer) { 155 void AudioHandler::AddVolumeObserver(VolumeObserver* observer) {
157 volume_observers_.AddObserver(observer); 156 volume_observers_.AddObserver(observer);
158 } 157 }
159 158
160 void AudioHandler::RemoveVolumeObserver(VolumeObserver* observer) { 159 void AudioHandler::RemoveVolumeObserver(VolumeObserver* observer) {
161 volume_observers_.RemoveObserver(observer); 160 volume_observers_.RemoveObserver(observer);
162 } 161 }
163 162
164 void AudioHandler::Observe(int type, 163 void AudioHandler::OnPreferenceChanged(PrefServiceBase* service,
165 const content::NotificationSource& source, 164 const std::string& pref_name) {
166 const content::NotificationDetails& details) { 165 DCHECK(pref_name == prefs::kAudioOutputAllowed ||
167 if (type == chrome::NOTIFICATION_PREF_CHANGED) { 166 pref_name == prefs::kAudioCaptureAllowed);
168 std::string* pref_name = content::Details<std::string>(details).ptr(); 167 ApplyAudioPolicy();
169 if (*pref_name == prefs::kAudioOutputAllowed ||
170 *pref_name == prefs::kAudioCaptureAllowed) {
171 ApplyAudioPolicy();
172 }
173 } else {
174 NOTREACHED() << "Unexpected notification type : " << type;
175 }
176 } 168 }
177 169
178 AudioHandler::AudioHandler(AudioMixer* mixer) 170 AudioHandler::AudioHandler(AudioMixer* mixer)
179 : mixer_(mixer), 171 : mixer_(mixer),
180 local_state_(g_browser_process->local_state()) { 172 local_state_(g_browser_process->local_state()) {
181 InitializePrefObservers(); 173 InitializePrefObservers();
182 mixer_->Init(); 174 mixer_->Init();
183 ApplyAudioPolicy(); 175 ApplyAudioPolicy();
184 SetMuted(local_state_->GetInteger(prefs::kAudioMute) == kPrefMuteOn); 176 SetMuted(local_state_->GetInteger(prefs::kAudioMute) == kPrefMuteOn);
185 SetVolumePercentInternal(local_state_->GetDouble(prefs::kAudioVolumePercent)); 177 SetVolumePercentInternal(local_state_->GetDouble(prefs::kAudioVolumePercent));
(...skipping 22 matching lines...) Expand all
208 mixer_->SetCaptureMuteLocked(false); 200 mixer_->SetCaptureMuteLocked(false);
209 if (local_state_->GetBoolean(prefs::kAudioCaptureAllowed)) { 201 if (local_state_->GetBoolean(prefs::kAudioCaptureAllowed)) {
210 mixer_->SetCaptureMuted(false); 202 mixer_->SetCaptureMuted(false);
211 } else { 203 } else {
212 mixer_->SetCaptureMuted(true); 204 mixer_->SetCaptureMuted(true);
213 mixer_->SetCaptureMuteLocked(true); 205 mixer_->SetCaptureMuteLocked(true);
214 } 206 }
215 } 207 }
216 208
217 } // namespace chromeos 209 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/audio/audio_handler.h ('k') | chrome/browser/chromeos/drive/drive_file_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698