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_WEBRTC_WEBRTC_INTERNALS_H_ | 5 #ifndef CONTENT_BROWSER_WEBRTC_WEBRTC_INTERNALS_H_ |
6 #define CONTENT_BROWSER_WEBRTC_WEBRTC_INTERNALS_H_ | 6 #define CONTENT_BROWSER_WEBRTC_WEBRTC_INTERNALS_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <queue> | 9 #include <queue> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
17 #include "base/process/process.h" | 17 #include "base/process/process.h" |
18 #include "base/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
19 #include "base/values.h" | 19 #include "base/values.h" |
20 #include "content/common/content_export.h" | 20 #include "content/common/content_export.h" |
21 #include "content/public/browser/render_process_host_observer.h" | 21 #include "content/public/browser/render_process_host_observer.h" |
22 #include "device/wake_lock/public/interfaces/wake_lock_service.mojom.h" | |
22 #include "media/media_features.h" | 23 #include "media/media_features.h" |
23 #include "ui/shell_dialogs/select_file_dialog.h" | 24 #include "ui/shell_dialogs/select_file_dialog.h" |
24 | 25 |
25 namespace device { | |
26 class PowerSaveBlocker; | |
27 } // namespace device | |
28 | |
29 namespace content { | 26 namespace content { |
30 | 27 |
31 class WebContents; | 28 class WebContents; |
32 class WebRTCInternalsUIObserver; | 29 class WebRTCInternalsUIObserver; |
33 | 30 |
34 // This is a singleton class running in the browser UI thread. | 31 // This is a singleton class running in the browser UI thread. |
35 // It collects peer connection infomation from the renderers, | 32 // It collects peer connection infomation from the renderers, |
36 // forwards the data to WebRTCInternalsUIObserver and | 33 // forwards the data to WebRTCInternalsUIObserver and |
37 // sends data collecting commands to the renderers. | 34 // sends data collecting commands to the renderers. |
38 class CONTENT_EXPORT WebRTCInternals : public RenderProcessHostObserver, | 35 class CONTENT_EXPORT WebRTCInternals : public RenderProcessHostObserver, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 const base::FilePath& GetAudioDebugRecordingsFilePath() const; | 101 const base::FilePath& GetAudioDebugRecordingsFilePath() const; |
105 | 102 |
106 // Enables or disables diagnostic event log. | 103 // Enables or disables diagnostic event log. |
107 void EnableEventLogRecordings(content::WebContents* web_contents); | 104 void EnableEventLogRecordings(content::WebContents* web_contents); |
108 void DisableEventLogRecordings(); | 105 void DisableEventLogRecordings(); |
109 | 106 |
110 bool IsEventLogRecordingsEnabled() const; | 107 bool IsEventLogRecordingsEnabled() const; |
111 const base::FilePath& GetEventLogFilePath() const; | 108 const base::FilePath& GetEventLogFilePath() const; |
112 | 109 |
113 int num_open_connections() const { return num_open_connections_; } | 110 int num_open_connections() const { return num_open_connections_; } |
114 bool IsPowerSavingBlocked() const { return !!power_save_blocker_; } | |
115 | 111 |
116 protected: | 112 protected: |
117 // Constructor/Destructor are protected to allow tests to derive from the | 113 // Constructor/Destructor are protected to allow tests to derive from the |
118 // class and do per-instance testing without having to use the global | 114 // class and do per-instance testing without having to use the global |
119 // instance. | 115 // instance. |
120 // The default ctor sets |aggregate_updates_ms| to 500ms. | 116 // The default ctor sets |aggregate_updates_ms| to 500ms. |
121 WebRTCInternals(); | 117 WebRTCInternals(); |
122 WebRTCInternals(int aggregate_updates_ms, bool should_block_power_saving); | 118 WebRTCInternals(int aggregate_updates_ms, bool should_block_power_saving); |
123 ~WebRTCInternals() override; | 119 ~WebRTCInternals() override; |
124 | 120 |
121 device::mojom::WakeLockServicePtr wake_lock_; | |
chfremer
2017/05/18 17:48:31
I recommend naming this |wake_lock_service_| to av
ke.he
2017/05/19 03:34:50
Done.
| |
122 | |
125 private: | 123 private: |
126 friend struct base::LazyInstanceTraitsBase<WebRTCInternals>; | 124 friend struct base::LazyInstanceTraitsBase<WebRTCInternals>; |
127 FRIEND_TEST_ALL_PREFIXES(WebRtcAudioDebugRecordingsBrowserTest, | 125 FRIEND_TEST_ALL_PREFIXES(WebRtcAudioDebugRecordingsBrowserTest, |
128 CallWithAudioDebugRecordings); | 126 CallWithAudioDebugRecordings); |
129 FRIEND_TEST_ALL_PREFIXES(WebRtcAudioDebugRecordingsBrowserTest, | 127 FRIEND_TEST_ALL_PREFIXES(WebRtcAudioDebugRecordingsBrowserTest, |
130 CallWithAudioDebugRecordingsEnabledThenDisabled); | 128 CallWithAudioDebugRecordingsEnabledThenDisabled); |
131 FRIEND_TEST_ALL_PREFIXES(WebRtcAudioDebugRecordingsBrowserTest, | 129 FRIEND_TEST_ALL_PREFIXES(WebRtcAudioDebugRecordingsBrowserTest, |
132 TwoCallsWithAudioDebugRecordings); | 130 TwoCallsWithAudioDebugRecordings); |
133 FRIEND_TEST_ALL_PREFIXES(WebRtcInternalsTest, | 131 FRIEND_TEST_ALL_PREFIXES(WebRtcInternalsTest, |
134 AudioDebugRecordingsFileSelectionCanceled); | 132 AudioDebugRecordingsFileSelectionCanceled); |
(...skipping 23 matching lines...) Expand all Loading... | |
158 // Enables event log recordings on all render process hosts using | 156 // Enables event log recordings on all render process hosts using |
159 // |event_log_recordings_file_path_|. | 157 // |event_log_recordings_file_path_|. |
160 void EnableEventLogRecordingsOnAllRenderProcessHosts(); | 158 void EnableEventLogRecordingsOnAllRenderProcessHosts(); |
161 #endif | 159 #endif |
162 | 160 |
163 // Updates the number of open PeerConnections. Called when a PeerConnection | 161 // Updates the number of open PeerConnections. Called when a PeerConnection |
164 // is stopped or removed. | 162 // is stopped or removed. |
165 void MaybeClosePeerConnection(base::DictionaryValue* record); | 163 void MaybeClosePeerConnection(base::DictionaryValue* record); |
166 | 164 |
167 // Called whenever a PeerConnection is created or stopped in order to | 165 // Called whenever a PeerConnection is created or stopped in order to |
168 // impose/release a block on suspending the current application for power | 166 // request/cancel a wake lock on suspending the current application for power |
169 // saving. | 167 // saving. |
170 void CreateOrReleasePowerSaveBlocker(); | 168 void UpdateWakeLock(); |
169 | |
170 device::mojom::WakeLockService* GetWakeLockService(); | |
171 | 171 |
172 // Called on a timer to deliver updates to javascript. | 172 // Called on a timer to deliver updates to javascript. |
173 // We throttle and bulk together updates to avoid DOS like scenarios where | 173 // We throttle and bulk together updates to avoid DOS like scenarios where |
174 // a page uses a lot of peerconnection instances with many event | 174 // a page uses a lot of peerconnection instances with many event |
175 // notifications. | 175 // notifications. |
176 void ProcessPendingUpdates(); | 176 void ProcessPendingUpdates(); |
177 | 177 |
178 base::DictionaryValue* FindRecord(base::ProcessId pid, | 178 base::DictionaryValue* FindRecord(base::ProcessId pid, |
179 int lid, | 179 int lid, |
180 size_t* index = nullptr); | 180 size_t* index = nullptr); |
(...skipping 30 matching lines...) Expand all Loading... | |
211 | 211 |
212 // Diagnostic audio recording state. | 212 // Diagnostic audio recording state. |
213 bool audio_debug_recordings_; | 213 bool audio_debug_recordings_; |
214 base::FilePath audio_debug_recordings_file_path_; | 214 base::FilePath audio_debug_recordings_file_path_; |
215 | 215 |
216 // Diagnostic event log recording state. | 216 // Diagnostic event log recording state. |
217 bool event_log_recordings_; | 217 bool event_log_recordings_; |
218 bool selecting_event_log_; | 218 bool selecting_event_log_; |
219 base::FilePath event_log_recordings_file_path_; | 219 base::FilePath event_log_recordings_file_path_; |
220 | 220 |
221 // While |num_open_connections_| is greater than zero, hold an instance of | 221 // While |num_open_connections_| is greater than zero, request a wake lock |
222 // PowerSaveBlocker. This prevents the application from being suspended while | 222 // service. This prevents the application from being suspended while remoting. |
223 // remoting. | |
224 int num_open_connections_; | 223 int num_open_connections_; |
225 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker_; | |
226 const bool should_block_power_saving_; | 224 const bool should_block_power_saving_; |
227 | 225 |
228 // Set of render process hosts that |this| is registered as an observer on. | 226 // Set of render process hosts that |this| is registered as an observer on. |
229 base::hash_set<int> render_process_id_set_; | 227 base::hash_set<int> render_process_id_set_; |
230 | 228 |
231 // Used to bulk up updates that we send to javascript. | 229 // Used to bulk up updates that we send to javascript. |
232 // The class owns the value/dictionary and command name of an update. | 230 // The class owns the value/dictionary and command name of an update. |
233 // For each update, a PendingUpdate is stored in the |pending_updates_| queue | 231 // For each update, a PendingUpdate is stored in the |pending_updates_| queue |
234 // and deleted as soon as the update has been delivered. | 232 // and deleted as soon as the update has been delivered. |
235 // The class is moveble and not copyable to avoid copying while still allowing | 233 // The class is moveble and not copyable to avoid copying while still allowing |
(...skipping 20 matching lines...) Expand all Loading... | |
256 std::queue<PendingUpdate> pending_updates_; | 254 std::queue<PendingUpdate> pending_updates_; |
257 const int aggregate_updates_ms_; | 255 const int aggregate_updates_ms_; |
258 | 256 |
259 // Weak factory for this object that we use for bulking up updates. | 257 // Weak factory for this object that we use for bulking up updates. |
260 base::WeakPtrFactory<WebRTCInternals> weak_factory_; | 258 base::WeakPtrFactory<WebRTCInternals> weak_factory_; |
261 }; | 259 }; |
262 | 260 |
263 } // namespace content | 261 } // namespace content |
264 | 262 |
265 #endif // CONTENT_BROWSER_WEBRTC_WEBRTC_INTERNALS_H_ | 263 #endif // CONTENT_BROWSER_WEBRTC_WEBRTC_INTERNALS_H_ |
OLD | NEW |