Reland the ULONG -> SIZE_T change from 317177
[chromium-blink-merge.git] / extensions / browser / api / audio / audio_service_linux.cc
blob4e70cef40ffb096ebd823e495cf20e0f2d9de616
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/browser/api/audio/audio_service.h"
7 #include "base/callback.h"
8 #include "base/memory/weak_ptr.h"
9 #include "base/observer_list.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/threading/thread_checker.h"
12 #include "content/public/browser/browser_thread.h"
14 using content::BrowserThread;
16 namespace extensions {
18 using core_api::audio::OutputDeviceInfo;
19 using core_api::audio::InputDeviceInfo;
21 class AudioServiceImpl : public AudioService {
22 public:
23 AudioServiceImpl();
24 ~AudioServiceImpl() override;
26 private:
27 // Called by listeners to this service to add/remove themselves as observers.
28 void AddObserver(AudioService::Observer* observer) override;
29 void RemoveObserver(AudioService::Observer* observer) override;
31 // Start to query audio device information.
32 void StartGetInfo(const GetInfoCallback& callback) override;
33 void SetActiveDevices(const DeviceIdList& device_list) override;
34 bool SetDeviceProperties(const std::string& device_id,
35 bool muted,
36 int volume,
37 int gain) override;
39 // List of observers.
40 ObserverList<AudioService::Observer> observer_list_;
42 base::ThreadChecker thread_checker_;
44 // Note: This should remain the last member so it'll be destroyed and
45 // invalidate the weak pointers before any other members are destroyed.
46 base::WeakPtrFactory<AudioServiceImpl> weak_ptr_factory_;
48 DISALLOW_COPY_AND_ASSIGN(AudioServiceImpl);
51 AudioServiceImpl::AudioServiceImpl() : weak_ptr_factory_(this) {
52 DCHECK(thread_checker_.CalledOnValidThread());
55 AudioServiceImpl::~AudioServiceImpl() {
56 DCHECK(thread_checker_.CalledOnValidThread());
59 void AudioServiceImpl::AddObserver(AudioService::Observer* observer) {
60 DCHECK(thread_checker_.CalledOnValidThread());
61 observer_list_.AddObserver(observer);
64 void AudioServiceImpl::RemoveObserver(AudioService::Observer* observer) {
65 DCHECK(thread_checker_.CalledOnValidThread());
66 observer_list_.RemoveObserver(observer);
69 void AudioServiceImpl::StartGetInfo(const GetInfoCallback& callback) {
70 DCHECK(thread_checker_.CalledOnValidThread());
71 if (!callback.is_null())
72 callback.Run(OutputInfo(), InputInfo(), false);
75 void AudioServiceImpl::SetActiveDevices(const DeviceIdList& device_list) {
76 DCHECK(thread_checker_.CalledOnValidThread());
79 bool AudioServiceImpl::SetDeviceProperties(const std::string& device_id,
80 bool muted,
81 int volume,
82 int gain) {
83 DCHECK(thread_checker_.CalledOnValidThread());
84 return false;
87 AudioService* AudioService::CreateInstance() {
88 return new AudioServiceImpl;
91 } // namespace extensions