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