| 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/ui/ash/volume_controller_chromeos.h" | 5 #include "chrome/browser/ui/ash/volume_controller_chromeos.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/browser_process.h" | |
| 9 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 8 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 10 #include "chrome/browser/extensions/api/system_private/system_private_api.h" | |
| 11 #include "chrome/grit/browser_resources.h" | 9 #include "chrome/grit/browser_resources.h" |
| 12 #include "chromeos/audio/chromeos_sounds.h" | 10 #include "chromeos/audio/chromeos_sounds.h" |
| 11 #include "chromeos/audio/cras_audio_handler.h" |
| 13 #include "chromeos/chromeos_switches.h" | 12 #include "chromeos/chromeos_switches.h" |
| 14 #include "content/public/browser/user_metrics.h" | |
| 15 #include "media/audio/sounds/sounds_manager.h" | 13 #include "media/audio/sounds/sounds_manager.h" |
| 16 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
| 17 | 15 |
| 18 using chromeos::CrasAudioHandler; | |
| 19 | |
| 20 namespace { | 16 namespace { |
| 21 | 17 |
| 22 // Percent by which the volume should be changed when a volume key is pressed. | 18 // Percent by which the volume should be changed when a volume key is pressed. |
| 23 const double kStepPercentage = 4.0; | 19 const double kStepPercentage = 4.0; |
| 24 | 20 |
| 25 bool VolumeAdjustSoundEnabled() { | 21 bool VolumeAdjustSoundEnabled() { |
| 26 return !base::CommandLine::ForCurrentProcess()->HasSwitch( | 22 return !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 27 chromeos::switches::kDisableVolumeAdjustSound); | 23 chromeos::switches::kDisableVolumeAdjustSound); |
| 28 } | 24 } |
| 29 | 25 |
| 30 void PlayVolumeAdjustSound() { | 26 void PlayVolumeAdjustSound() { |
| 31 if (VolumeAdjustSoundEnabled()) { | 27 if (VolumeAdjustSoundEnabled()) { |
| 32 chromeos::AccessibilityManager::Get()->PlayEarcon( | 28 chromeos::AccessibilityManager::Get()->PlayEarcon( |
| 33 chromeos::SOUND_VOLUME_ADJUST, | 29 chromeos::SOUND_VOLUME_ADJUST, |
| 34 chromeos::PlaySoundOption::SPOKEN_FEEDBACK_ENABLED); | 30 chromeos::PlaySoundOption::SPOKEN_FEEDBACK_ENABLED); |
| 35 } | 31 } |
| 36 } | 32 } |
| 37 | 33 |
| 38 } // namespace | 34 } // namespace |
| 39 | 35 |
| 40 VolumeController::VolumeController() { | 36 VolumeController::VolumeController() { |
| 41 CrasAudioHandler::Get()->AddAudioObserver(this); | |
| 42 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 37 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 43 if (VolumeAdjustSoundEnabled()) { | 38 if (VolumeAdjustSoundEnabled()) { |
| 44 media::SoundsManager::Get()->Initialize( | 39 media::SoundsManager::Get()->Initialize( |
| 45 chromeos::SOUND_VOLUME_ADJUST, | 40 chromeos::SOUND_VOLUME_ADJUST, |
| 46 bundle.GetRawDataResource(IDR_SOUND_VOLUME_ADJUST_WAV)); | 41 bundle.GetRawDataResource(IDR_SOUND_VOLUME_ADJUST_WAV)); |
| 47 } | 42 } |
| 48 } | 43 } |
| 49 | 44 |
| 50 VolumeController::~VolumeController() { | 45 VolumeController::~VolumeController() {} |
| 51 if (CrasAudioHandler::IsInitialized()) | 46 |
| 52 CrasAudioHandler::Get()->RemoveAudioObserver(this); | 47 void VolumeController::BindRequest( |
| 48 ash::mojom::VolumeControllerRequest request) { |
| 49 bindings_.AddBinding(this, std::move(request)); |
| 53 } | 50 } |
| 54 | 51 |
| 55 void VolumeController::HandleVolumeMute(const ui::Accelerator& accelerator) { | 52 void VolumeController::VolumeMute() { |
| 56 if (accelerator.key_code() == ui::VKEY_VOLUME_MUTE) | 53 chromeos::CrasAudioHandler::Get()->SetOutputMute(true); |
| 57 content::RecordAction(base::UserMetricsAction("Accel_VolumeMute_F8")); | |
| 58 | |
| 59 CrasAudioHandler::Get()->SetOutputMute(true); | |
| 60 } | 54 } |
| 61 | 55 |
| 62 void VolumeController::HandleVolumeDown(const ui::Accelerator& accelerator) { | 56 void VolumeController::VolumeDown() { |
| 63 if (accelerator.key_code() == ui::VKEY_VOLUME_DOWN) | 57 chromeos::CrasAudioHandler* audio_handler = chromeos::CrasAudioHandler::Get(); |
| 64 content::RecordAction(base::UserMetricsAction("Accel_VolumeDown_F9")); | |
| 65 | |
| 66 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); | |
| 67 if (audio_handler->IsOutputMuted()) { | 58 if (audio_handler->IsOutputMuted()) { |
| 68 audio_handler->SetOutputVolumePercent(0); | 59 audio_handler->SetOutputVolumePercent(0); |
| 69 } else { | 60 } else { |
| 70 audio_handler->AdjustOutputVolumeByPercent(-kStepPercentage); | 61 audio_handler->AdjustOutputVolumeByPercent(-kStepPercentage); |
| 71 if (audio_handler->IsOutputVolumeBelowDefaultMuteLevel()) | 62 if (audio_handler->IsOutputVolumeBelowDefaultMuteLevel()) |
| 72 audio_handler->SetOutputMute(true); | 63 audio_handler->SetOutputMute(true); |
| 73 else | 64 else |
| 74 PlayVolumeAdjustSound(); | 65 PlayVolumeAdjustSound(); |
| 75 } | 66 } |
| 76 } | 67 } |
| 77 | 68 |
| 78 void VolumeController::HandleVolumeUp(const ui::Accelerator& accelerator) { | 69 void VolumeController::VolumeUp() { |
| 79 if (accelerator.key_code() == ui::VKEY_VOLUME_UP) | 70 chromeos::CrasAudioHandler* audio_handler = chromeos::CrasAudioHandler::Get(); |
| 80 content::RecordAction(base::UserMetricsAction("Accel_VolumeUp_F10")); | |
| 81 | |
| 82 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); | |
| 83 bool play_sound = false; | 71 bool play_sound = false; |
| 84 if (audio_handler->IsOutputMuted()) { | 72 if (audio_handler->IsOutputMuted()) { |
| 85 audio_handler->SetOutputMute(false); | 73 audio_handler->SetOutputMute(false); |
| 86 audio_handler->AdjustOutputVolumeToAudibleLevel(); | 74 audio_handler->AdjustOutputVolumeToAudibleLevel(); |
| 87 play_sound = true; | 75 play_sound = true; |
| 88 } else { | 76 } else { |
| 89 play_sound = audio_handler->GetOutputVolumePercent() != 100; | 77 play_sound = audio_handler->GetOutputVolumePercent() != 100; |
| 90 audio_handler->AdjustOutputVolumeByPercent(kStepPercentage); | 78 audio_handler->AdjustOutputVolumeByPercent(kStepPercentage); |
| 91 } | 79 } |
| 92 | 80 |
| 93 if (play_sound) | 81 if (play_sound) |
| 94 PlayVolumeAdjustSound(); | 82 PlayVolumeAdjustSound(); |
| 95 } | 83 } |
| 96 | |
| 97 void VolumeController::OnOutputNodeVolumeChanged(uint64_t node_id, int volume) { | |
| 98 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); | |
| 99 extensions::DispatchVolumeChangedEvent( | |
| 100 audio_handler->GetOutputVolumePercent(), | |
| 101 audio_handler->IsOutputMuted()); | |
| 102 } | |
| 103 | |
| 104 void VolumeController::OnOutputMuteChanged(bool /* mute_on */, | |
| 105 bool /* system_adjust */) { | |
| 106 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); | |
| 107 extensions::DispatchVolumeChangedEvent( | |
| 108 audio_handler->GetOutputVolumePercent(), | |
| 109 audio_handler->IsOutputMuted()); | |
| 110 } | |
| OLD | NEW |