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

Unified Diff: content/renderer/media/webrtc/stun_field_trial.h

Issue 1417663004: Create an experiment to study whether too many bindings cause NAT failure (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update UMA name in code to match with histograms.xml Created 5 years, 1 month 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
Index: content/renderer/media/webrtc/stun_field_trial.h
diff --git a/content/renderer/media/webrtc/stun_field_trial.h b/content/renderer/media/webrtc/stun_field_trial.h
index 4095bede6812c01ab81f8b934d2f642a2731e52f..dc1629e4d4b15fb84fd34169847a5038689b95c7 100644
--- a/content/renderer/media/webrtc/stun_field_trial.h
+++ b/content/renderer/media/webrtc/stun_field_trial.h
@@ -6,20 +6,25 @@
#define CONTENT_RENDERER_MEDIA_WEBRTC_STUN_FIELD_TRIAL_H_
#include <string>
+#include <vector>
+#include "base/gtest_prod_util.h"
+#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
+#include "base/threading/thread_checker.h"
+#include "base/timer/timer.h"
#include "content/common/content_export.h"
+#include "content/renderer/p2p/network_list_manager.h"
+#include "content/renderer/p2p/network_list_observer.h"
#include "third_party/webrtc/base/network.h"
+#include "third_party/webrtc/base/sigslot.h"
+#include "third_party/webrtc/p2p/stunprober/stunprober.h"
namespace rtc {
class PacketSocketFactory;
class SocketAddress;
} // namespace rtc
-namespace stunprober {
-class StunProber;
-} // namespace stunprober
-
namespace content {
// Wait for 30 seconds to avoid high CPU usage during browser start-up which
@@ -28,21 +33,70 @@ namespace content {
// stun probe.
static const int kExperimentStartDelayMs = 30000;
-// This will use |factory| to create sockets, send stun binding requests with
-// various intervals as determined by |params|, observed the success rate and
-// latency of the stun responses and report through UMA.
-scoped_ptr<stunprober::StunProber> StartStunProbeTrial(
- const rtc::NetworkManager::NetworkList& networks,
- const std::string& params,
- rtc::PacketSocketFactory* factory);
-
-// Parsing function to decode the '/' separated parameter string |params|.
-CONTENT_EXPORT bool ParseStunProbeParameters(
- const std::string& params,
- int* requests_per_ip,
- int* interval_ms,
- int* shared_socket_mode,
- std::vector<rtc::SocketAddress>* servers);
+class StunProberTrial : public stunprober::StunProber::Observer,
+ public sigslot::has_slots<> {
+ public:
+ struct CONTENT_EXPORT Param {
+ Param();
+ ~Param();
+ int requests_per_ip = 0;
+ int interval_ms = 0;
+ int shared_socket_mode = 0;
+ int batch_size = 0;
+ int total_batches = 0;
+ std::vector<rtc::SocketAddress> servers;
+ };
+
+ StunProberTrial(rtc::NetworkManager* network_manager,
+ const std::string& params,
+ rtc::PacketSocketFactory* factory);
+ ~StunProberTrial() override;
+
+ private:
+ // This will use |factory_| to create sockets, send stun binding requests with
+ // various intervals as determined by |params|, observed the success rate and
+ // latency of the stun responses and report through UMA.
+ void OnNetworksChanged();
+
+ // Parsing function to decode the '/' separated parameter string |params|.
+ static CONTENT_EXPORT bool ParseParameters(const std::string& param_line,
+ Param* params);
+
+ // stunprober::StunProber::Observer:
+ void OnPrepared(stunprober::StunProber* prober,
+ stunprober::StunProber::Status status) override;
+ // OnFinished is invoked when the StunProber receives all the responses or
+ // times out.
+ void OnFinished(stunprober::StunProber* prober,
+ stunprober::StunProber::Status status) override;
+
+ // This will be invoked repeatedly for |total_probers_| times with the
+ // interval equal to the estimated run time of a prober.
+ void OnTimer();
+
+ void SaveHistogramData();
+
+ rtc::NetworkManager* network_manager_;
+ std::string param_line_;
+ rtc::PacketSocketFactory* factory_ = nullptr;
+ int total_probers_ = 0;
+ int batch_size_ = 0;
+ int ready_probers_ = 0;
+ int started_probers_ = 0;
+ int finished_probers_ = 0;
+ std::vector<stunprober::StunProber*> probers_;
+ base::ThreadChecker thread_checker_;
+
+ // The reason we use a timer instead of depending on the OnFinished callback
+ // of each prober is that the OnFinished is not fired at the last of STUN
+ // request of each prober, instead, it includes a timeout period which waits
+ // the server response to come back. Having a timer guarantees the
+ // inter-prober intervals is the same as the STUN interval inside a prober.
+ base::RepeatingTimer timer_;
+
+ FRIEND_TEST_ALL_PREFIXES(StunProbeTrial, VerifyParameterParsing);
+ DISALLOW_COPY_AND_ASSIGN(StunProberTrial);
+};
} // namespace content
« no previous file with comments | « content/renderer/media/webrtc/peer_connection_dependency_factory.cc ('k') | content/renderer/media/webrtc/stun_field_trial.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698