Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_ANDROID_AUDIO_MONITOR_ANDROID_H_ | |
| 6 #define CONTENT_BROWSER_ANDROID_AUDIO_MONITOR_ANDROID_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 namespace content { | |
| 11 | |
| 12 class WebContents; | |
| 13 class RenderFrameHost; | |
| 14 | |
| 15 // This class maintains the audible state of many players | |
| 16 // together. That state is accociated with one Chrome tab that might have | |
| 17 // several players. | |
| 18 // The audible state is true if at least one player is playing a sound. | |
| 19 // Whenever the audible state of the tab changes, this class sends | |
| 20 // notification to the WebContents that represents the tab. | |
| 21 class AudioMonitorAndroid { | |
| 22 public: | |
| 23 // Constructor, web_contents represents the tab. | |
| 24 explicit AudioMonitorAndroid(WebContents* web_contents); | |
| 25 ~AudioMonitorAndroid(); | |
| 26 | |
| 27 // Returns the audible state of the whole tab. | |
| 28 bool is_audible() const { return is_audible_; } | |
| 29 | |
| 30 // These methods constitute the observer pattern, should | |
| 31 // be called when corresponding event happens. They will notify | |
| 32 // WebContents whenever the whole tab audible state changes. | |
| 33 void OnAudibleStateChanged(RenderFrameHost* rfh, int player_id, | |
| 34 bool is_audible); | |
| 35 void RemovePlayer(RenderFrameHost* rfh, int player_id); | |
| 36 void RenderFrameDeleted(RenderFrameHost* rfh); | |
| 37 | |
| 38 private: | |
| 39 void UpdateStatusAndNotify(); | |
| 40 | |
| 41 // Contents of the tab this monitor is associated with | |
| 42 WebContents* web_contents_; | |
| 43 | |
| 44 // Audible status per player ID and frame | |
| 45 typedef std::pair<RenderFrameHost*, int> Key; | |
| 46 typedef std::map<Key, bool> StatusMap; | |
| 47 StatusMap audio_status_map_; | |
| 48 | |
| 49 // The audible state of the whole tab | |
| 50 bool is_audible_; | |
|
qinmin
2015/02/04 03:27:54
DISALLOW_COPY_AND_ASSIGN(AudioMonitorAndroid);
Tima Vaisburd
2015/02/05 23:22:27
Done.
| |
| 51 }; | |
| 52 | |
| 53 } // namespace content | |
| 54 | |
| 55 #endif // CONTENT_BROWSER_ANDROID_AUDIO_MONITOR_ANDROID_H_ | |
| OLD | NEW |