OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
James Cook
2016/10/18 23:53:40
nit: I don't think you need to update this.
msw
2016/10/19 15:24:10
Done.
| |
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" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 9 #include "chrome/browser/chromeos/accessibility/accessibility_manager.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 "chrome/grit/browser_resources.h" | 11 #include "chrome/grit/browser_resources.h" |
12 #include "chromeos/audio/chromeos_sounds.h" | 12 #include "chromeos/audio/chromeos_sounds.h" |
13 #include "chromeos/chromeos_switches.h" | 13 #include "chromeos/chromeos_switches.h" |
14 #include "content/public/browser/user_metrics.h" | 14 #include "content/public/browser/user_metrics.h" |
James Cook
2016/10/18 23:53:40
nit: remove?
msw
2016/10/19 15:24:10
Done.
| |
15 #include "media/audio/sounds/sounds_manager.h" | 15 #include "media/audio/sounds/sounds_manager.h" |
16 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
17 | 17 |
18 using chromeos::CrasAudioHandler; | 18 using chromeos::CrasAudioHandler; |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // 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. |
23 const double kStepPercentage = 4.0; | 23 const double kStepPercentage = 4.0; |
24 | 24 |
(...skipping 20 matching lines...) Expand all Loading... | |
45 chromeos::SOUND_VOLUME_ADJUST, | 45 chromeos::SOUND_VOLUME_ADJUST, |
46 bundle.GetRawDataResource(IDR_SOUND_VOLUME_ADJUST_WAV)); | 46 bundle.GetRawDataResource(IDR_SOUND_VOLUME_ADJUST_WAV)); |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
50 VolumeController::~VolumeController() { | 50 VolumeController::~VolumeController() { |
51 if (CrasAudioHandler::IsInitialized()) | 51 if (CrasAudioHandler::IsInitialized()) |
52 CrasAudioHandler::Get()->RemoveAudioObserver(this); | 52 CrasAudioHandler::Get()->RemoveAudioObserver(this); |
53 } | 53 } |
54 | 54 |
55 void VolumeController::HandleVolumeMute(const ui::Accelerator& accelerator) { | 55 void VolumeController::BindRequest( |
56 if (accelerator.key_code() == ui::VKEY_VOLUME_MUTE) | 56 ash::mojom::VolumeControllerRequest request) { |
57 content::RecordAction(base::UserMetricsAction("Accel_VolumeMute_F8")); | 57 bindings_.AddBinding(this, std::move(request)); |
58 } | |
58 | 59 |
60 void VolumeController::VolumeMute() { | |
59 CrasAudioHandler::Get()->SetOutputMute(true); | 61 CrasAudioHandler::Get()->SetOutputMute(true); |
60 } | 62 } |
61 | 63 |
62 void VolumeController::HandleVolumeDown(const ui::Accelerator& accelerator) { | 64 void VolumeController::VolumeDown() { |
63 if (accelerator.key_code() == ui::VKEY_VOLUME_DOWN) | |
64 content::RecordAction(base::UserMetricsAction("Accel_VolumeDown_F9")); | |
65 | |
66 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); | 65 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); |
67 if (audio_handler->IsOutputMuted()) { | 66 if (audio_handler->IsOutputMuted()) { |
68 audio_handler->SetOutputVolumePercent(0); | 67 audio_handler->SetOutputVolumePercent(0); |
69 } else { | 68 } else { |
70 audio_handler->AdjustOutputVolumeByPercent(-kStepPercentage); | 69 audio_handler->AdjustOutputVolumeByPercent(-kStepPercentage); |
71 if (audio_handler->IsOutputVolumeBelowDefaultMuteLevel()) | 70 if (audio_handler->IsOutputVolumeBelowDefaultMuteLevel()) |
72 audio_handler->SetOutputMute(true); | 71 audio_handler->SetOutputMute(true); |
73 else | 72 else |
74 PlayVolumeAdjustSound(); | 73 PlayVolumeAdjustSound(); |
75 } | 74 } |
76 } | 75 } |
77 | 76 |
78 void VolumeController::HandleVolumeUp(const ui::Accelerator& accelerator) { | 77 void VolumeController::VolumeUp() { |
79 if (accelerator.key_code() == ui::VKEY_VOLUME_UP) | |
80 content::RecordAction(base::UserMetricsAction("Accel_VolumeUp_F10")); | |
81 | |
82 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); | 78 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); |
83 bool play_sound = false; | 79 bool play_sound = false; |
84 if (audio_handler->IsOutputMuted()) { | 80 if (audio_handler->IsOutputMuted()) { |
85 audio_handler->SetOutputMute(false); | 81 audio_handler->SetOutputMute(false); |
86 audio_handler->AdjustOutputVolumeToAudibleLevel(); | 82 audio_handler->AdjustOutputVolumeToAudibleLevel(); |
87 play_sound = true; | 83 play_sound = true; |
88 } else { | 84 } else { |
89 play_sound = audio_handler->GetOutputVolumePercent() != 100; | 85 play_sound = audio_handler->GetOutputVolumePercent() != 100; |
90 audio_handler->AdjustOutputVolumeByPercent(kStepPercentage); | 86 audio_handler->AdjustOutputVolumeByPercent(kStepPercentage); |
91 } | 87 } |
92 | 88 |
93 if (play_sound) | 89 if (play_sound) |
94 PlayVolumeAdjustSound(); | 90 PlayVolumeAdjustSound(); |
95 } | 91 } |
96 | 92 |
97 void VolumeController::OnOutputNodeVolumeChanged(uint64_t node_id, int volume) { | 93 void VolumeController::OnOutputNodeVolumeChanged(uint64_t node_id, int volume) { |
98 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); | 94 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); |
99 extensions::DispatchVolumeChangedEvent( | 95 extensions::DispatchVolumeChangedEvent( |
100 audio_handler->GetOutputVolumePercent(), | 96 audio_handler->GetOutputVolumePercent(), |
101 audio_handler->IsOutputMuted()); | 97 audio_handler->IsOutputMuted()); |
102 } | 98 } |
103 | 99 |
104 void VolumeController::OnOutputMuteChanged(bool /* mute_on */, | 100 void VolumeController::OnOutputMuteChanged(bool /* mute_on */, |
105 bool /* system_adjust */) { | 101 bool /* system_adjust */) { |
106 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); | 102 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); |
107 extensions::DispatchVolumeChangedEvent( | 103 extensions::DispatchVolumeChangedEvent( |
108 audio_handler->GetOutputVolumePercent(), | 104 audio_handler->GetOutputVolumePercent(), |
109 audio_handler->IsOutputMuted()); | 105 audio_handler->IsOutputMuted()); |
110 } | 106 } |
OLD | NEW |