OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/extensions/extension_volume_observer.h" |
| 6 |
| 7 #include "chrome/browser/extensions/api/system_private/system_private_api.h" |
| 8 #include "chromeos/audio/cras_audio_handler.h" |
| 9 |
| 10 namespace chromeos { |
| 11 |
| 12 namespace { |
| 13 |
| 14 // A helper to call the corresponding extensions method. |
| 15 void DispatchVolumeChangedEvent() { |
| 16 CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); |
| 17 extensions::DispatchVolumeChangedEvent( |
| 18 audio_handler->GetOutputVolumePercent(), audio_handler->IsOutputMuted()); |
| 19 } |
| 20 |
| 21 } // namespace |
| 22 |
| 23 ExtensionVolumeObserver::ExtensionVolumeObserver() { |
| 24 CrasAudioHandler::Get()->AddAudioObserver(this); |
| 25 } |
| 26 |
| 27 ExtensionVolumeObserver::~ExtensionVolumeObserver() { |
| 28 if (CrasAudioHandler::IsInitialized()) |
| 29 CrasAudioHandler::Get()->RemoveAudioObserver(this); |
| 30 } |
| 31 |
| 32 void ExtensionVolumeObserver::OnOutputNodeVolumeChanged(uint64_t node_id, |
| 33 int volume) { |
| 34 DispatchVolumeChangedEvent(); |
| 35 } |
| 36 |
| 37 void ExtensionVolumeObserver::OnOutputMuteChanged(bool /* mute_on */, |
| 38 bool /* system_adjust */) { |
| 39 DispatchVolumeChangedEvent(); |
| 40 } |
| 41 |
| 42 } // namespace chromeos |
OLD | NEW |