blob: ce6cbdbb1e34c3069486ea4d60eeb0a93558f718 (
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
|
// Copyright 2013 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.
#ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_AUDIO_CONTROLLER_H_
#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_AUDIO_CONTROLLER_H_
#include <string>
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_vector.h"
#include "base/string_piece.h"
#include "media/audio/audio_parameters.h"
namespace base {
class MessageLoopProxy;
}
class Profile;
// This class controls the sound playing for notifications. Note that this class
// belongs to the audio thread and self-owned.
class NotificationAudioController {
public:
NotificationAudioController();
// Requests the audio thread to play a sound for a notification. |data|
// specifies the raw audio data in wav file format. |notification_id|
// and |profile| represents the id of the notification for the sound.
// When this method is called during playing sound for the specified
// |notification_id|, it will stop playing the sound and start the sound for
// the newly specified |data|.
void RequestPlayNotificationSound(
const std::string& notification_id,
const Profile* profile,
const base::StringPiece& data);
// Request shutdown process in the audio thread. Delete itself when all
// processes have finished.
void RequestShutdown();
private:
class AudioHandler;
friend class NotificationAudioControllerTest;
~NotificationAudioController();
void UseFakeAudioOutputForTest();
// Request the current number of audio handlers to the audio thread. |on_get|
// will be called with the result when finished.
void GetAudioHandlersSizeForTest(const base::Callback<void(size_t)>& on_get);
// Actually start playing the notification sound in the audio thread.
void PlayNotificationSound(
const std::string& notification_id,
const Profile* profile,
const base::StringPiece& data);
// Removes all instances in |audio_handlers_|.
void Shutdown();
// Gets the current size of |audio_handlers_| in the audio thread.
size_t GetAudioHandlersSizeCallback();
// Called when the sound for |audio_handler| has finished.
void OnNotificationSoundFinished(AudioHandler* audio_handler);
scoped_refptr<base::MessageLoopProxy> message_loop_;
ScopedVector<AudioHandler> audio_handlers_;
media::AudioParameters::Format output_format_;
DISALLOW_COPY_AND_ASSIGN(NotificationAudioController);
};
#endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_AUDIO_CONTROLLER_H_
|