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 CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ | 5 #ifndef CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ |
6 #define CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ | 6 #define CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ |
7 | 7 |
| 8 #include <list> |
| 9 #include <map> |
8 #include <string> | 10 #include <string> |
9 #include <vector> | 11 #include <vector> |
10 | 12 |
11 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
12 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
13 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
14 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
15 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
16 #include "base/values.h" | 18 #include "base/values.h" |
17 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
| 20 #include "content/public/browser/notification_observer.h" |
| 21 #include "content/public/browser/notification_registrar.h" |
18 #include "media/audio/audio_logging.h" | 22 #include "media/audio/audio_logging.h" |
19 #include "media/base/media_log.h" | 23 #include "media/base/media_log.h" |
20 #include "media/video/capture/video_capture_device_info.h" | 24 #include "media/video/capture/video_capture_device_info.h" |
21 | 25 |
22 namespace media { | 26 namespace media { |
23 class AudioParameters; | 27 class AudioParameters; |
24 struct MediaLogEvent; | 28 struct MediaLogEvent; |
25 } | 29 } |
26 | 30 |
27 namespace content { | 31 namespace content { |
28 | 32 |
29 // This class stores information about currently active media. | 33 // This class stores information about currently active media. |
30 class CONTENT_EXPORT MediaInternals | 34 class CONTENT_EXPORT MediaInternals |
31 : NON_EXPORTED_BASE(public media::AudioLogFactory) { | 35 : NON_EXPORTED_BASE(public media::AudioLogFactory), |
| 36 public NotificationObserver { |
32 public: | 37 public: |
33 // Called with the update string. | 38 // Called with the update string. |
34 typedef base::Callback<void(const base::string16&)> UpdateCallback; | 39 typedef base::Callback<void(const base::string16&)> UpdateCallback; |
35 | 40 |
36 static MediaInternals* GetInstance(); | 41 static MediaInternals* GetInstance(); |
37 | 42 |
38 ~MediaInternals() override; | 43 ~MediaInternals() override; |
39 | 44 |
| 45 // NotificationObserver implementation. |
| 46 void Observe(int type, |
| 47 const NotificationSource& source, |
| 48 const NotificationDetails& details) override; |
| 49 |
40 // Called when a MediaEvent occurs. | 50 // Called when a MediaEvent occurs. |
41 void OnMediaEvents(int render_process_id, | 51 void OnMediaEvents(int render_process_id, |
42 const std::vector<media::MediaLogEvent>& events); | 52 const std::vector<media::MediaLogEvent>& events); |
43 | 53 |
44 // Add/remove update callbacks (see above). Must be called on the UI thread. | 54 // Add/remove update callbacks (see above). Must be called on the UI thread. |
45 // The callbacks must also be fired on UI thread. | 55 // The callbacks must also be fired on UI thread. |
46 void AddUpdateCallback(const UpdateCallback& callback); | 56 void AddUpdateCallback(const UpdateCallback& callback); |
47 void RemoveUpdateCallback(const UpdateCallback& callback); | 57 void RemoveUpdateCallback(const UpdateCallback& callback); |
48 | 58 |
49 // Whether there are any update callbacks available. Can be called on any | 59 // Whether there are any update callbacks available. Can be called on any |
50 // thread. | 60 // thread. |
51 bool CanUpdate(); | 61 bool CanUpdate(); |
52 | 62 |
| 63 // Replay all saved media events. |
| 64 void SendHistoricalMediaEvents(); |
| 65 |
53 // Sends all audio cached data to each registered UpdateCallback. | 66 // Sends all audio cached data to each registered UpdateCallback. |
54 void SendAudioStreamData(); | 67 void SendAudioStreamData(); |
55 | 68 |
56 // Sends all video capture capabilities cached data to each registered | 69 // Sends all video capture capabilities cached data to each registered |
57 // UpdateCallback. | 70 // UpdateCallback. |
58 void SendVideoCaptureDeviceCapabilities(); | 71 void SendVideoCaptureDeviceCapabilities(); |
59 | 72 |
60 // Called to inform of the capabilities enumerated for video devices. | 73 // Called to inform of the capabilities enumerated for video devices. |
61 void UpdateVideoCaptureDeviceCapabilities( | 74 void UpdateVideoCaptureDeviceCapabilities( |
62 const media::VideoCaptureDeviceInfos& video_capture_device_infos); | 75 const media::VideoCaptureDeviceInfos& video_capture_device_infos); |
(...skipping 10 matching lines...) Expand all Loading... |
73 media::AudioLog* audio_log); | 86 media::AudioLog* audio_log); |
74 | 87 |
75 private: | 88 private: |
76 // Inner class to handle reporting pipelinestatus to UMA | 89 // Inner class to handle reporting pipelinestatus to UMA |
77 class MediaInternalsUMAHandler; | 90 class MediaInternalsUMAHandler; |
78 | 91 |
79 friend class AudioLogImpl; | 92 friend class AudioLogImpl; |
80 friend class MediaInternalsTest; | 93 friend class MediaInternalsTest; |
81 friend struct base::DefaultLazyInstanceTraits<MediaInternals>; | 94 friend struct base::DefaultLazyInstanceTraits<MediaInternals>; |
82 | 95 |
| 96 // Pending events for a particular process. |
| 97 using PendingEvents = std::list<media::MediaLogEvent>; |
| 98 |
| 99 // The maps between process ID and PendingEvents. |
| 100 using PendingEventsMap = std::map<int, PendingEvents>; |
| 101 |
83 MediaInternals(); | 102 MediaInternals(); |
84 | 103 |
85 // Sends |update| to each registered UpdateCallback. Safe to call from any | 104 // Sends |update| to each registered UpdateCallback. Safe to call from any |
86 // thread, but will forward to the IO thread. | 105 // thread, but will forward to the IO thread. |
87 void SendUpdate(const base::string16& update); | 106 void SendUpdate(const base::string16& update); |
88 | 107 |
| 108 // Saves |event| so that it can be sent later in SendHistoricalMediaEvents(). |
| 109 void SaveEvent(int process_id, const media::MediaLogEvent& event); |
| 110 |
89 // Caches |value| under |cache_key| so that future SendAudioLogUpdate() calls | 111 // Caches |value| under |cache_key| so that future SendAudioLogUpdate() calls |
90 // will include the current data. Calls JavaScript |function|(|value|) for | 112 // will include the current data. Calls JavaScript |function|(|value|) for |
91 // each registered UpdateCallback. | 113 // each registered UpdateCallback. |
92 enum AudioLogUpdateType { | 114 enum AudioLogUpdateType { |
93 CREATE, // Creates a new AudioLog cache entry. | 115 CREATE, // Creates a new AudioLog cache entry. |
94 UPDATE_IF_EXISTS, // Updates an existing AudioLog cache entry, does | 116 UPDATE_IF_EXISTS, // Updates an existing AudioLog cache entry, does |
95 // nothing if it doesn't exist. | 117 // nothing if it doesn't exist. |
96 UPDATE_AND_DELETE, // Deletes an existing AudioLog cache entry. | 118 UPDATE_AND_DELETE, // Deletes an existing AudioLog cache entry. |
97 }; | 119 }; |
98 void SendAudioLogUpdate(AudioLogUpdateType type, | 120 void SendAudioLogUpdate(AudioLogUpdateType type, |
99 const std::string& cache_key, | 121 const std::string& cache_key, |
100 const std::string& function, | 122 const std::string& function, |
101 const base::DictionaryValue* value); | 123 const base::DictionaryValue* value); |
102 | 124 |
103 // Must only be accessed on the UI thread. | 125 // Must only be accessed on the UI thread. |
104 std::vector<UpdateCallback> update_callbacks_; | 126 std::vector<UpdateCallback> update_callbacks_; |
105 | 127 |
106 // Must only be accessed on the IO thread. | 128 // Must only be accessed on the IO thread. |
107 base::ListValue video_capture_capabilities_cached_data_; | 129 base::ListValue video_capture_capabilities_cached_data_; |
108 | 130 |
| 131 NotificationRegistrar registrar_; |
| 132 |
109 // All variables below must be accessed under |lock_|. | 133 // All variables below must be accessed under |lock_|. |
110 base::Lock lock_; | 134 base::Lock lock_; |
111 bool can_update_; | 135 bool can_update_; |
| 136 PendingEventsMap pending_events_map_; |
112 base::DictionaryValue audio_streams_cached_data_; | 137 base::DictionaryValue audio_streams_cached_data_; |
113 int owner_ids_[AUDIO_COMPONENT_MAX]; | 138 int owner_ids_[AUDIO_COMPONENT_MAX]; |
114 scoped_ptr<MediaInternalsUMAHandler> uma_handler_; | 139 scoped_ptr<MediaInternalsUMAHandler> uma_handler_; |
115 | 140 |
116 DISALLOW_COPY_AND_ASSIGN(MediaInternals); | 141 DISALLOW_COPY_AND_ASSIGN(MediaInternals); |
117 }; | 142 }; |
118 | 143 |
119 } // namespace content | 144 } // namespace content |
120 | 145 |
121 #endif // CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ | 146 #endif // CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ |
OLD | NEW |