Finish refactoring of DomCodeToUsLayoutKeyboardCode().
[chromium-blink-merge.git] / extensions / browser / api / audio / audio_service.h
blob41da2bd202a2a3f6d817daf774a833cc4ec04a3f
1 // Copyright (c) 2013 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 #ifndef EXTENSIONS_BROWSER_API_AUDIO_AUDIO_SERVICE_H_
6 #define EXTENSIONS_BROWSER_API_AUDIO_AUDIO_SERVICE_H_
8 #include <string>
9 #include <vector>
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "base/memory/linked_ptr.h"
14 #include "extensions/common/api/audio.h"
16 namespace extensions {
18 using OutputInfo = std::vector<linked_ptr<core_api::audio::OutputDeviceInfo>>;
19 using InputInfo = std::vector<linked_ptr<core_api::audio::InputDeviceInfo>>;
20 using DeviceIdList = std::vector<std::string>;
21 using DeviceInfoList =
22 std::vector<linked_ptr<core_api::audio::AudioDeviceInfo>>;
24 class AudioService {
25 public:
26 class Observer {
27 public:
28 // Called when anything changes to the audio device configuration.
29 virtual void OnDeviceChanged() = 0;
31 // Called when the sound level of an active audio device changes.
32 virtual void OnLevelChanged(const std::string& id, int level) = 0;
34 // Called when the mute state of audio input/output changes.
35 virtual void OnMuteChanged(bool is_input, bool is_muted) = 0;
37 // Called when the audio devices change, either new devices being added, or
38 // existing devices being removed.
39 virtual void OnDevicesChanged(const DeviceInfoList&) = 0;
41 protected:
42 virtual ~Observer() {}
45 // Callback type for completing to get audio device information.
46 typedef base::Callback<void(const OutputInfo&, const InputInfo&, bool)>
47 GetInfoCallback;
49 // Creates a platform-specific AudioService instance.
50 static AudioService* CreateInstance();
52 virtual ~AudioService() {}
54 // Called by listeners to this service to add/remove themselves as observers.
55 virtual void AddObserver(Observer* observer) = 0;
56 virtual void RemoveObserver(Observer* observer) = 0;
58 // Start to query audio device information. Should be called on UI thread.
59 // The |callback| will be invoked once the query is completed.
60 virtual void StartGetInfo(const GetInfoCallback& callback) = 0;
62 // Sets the active devices to the devices specified by |device_list|.
63 // It can pass in the "complete" active device list of either input
64 // devices, or output devices, or both. If only input devices are passed in,
65 // it will only change the input devices' active status, output devices will
66 // NOT be changed; similarly for the case if only output devices are passed.
67 // If the devices specified in |new_active_ids| are already active, they will
68 // remain active. Otherwise, the old active devices will be de-activated
69 // before we activate the new devices with the same type(input/output).
70 virtual void SetActiveDevices(const DeviceIdList& device_list) = 0;
72 // Set the muted and volume/gain properties of a device.
73 virtual bool SetDeviceProperties(const std::string& device_id,
74 bool muted,
75 int volume,
76 int gain) = 0;
78 protected:
79 AudioService() {}
81 private:
82 DISALLOW_COPY_AND_ASSIGN(AudioService);
85 } // namespace extensions
87 #endif // EXTENSIONS_BROWSER_API_AUDIO_AUDIO_SERVICE_H_