Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / browser / media / audio_state_provider.h
blob5bd1b7189aa7fe37d213e75f65acb2a2aac01ec2
1 // Copyright 2015 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 CONTENT_BROWSER_MEDIA_AUDIO_STATE_PROVIDER_H_
6 #define CONTENT_BROWSER_MEDIA_AUDIO_STATE_PROVIDER_H_
8 #include "content/common/content_export.h"
10 namespace content {
11 class WebContents;
12 class AudioStreamMonitor;
14 // This class is associated with a WebContents, and maintains the audible
15 // state regarding all the players in it.
16 // The audible state is true if at least one player is playing a sound.
17 // Whenever the audible state of the WebContents as a whole changes, this
18 // class sends a notification to it.
20 // Each WebContentsImpl owns an AudioStateProvider
21 class CONTENT_EXPORT AudioStateProvider {
22 public:
23 explicit AudioStateProvider(WebContents* web_contents);
24 virtual ~AudioStateProvider() {}
26 // Indicates whether this service is available on the system.
27 virtual bool IsAudioStateAvailable() const = 0;
29 // If this provider uses monitoring (i.e. measure the signal),
30 // return its monitor.
31 virtual AudioStreamMonitor* audio_stream_monitor() = 0;
33 // Returns true if the WebContents is playing or has recently been
34 // playing the sound.
35 virtual bool WasRecentlyAudible() const;
37 void set_was_recently_audible_for_testing(bool value) {
38 was_recently_audible_ = value;
41 protected:
42 // Notify WebContents that the audio state has changed.
43 void Notify(bool new_state);
45 // The WebContents instance instance to receive indicator toggle
46 // notifications. This pointer should be valid for the lifetime of
47 // AudioStreamMonitor.
48 WebContents* const web_contents_;
50 // The audio state that is being maintained
51 bool was_recently_audible_;
55 } // namespace content
57 #endif // CONTENT_BROWSER_MEDIA_AUDIO_STATE_PROVIDER_H_