Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / audio / audio_service_linux.cc
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.
4
5 #include "chrome/browser/extensions/api/audio/audio_service.h"
6
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"
13
14 using content::BrowserThread;
15
16 namespace extensions {
17
18 using api::audio::OutputDeviceInfo;
19 using api::audio::InputDeviceInfo;
20
21 class AudioServiceImpl : public AudioService {
22  public:
23   AudioServiceImpl();
24   virtual ~AudioServiceImpl();
25
26  private:
27   // Called by listeners to this service to add/remove themselves as observers.
28   virtual void AddObserver(AudioService::Observer* observer) OVERRIDE;
29   virtual void RemoveObserver(AudioService::Observer* observer) OVERRIDE;
30
31   // Start to query audio device information.
32   virtual void StartGetInfo(const GetInfoCallback& callback) OVERRIDE;
33   virtual void SetActiveDevices(const DeviceIdList& device_list) OVERRIDE;
34   virtual bool SetDeviceProperties(const std::string& device_id,
35                                    bool muted,
36                                    int volume,
37                                    int gain) OVERRIDE;
38
39   // List of observers.
40   ObserverList<AudioService::Observer> observer_list_;
41
42   base::ThreadChecker thread_checker_;
43
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_;
47
48   DISALLOW_COPY_AND_ASSIGN(AudioServiceImpl);
49 };
50
51 AudioServiceImpl::AudioServiceImpl() : weak_ptr_factory_(this) {
52   DCHECK(thread_checker_.CalledOnValidThread());
53 }
54
55 AudioServiceImpl::~AudioServiceImpl() {
56   DCHECK(thread_checker_.CalledOnValidThread());
57 }
58
59 void AudioServiceImpl::AddObserver(AudioService::Observer* observer) {
60   DCHECK(thread_checker_.CalledOnValidThread());
61   observer_list_.AddObserver(observer);
62 }
63
64 void AudioServiceImpl::RemoveObserver(AudioService::Observer* observer) {
65   DCHECK(thread_checker_.CalledOnValidThread());
66   observer_list_.RemoveObserver(observer);
67 }
68
69 void AudioServiceImpl::StartGetInfo(const GetInfoCallback& callback) {
70   DCHECK(thread_checker_.CalledOnValidThread());
71   if (!callback.is_null())
72     callback.Run(OutputInfo(), InputInfo(), false);
73 }
74
75 void AudioServiceImpl::SetActiveDevices(const DeviceIdList& device_list) {
76   DCHECK(thread_checker_.CalledOnValidThread());
77 }
78
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;
85 }
86
87 AudioService* AudioService::CreateInstance() {
88   return new AudioServiceImpl;
89 }
90
91 }  // namespace extensions