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. 4 5 #ifndef MEDIA_AUDIO_SOUNDS_SOUNDS_MANAGER_H_ 6 #define MEDIA_AUDIO_SOUNDS_SOUNDS_MANAGER_H_ 7 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" 14 15 namespace media { 16 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; 22 23 // Creates a singleton instance of the SoundsManager. 24 static void Create(); 25 26 // Removes a singleton instance of the SoundsManager. 27 static void Shutdown(); 28 29 // Returns a pointer to a singleton instance of the SoundsManager. 30 static SoundsManager* Get(); 31 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); 35 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; 40 41 // Plays sound identified by |key|, returns false if SoundsManager 42 // was not properly initialized. 43 virtual bool Play(SoundKey key) = 0; 44 45 // Returns duration of the sound identified by |key|. If SoundsManager 46 // was not properly initialized or |key| was not registered, this 47 // method returns an empty value. 48 virtual base::TimeDelta GetDuration(SoundKey key) = 0; 49 50 protected: 51 SoundsManager(); 52 virtual ~SoundsManager(); 53 54 private: 55 DISALLOW_COPY_AND_ASSIGN(SoundsManager); 56 }; 57 58 } // namespace media 59 60 #endif // MEDIA_AUDIO_SOUNDS_SOUNDS_MANAGER_H_ 61