Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: content/browser/media/webrtc_internals.h

Issue 1676043002: Deliver webrtc-internals updates in bulk, every 500ms at most. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/media/webrtc_internals.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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.
111 // The default ctor sets |aggregate_updates_ms| to 500ms.
112 WebRTCInternals();
113 explicit WebRTCInternals(int aggregate_updates_ms);
114 ~WebRTCInternals() override;
104 115
105 private: 116 private:
106 friend struct base::DefaultLazyInstanceTraits<WebRTCInternals>; 117 friend struct base::DefaultLazyInstanceTraits<WebRTCInternals>;
107 FRIEND_TEST_ALL_PREFIXES(WebRtcAudioDebugRecordingsBrowserTest, 118 FRIEND_TEST_ALL_PREFIXES(WebRtcAudioDebugRecordingsBrowserTest,
108 CallWithAudioDebugRecordings); 119 CallWithAudioDebugRecordings);
109 FRIEND_TEST_ALL_PREFIXES(WebRtcAudioDebugRecordingsBrowserTest, 120 FRIEND_TEST_ALL_PREFIXES(WebRtcAudioDebugRecordingsBrowserTest,
110 CallWithAudioDebugRecordingsEnabledThenDisabled); 121 CallWithAudioDebugRecordingsEnabledThenDisabled);
111 FRIEND_TEST_ALL_PREFIXES(WebRtcAudioDebugRecordingsBrowserTest, 122 FRIEND_TEST_ALL_PREFIXES(WebRtcAudioDebugRecordingsBrowserTest,
112 TwoCallsWithAudioDebugRecordings); 123 TwoCallsWithAudioDebugRecordings);
113 FRIEND_TEST_ALL_PREFIXES(WebRtcInternalsTest, 124 FRIEND_TEST_ALL_PREFIXES(WebRtcInternalsTest,
114 AudioDebugRecordingsFileSelectionCanceled); 125 AudioDebugRecordingsFileSelectionCanceled);
115 126
116 WebRTCInternals(); 127 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 128
121 // RenderProcessHostObserver implementation. 129 // RenderProcessHostObserver implementation.
122 void RenderProcessHostDestroyed(RenderProcessHost* host) override; 130 void RenderProcessHostDestroyed(RenderProcessHost* host) override;
123 131
124 // ui::SelectFileDialog::Listener implementation. 132 // ui::SelectFileDialog::Listener implementation.
125 void FileSelected(const base::FilePath& path, 133 void FileSelected(const base::FilePath& path,
126 int index, 134 int index,
127 void* unused_params) override; 135 void* unused_params) override;
128 void FileSelectionCanceled(void* params) override; 136 void FileSelectionCanceled(void* params) override;
129 137
130 // Called when a renderer exits (including crashes). 138 // Called when a renderer exits (including crashes).
131 void OnRendererExit(int render_process_id); 139 void OnRendererExit(int render_process_id);
132 140
133 #if defined(ENABLE_WEBRTC) 141 #if defined(ENABLE_WEBRTC)
134 // Enables diagnostic audio recordings on all render process hosts using 142 // Enables diagnostic audio recordings on all render process hosts using
135 // |audio_debug_recordings_file_path_|. 143 // |audio_debug_recordings_file_path_|.
136 void EnableAudioDebugRecordingsOnAllRenderProcessHosts(); 144 void EnableAudioDebugRecordingsOnAllRenderProcessHosts();
137 145
138 // Enables event log recordings on all render process hosts using 146 // Enables event log recordings on all render process hosts using
139 // |event_log_recordings_file_path_|. 147 // |event_log_recordings_file_path_|.
140 void EnableEventLogRecordingsOnAllRenderProcessHosts(); 148 void EnableEventLogRecordingsOnAllRenderProcessHosts();
141 #endif 149 #endif
142 150
143 // Called whenever an element is added to or removed from 151 // Called whenever an element is added to or removed from
144 // |peer_connection_data_| to impose/release a block on suspending the current 152 // |peer_connection_data_| to impose/release a block on suspending the current
145 // application for power-saving. 153 // application for power-saving.
146 void CreateOrReleasePowerSaveBlocker(); 154 void CreateOrReleasePowerSaveBlocker();
147 155
156 // Called on a timer to deliver updates to javascript.
157 // We throttle and bulk together updates to avoid DOS like scenarios where
158 // a page uses a lot of peerconnection instances with many event
159 // notifications.
160 void ProcessPendingUpdates();
161
148 base::ObserverList<WebRTCInternalsUIObserver> observers_; 162 base::ObserverList<WebRTCInternalsUIObserver> observers_;
149 163
150 // |peer_connection_data_| is a list containing all the PeerConnection 164 // |peer_connection_data_| is a list containing all the PeerConnection
151 // updates. 165 // updates.
152 // Each item of the list represents the data for one PeerConnection, which 166 // Each item of the list represents the data for one PeerConnection, which
153 // contains these fields: 167 // contains these fields:
154 // "rid" -- the renderer id. 168 // "rid" -- the renderer id.
155 // "pid" -- OS process id of the renderer that creates the PeerConnection. 169 // "pid" -- OS process id of the renderer that creates the PeerConnection.
156 // "lid" -- local Id assigned to the PeerConnection. 170 // "lid" -- local Id assigned to the PeerConnection.
157 // "url" -- url of the web page that created the PeerConnection. 171 // "url" -- url of the web page that created the PeerConnection.
(...skipping 26 matching lines...) Expand all
184 bool selecting_event_log_; 198 bool selecting_event_log_;
185 base::FilePath event_log_recordings_file_path_; 199 base::FilePath event_log_recordings_file_path_;
186 200
187 // While |peer_connection_data_| is non-empty, hold an instance of 201 // While |peer_connection_data_| is non-empty, hold an instance of
188 // PowerSaveBlocker. This prevents the application from being suspended while 202 // PowerSaveBlocker. This prevents the application from being suspended while
189 // remoting. 203 // remoting.
190 scoped_ptr<PowerSaveBlocker> power_save_blocker_; 204 scoped_ptr<PowerSaveBlocker> power_save_blocker_;
191 205
192 // Set of render process hosts that |this| is registered as an observer on. 206 // Set of render process hosts that |this| is registered as an observer on.
193 base::hash_set<int> render_process_id_set_; 207 base::hash_set<int> render_process_id_set_;
208
209 // Used to bulk up updates that we send to javascript.
210 // The class owns the value/dictionary and command name of an update.
211 // For each update, a PendingUpdate is stored in the |pending_updates_| queue
212 // and deleted as soon as the update has been delivered.
213 // The class is moveble and not copyable to avoid copying while still allowing
214 // us to use an stl container without needing scoped_ptr or similar.
215 // The class is single threaded, so all operations must occur on the same
216 // thread.
217 class PendingUpdate {
218 public:
219 PendingUpdate(const std::string& command, scoped_ptr<base::Value> value);
220 PendingUpdate(PendingUpdate&& other);
221 ~PendingUpdate();
222
223 const std::string& command() const;
224 const base::Value* value() const;
225
226 private:
227 base::ThreadChecker thread_checker_;
228 std::string command_;
229 scoped_ptr<base::Value> value_;
230 DISALLOW_COPY_AND_ASSIGN(PendingUpdate);
231 };
232
233 std::queue<PendingUpdate> pending_updates_;
234 const int aggregate_updates_ms_;
235
236 // Weak factory for this object that we use for bulking up updates.
237 base::WeakPtrFactory<WebRTCInternals> weak_factory_;
194 }; 238 };
195 239
196 } // namespace content 240 } // namespace content
197 241
198 #endif // CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_H_ 242 #endif // CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/media/webrtc_internals.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698