Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_RENDERER_MEDIA_WEBRTC_STUN_FIELD_TRIAL_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_STUN_FIELD_TRIAL_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_STUN_FIELD_TRIAL_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_STUN_FIELD_TRIAL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "base/threading/thread_checker.h" | |
| 11 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 15 #include "content/renderer/p2p/network_list_manager.h" | |
| 16 #include "content/renderer/p2p/network_list_observer.h" | |
| 12 #include "third_party/webrtc/base/network.h" | 17 #include "third_party/webrtc/base/network.h" |
| 18 #include "third_party/webrtc/base/sigslot.h" | |
| 19 #include "third_party/webrtc/p2p/stunprober/stunprober.h" | |
| 13 | 20 |
| 14 namespace rtc { | 21 namespace rtc { |
| 15 class PacketSocketFactory; | 22 class PacketSocketFactory; |
| 16 class SocketAddress; | 23 class SocketAddress; |
| 17 } // namespace rtc | 24 } // namespace rtc |
| 18 | 25 |
| 19 namespace stunprober { | 26 namespace content { |
| 20 class StunProber; | |
| 21 } // namespace stunprober | |
| 22 | 27 |
| 23 namespace content { | 28 using StunProber = stunprober::StunProber; |
|
Sergey Ulanov
2015/10/30 18:27:49
style guide doesn't allow 'using' in headers
guoweis_left_chromium
2015/10/30 21:47:13
Done.
| |
| 29 | |
| 30 // Helper class to link the StunProbers together such that the first STUN ping | |
| 31 // in the next prober could be sent at the same interval as inside a | |
| 32 // prober. This is to maintain the consistency of intervals across the whole | |
| 33 // trial. It uses weak pointer to trigger next prober's Start(), in case if the | |
| 34 // owning PeerConnectionDependencyFactory is deleted in between. | |
| 35 class StunProberWithWeakPtr { | |
|
Sergey Ulanov
2015/10/30 18:27:49
It looks to me that this is not just StunPropber w
guoweis_left_chromium
2015/10/30 21:47:13
Done.
| |
| 36 public: | |
| 37 explicit StunProberWithWeakPtr(StunProber* prober); | |
| 38 virtual ~StunProberWithWeakPtr(); | |
| 39 | |
| 40 void set_next_prober(StunProberWithWeakPtr* prober); | |
| 41 void Start(StunProber::Observer* observer); | |
| 42 base::WeakPtr<StunProberWithWeakPtr> GetWeakPtr() { | |
| 43 return weak_factory_.GetWeakPtr(); | |
| 44 } | |
| 45 bool GetStats(StunProber::Stats* stats) { return prober_->GetStats(stats); } | |
| 46 StunProberWithWeakPtr* GetNextProber() { return next_prober_; } | |
|
Alexei Svitkine (slow)
2015/10/30 17:32:19
Nit: This code doesn't seem to match the style gui
guoweis_left_chromium
2015/10/30 21:47:13
Done.
| |
| 47 | |
| 48 private: | |
| 49 scoped_ptr<StunProber> prober_; | |
| 50 StunProberWithWeakPtr* next_prober_ = nullptr; | |
| 51 base::WeakPtrFactory<StunProberWithWeakPtr> weak_factory_; | |
| 52 | |
| 53 DISALLOW_COPY_AND_ASSIGN(StunProberWithWeakPtr); | |
| 54 }; | |
| 24 | 55 |
| 25 // Wait for 30 seconds to avoid high CPU usage during browser start-up which | 56 // Wait for 30 seconds to avoid high CPU usage during browser start-up which |
| 26 // might affect the accuracy of the trial. The trial wakes up the browser every | 57 // might affect the accuracy of the trial. The trial wakes up the browser every |
| 27 // 1 ms for no more than 3 seconds to see if time has passed for sending next | 58 // 1 ms for no more than 3 seconds to see if time has passed for sending next |
| 28 // stun probe. | 59 // stun probe. |
| 29 static const int kExperimentStartDelayMs = 30000; | 60 static const int kExperimentStartDelayMs = 30000; |
| 30 | 61 |
| 31 // This will use |factory| to create sockets, send stun binding requests with | 62 class StunProberTrial : public StunProber::Observer, |
| 32 // various intervals as determined by |params|, observed the success rate and | 63 public sigslot::has_slots<> { |
| 33 // latency of the stun responses and report through UMA. | 64 public: |
| 34 scoped_ptr<stunprober::StunProber> StartStunProbeTrial( | 65 StunProberTrial(rtc::NetworkManager* network_manager, |
| 35 const rtc::NetworkManager::NetworkList& networks, | 66 const std::string& params, |
| 36 const std::string& params, | 67 rtc::PacketSocketFactory* factory); |
| 37 rtc::PacketSocketFactory* factory); | 68 ~StunProberTrial() override; |
| 38 | 69 |
| 39 // Parsing function to decode the '/' separated parameter string |params|. | 70 // This will use |factory_| to create sockets, send stun binding requests with |
| 40 CONTENT_EXPORT bool ParseStunProbeParameters( | 71 // various intervals as determined by |params|, observed the success rate and |
| 41 const std::string& params, | 72 // latency of the stun responses and report through UMA. |
| 42 int* requests_per_ip, | 73 void OnNetworksChanged(); |
| 43 int* interval_ms, | 74 |
| 44 int* shared_socket_mode, | 75 // Parsing function to decode the '/' separated parameter string |params|. |
| 45 std::vector<rtc::SocketAddress>* servers); | 76 static CONTENT_EXPORT bool ParseParameters( |
| 77 const std::string& params, | |
| 78 int* requests_per_ip, | |
| 79 int* interval_ms, | |
| 80 int* shared_socket_mode, | |
| 81 int* batch_size, | |
| 82 int* total_batches, | |
| 83 std::vector<rtc::SocketAddress>* servers); | |
| 84 | |
| 85 // stunprober::StunProber::Observer | |
| 86 void OnPrepared(StunProber* prober, StunProber::Status status) override; | |
| 87 void OnFinished(StunProber* prober, StunProber::Status status) override; | |
| 88 | |
| 89 private: | |
| 90 void SaveHistogramData(); | |
| 91 | |
| 92 rtc::NetworkManager* network_manager_; | |
| 93 std::string params_; | |
| 94 rtc::PacketSocketFactory* factory_ = nullptr; | |
| 95 int total_probers_ = 0; | |
| 96 int batch_size_ = 0; | |
| 97 int ready_probers_ = 0; | |
| 98 int finished_probers_ = 0; | |
| 99 scoped_ptr<StunProberWithWeakPtr> prober_head_; | |
| 100 base::ThreadChecker thread_checker_; | |
| 101 | |
| 102 DISALLOW_COPY_AND_ASSIGN(StunProberTrial); | |
| 103 }; | |
| 46 | 104 |
| 47 } // namespace content | 105 } // namespace content |
| 48 | 106 |
| 49 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_STUN_FIELD_TRIAL_H_ | 107 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_STUN_FIELD_TRIAL_H_ |
| OLD | NEW |