| 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.h" |
| 6 | 6 |
| 7 #include "ash/public/interfaces/accelerator_controller.mojom.h" |
| 7 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 8 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 9 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 10 #include "chrome/browser/ui/ash/ash_util.h" |
| 9 #include "chrome/grit/browser_resources.h" | 11 #include "chrome/grit/browser_resources.h" |
| 10 #include "chromeos/audio/chromeos_sounds.h" | 12 #include "chromeos/audio/chromeos_sounds.h" |
| 11 #include "chromeos/audio/cras_audio_handler.h" | 13 #include "chromeos/audio/cras_audio_handler.h" |
| 12 #include "chromeos/chromeos_switches.h" | 14 #include "chromeos/chromeos_switches.h" |
| 15 #include "content/public/common/service_manager_connection.h" |
| 13 #include "media/audio/sounds/sounds_manager.h" | 16 #include "media/audio/sounds/sounds_manager.h" |
| 17 #include "services/service_manager/public/cpp/connector.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 15 | 19 |
| 16 namespace { | 20 namespace { |
| 17 | 21 |
| 18 // 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. |
| 19 const double kStepPercentage = 4.0; | 23 const double kStepPercentage = 4.0; |
| 20 | 24 |
| 21 bool VolumeAdjustSoundEnabled() { | 25 bool VolumeAdjustSoundEnabled() { |
| 22 return !base::CommandLine::ForCurrentProcess()->HasSwitch( | 26 return !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 23 chromeos::switches::kDisableVolumeAdjustSound); | 27 chromeos::switches::kDisableVolumeAdjustSound); |
| 24 } | 28 } |
| 25 | 29 |
| 26 void PlayVolumeAdjustSound() { | 30 void PlayVolumeAdjustSound() { |
| 27 if (VolumeAdjustSoundEnabled()) { | 31 if (VolumeAdjustSoundEnabled()) { |
| 28 chromeos::AccessibilityManager::Get()->PlayEarcon( | 32 chromeos::AccessibilityManager::Get()->PlayEarcon( |
| 29 chromeos::SOUND_VOLUME_ADJUST, | 33 chromeos::SOUND_VOLUME_ADJUST, |
| 30 chromeos::PlaySoundOption::SPOKEN_FEEDBACK_ENABLED); | 34 chromeos::PlaySoundOption::SPOKEN_FEEDBACK_ENABLED); |
| 31 } | 35 } |
| 32 } | 36 } |
| 33 | 37 |
| 34 } // namespace | 38 } // namespace |
| 35 | 39 |
| 36 VolumeController::VolumeController() { | 40 VolumeController::VolumeController() : binding_(this) { |
| 37 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 41 // Connect to the accelerator controller interface in the ash service. |
| 42 service_manager::Connector* connector = |
| 43 content::ServiceManagerConnection::GetForProcess()->GetConnector(); |
| 44 ash::mojom::AcceleratorControllerPtr accelerator_controller_ptr; |
| 45 connector->ConnectToInterface(ash_util::GetAshServiceName(), |
| 46 &accelerator_controller_ptr); |
| 47 |
| 48 // Register this object as the volume controller. |
| 49 accelerator_controller_ptr->SetVolumeController( |
| 50 binding_.CreateInterfacePtrAndBind()); |
| 51 |
| 38 if (VolumeAdjustSoundEnabled()) { | 52 if (VolumeAdjustSoundEnabled()) { |
| 53 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 39 media::SoundsManager::Get()->Initialize( | 54 media::SoundsManager::Get()->Initialize( |
| 40 chromeos::SOUND_VOLUME_ADJUST, | 55 chromeos::SOUND_VOLUME_ADJUST, |
| 41 bundle.GetRawDataResource(IDR_SOUND_VOLUME_ADJUST_WAV)); | 56 bundle.GetRawDataResource(IDR_SOUND_VOLUME_ADJUST_WAV)); |
| 42 } | 57 } |
| 43 } | 58 } |
| 44 | 59 |
| 45 VolumeController::~VolumeController() {} | 60 VolumeController::~VolumeController() {} |
| 46 | 61 |
| 47 void VolumeController::BindRequest( | |
| 48 ash::mojom::VolumeControllerRequest request) { | |
| 49 bindings_.AddBinding(this, std::move(request)); | |
| 50 } | |
| 51 | |
| 52 void VolumeController::VolumeMute() { | 62 void VolumeController::VolumeMute() { |
| 53 chromeos::CrasAudioHandler::Get()->SetOutputMute(true); | 63 chromeos::CrasAudioHandler::Get()->SetOutputMute(true); |
| 54 } | 64 } |
| 55 | 65 |
| 56 void VolumeController::VolumeDown() { | 66 void VolumeController::VolumeDown() { |
| 57 chromeos::CrasAudioHandler* audio_handler = chromeos::CrasAudioHandler::Get(); | 67 chromeos::CrasAudioHandler* audio_handler = chromeos::CrasAudioHandler::Get(); |
| 58 if (audio_handler->IsOutputMuted()) { | 68 if (audio_handler->IsOutputMuted()) { |
| 59 audio_handler->SetOutputVolumePercent(0); | 69 audio_handler->SetOutputVolumePercent(0); |
| 60 } else { | 70 } else { |
| 61 audio_handler->AdjustOutputVolumeByPercent(-kStepPercentage); | 71 audio_handler->AdjustOutputVolumeByPercent(-kStepPercentage); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 74 audio_handler->AdjustOutputVolumeToAudibleLevel(); | 84 audio_handler->AdjustOutputVolumeToAudibleLevel(); |
| 75 play_sound = true; | 85 play_sound = true; |
| 76 } else { | 86 } else { |
| 77 play_sound = audio_handler->GetOutputVolumePercent() != 100; | 87 play_sound = audio_handler->GetOutputVolumePercent() != 100; |
| 78 audio_handler->AdjustOutputVolumeByPercent(kStepPercentage); | 88 audio_handler->AdjustOutputVolumeByPercent(kStepPercentage); |
| 79 } | 89 } |
| 80 | 90 |
| 81 if (play_sound) | 91 if (play_sound) |
| 82 PlayVolumeAdjustSound(); | 92 PlayVolumeAdjustSound(); |
| 83 } | 93 } |
| OLD | NEW |