Pepper: Fix PPB_TrueTypeFont GetFontsInFamily function.
[chromium-blink-merge.git] / extensions / shell / browser / shell_audio_controller_chromeos.cc
blob760da0502650e1639485fdf6725b44f7221fc2f0
1 // Copyright 2014 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.
5 #include "extensions/shell/browser/shell_audio_controller_chromeos.h"
7 #include <algorithm>
9 #include "chromeos/audio/audio_device.h"
11 namespace extensions {
13 namespace {
15 // Returns a pointer to the device in |devices| with ID |node_id|, or NULL if it
16 // isn't present.
17 const chromeos::AudioDevice* GetDevice(const chromeos::AudioDeviceList& devices,
18 uint64 node_id) {
19 for (chromeos::AudioDeviceList::const_iterator it = devices.begin();
20 it != devices.end(); ++it) {
21 if (it->id == node_id)
22 return &(*it);
24 return NULL;
27 } // namespace
29 ShellAudioController::ShellAudioController() {
30 chromeos::CrasAudioHandler::Get()->AddAudioObserver(this);
31 ActivateDevices();
34 ShellAudioController::~ShellAudioController() {
35 chromeos::CrasAudioHandler::Get()->RemoveAudioObserver(this);
38 void ShellAudioController::OnOutputVolumeChanged() {}
40 void ShellAudioController::OnOutputMuteChanged() {}
42 void ShellAudioController::OnInputGainChanged() {}
44 void ShellAudioController::OnInputMuteChanged() {}
46 void ShellAudioController::OnAudioNodesChanged() {
47 VLOG(1) << "Audio nodes changed";
48 ActivateDevices();
51 void ShellAudioController::OnActiveOutputNodeChanged() {}
53 void ShellAudioController::OnActiveInputNodeChanged() {}
55 void ShellAudioController::ActivateDevices() {
56 chromeos::CrasAudioHandler* handler = chromeos::CrasAudioHandler::Get();
57 chromeos::AudioDeviceList devices;
58 handler->GetAudioDevices(&devices);
59 sort(devices.begin(), devices.end(), chromeos::AudioDeviceCompare());
61 uint64 best_input = 0, best_output = 0;
62 for (chromeos::AudioDeviceList::const_reverse_iterator it = devices.rbegin();
63 it != devices.rend() && (!best_input || !best_output); ++it) {
64 // TODO(derat): Need to check |plugged_time|?
65 if (it->is_input && !best_input)
66 best_input = it->id;
67 else if (!it->is_input && !best_output)
68 best_output = it->id;
71 if (best_input && best_input != handler->GetPrimaryActiveInputNode()) {
72 const chromeos::AudioDevice* device = GetDevice(devices, best_input);
73 DCHECK(device);
74 VLOG(1) << "Activating input device: " << device->ToString();
75 handler->SwitchToDevice(*device, true);
77 if (best_output && best_output != handler->GetPrimaryActiveOutputNode()) {
78 const chromeos::AudioDevice* device = GetDevice(devices, best_output);
79 DCHECK(device);
80 VLOG(1) << "Activating output device: " << device->ToString();
81 handler->SwitchToDevice(*device, true);
85 } // namespace extensions