OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_NET_DNS_PROBE_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_NET_DNS_PROBE_SERVICE_H_ |
6 #define CHROME_BROWSER_NET_DNS_PROBE_SERVICE_H_ | 6 #define CHROME_BROWSER_NET_DNS_PROBE_SERVICE_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/bind.h" | |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "base/time.h" | 13 #include "base/time.h" |
13 #include "chrome/browser/net/dns_probe_job.h" | 14 #include "chrome/browser/net/dns_probe_runner.h" |
14 #include "chrome/common/net/net_error_info.h" | 15 #include "chrome/common/net/net_error_info.h" |
15 #include "net/base/network_change_notifier.h" | 16 #include "net/base/network_change_notifier.h" |
16 | 17 |
17 namespace net { | 18 namespace net { |
19 class DnsClient; | |
18 struct DnsConfig; | 20 struct DnsConfig; |
19 } | 21 } |
20 | 22 |
21 namespace chrome_browser_net { | 23 namespace chrome_browser_net { |
22 | 24 |
23 class DnsProbeService : public net::NetworkChangeNotifier::IPAddressObserver { | 25 // Probes the system and public DNS servers to determine the (probable) cause |
26 // of a recent DNS-related page load error. Coalesces multiple probe requests | |
27 // (perhaps from multiple tabs) and caches the results. | |
28 class DnsProbeService : public net::NetworkChangeNotifier::DNSObserver { | |
24 public: | 29 public: |
25 typedef base::Callback<void(chrome_common_net::DnsProbeResult result)> | 30 typedef base::Callback<void(chrome_common_net::DnsProbeStatus result)> |
26 CallbackType; | 31 ProbeCallback; |
27 | 32 |
28 DnsProbeService(); | 33 DnsProbeService(); |
29 virtual ~DnsProbeService(); | 34 virtual ~DnsProbeService(); |
30 | 35 |
31 void ProbeDns(const CallbackType& callback); | 36 void ProbeDns(const ProbeCallback& callback); |
32 | 37 |
33 // NetworkChangeNotifier::IPAddressObserver implementation: | 38 // NetworkChangeNotifier::DNSObserver implementation: |
34 virtual void OnIPAddressChanged() OVERRIDE; | 39 virtual void OnDNSChanged() OVERRIDE; |
35 | 40 |
36 protected: | 41 void SetSystemClientForTesting(scoped_ptr<net::DnsClient> system_client); |
37 // This can be called by tests to pretend the cached reuslt has expired. | 42 void SetPublicClientForTesting(scoped_ptr<net::DnsClient> public_client); |
38 void ExpireResults(); | 43 void ExpireResultForTesting(); |
39 | 44 |
40 private: | 45 private: |
41 enum State { | 46 enum State { |
42 STATE_NO_RESULTS, | 47 STATE_NO_RESULTS, |
43 STATE_PROBE_RUNNING, | 48 STATE_PROBE_RUNNING, |
44 STATE_RESULTS_CACHED, | 49 STATE_RESULTS_CACHED, |
45 }; | 50 }; |
46 | 51 |
52 enum ProbeType { | |
53 SYSTEM, | |
54 PUBLIC | |
55 }; | |
56 | |
57 void SetSystemClientToCurrentConfig(); | |
58 void SetPublicClientToGooglePublicDns(); | |
59 | |
60 void SetSystemClient(scoped_ptr<net::DnsClient> system_client); | |
61 void SetPublicClient(scoped_ptr<net::DnsClient> public_client); | |
62 | |
47 void StartProbes(); | 63 void StartProbes(); |
48 void OnProbesComplete(); | 64 void OnProbeComplete(ProbeType type, DnsProbeRunner::Result result); |
65 chrome_common_net::DnsProbeStatus EvaluateResults() const; | |
mmenke
2013/06/11 16:15:35
Think a couple of these may be woth comments.
Deprecated (see juliatuttle)
2013/06/13 14:37:04
Done.
| |
66 void HistogramProbes() const; | |
49 void CallCallbacks(); | 67 void CallCallbacks(); |
68 void ExpireResult(); | |
50 | 69 |
51 void OnProbeJobComplete(DnsProbeJob* job, DnsProbeJob::Result result); | |
52 chrome_common_net::DnsProbeResult EvaluateResults() const; | |
53 void HistogramProbes() const; | |
54 | |
55 // These are expected to be overridden by tests to return mock jobs. | |
56 virtual scoped_ptr<DnsProbeJob> CreateSystemProbeJob( | |
57 const DnsProbeJob::CallbackType& job_callback); | |
58 virtual scoped_ptr<DnsProbeJob> CreatePublicProbeJob( | |
59 const DnsProbeJob::CallbackType& job_callback); | |
60 | |
61 scoped_ptr<DnsProbeJob> CreateProbeJob( | |
62 const net::DnsConfig& dns_config, | |
63 const DnsProbeJob::CallbackType& job_callback); | |
64 void GetSystemDnsConfig(net::DnsConfig* config); | |
65 void GetPublicDnsConfig(net::DnsConfig* config); | |
66 bool ResultsExpired(); | 70 bool ResultsExpired(); |
mmenke
2013/06/12 19:17:12
nit: const.
Deprecated (see juliatuttle)
2013/06/13 14:37:04
Done.
| |
67 | 71 |
68 scoped_ptr<DnsProbeJob> system_job_; | |
69 scoped_ptr<DnsProbeJob> public_job_; | |
70 DnsProbeJob::Result system_result_; | |
71 DnsProbeJob::Result public_result_; | |
72 std::vector<CallbackType> callbacks_; | |
73 State state_; | 72 State state_; |
74 chrome_common_net::DnsProbeResult result_; | 73 std::vector<ProbeCallback> pending_callbacks_; |
75 base::Time probe_start_time_; | 74 base::Time probe_start_time_; |
76 // How many DNS request attempts the probe jobs will make before giving up | 75 chrome_common_net::DnsProbeStatus result_; |
mmenke
2013/06/11 16:15:35
cached_result_, maybe?
Deprecated (see juliatuttle)
2013/06/13 14:37:04
Done.
| |
77 // (Overrides the attempts field in the system DnsConfig.) | 76 |
78 const int dns_attempts_; | 77 DnsProbeRunner system_runner_; |
79 // How many nameservers the system config has. | 78 DnsProbeRunner public_runner_; |
80 int system_nameserver_count_; | 79 DnsProbeRunner::Result system_result_; |
81 // Whether the only system nameserver is 127.0.0.1. | 80 DnsProbeRunner::Result public_result_; |
mmenke
2013/06/11 16:15:35
Think these are worth comments.
Deprecated (see juliatuttle)
2013/06/13 14:37:04
Done.
| |
82 bool system_is_localhost_; | |
83 | 81 |
84 DISALLOW_COPY_AND_ASSIGN(DnsProbeService); | 82 DISALLOW_COPY_AND_ASSIGN(DnsProbeService); |
85 }; | 83 }; |
86 | 84 |
87 } // namespace chrome_browser_net | 85 } // namespace chrome_browser_net |
88 | 86 |
89 #endif // CHROME_BROWSER_NET_DNS_PROBE_SERVICE_H_ | 87 #endif // CHROME_BROWSER_NET_DNS_PROBE_SERVICE_H_ |
OLD | NEW |