| 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 "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/chromeos/audio/audio_handler.h" | 9 #include "chrome/browser/chromeos/audio/audio_handler.h" |
| 10 #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 "content/public/browser/user_metrics.h" | 11 #include "content/public/browser/user_metrics.h" |
| 12 | 12 |
| 13 using chromeos::CrasAudioHandler; |
| 14 |
| 13 namespace { | 15 namespace { |
| 14 | 16 |
| 15 // Percent by which the volume should be changed when a volume key is pressed. | 17 // Percent by which the volume should be changed when a volume key is pressed. |
| 16 const double kStepPercentage = 4.0; | 18 const double kStepPercentage = 4.0; |
| 17 | 19 |
| 18 } // namespace | 20 } // namespace |
| 19 | 21 |
| 20 VolumeController::VolumeController() { | 22 VolumeController::VolumeController() { |
| 21 if (ash::switches::UseNewAudioHandler()) | 23 if (ash::switches::UseNewAudioHandler()) |
| 22 chromeos::CrasAudioHandler::Get()->AddAudioObserver(this); | 24 CrasAudioHandler::Get()->AddAudioObserver(this); |
| 23 } | 25 } |
| 24 | 26 |
| 25 VolumeController::~VolumeController() { | 27 VolumeController::~VolumeController() { |
| 26 if (ash::switches::UseNewAudioHandler() && | 28 if (ash::switches::UseNewAudioHandler() && CrasAudioHandler::IsInitialized()) |
| 27 chromeos::CrasAudioHandler::IsInitialized()) | 29 CrasAudioHandler::Get()->RemoveAudioObserver(this); |
| 28 chromeos::CrasAudioHandler::Get()->RemoveAudioObserver(this); | |
| 29 } | 30 } |
| 30 | 31 |
| 31 bool VolumeController::HandleVolumeMute(const ui::Accelerator& accelerator) { | 32 bool VolumeController::HandleVolumeMute(const ui::Accelerator& accelerator) { |
| 32 if (accelerator.key_code() == ui::VKEY_VOLUME_MUTE) | 33 if (accelerator.key_code() == ui::VKEY_VOLUME_MUTE) |
| 33 content::RecordAction(content::UserMetricsAction("Accel_VolumeMute_F8")); | 34 content::RecordAction(content::UserMetricsAction("Accel_VolumeMute_F8")); |
| 34 | 35 |
| 35 if (ash::switches::UseNewAudioHandler()) { | 36 if (ash::switches::UseNewAudioHandler()) { |
| 36 chromeos::CrasAudioHandler::Get()->SetOutputMute(true); | 37 CrasAudioHandler::Get()->SetOutputMute(true); |
| 37 return true; | 38 return true; |
| 38 } | 39 } |
| 39 | 40 |
| 40 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance(); | 41 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance(); |
| 41 | 42 |
| 42 // Always muting (and not toggling) as per final decision on | 43 // Always muting (and not toggling) as per final decision on |
| 43 // http://crosbug.com/3751 | 44 // http://crosbug.com/3751 |
| 44 audio_handler->SetMuted(true); | 45 audio_handler->SetMuted(true); |
| 45 | 46 |
| 46 extensions::DispatchVolumeChangedEvent(audio_handler->GetVolumePercent(), | 47 extensions::DispatchVolumeChangedEvent(audio_handler->GetVolumePercent(), |
| 47 audio_handler->IsMuted()); | 48 audio_handler->IsMuted()); |
| 48 return true; | 49 return true; |
| 49 } | 50 } |
| 50 | 51 |
| 51 bool VolumeController::HandleVolumeDown(const ui::Accelerator& accelerator) { | 52 bool VolumeController::HandleVolumeDown(const ui::Accelerator& accelerator) { |
| 52 if (accelerator.key_code() == ui::VKEY_VOLUME_DOWN) | 53 if (accelerator.key_code() == ui::VKEY_VOLUME_DOWN) |
| 53 content::RecordAction(content::UserMetricsAction("Accel_VolumeDown_F9")); | 54 content::RecordAction(content::UserMetricsAction("Accel_VolumeDown_F9")); |
| 54 | 55 |
| 55 if (ash::switches::UseNewAudioHandler()) { | 56 if (ash::switches::UseNewAudioHandler()) { |
| 56 chromeos::CrasAudioHandler* audio_handler = | 57 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); |
| 57 chromeos::CrasAudioHandler::Get(); | 58 |
| 58 if (audio_handler->IsOutputMuted()) | 59 if (audio_handler->IsOutputMuted()) { |
| 59 audio_handler->SetOutputVolumePercent(0); | 60 audio_handler->SetOutputVolumePercent(0); |
| 60 else | 61 } else { |
| 61 audio_handler->AdjustOutputVolumeByPercent(-kStepPercentage); | 62 audio_handler->AdjustOutputVolumeByPercent(-kStepPercentage); |
| 63 if (audio_handler->IsOutputVolumeBelowDefaultMuteLvel()) |
| 64 audio_handler->SetOutputMute(true); |
| 65 } |
| 62 return true; | 66 return true; |
| 63 } | 67 } |
| 64 | 68 |
| 65 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance(); | 69 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance(); |
| 66 if (audio_handler->IsMuted()) | 70 if (audio_handler->IsMuted()) |
| 67 audio_handler->SetVolumePercent(0.0); | 71 audio_handler->SetVolumePercent(0.0); |
| 68 else | 72 else |
| 69 audio_handler->AdjustVolumeByPercent(-kStepPercentage); | 73 audio_handler->AdjustVolumeByPercent(-kStepPercentage); |
| 70 | 74 |
| 71 extensions::DispatchVolumeChangedEvent(audio_handler->GetVolumePercent(), | 75 extensions::DispatchVolumeChangedEvent(audio_handler->GetVolumePercent(), |
| 72 audio_handler->IsMuted()); | 76 audio_handler->IsMuted()); |
| 73 return true; | 77 return true; |
| 74 } | 78 } |
| 75 | 79 |
| 76 bool VolumeController::HandleVolumeUp(const ui::Accelerator& accelerator) { | 80 bool VolumeController::HandleVolumeUp(const ui::Accelerator& accelerator) { |
| 77 if (accelerator.key_code() == ui::VKEY_VOLUME_UP) | 81 if (accelerator.key_code() == ui::VKEY_VOLUME_UP) |
| 78 content::RecordAction(content::UserMetricsAction("Accel_VolumeUp_F10")); | 82 content::RecordAction(content::UserMetricsAction("Accel_VolumeUp_F10")); |
| 79 | 83 |
| 80 if (ash::switches::UseNewAudioHandler()) { | 84 if (ash::switches::UseNewAudioHandler()) { |
| 81 chromeos::CrasAudioHandler* audio_handler = | 85 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); |
| 82 chromeos::CrasAudioHandler::Get(); | 86 |
| 83 if (audio_handler->IsOutputMuted()) | 87 if (audio_handler->IsOutputMuted()) |
| 84 audio_handler->SetOutputMute(false); | 88 audio_handler->SetOutputMute(false); |
| 85 else | 89 audio_handler->AdjustOutputVolumeByPercent(kStepPercentage); |
| 86 audio_handler->AdjustOutputVolumeByPercent(kStepPercentage); | |
| 87 return true; | 90 return true; |
| 88 } | 91 } |
| 89 | 92 |
| 90 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance(); | 93 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance(); |
| 91 if (audio_handler->IsMuted()) { | 94 if (audio_handler->IsMuted()) { |
| 92 audio_handler->SetMuted(false); | 95 audio_handler->SetMuted(false); |
| 93 } else { | 96 } else { |
| 94 audio_handler->AdjustVolumeByPercent(kStepPercentage); | 97 audio_handler->AdjustVolumeByPercent(kStepPercentage); |
| 95 } | 98 } |
| 96 | 99 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 123 void VolumeController::SetVolumePercent(double percent) { | 126 void VolumeController::SetVolumePercent(double percent) { |
| 124 DCHECK(!ash::switches::UseNewAudioHandler()); | 127 DCHECK(!ash::switches::UseNewAudioHandler()); |
| 125 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance(); | 128 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance(); |
| 126 audio_handler->SetVolumePercent(percent); | 129 audio_handler->SetVolumePercent(percent); |
| 127 extensions::DispatchVolumeChangedEvent(audio_handler->GetVolumePercent(), | 130 extensions::DispatchVolumeChangedEvent(audio_handler->GetVolumePercent(), |
| 128 audio_handler->IsMuted()); | 131 audio_handler->IsMuted()); |
| 129 } | 132 } |
| 130 | 133 |
| 131 void VolumeController::OnOutputVolumeChanged() { | 134 void VolumeController::OnOutputVolumeChanged() { |
| 132 DCHECK(ash::switches::UseNewAudioHandler()); | 135 DCHECK(ash::switches::UseNewAudioHandler()); |
| 133 chromeos::CrasAudioHandler* audio_handler = chromeos::CrasAudioHandler::Get(); | 136 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); |
| 134 extensions::DispatchVolumeChangedEvent( | 137 extensions::DispatchVolumeChangedEvent( |
| 135 audio_handler->GetOutputVolumePercent(), | 138 audio_handler->GetOutputVolumePercent(), |
| 136 audio_handler->IsOutputMuted()); | 139 audio_handler->IsOutputMuted()); |
| 137 } | 140 } |
| 138 | 141 |
| 139 void VolumeController::OnOutputMuteChanged() { | 142 void VolumeController::OnOutputMuteChanged() { |
| 140 DCHECK(ash::switches::UseNewAudioHandler()); | 143 DCHECK(ash::switches::UseNewAudioHandler()); |
| 141 chromeos::CrasAudioHandler* audio_handler = chromeos::CrasAudioHandler::Get(); | 144 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); |
| 142 extensions::DispatchVolumeChangedEvent( | 145 extensions::DispatchVolumeChangedEvent( |
| 143 audio_handler->GetOutputVolumePercent(), | 146 audio_handler->GetOutputVolumePercent(), |
| 144 audio_handler->IsOutputMuted()); | 147 audio_handler->IsOutputMuted()); |
| 145 } | 148 } |
| OLD | NEW |