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 #include <vector> |
9 | 10 |
| 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/macros.h" |
10 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/threading/thread_checker.h" |
| 15 #include "base/timer/timer.h" |
11 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 17 #include "content/renderer/p2p/network_list_manager.h" |
| 18 #include "content/renderer/p2p/network_list_observer.h" |
12 #include "third_party/webrtc/base/network.h" | 19 #include "third_party/webrtc/base/network.h" |
| 20 #include "third_party/webrtc/base/sigslot.h" |
| 21 #include "third_party/webrtc/p2p/stunprober/stunprober.h" |
13 | 22 |
14 namespace rtc { | 23 namespace rtc { |
15 class PacketSocketFactory; | 24 class PacketSocketFactory; |
16 class SocketAddress; | 25 class SocketAddress; |
17 } // namespace rtc | 26 } // namespace rtc |
18 | 27 |
19 namespace stunprober { | |
20 class StunProber; | |
21 } // namespace stunprober | |
22 | |
23 namespace content { | 28 namespace content { |
24 | 29 |
25 // Wait for 30 seconds to avoid high CPU usage during browser start-up which | 30 // 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 | 31 // 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 | 32 // 1 ms for no more than 3 seconds to see if time has passed for sending next |
28 // stun probe. | 33 // stun probe. |
29 static const int kExperimentStartDelayMs = 30000; | 34 static const int kExperimentStartDelayMs = 30000; |
30 | 35 |
31 // This will use |factory| to create sockets, send stun binding requests with | 36 class StunProberTrial : public stunprober::StunProber::Observer, |
32 // various intervals as determined by |params|, observed the success rate and | 37 public sigslot::has_slots<> { |
33 // latency of the stun responses and report through UMA. | 38 public: |
34 scoped_ptr<stunprober::StunProber> StartStunProbeTrial( | 39 struct CONTENT_EXPORT Param { |
35 const rtc::NetworkManager::NetworkList& networks, | 40 Param(); |
36 const std::string& params, | 41 ~Param(); |
37 rtc::PacketSocketFactory* factory); | 42 int requests_per_ip = 0; |
| 43 int interval_ms = 0; |
| 44 int shared_socket_mode = 0; |
| 45 int batch_size = 0; |
| 46 int total_batches = 0; |
| 47 std::vector<rtc::SocketAddress> servers; |
| 48 }; |
38 | 49 |
39 // Parsing function to decode the '/' separated parameter string |params|. | 50 StunProberTrial(rtc::NetworkManager* network_manager, |
40 CONTENT_EXPORT bool ParseStunProbeParameters( | 51 const std::string& params, |
41 const std::string& params, | 52 rtc::PacketSocketFactory* factory); |
42 int* requests_per_ip, | 53 ~StunProberTrial() override; |
43 int* interval_ms, | 54 |
44 int* shared_socket_mode, | 55 private: |
45 std::vector<rtc::SocketAddress>* servers); | 56 // This will use |factory_| to create sockets, send stun binding requests with |
| 57 // various intervals as determined by |params|, observed the success rate and |
| 58 // latency of the stun responses and report through UMA. |
| 59 void OnNetworksChanged(); |
| 60 |
| 61 // Parsing function to decode the '/' separated parameter string |params|. |
| 62 static CONTENT_EXPORT bool ParseParameters(const std::string& param_line, |
| 63 Param* params); |
| 64 |
| 65 // stunprober::StunProber::Observer: |
| 66 void OnPrepared(stunprober::StunProber* prober, |
| 67 stunprober::StunProber::Status status) override; |
| 68 // OnFinished is invoked when the StunProber receives all the responses or |
| 69 // times out. |
| 70 void OnFinished(stunprober::StunProber* prober, |
| 71 stunprober::StunProber::Status status) override; |
| 72 |
| 73 // This will be invoked repeatedly for |total_probers_| times with the |
| 74 // interval equal to the estimated run time of a prober. |
| 75 void OnTimer(); |
| 76 |
| 77 void SaveHistogramData(); |
| 78 |
| 79 rtc::NetworkManager* network_manager_; |
| 80 std::string param_line_; |
| 81 rtc::PacketSocketFactory* factory_ = nullptr; |
| 82 int total_probers_ = 0; |
| 83 int batch_size_ = 0; |
| 84 int ready_probers_ = 0; |
| 85 int started_probers_ = 0; |
| 86 int finished_probers_ = 0; |
| 87 std::vector<stunprober::StunProber*> probers_; |
| 88 base::ThreadChecker thread_checker_; |
| 89 |
| 90 // The reason we use a timer instead of depending on the OnFinished callback |
| 91 // of each prober is that the OnFinished is not fired at the last of STUN |
| 92 // request of each prober, instead, it includes a timeout period which waits |
| 93 // the server response to come back. Having a timer guarantees the |
| 94 // inter-prober intervals is the same as the STUN interval inside a prober. |
| 95 base::RepeatingTimer timer_; |
| 96 |
| 97 FRIEND_TEST_ALL_PREFIXES(StunProbeTrial, VerifyParameterParsing); |
| 98 DISALLOW_COPY_AND_ASSIGN(StunProberTrial); |
| 99 }; |
46 | 100 |
47 } // namespace content | 101 } // namespace content |
48 | 102 |
49 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_STUN_FIELD_TRIAL_H_ | 103 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_STUN_FIELD_TRIAL_H_ |
OLD | NEW |