Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_WEBRTC_INTERNALS_H_ | 5 #ifndef CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_H_ |
| 6 #define CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_H_ | 6 #define CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_H_ |
| 7 | 7 |
| 8 #include <queue> | |
| 9 | |
| 8 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| 9 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 10 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | |
| 12 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 13 #include "base/process/process.h" | 16 #include "base/process/process.h" |
| 14 #include "base/values.h" | 17 #include "base/values.h" |
| 15 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
| 16 #include "content/public/browser/render_process_host_observer.h" | 19 #include "content/public/browser/render_process_host_observer.h" |
| 17 #include "ui/shell_dialogs/select_file_dialog.h" | 20 #include "ui/shell_dialogs/select_file_dialog.h" |
| 18 | 21 |
| 19 namespace content { | 22 namespace content { |
| 20 | 23 |
| 21 class PowerSaveBlocker; | 24 class PowerSaveBlocker; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 // is the constraints for the video. | 77 // is the constraints for the video. |
| 75 void OnGetUserMedia(int render_process_id, | 78 void OnGetUserMedia(int render_process_id, |
| 76 base::ProcessId pid, | 79 base::ProcessId pid, |
| 77 const std::string& origin, | 80 const std::string& origin, |
| 78 bool audio, | 81 bool audio, |
| 79 bool video, | 82 bool video, |
| 80 const std::string& audio_constraints, | 83 const std::string& audio_constraints, |
| 81 const std::string& video_constraints); | 84 const std::string& video_constraints); |
| 82 | 85 |
| 83 // Methods for adding or removing WebRTCInternalsUIObserver. | 86 // Methods for adding or removing WebRTCInternalsUIObserver. |
| 84 void AddObserver(WebRTCInternalsUIObserver *observer); | 87 void AddObserver(WebRTCInternalsUIObserver* observer); |
| 85 void RemoveObserver(WebRTCInternalsUIObserver *observer); | 88 void RemoveObserver(WebRTCInternalsUIObserver* observer); |
| 86 | 89 |
| 87 // Sends all update data to |observer|. | 90 // Sends all update data to |observer|. |
| 88 void UpdateObserver(WebRTCInternalsUIObserver* observer); | 91 void UpdateObserver(WebRTCInternalsUIObserver* observer); |
| 89 | 92 |
| 90 // Enables or disables diagnostic audio recordings for debugging purposes. | 93 // Enables or disables diagnostic audio recordings for debugging purposes. |
| 91 void EnableAudioDebugRecordings(content::WebContents* web_contents); | 94 void EnableAudioDebugRecordings(content::WebContents* web_contents); |
| 92 void DisableAudioDebugRecordings(); | 95 void DisableAudioDebugRecordings(); |
| 93 | 96 |
| 94 bool IsAudioDebugRecordingsEnabled() const; | 97 bool IsAudioDebugRecordingsEnabled() const; |
| 95 const base::FilePath& GetAudioDebugRecordingsFilePath() const; | 98 const base::FilePath& GetAudioDebugRecordingsFilePath() const; |
| 96 | 99 |
| 97 // Enables or disables diagnostic event log. | 100 // Enables or disables diagnostic event log. |
| 98 void SetEventLogRecordings(bool enable, content::WebContents* web_contents); | 101 void SetEventLogRecordings(bool enable, content::WebContents* web_contents); |
| 99 | 102 |
| 100 bool IsEventLogRecordingsEnabled() const; | 103 bool IsEventLogRecordingsEnabled() const; |
| 101 const base::FilePath& GetEventLogRecordingsFilePath() const; | 104 const base::FilePath& GetEventLogRecordingsFilePath() const; |
| 102 | 105 |
| 103 void ResetForTesting(); | 106 protected: |
|
Henrik Grunell
2016/02/09 08:18:11
Nice to get rid of the testing function!
| |
| 107 // Constructor/Destructor are protected to allow tests to derive from the | |
| 108 // class and do per-instance testing without having to use the global | |
| 109 // instance. | |
| 110 WebRTCInternals(); | |
| 111 explicit WebRTCInternals(int aggregate_updates_ms); | |
| 112 ~WebRTCInternals() override; | |
| 104 | 113 |
| 105 private: | 114 private: |
| 106 friend struct base::DefaultLazyInstanceTraits<WebRTCInternals>; | 115 friend struct base::DefaultLazyInstanceTraits<WebRTCInternals>; |
| 107 FRIEND_TEST_ALL_PREFIXES(WebRtcAudioDebugRecordingsBrowserTest, | 116 FRIEND_TEST_ALL_PREFIXES(WebRtcAudioDebugRecordingsBrowserTest, |
| 108 CallWithAudioDebugRecordings); | 117 CallWithAudioDebugRecordings); |
| 109 FRIEND_TEST_ALL_PREFIXES(WebRtcAudioDebugRecordingsBrowserTest, | 118 FRIEND_TEST_ALL_PREFIXES(WebRtcAudioDebugRecordingsBrowserTest, |
| 110 CallWithAudioDebugRecordingsEnabledThenDisabled); | 119 CallWithAudioDebugRecordingsEnabledThenDisabled); |
| 111 FRIEND_TEST_ALL_PREFIXES(WebRtcAudioDebugRecordingsBrowserTest, | 120 FRIEND_TEST_ALL_PREFIXES(WebRtcAudioDebugRecordingsBrowserTest, |
| 112 TwoCallsWithAudioDebugRecordings); | 121 TwoCallsWithAudioDebugRecordings); |
| 113 FRIEND_TEST_ALL_PREFIXES(WebRtcInternalsTest, | 122 FRIEND_TEST_ALL_PREFIXES(WebRtcInternalsTest, |
| 114 AudioDebugRecordingsFileSelectionCanceled); | 123 AudioDebugRecordingsFileSelectionCanceled); |
| 115 | 124 |
| 116 WebRTCInternals(); | 125 void SendUpdate(const std::string& command, scoped_ptr<base::Value> value); |
| 117 ~WebRTCInternals() override; | |
| 118 | |
| 119 void SendUpdate(const std::string& command, base::Value* value); | |
| 120 | 126 |
| 121 // RenderProcessHostObserver implementation. | 127 // RenderProcessHostObserver implementation. |
| 122 void RenderProcessHostDestroyed(RenderProcessHost* host) override; | 128 void RenderProcessHostDestroyed(RenderProcessHost* host) override; |
| 123 | 129 |
| 124 // ui::SelectFileDialog::Listener implementation. | 130 // ui::SelectFileDialog::Listener implementation. |
| 125 void FileSelected(const base::FilePath& path, | 131 void FileSelected(const base::FilePath& path, |
| 126 int index, | 132 int index, |
| 127 void* unused_params) override; | 133 void* unused_params) override; |
| 128 void FileSelectionCanceled(void* params) override; | 134 void FileSelectionCanceled(void* params) override; |
| 129 | 135 |
| 130 // Called when a renderer exits (including crashes). | 136 // Called when a renderer exits (including crashes). |
| 131 void OnRendererExit(int render_process_id); | 137 void OnRendererExit(int render_process_id); |
| 132 | 138 |
| 133 #if defined(ENABLE_WEBRTC) | 139 #if defined(ENABLE_WEBRTC) |
| 134 // Enables diagnostic audio recordings on all render process hosts using | 140 // Enables diagnostic audio recordings on all render process hosts using |
| 135 // |audio_debug_recordings_file_path_|. | 141 // |audio_debug_recordings_file_path_|. |
| 136 void EnableAudioDebugRecordingsOnAllRenderProcessHosts(); | 142 void EnableAudioDebugRecordingsOnAllRenderProcessHosts(); |
| 137 | 143 |
| 138 // Enables event log recordings on all render process hosts using | 144 // Enables event log recordings on all render process hosts using |
| 139 // |event_log_recordings_file_path_|. | 145 // |event_log_recordings_file_path_|. |
| 140 void EnableEventLogRecordingsOnAllRenderProcessHosts(); | 146 void EnableEventLogRecordingsOnAllRenderProcessHosts(); |
| 141 #endif | 147 #endif |
| 142 | 148 |
| 143 // Called whenever an element is added to or removed from | 149 // Called whenever an element is added to or removed from |
| 144 // |peer_connection_data_| to impose/release a block on suspending the current | 150 // |peer_connection_data_| to impose/release a block on suspending the current |
| 145 // application for power-saving. | 151 // application for power-saving. |
| 146 void CreateOrReleasePowerSaveBlocker(); | 152 void CreateOrReleasePowerSaveBlocker(); |
| 147 | 153 |
| 154 // Called on a timer to deliver updates to javascript. | |
| 155 // We throttle and bulk together updates to avoid DOS like scenarios where | |
| 156 // a page uses a lot of peerconnection instances with many event | |
| 157 // notifications. | |
| 158 void ProcessPendingUpdates(); | |
| 159 | |
| 148 base::ObserverList<WebRTCInternalsUIObserver> observers_; | 160 base::ObserverList<WebRTCInternalsUIObserver> observers_; |
| 149 | 161 |
| 150 // |peer_connection_data_| is a list containing all the PeerConnection | 162 // |peer_connection_data_| is a list containing all the PeerConnection |
| 151 // updates. | 163 // updates. |
| 152 // Each item of the list represents the data for one PeerConnection, which | 164 // Each item of the list represents the data for one PeerConnection, which |
| 153 // contains these fields: | 165 // contains these fields: |
| 154 // "rid" -- the renderer id. | 166 // "rid" -- the renderer id. |
| 155 // "pid" -- OS process id of the renderer that creates the PeerConnection. | 167 // "pid" -- OS process id of the renderer that creates the PeerConnection. |
| 156 // "lid" -- local Id assigned to the PeerConnection. | 168 // "lid" -- local Id assigned to the PeerConnection. |
| 157 // "url" -- url of the web page that created the PeerConnection. | 169 // "url" -- url of the web page that created the PeerConnection. |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 184 bool selecting_event_log_; | 196 bool selecting_event_log_; |
| 185 base::FilePath event_log_recordings_file_path_; | 197 base::FilePath event_log_recordings_file_path_; |
| 186 | 198 |
| 187 // While |peer_connection_data_| is non-empty, hold an instance of | 199 // While |peer_connection_data_| is non-empty, hold an instance of |
| 188 // PowerSaveBlocker. This prevents the application from being suspended while | 200 // PowerSaveBlocker. This prevents the application from being suspended while |
| 189 // remoting. | 201 // remoting. |
| 190 scoped_ptr<PowerSaveBlocker> power_save_blocker_; | 202 scoped_ptr<PowerSaveBlocker> power_save_blocker_; |
| 191 | 203 |
| 192 // Set of render process hosts that |this| is registered as an observer on. | 204 // Set of render process hosts that |this| is registered as an observer on. |
| 193 base::hash_set<int> render_process_id_set_; | 205 base::hash_set<int> render_process_id_set_; |
| 206 | |
| 207 class PendingUpdate { | |
| 208 public: | |
| 209 PendingUpdate(const std::string& command, scoped_ptr<base::Value> value); | |
| 210 PendingUpdate(PendingUpdate&& other); | |
| 211 ~PendingUpdate(); | |
| 212 | |
| 213 const std::string& command() const { return command_; } | |
| 214 const base::Value* value() const { return value_.get(); } | |
| 215 | |
| 216 private: | |
| 217 std::string command_; | |
| 218 scoped_ptr<base::Value> value_; | |
| 219 DISALLOW_COPY_AND_ASSIGN(PendingUpdate); | |
| 220 }; | |
| 221 | |
| 222 bool pending_updates_queued_; | |
| 223 std::queue<PendingUpdate> pending_updates_; | |
| 224 const int aggregate_updates_ms_; | |
| 225 | |
| 226 // Weak factory for this object that we use for bulking up updates. | |
| 227 base::WeakPtrFactory<WebRTCInternals> weak_factory_; | |
| 194 }; | 228 }; |
| 195 | 229 |
| 196 } // namespace content | 230 } // namespace content |
| 197 | 231 |
| 198 #endif // CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_H_ | 232 #endif // CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_H_ |
| OLD | NEW |