blob: a5922649bebb8d5786ed66347208c7e954c53805 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/extensions/api/audio/audio_service.h"
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/strings/string_number_conversions.h"
#include "base/threading/thread_checker.h"
#include "content/public/browser/browser_thread.h"
using content::BrowserThread;
namespace extensions {
using api::audio::OutputDeviceInfo;
using api::audio::InputDeviceInfo;
class AudioServiceImpl : public AudioService {
public:
AudioServiceImpl();
virtual ~AudioServiceImpl();
private:
// Called by listeners to this service to add/remove themselves as observers.
virtual void AddObserver(AudioService::Observer* observer) OVERRIDE;
virtual void RemoveObserver(AudioService::Observer* observer) OVERRIDE;
// Start to query audio device information.
virtual void StartGetInfo(const GetInfoCallback& callback) OVERRIDE;
virtual void SetActiveDevices(const DeviceIdList& device_list) OVERRIDE;
virtual bool SetDeviceProperties(const std::string& device_id,
bool muted,
int volume,
int gain) OVERRIDE;
// List of observers.
ObserverList<AudioService::Observer> observer_list_;
base::ThreadChecker thread_checker_;
// Note: This should remain the last member so it'll be destroyed and
// invalidate the weak pointers before any other members are destroyed.
base::WeakPtrFactory<AudioServiceImpl> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(AudioServiceImpl);
};
AudioServiceImpl::AudioServiceImpl() : weak_ptr_factory_(this) {
DCHECK(thread_checker_.CalledOnValidThread());
}
AudioServiceImpl::~AudioServiceImpl() {
DCHECK(thread_checker_.CalledOnValidThread());
}
void AudioServiceImpl::AddObserver(AudioService::Observer* observer) {
DCHECK(thread_checker_.CalledOnValidThread());
observer_list_.AddObserver(observer);
}
void AudioServiceImpl::RemoveObserver(AudioService::Observer* observer) {
DCHECK(thread_checker_.CalledOnValidThread());
observer_list_.RemoveObserver(observer);
}
void AudioServiceImpl::StartGetInfo(const GetInfoCallback& callback) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!callback.is_null())
callback.Run(OutputInfo(), InputInfo(), false);
}
void AudioServiceImpl::SetActiveDevices(const DeviceIdList& device_list) {
DCHECK(thread_checker_.CalledOnValidThread());
}
bool AudioServiceImpl::SetDeviceProperties(const std::string& device_id,
bool muted,
int volume,
int gain) {
DCHECK(thread_checker_.CalledOnValidThread());
return false;
}
AudioService* AudioService::CreateInstance() {
return new AudioServiceImpl;
}
} // namespace extensions
|