| 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/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/time.h" | 12 #include "base/time.h" |
| 13 #include "chrome/browser/net/dns_probe_job.h" | 13 #include "chrome/browser/net/dns_probe_job.h" |
| 14 #include "chrome/common/net/net_error_info.h" | 14 #include "chrome/common/net/net_error_info.h" |
| 15 #include "net/base/network_change_notifier.h" | 15 #include "net/base/network_change_notifier.h" |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 struct DnsConfig; | 18 struct DnsConfig; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace chrome_browser_net { | 21 namespace chrome_browser_net { |
| 22 | 22 |
| 23 class DnsProbeService : public net::NetworkChangeNotifier::IPAddressObserver { | 23 class DnsProbeService : public net::NetworkChangeNotifier::IPAddressObserver { |
| 24 public: | 24 public: |
| 25 typedef base::Callback<void(chrome_common_net::DnsProbeResult result)> | 25 typedef base::Callback<void(chrome_common_net::DnsProbeStatus result)> |
| 26 CallbackType; | 26 CallbackType; |
| 27 | 27 |
| 28 DnsProbeService(); | 28 DnsProbeService(); |
| 29 virtual ~DnsProbeService(); | 29 virtual ~DnsProbeService(); |
| 30 | 30 |
| 31 void ProbeDns(const CallbackType& callback); | 31 void ProbeDns(const CallbackType& callback); |
| 32 | 32 |
| 33 // NetworkChangeNotifier::IPAddressObserver implementation: | 33 // NetworkChangeNotifier::IPAddressObserver implementation: |
| 34 virtual void OnIPAddressChanged() OVERRIDE; | 34 virtual void OnIPAddressChanged() OVERRIDE; |
| 35 | 35 |
| 36 protected: | 36 protected: |
| 37 // This can be called by tests to pretend the cached reuslt has expired. | 37 // This can be called by tests to pretend the cached reuslt has expired. |
| 38 void ExpireResults(); | 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 OnProbesComplete(); | 48 void OnProbesComplete(); |
| 49 void CallCallbacks(); | 49 void CallCallbacks(); |
| 50 | 50 |
| 51 void OnProbeJobComplete(DnsProbeJob* job, DnsProbeJob::Result result); | 51 void OnProbeJobComplete(DnsProbeJob* job, DnsProbeJob::Result result); |
| 52 chrome_common_net::DnsProbeResult EvaluateResults() const; | 52 chrome_common_net::DnsProbeStatus EvaluateResults() const; |
| 53 void HistogramProbes() const; | 53 void HistogramProbes() const; |
| 54 | 54 |
| 55 // These are expected to be overridden by tests to return mock jobs. | 55 // These are expected to be overridden by tests to return mock jobs. |
| 56 virtual scoped_ptr<DnsProbeJob> CreateSystemProbeJob( | 56 virtual scoped_ptr<DnsProbeJob> CreateSystemProbeJob( |
| 57 const DnsProbeJob::CallbackType& job_callback); | 57 const DnsProbeJob::CallbackType& job_callback); |
| 58 virtual scoped_ptr<DnsProbeJob> CreatePublicProbeJob( | 58 virtual scoped_ptr<DnsProbeJob> CreatePublicProbeJob( |
| 59 const DnsProbeJob::CallbackType& job_callback); | 59 const DnsProbeJob::CallbackType& job_callback); |
| 60 | 60 |
| 61 scoped_ptr<DnsProbeJob> CreateProbeJob( | 61 scoped_ptr<DnsProbeJob> CreateProbeJob( |
| 62 const net::DnsConfig& dns_config, | 62 const net::DnsConfig& dns_config, |
| 63 const DnsProbeJob::CallbackType& job_callback); | 63 const DnsProbeJob::CallbackType& job_callback); |
| 64 void GetSystemDnsConfig(net::DnsConfig* config); | 64 void GetSystemDnsConfig(net::DnsConfig* config); |
| 65 void GetPublicDnsConfig(net::DnsConfig* config); | 65 void GetPublicDnsConfig(net::DnsConfig* config); |
| 66 bool ResultsExpired(); | 66 bool ResultsExpired(); |
| 67 | 67 |
| 68 scoped_ptr<DnsProbeJob> system_job_; | 68 scoped_ptr<DnsProbeJob> system_job_; |
| 69 scoped_ptr<DnsProbeJob> public_job_; | 69 scoped_ptr<DnsProbeJob> public_job_; |
| 70 DnsProbeJob::Result system_result_; | 70 DnsProbeJob::Result system_result_; |
| 71 DnsProbeJob::Result public_result_; | 71 DnsProbeJob::Result public_result_; |
| 72 std::vector<CallbackType> callbacks_; | 72 std::vector<CallbackType> callbacks_; |
| 73 State state_; | 73 State state_; |
| 74 chrome_common_net::DnsProbeResult result_; | 74 chrome_common_net::DnsProbeStatus result_; |
| 75 base::Time probe_start_time_; | 75 base::Time probe_start_time_; |
| 76 // How many DNS request attempts the probe jobs will make before giving up | 76 // How many DNS request attempts the probe jobs will make before giving up |
| 77 // (Overrides the attempts field in the system DnsConfig.) | 77 // (Overrides the attempts field in the system DnsConfig.) |
| 78 const int dns_attempts_; | 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 | 79 |
| 84 DISALLOW_COPY_AND_ASSIGN(DnsProbeService); | 80 DISALLOW_COPY_AND_ASSIGN(DnsProbeService); |
| 85 }; | 81 }; |
| 86 | 82 |
| 87 } // namespace chrome_browser_net | 83 } // namespace chrome_browser_net |
| 88 | 84 |
| 89 #endif // CHROME_BROWSER_NET_DNS_PROBE_SERVICE_H_ | 85 #endif // CHROME_BROWSER_NET_DNS_PROBE_SERVICE_H_ |
| OLD | NEW |