OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/ash/volume_controller_chromeos.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | |
9 #include "chrome/grit/browser_resources.h" | |
10 #include "chromeos/audio/chromeos_sounds.h" | |
11 #include "chromeos/audio/cras_audio_handler.h" | |
12 #include "chromeos/chromeos_switches.h" | |
13 #include "media/audio/sounds/sounds_manager.h" | |
14 #include "ui/base/resource/resource_bundle.h" | |
15 | |
16 namespace { | |
17 | |
18 // Percent by which the volume should be changed when a volume key is pressed. | |
19 const double kStepPercentage = 4.0; | |
20 | |
21 bool VolumeAdjustSoundEnabled() { | |
22 return !base::CommandLine::ForCurrentProcess()->HasSwitch( | |
23 chromeos::switches::kDisableVolumeAdjustSound); | |
24 } | |
25 | |
26 void PlayVolumeAdjustSound() { | |
27 if (VolumeAdjustSoundEnabled()) { | |
28 chromeos::AccessibilityManager::Get()->PlayEarcon( | |
29 chromeos::SOUND_VOLUME_ADJUST, | |
30 chromeos::PlaySoundOption::SPOKEN_FEEDBACK_ENABLED); | |
31 } | |
32 } | |
33 | |
34 } // namespace | |
35 | |
36 VolumeController::VolumeController() { | |
37 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
38 if (VolumeAdjustSoundEnabled()) { | |
39 media::SoundsManager::Get()->Initialize( | |
40 chromeos::SOUND_VOLUME_ADJUST, | |
41 bundle.GetRawDataResource(IDR_SOUND_VOLUME_ADJUST_WAV)); | |
42 } | |
43 } | |
44 | |
45 VolumeController::~VolumeController() {} | |
46 | |
47 void VolumeController::BindRequest( | |
48 ash::mojom::VolumeControllerRequest request) { | |
49 bindings_.AddBinding(this, std::move(request)); | |
50 } | |
51 | |
52 void VolumeController::VolumeMute() { | |
53 chromeos::CrasAudioHandler::Get()->SetOutputMute(true); | |
54 } | |
55 | |
56 void VolumeController::VolumeDown() { | |
57 chromeos::CrasAudioHandler* audio_handler = chromeos::CrasAudioHandler::Get(); | |
58 if (audio_handler->IsOutputMuted()) { | |
59 audio_handler->SetOutputVolumePercent(0); | |
60 } else { | |
61 audio_handler->AdjustOutputVolumeByPercent(-kStepPercentage); | |
62 if (audio_handler->IsOutputVolumeBelowDefaultMuteLevel()) | |
63 audio_handler->SetOutputMute(true); | |
64 else | |
65 PlayVolumeAdjustSound(); | |
66 } | |
67 } | |
68 | |
69 void VolumeController::VolumeUp() { | |
70 chromeos::CrasAudioHandler* audio_handler = chromeos::CrasAudioHandler::Get(); | |
71 bool play_sound = false; | |
72 if (audio_handler->IsOutputMuted()) { | |
73 audio_handler->SetOutputMute(false); | |
74 audio_handler->AdjustOutputVolumeToAudibleLevel(); | |
75 play_sound = true; | |
76 } else { | |
77 play_sound = audio_handler->GetOutputVolumePercent() != 100; | |
78 audio_handler->AdjustOutputVolumeByPercent(kStepPercentage); | |
79 } | |
80 | |
81 if (play_sound) | |
82 PlayVolumeAdjustSound(); | |
83 } | |
OLD | NEW |