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_; } | 111 bool HasWakeLockForTesting() const { return has_wake_lock_for_testing_; } |
emircan
2017/05/18 00:09:33
I think adding *ForTesting() methods should be the
ke.he
2017/05/18 05:34:15
I'll remove the *ForTesting() methods, Thanks!
| |
115 | 112 |
116 protected: | 113 protected: |
117 // Constructor/Destructor are protected to allow tests to derive from the | 114 // Constructor/Destructor are protected to allow tests to derive from the |
118 // class and do per-instance testing without having to use the global | 115 // class and do per-instance testing without having to use the global |
119 // instance. | 116 // instance. |
120 // The default ctor sets |aggregate_updates_ms| to 500ms. | 117 // The default ctor sets |aggregate_updates_ms| to 500ms. |
121 WebRTCInternals(); | 118 WebRTCInternals(); |
122 WebRTCInternals(int aggregate_updates_ms, bool should_block_power_saving); | 119 WebRTCInternals(int aggregate_updates_ms, bool should_block_power_saving); |
123 ~WebRTCInternals() override; | 120 ~WebRTCInternals() override; |
124 | 121 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 // Enables event log recordings on all render process hosts using | 155 // Enables event log recordings on all render process hosts using |
159 // |event_log_recordings_file_path_|. | 156 // |event_log_recordings_file_path_|. |
160 void EnableEventLogRecordingsOnAllRenderProcessHosts(); | 157 void EnableEventLogRecordingsOnAllRenderProcessHosts(); |
161 #endif | 158 #endif |
162 | 159 |
163 // Updates the number of open PeerConnections. Called when a PeerConnection | 160 // Updates the number of open PeerConnections. Called when a PeerConnection |
164 // is stopped or removed. | 161 // is stopped or removed. |
165 void MaybeClosePeerConnection(base::DictionaryValue* record); | 162 void MaybeClosePeerConnection(base::DictionaryValue* record); |
166 | 163 |
167 // Called whenever a PeerConnection is created or stopped in order to | 164 // Called whenever a PeerConnection is created or stopped in order to |
168 // impose/release a block on suspending the current application for power | 165 // request/cancel a wake lock on suspending the current application for power |
169 // saving. | 166 // saving. |
170 void CreateOrReleasePowerSaveBlocker(); | 167 void UpdateWakeLock(); |
168 | |
169 device::mojom::WakeLockService* GetWakeLock(); | |
chfremer
2017/05/17 22:51:15
nit: Should this method be named GetWakeLockServic
ke.he
2017/05/18 05:34:15
Done.
| |
171 | 170 |
172 // Called on a timer to deliver updates to javascript. | 171 // Called on a timer to deliver updates to javascript. |
173 // We throttle and bulk together updates to avoid DOS like scenarios where | 172 // We throttle and bulk together updates to avoid DOS like scenarios where |
174 // a page uses a lot of peerconnection instances with many event | 173 // a page uses a lot of peerconnection instances with many event |
175 // notifications. | 174 // notifications. |
176 void ProcessPendingUpdates(); | 175 void ProcessPendingUpdates(); |
177 | 176 |
178 base::DictionaryValue* FindRecord(base::ProcessId pid, | 177 base::DictionaryValue* FindRecord(base::ProcessId pid, |
179 int lid, | 178 int lid, |
180 size_t* index = nullptr); | 179 size_t* index = nullptr); |
(...skipping 30 matching lines...) Expand all Loading... | |
211 | 210 |
212 // Diagnostic audio recording state. | 211 // Diagnostic audio recording state. |
213 bool audio_debug_recordings_; | 212 bool audio_debug_recordings_; |
214 base::FilePath audio_debug_recordings_file_path_; | 213 base::FilePath audio_debug_recordings_file_path_; |
215 | 214 |
216 // Diagnostic event log recording state. | 215 // Diagnostic event log recording state. |
217 bool event_log_recordings_; | 216 bool event_log_recordings_; |
218 bool selecting_event_log_; | 217 bool selecting_event_log_; |
219 base::FilePath event_log_recordings_file_path_; | 218 base::FilePath event_log_recordings_file_path_; |
220 | 219 |
221 // While |num_open_connections_| is greater than zero, hold an instance of | 220 // While |num_open_connections_| is greater than zero, request a wake lock |
222 // PowerSaveBlocker. This prevents the application from being suspended while | 221 // service. This prevents the application from being suspended while remoting. |
223 // remoting. | |
224 int num_open_connections_; | 222 int num_open_connections_; |
225 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker_; | 223 device::mojom::WakeLockServicePtr wake_lock_; |
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 13 matching lines...) Expand all Loading... | |
249 private: | 247 private: |
250 base::ThreadChecker thread_checker_; | 248 base::ThreadChecker thread_checker_; |
251 const char* command_; | 249 const char* command_; |
252 std::unique_ptr<base::Value> value_; | 250 std::unique_ptr<base::Value> value_; |
253 DISALLOW_COPY_AND_ASSIGN(PendingUpdate); | 251 DISALLOW_COPY_AND_ASSIGN(PendingUpdate); |
254 }; | 252 }; |
255 | 253 |
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 |
257 bool has_wake_lock_for_testing_; | |
chfremer
2017/05/17 22:51:15
As an idea for how the same thing could be achieve
ke.he
2017/05/18 05:34:15
Inject an instance of "WakeLockService" IIUC. Than
chfremer
2017/05/18 17:48:31
Nice, the solution in PatchSet 3 no longer require
ke.he
2017/05/19 03:34:50
Now I understand what you mean, thanks very much f
| |
258 | |
259 // Weak factory for this object that we use for bulking up updates. | 259 // Weak factory for this object that we use for bulking up updates. |
260 base::WeakPtrFactory<WebRTCInternals> weak_factory_; | 260 base::WeakPtrFactory<WebRTCInternals> weak_factory_; |
261 }; | 261 }; |
262 | 262 |
263 } // namespace content | 263 } // namespace content |
264 | 264 |
265 #endif // CONTENT_BROWSER_WEBRTC_WEBRTC_INTERNALS_H_ | 265 #endif // CONTENT_BROWSER_WEBRTC_WEBRTC_INTERNALS_H_ |
OLD | NEW |