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" |
| 17 #include "base/threading/thread_checker.h" | |
| 14 #include "base/values.h" | 18 #include "base/values.h" |
| 15 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
| 16 #include "content/public/browser/render_process_host_observer.h" | 20 #include "content/public/browser/render_process_host_observer.h" |
| 17 #include "ui/shell_dialogs/select_file_dialog.h" | 21 #include "ui/shell_dialogs/select_file_dialog.h" |
| 18 | 22 |
| 19 namespace content { | 23 namespace content { |
| 20 | 24 |
| 21 class PowerSaveBlocker; | 25 class PowerSaveBlocker; |
| 22 class WebContents; | 26 class WebContents; |
| 23 class WebRTCInternalsUIObserver; | 27 class WebRTCInternalsUIObserver; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 // is the constraints for the video. | 78 // is the constraints for the video. |
| 75 void OnGetUserMedia(int render_process_id, | 79 void OnGetUserMedia(int render_process_id, |
| 76 base::ProcessId pid, | 80 base::ProcessId pid, |
| 77 const std::string& origin, | 81 const std::string& origin, |
| 78 bool audio, | 82 bool audio, |
| 79 bool video, | 83 bool video, |
| 80 const std::string& audio_constraints, | 84 const std::string& audio_constraints, |
| 81 const std::string& video_constraints); | 85 const std::string& video_constraints); |
| 82 | 86 |
| 83 // Methods for adding or removing WebRTCInternalsUIObserver. | 87 // Methods for adding or removing WebRTCInternalsUIObserver. |
| 84 void AddObserver(WebRTCInternalsUIObserver *observer); | 88 void AddObserver(WebRTCInternalsUIObserver* observer); |
| 85 void RemoveObserver(WebRTCInternalsUIObserver *observer); | 89 void RemoveObserver(WebRTCInternalsUIObserver* observer); |
| 86 | 90 |
| 87 // Sends all update data to |observer|. | 91 // Sends all update data to |observer|. |
| 88 void UpdateObserver(WebRTCInternalsUIObserver* observer); | 92 void UpdateObserver(WebRTCInternalsUIObserver* observer); |
| 89 | 93 |
| 90 // Enables or disables diagnostic audio recordings for debugging purposes. | 94 // Enables or disables diagnostic audio recordings for debugging purposes. |
| 91 void EnableAudioDebugRecordings(content::WebContents* web_contents); | 95 void EnableAudioDebugRecordings(content::WebContents* web_contents); |
| 92 void DisableAudioDebugRecordings(); | 96 void DisableAudioDebugRecordings(); |
| 93 | 97 |
| 94 bool IsAudioDebugRecordingsEnabled() const; | 98 bool IsAudioDebugRecordingsEnabled() const; |
| 95 const base::FilePath& GetAudioDebugRecordingsFilePath() const; | 99 const base::FilePath& GetAudioDebugRecordingsFilePath() const; |
| 96 | 100 |
| 97 // Enables or disables diagnostic event log. | 101 // Enables or disables diagnostic event log. |
| 98 void SetEventLogRecordings(bool enable, content::WebContents* web_contents); | 102 void SetEventLogRecordings(bool enable, content::WebContents* web_contents); |
| 99 | 103 |
| 100 bool IsEventLogRecordingsEnabled() const; | 104 bool IsEventLogRecordingsEnabled() const; |
| 101 const base::FilePath& GetEventLogRecordingsFilePath() const; | 105 const base::FilePath& GetEventLogRecordingsFilePath() const; |
| 102 | 106 |
| 103 void ResetForTesting(); | 107 protected: |
| 108 // Constructor/Destructor are protected to allow tests to derive from the | |
| 109 // class and do per-instance testing without having to use the global | |
| 110 // instance. | |
|
Henrik Grunell
2016/02/09 11:47:48
Maybe comment that 500 ms is the default used with
tommi (sloooow) - chröme
2016/02/09 12:13:53
Done.
| |
| 111 WebRTCInternals(); | |
| 112 explicit WebRTCInternals(int aggregate_updates_ms); | |
| 113 ~WebRTCInternals() override; | |
| 104 | 114 |
| 105 private: | 115 private: |
| 106 friend struct base::DefaultLazyInstanceTraits<WebRTCInternals>; | 116 friend struct base::DefaultLazyInstanceTraits<WebRTCInternals>; |
| 107 FRIEND_TEST_ALL_PREFIXES(WebRtcAudioDebugRecordingsBrowserTest, | 117 FRIEND_TEST_ALL_PREFIXES(WebRtcAudioDebugRecordingsBrowserTest, |
| 108 CallWithAudioDebugRecordings); | 118 CallWithAudioDebugRecordings); |
| 109 FRIEND_TEST_ALL_PREFIXES(WebRtcAudioDebugRecordingsBrowserTest, | 119 FRIEND_TEST_ALL_PREFIXES(WebRtcAudioDebugRecordingsBrowserTest, |
| 110 CallWithAudioDebugRecordingsEnabledThenDisabled); | 120 CallWithAudioDebugRecordingsEnabledThenDisabled); |
| 111 FRIEND_TEST_ALL_PREFIXES(WebRtcAudioDebugRecordingsBrowserTest, | 121 FRIEND_TEST_ALL_PREFIXES(WebRtcAudioDebugRecordingsBrowserTest, |
| 112 TwoCallsWithAudioDebugRecordings); | 122 TwoCallsWithAudioDebugRecordings); |
| 113 FRIEND_TEST_ALL_PREFIXES(WebRtcInternalsTest, | 123 FRIEND_TEST_ALL_PREFIXES(WebRtcInternalsTest, |
| 114 AudioDebugRecordingsFileSelectionCanceled); | 124 AudioDebugRecordingsFileSelectionCanceled); |
| 115 | 125 |
| 116 WebRTCInternals(); | 126 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 | 127 |
| 121 // RenderProcessHostObserver implementation. | 128 // RenderProcessHostObserver implementation. |
| 122 void RenderProcessHostDestroyed(RenderProcessHost* host) override; | 129 void RenderProcessHostDestroyed(RenderProcessHost* host) override; |
| 123 | 130 |
| 124 // ui::SelectFileDialog::Listener implementation. | 131 // ui::SelectFileDialog::Listener implementation. |
| 125 void FileSelected(const base::FilePath& path, | 132 void FileSelected(const base::FilePath& path, |
| 126 int index, | 133 int index, |
| 127 void* unused_params) override; | 134 void* unused_params) override; |
| 128 void FileSelectionCanceled(void* params) override; | 135 void FileSelectionCanceled(void* params) override; |
| 129 | 136 |
| 130 // Called when a renderer exits (including crashes). | 137 // Called when a renderer exits (including crashes). |
| 131 void OnRendererExit(int render_process_id); | 138 void OnRendererExit(int render_process_id); |
| 132 | 139 |
| 133 #if defined(ENABLE_WEBRTC) | 140 #if defined(ENABLE_WEBRTC) |
| 134 // Enables diagnostic audio recordings on all render process hosts using | 141 // Enables diagnostic audio recordings on all render process hosts using |
| 135 // |audio_debug_recordings_file_path_|. | 142 // |audio_debug_recordings_file_path_|. |
| 136 void EnableAudioDebugRecordingsOnAllRenderProcessHosts(); | 143 void EnableAudioDebugRecordingsOnAllRenderProcessHosts(); |
| 137 | 144 |
| 138 // Enables event log recordings on all render process hosts using | 145 // Enables event log recordings on all render process hosts using |
| 139 // |event_log_recordings_file_path_|. | 146 // |event_log_recordings_file_path_|. |
| 140 void EnableEventLogRecordingsOnAllRenderProcessHosts(); | 147 void EnableEventLogRecordingsOnAllRenderProcessHosts(); |
| 141 #endif | 148 #endif |
| 142 | 149 |
| 143 // Called whenever an element is added to or removed from | 150 // Called whenever an element is added to or removed from |
| 144 // |peer_connection_data_| to impose/release a block on suspending the current | 151 // |peer_connection_data_| to impose/release a block on suspending the current |
| 145 // application for power-saving. | 152 // application for power-saving. |
| 146 void CreateOrReleasePowerSaveBlocker(); | 153 void CreateOrReleasePowerSaveBlocker(); |
| 147 | 154 |
| 155 // Called on a timer to deliver updates to javascript. | |
| 156 // We throttle and bulk together updates to avoid DOS like scenarios where | |
| 157 // a page uses a lot of peerconnection instances with many event | |
| 158 // notifications. | |
| 159 void ProcessPendingUpdates(); | |
| 160 | |
| 148 base::ObserverList<WebRTCInternalsUIObserver> observers_; | 161 base::ObserverList<WebRTCInternalsUIObserver> observers_; |
| 149 | 162 |
| 150 // |peer_connection_data_| is a list containing all the PeerConnection | 163 // |peer_connection_data_| is a list containing all the PeerConnection |
| 151 // updates. | 164 // updates. |
| 152 // Each item of the list represents the data for one PeerConnection, which | 165 // Each item of the list represents the data for one PeerConnection, which |
| 153 // contains these fields: | 166 // contains these fields: |
| 154 // "rid" -- the renderer id. | 167 // "rid" -- the renderer id. |
| 155 // "pid" -- OS process id of the renderer that creates the PeerConnection. | 168 // "pid" -- OS process id of the renderer that creates the PeerConnection. |
| 156 // "lid" -- local Id assigned to the PeerConnection. | 169 // "lid" -- local Id assigned to the PeerConnection. |
| 157 // "url" -- url of the web page that created the PeerConnection. | 170 // "url" -- url of the web page that created the PeerConnection. |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 184 bool selecting_event_log_; | 197 bool selecting_event_log_; |
| 185 base::FilePath event_log_recordings_file_path_; | 198 base::FilePath event_log_recordings_file_path_; |
| 186 | 199 |
| 187 // While |peer_connection_data_| is non-empty, hold an instance of | 200 // While |peer_connection_data_| is non-empty, hold an instance of |
| 188 // PowerSaveBlocker. This prevents the application from being suspended while | 201 // PowerSaveBlocker. This prevents the application from being suspended while |
| 189 // remoting. | 202 // remoting. |
| 190 scoped_ptr<PowerSaveBlocker> power_save_blocker_; | 203 scoped_ptr<PowerSaveBlocker> power_save_blocker_; |
| 191 | 204 |
| 192 // Set of render process hosts that |this| is registered as an observer on. | 205 // Set of render process hosts that |this| is registered as an observer on. |
| 193 base::hash_set<int> render_process_id_set_; | 206 base::hash_set<int> render_process_id_set_; |
| 207 | |
| 208 // Used to bulk up updates that we send to javascript. | |
| 209 // The class owns the value/dictionary and command name of an update. | |
| 210 // For each update, a PendingUpdate is stored in the |pending_updates_| queue | |
| 211 // and deleted as soon as the update has been delivered. | |
| 212 // The class is moveble and not copyable to avoid copying while still allowing | |
| 213 // us to use an stl container while not having to wrap it in a scoped_ptr or | |
|
Henrik Grunell
2016/02/09 11:47:47
Hard to read this sentence. Repeated "while". (Pun
tommi (sloooow) - chröme
2016/02/09 12:13:53
Done.
| |
| 214 // similar. | |
| 215 // The class is single threaded, so must be | |
|
Henrik Grunell
2016/02/09 11:47:48
Incomplete... :)
tommi (sloooow) - chröme
2016/02/09 12:13:53
Done. I was working over an extremely slow connec
| |
| 216 class PendingUpdate { | |
| 217 public: | |
| 218 PendingUpdate(const std::string& command, scoped_ptr<base::Value> value); | |
| 219 PendingUpdate(PendingUpdate&& other); | |
| 220 ~PendingUpdate(); | |
| 221 | |
| 222 const std::string& command() const; | |
| 223 const base::Value* value() const; | |
| 224 | |
| 225 private: | |
| 226 base::ThreadChecker thread_checker_; | |
| 227 std::string command_; | |
| 228 scoped_ptr<base::Value> value_; | |
| 229 DISALLOW_COPY_AND_ASSIGN(PendingUpdate); | |
| 230 }; | |
| 231 | |
| 232 std::queue<PendingUpdate> pending_updates_; | |
| 233 const int aggregate_updates_ms_; | |
| 234 | |
| 235 // Weak factory for this object that we use for bulking up updates. | |
| 236 base::WeakPtrFactory<WebRTCInternals> weak_factory_; | |
| 194 }; | 237 }; |
| 195 | 238 |
| 196 } // namespace content | 239 } // namespace content |
| 197 | 240 |
| 198 #endif // CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_H_ | 241 #endif // CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_H_ |
| OLD | NEW |