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