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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/browser/media/webrtc_internals.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/media/webrtc_internals.h
diff --git a/content/browser/media/webrtc_internals.h b/content/browser/media/webrtc_internals.h
index f6470008dd45937dcb0e016db8528ae58cc6e367..7b64ebc3c158f4ed5eaf6ab981473458e50ad42e 100644
--- a/content/browser/media/webrtc_internals.h
+++ b/content/browser/media/webrtc_internals.h
@@ -5,12 +5,16 @@
#ifndef CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_H_
#define CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_H_
+#include <queue>
+
#include "base/containers/hash_tables.h"
#include "base/gtest_prod_util.h"
#include "base/lazy_instance.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/process/process.h"
+#include "base/threading/thread_checker.h"
#include "base/values.h"
#include "content/common/content_export.h"
#include "content/public/browser/render_process_host_observer.h"
@@ -81,8 +85,8 @@ class CONTENT_EXPORT WebRTCInternals : public RenderProcessHostObserver,
const std::string& video_constraints);
// Methods for adding or removing WebRTCInternalsUIObserver.
- void AddObserver(WebRTCInternalsUIObserver *observer);
- void RemoveObserver(WebRTCInternalsUIObserver *observer);
+ void AddObserver(WebRTCInternalsUIObserver* observer);
+ void RemoveObserver(WebRTCInternalsUIObserver* observer);
// Sends all update data to |observer|.
void UpdateObserver(WebRTCInternalsUIObserver* observer);
@@ -100,7 +104,14 @@ class CONTENT_EXPORT WebRTCInternals : public RenderProcessHostObserver,
bool IsEventLogRecordingsEnabled() const;
const base::FilePath& GetEventLogRecordingsFilePath() const;
- void ResetForTesting();
+ protected:
+ // Constructor/Destructor are protected to allow tests to derive from the
+ // class and do per-instance testing without having to use the global
+ // instance.
+ // The default ctor sets |aggregate_updates_ms| to 500ms.
+ WebRTCInternals();
+ explicit WebRTCInternals(int aggregate_updates_ms);
+ ~WebRTCInternals() override;
private:
friend struct base::DefaultLazyInstanceTraits<WebRTCInternals>;
@@ -113,10 +124,7 @@ class CONTENT_EXPORT WebRTCInternals : public RenderProcessHostObserver,
FRIEND_TEST_ALL_PREFIXES(WebRtcInternalsTest,
AudioDebugRecordingsFileSelectionCanceled);
- WebRTCInternals();
- ~WebRTCInternals() override;
-
- void SendUpdate(const std::string& command, base::Value* value);
+ void SendUpdate(const std::string& command, scoped_ptr<base::Value> value);
// RenderProcessHostObserver implementation.
void RenderProcessHostDestroyed(RenderProcessHost* host) override;
@@ -145,6 +153,12 @@ class CONTENT_EXPORT WebRTCInternals : public RenderProcessHostObserver,
// application for power-saving.
void CreateOrReleasePowerSaveBlocker();
+ // Called on a timer to deliver updates to javascript.
+ // We throttle and bulk together updates to avoid DOS like scenarios where
+ // a page uses a lot of peerconnection instances with many event
+ // notifications.
+ void ProcessPendingUpdates();
+
base::ObserverList<WebRTCInternalsUIObserver> observers_;
// |peer_connection_data_| is a list containing all the PeerConnection
@@ -191,6 +205,36 @@ class CONTENT_EXPORT WebRTCInternals : public RenderProcessHostObserver,
// Set of render process hosts that |this| is registered as an observer on.
base::hash_set<int> render_process_id_set_;
+
+ // Used to bulk up updates that we send to javascript.
+ // The class owns the value/dictionary and command name of an update.
+ // For each update, a PendingUpdate is stored in the |pending_updates_| queue
+ // and deleted as soon as the update has been delivered.
+ // The class is moveble and not copyable to avoid copying while still allowing
+ // us to use an stl container without needing scoped_ptr or similar.
+ // The class is single threaded, so all operations must occur on the same
+ // thread.
+ class PendingUpdate {
+ public:
+ PendingUpdate(const std::string& command, scoped_ptr<base::Value> value);
+ PendingUpdate(PendingUpdate&& other);
+ ~PendingUpdate();
+
+ const std::string& command() const;
+ const base::Value* value() const;
+
+ private:
+ base::ThreadChecker thread_checker_;
+ std::string command_;
+ scoped_ptr<base::Value> value_;
+ DISALLOW_COPY_AND_ASSIGN(PendingUpdate);
+ };
+
+ std::queue<PendingUpdate> pending_updates_;
+ const int aggregate_updates_ms_;
+
+ // Weak factory for this object that we use for bulking up updates.
+ base::WeakPtrFactory<WebRTCInternals> weak_factory_;
};
} // namespace content
« 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