Chromium Code Reviews| 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..82ab259a45ddfbd37c1c7db5b4e36f5308092015 100644 |
| --- a/content/renderer/media/webrtc/stun_field_trial.h |
| +++ b/content/renderer/media/webrtc/stun_field_trial.h |
| @@ -8,41 +8,92 @@ |
| #include <string> |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/threading/thread_checker.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 { |
| +using StunProber = stunprober::StunProber; |
| + |
| +// Helper class to link the StunProbers together such that the first STUN ping |
| +// in the next prober could be sent at the same interval as inside a |
| +// prober. This is to maintain the consistency of intervals across the whole |
| +// trial. |
| +class StunProberWithWeakPtr { |
|
pthatcher2
2015/10/29 14:13:13
This still seems an awkward way of storing a list
guoweis_webrtc
2015/10/29 21:45:30
If the pc gets deleted after a Start has been sche
|
| + public: |
| + StunProberWithWeakPtr(StunProber* prober); |
| + virtual ~StunProberWithWeakPtr(); |
| + void set_next_prober(StunProberWithWeakPtr* prober); |
| + void Start(StunProber::Observer* observer); |
| + base::WeakPtr<StunProberWithWeakPtr> GetWeakPtr() { |
| + return weak_factory_.GetWeakPtr(); |
| + } |
| + bool GetStats(StunProber::Stats* stats) { return prober_->GetStats(stats); } |
| + StunProberWithWeakPtr* GetNextProber() { return next_prober_; } |
| + |
| + private: |
| + scoped_ptr<StunProber> prober_; |
| + StunProberWithWeakPtr* next_prober_ = nullptr; |
| + base::WeakPtrFactory<StunProberWithWeakPtr> weak_factory_; |
| +}; |
| + |
| // Wait for 30 seconds to avoid high CPU usage during browser start-up which |
| // might affect the accuracy of the trial. The trial wakes up the browser every |
| // 1 ms for no more than 3 seconds to see if time has passed for sending next |
| // 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::Observer, |
| + public sigslot::has_slots<> { |
| + public: |
| + StunProberTrial(rtc::NetworkManager* network_manager, |
| + const std::string& params, |
| + rtc::PacketSocketFactory* factory); |
| + ~StunProberTrial() override; |
| + |
| + // This will use |factory| to create sockets, send stun binding requests with |
|
pthatcher2
2015/10/29 14:13:13
|factory_|?
guoweis_webrtc
2015/10/29 21:45:30
Done.
|
| + // 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& params, |
| + int* requests_per_ip, |
| + int* interval_ms, |
| + int* shared_socket_mode, |
| + int* batch_size, |
| + int* total_batches, |
| + std::vector<rtc::SocketAddress>* servers); |
| + |
| + // stunprober::StunProber::Observer |
| + void OnPrepared(StunProber* prober, StunProber::Status status) override; |
| + void OnFinished(StunProber* prober, StunProber::Status status) override; |
| + |
| + private: |
| + void SaveHistogramData(); |
| + |
| + rtc::NetworkManager* network_manager_; |
| + std::string params_; |
| + rtc::PacketSocketFactory* factory_ = nullptr; |
| + int total_probers_ = 0; |
| + int batch_size_ = 0; |
| + int ready_probers_ = 0; |
| + int finished_probers_ = 0; |
| + scoped_ptr<StunProberWithWeakPtr> prober_head_; |
| + base::ThreadChecker thread_checker_; |
| +}; |
| } // namespace content |