Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / media / audio / sounds / sounds_manager.h
blob7db164fa3be19f14151daa3c6d45650d781b5e79
1 // Copyright 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 MEDIA_AUDIO_SOUNDS_SOUNDS_MANAGER_H_
6 #define MEDIA_AUDIO_SOUNDS_SOUNDS_MANAGER_H_
8 #include "base/basictypes.h"
9 #include "base/containers/hash_tables.h"
10 #include "base/strings/string_piece.h"
11 #include "base/threading/non_thread_safe.h"
12 #include "base/time/time.h"
13 #include "media/base/media_export.h"
15 namespace media {
17 // This class is used for reproduction of system sounds. All methods
18 // should be accessed from the Audio thread.
19 class MEDIA_EXPORT SoundsManager : public base::NonThreadSafe {
20 public:
21 typedef int SoundKey;
23 // Creates a singleton instance of the SoundsManager.
24 static void Create();
26 // Removes a singleton instance of the SoundsManager.
27 static void Shutdown();
29 // Returns a pointer to a singleton instance of the SoundsManager.
30 static SoundsManager* Get();
32 // Initializes sounds manager for testing. The |manager| will be owned
33 // by the internal pointer and will be deleted by Shutdown().
34 static void InitializeForTesting(SoundsManager* manager);
36 // Initializes SoundsManager with the wav data for the system
37 // sounds. Returns true if SoundsManager was successfully
38 // initialized.
39 virtual bool Initialize(SoundKey key, const base::StringPiece& data) = 0;
41 // Plays sound identified by |key|, returns false if SoundsManager
42 // was not properly initialized.
43 virtual bool Play(SoundKey key) = 0;
45 // Stops playing sound identified by |key|, returns false if SoundsManager
46 // was not properly initialized.
47 virtual bool Stop(SoundKey key) = 0;
49 // Returns duration of the sound identified by |key|. If SoundsManager
50 // was not properly initialized or |key| was not registered, this
51 // method returns an empty value.
52 virtual base::TimeDelta GetDuration(SoundKey key) = 0;
54 protected:
55 SoundsManager();
56 virtual ~SoundsManager();
58 private:
59 DISALLOW_COPY_AND_ASSIGN(SoundsManager);
62 } // namespace media
64 #endif // MEDIA_AUDIO_SOUNDS_SOUNDS_MANAGER_H_