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

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: Fix gn build 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 | « content/browser/BUILD.gn ('k') | 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..4fbcd1d5337c22c86a5234e2308e9ba7891ca141 100644
--- a/content/browser/media/webrtc_internals.h
+++ b/content/browser/media/webrtc_internals.h
@@ -5,10 +5,13 @@
#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/values.h"
@@ -81,8 +84,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 +103,13 @@ class CONTENT_EXPORT WebRTCInternals : public RenderProcessHostObserver,
bool IsEventLogRecordingsEnabled() const;
const base::FilePath& GetEventLogRecordingsFilePath() const;
- void ResetForTesting();
+ protected:
Henrik Grunell 2016/02/09 08:18:11 Nice to get rid of the testing function!
+ // Constructor/Destructor are protected to allow tests to derive from the
+ // class and do per-instance testing without having to use the global
+ // instance.
+ WebRTCInternals();
+ explicit WebRTCInternals(int aggregate_updates_ms);
+ ~WebRTCInternals() override;
private:
friend struct base::DefaultLazyInstanceTraits<WebRTCInternals>;
@@ -113,10 +122,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 +151,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 +203,28 @@ 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_;
+
+ class PendingUpdate {
+ public:
+ PendingUpdate(const std::string& command, scoped_ptr<base::Value> value);
+ PendingUpdate(PendingUpdate&& other);
+ ~PendingUpdate();
+
+ const std::string& command() const { return command_; }
+ const base::Value* value() const { return value_.get(); }
+
+ private:
+ std::string command_;
+ scoped_ptr<base::Value> value_;
+ DISALLOW_COPY_AND_ASSIGN(PendingUpdate);
+ };
+
+ bool pending_updates_queued_;
+ 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 | « content/browser/BUILD.gn ('k') | content/browser/media/webrtc_internals.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698