OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_MEDIA_AUDIO_STREAM_INDICATOR_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_AUDIO_STREAM_INDICATOR_H_ |
6 #define CHROME_BROWSER_MEDIA_AUDIO_STREAM_INDICATOR_H_ | 6 #define CHROME_BROWSER_MEDIA_AUDIO_STREAM_INDICATOR_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 | 12 |
13 namespace content { | 13 namespace content { |
14 class WebContents; | 14 class WebContents; |
15 } | 15 } |
| 16 class TabAudioIndicatorTest; |
16 | 17 |
17 class AudioStreamIndicator | 18 class AudioStreamIndicator |
18 : public base::RefCountedThreadSafe<AudioStreamIndicator> { | 19 : public base::RefCountedThreadSafe<AudioStreamIndicator> { |
19 public: | 20 public: |
20 AudioStreamIndicator(); | 21 AudioStreamIndicator(); |
21 | 22 |
22 // This method should be called on the IO thread. | 23 // This method should be called on the IO thread. |
23 void UpdateWebContentsStatus(int render_process_id, | 24 void UpdateWebContentsStatus(int render_process_id, |
24 int render_view_id, | 25 int render_view_id, |
25 int stream_id, | 26 int stream_id, |
26 bool is_playing_and_audible); | 27 bool is_playing_and_audible); |
27 | 28 |
28 // This method should be called on the IO thread. | 29 // This method should be called on the UI thread. |
29 bool IsPlayingAudio(content::WebContents* contents); | 30 bool IsPlayingAudio(content::WebContents* contents); |
30 | 31 |
31 private: | 32 private: |
| 33 friend class TabAudioIndicatorTest; |
| 34 |
32 struct RenderViewId { | 35 struct RenderViewId { |
33 RenderViewId(int render_process_id, | 36 RenderViewId(int render_process_id, |
34 int render_view_id); | 37 int render_view_id); |
35 | 38 |
36 // Required to use this struct in the std::multiset below. | 39 // Required to use this struct in the std::multiset below. |
37 bool operator<(const RenderViewId& other) const; | 40 bool operator<(const RenderViewId& other) const; |
38 | 41 |
39 int render_process_id; | 42 int render_process_id; |
40 int render_view_id; | 43 int render_view_id; |
41 }; | 44 }; |
42 | 45 |
43 friend class base::RefCountedThreadSafe<AudioStreamIndicator>; | 46 friend class base::RefCountedThreadSafe<AudioStreamIndicator>; |
44 virtual ~AudioStreamIndicator(); | 47 virtual ~AudioStreamIndicator(); |
45 | 48 |
46 void UpdateWebContentsStatusOnUIThread(int render_process_id, | 49 void UpdateWebContentsStatusOnUIThread(int render_process_id, |
47 int render_view_id, | 50 int render_view_id, |
48 int stream_id, | 51 int stream_id, |
49 bool playing); | 52 bool playing); |
50 | 53 |
51 // A map from RenderViews to sets of streams playing in them (each RenderView | 54 // A map from RenderViews to sets of streams playing in them (each RenderView |
52 // might have more than one stream). | 55 // might have more than one stream). |
53 std::map<RenderViewId, std::set<int> > audio_streams_; | 56 std::map<RenderViewId, std::set<int> > audio_streams_; |
54 }; | 57 }; |
55 | 58 |
56 #endif // CHROME_BROWSER_MEDIA_AUDIO_STREAM_INDICATOR_H_ | 59 #endif // CHROME_BROWSER_MEDIA_AUDIO_STREAM_INDICATOR_H_ |
OLD | NEW |