Chromium Code Reviews| 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 { |
| 18 struct DnsConfig; | 19 struct DnsConfig; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace chrome_browser_net { | 22 class DnsProbeService : public net::NetworkChangeNotifier::DNSObserver { |
|
cbentzel
2013/06/10 17:10:00
Why did you remove the namespace?
Deprecated (see juliatuttle)
2013/06/11 01:07:34
Obsolete.
| |
| 22 | |
| 23 class DnsProbeService : public net::NetworkChangeNotifier::IPAddressObserver { | |
| 24 public: | 23 public: |
| 25 typedef base::Callback<void(chrome_common_net::DnsProbeResult result)> | 24 typedef base::Callback<void(chrome_common_net::DnsProbeStatus result)> |
| 26 CallbackType; | 25 ProbeCallback; |
| 27 | 26 |
| 28 DnsProbeService(); | 27 DnsProbeService(); |
| 29 virtual ~DnsProbeService(); | 28 virtual ~DnsProbeService(); |
| 30 | 29 |
| 31 void ProbeDns(const CallbackType& callback); | 30 void ProbeDns(const ProbeCallback& callback); |
| 31 void ExpireResultForTesting(); | |
| 32 DnsProbeRunner* GetProbeRunnerForTesting(); | |
| 32 | 33 |
| 33 // NetworkChangeNotifier::IPAddressObserver implementation: | 34 // NetworkChangeNotifier::DNSObserver implementation: |
| 34 virtual void OnIPAddressChanged() OVERRIDE; | 35 virtual void OnDNSChanged() OVERRIDE; |
|
szym
2013/06/07 19:31:28
You have it both here and in DnsProbeRunner.
In D
Deprecated (see juliatuttle)
2013/06/11 01:07:34
Done.
| |
| 35 | 36 |
| 36 protected: | 37 protected: |
| 37 // This can be called by tests to pretend the cached reuslt has expired. | 38 void ExpireResult(); |
| 38 void ExpireResults(); | |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 enum State { | 41 enum State { |
| 42 STATE_NO_RESULTS, | 42 STATE_NO_RESULTS, |
| 43 STATE_PROBE_RUNNING, | 43 STATE_PROBE_RUNNING, |
| 44 STATE_RESULTS_CACHED, | 44 STATE_RESULTS_CACHED, |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 void StartProbes(); | 47 void StartProbes(); |
| 48 void OnProbeComplete(DnsProbeRunner::Type type, | |
| 49 DnsProbeRunner::Result result); | |
| 48 void OnProbesComplete(); | 50 void OnProbesComplete(); |
| 51 chrome_common_net::DnsProbeStatus EvaluateResults() const; | |
| 52 void HistogramProbes() const; | |
| 49 void CallCallbacks(); | 53 void CallCallbacks(); |
| 50 | 54 |
| 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(); | 55 bool ResultsExpired(); |
| 67 | 56 |
| 68 scoped_ptr<DnsProbeJob> system_job_; | 57 DnsProbeRunner probe_runner_; |
| 69 scoped_ptr<DnsProbeJob> public_job_; | |
| 70 DnsProbeJob::Result system_result_; | |
| 71 DnsProbeJob::Result public_result_; | |
| 72 std::vector<CallbackType> callbacks_; | |
| 73 State state_; | 58 State state_; |
| 74 chrome_common_net::DnsProbeResult result_; | 59 bool system_done_; |
| 60 bool public_done_; | |
| 61 DnsProbeRunner::Result system_result_; | |
| 62 DnsProbeRunner::Result public_result_; | |
| 63 std::vector<ProbeCallback> pending_callbacks_; | |
| 64 chrome_common_net::DnsProbeStatus result_; | |
| 75 base::Time probe_start_time_; | 65 base::Time probe_start_time_; |
| 76 // How many DNS request attempts the probe jobs will make before giving up | |
| 77 // (Overrides the attempts field in the system DnsConfig.) | |
| 78 const int dns_attempts_; | |
| 79 // How many nameservers the system config has. | |
| 80 int system_nameserver_count_; | |
| 81 // Whether the only system nameserver is 127.0.0.1. | |
| 82 bool system_is_localhost_; | |
| 83 | 66 |
| 84 DISALLOW_COPY_AND_ASSIGN(DnsProbeService); | 67 DISALLOW_COPY_AND_ASSIGN(DnsProbeService); |
| 85 }; | 68 }; |
| 86 | 69 |
| 87 } // namespace chrome_browser_net | |
| 88 | |
| 89 #endif // CHROME_BROWSER_NET_DNS_PROBE_SERVICE_H_ | 70 #endif // CHROME_BROWSER_NET_DNS_PROBE_SERVICE_H_ |
| OLD | NEW |