Chromium Code Reviews| Index: content/browser/android/audio_monitor_android.h |
| diff --git a/content/browser/android/audio_monitor_android.h b/content/browser/android/audio_monitor_android.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cebbd55aa8e43863de02997cab3e7fa7485333f6 |
| --- /dev/null |
| +++ b/content/browser/android/audio_monitor_android.h |
| @@ -0,0 +1,55 @@ |
| +// Copyright (c) 2015 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 CONTENT_BROWSER_ANDROID_AUDIO_MONITOR_ANDROID_H_ |
| +#define CONTENT_BROWSER_ANDROID_AUDIO_MONITOR_ANDROID_H_ |
| + |
| +#include <map> |
| + |
| +namespace content { |
| + |
| +class WebContents; |
| +class RenderFrameHost; |
| + |
| +// This class maintains the audible state of many players |
| +// together. That state is accociated with one Chrome tab that might have |
| +// several players. |
| +// The audible state is true if at least one player is playing a sound. |
| +// Whenever the audible state of the tab changes, this class sends |
| +// notification to the WebContents that represents the tab. |
| +class AudioMonitorAndroid { |
| + public: |
| + // Constructor, web_contents represents the tab. |
| + explicit AudioMonitorAndroid(WebContents* web_contents); |
| + ~AudioMonitorAndroid(); |
| + |
| + // Returns the audible state of the whole tab. |
| + bool is_audible() const { return is_audible_; } |
| + |
| + // These methods constitute the observer pattern, should |
| + // be called when corresponding event happens. They will notify |
| + // WebContents whenever the whole tab audible state changes. |
| + void OnAudibleStateChanged(RenderFrameHost* rfh, int player_id, |
| + bool is_audible); |
| + void RemovePlayer(RenderFrameHost* rfh, int player_id); |
| + void RenderFrameDeleted(RenderFrameHost* rfh); |
| + |
| + private: |
| + void UpdateStatusAndNotify(); |
| + |
| + // Contents of the tab this monitor is associated with |
| + WebContents* web_contents_; |
| + |
| + // Audible status per player ID and frame |
| + typedef std::pair<RenderFrameHost*, int> Key; |
| + typedef std::map<Key, bool> StatusMap; |
| + StatusMap audio_status_map_; |
| + |
| + // The audible state of the whole tab |
| + bool is_audible_; |
|
qinmin
2015/02/04 03:27:54
DISALLOW_COPY_AND_ASSIGN(AudioMonitorAndroid);
Tima Vaisburd
2015/02/05 23:22:27
Done.
|
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_ANDROID_AUDIO_MONITOR_ANDROID_H_ |