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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_NET_DNS_PROBE_SERVICE_H_
6 #define CHROME_BROWSER_NET_DNS_PROBE_SERVICE_H_
10 #include "base/basictypes.h"
11 #include "base/bind.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/time/time.h"
14 #include "chrome/browser/net/dns_probe_runner.h"
15 #include "components/error_page/common/net_error_info.h"
16 #include "net/base/network_change_notifier.h"
23 namespace chrome_browser_net
{
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.
29 // Uses a single DNS attempt per config, and doesn't randomize source ports.
30 class DnsProbeService
: public net::NetworkChangeNotifier::DNSObserver
{
32 typedef base::Callback
<void(chrome_common_net::DnsProbeStatus result
)>
36 ~DnsProbeService() override
;
38 virtual void ProbeDns(const ProbeCallback
& callback
);
40 // NetworkChangeNotifier::DNSObserver implementation:
41 void OnDNSChanged() override
;
43 void SetSystemClientForTesting(scoped_ptr
<net::DnsClient
> system_client
);
44 void SetPublicClientForTesting(scoped_ptr
<net::DnsClient
> public_client
);
45 void ClearCachedResultForTesting();
54 void SetSystemClientToCurrentConfig();
55 void SetPublicClientToGooglePublicDns();
57 // Starts a probe (runs system and public probes).
59 void OnProbeComplete();
60 // Calls all |pending_callbacks_| with the |cached_result_|.
62 // Clears a cached probe result.
63 void ClearCachedResult();
65 bool CachedResultIsExpired() const;
68 std::vector
<ProbeCallback
> pending_callbacks_
;
69 base::Time probe_start_time_
;
70 chrome_common_net::DnsProbeStatus cached_result_
;
72 // DnsProbeRunners for the system DNS configuration and a public DNS server.
73 DnsProbeRunner system_runner_
;
74 DnsProbeRunner public_runner_
;
76 DISALLOW_COPY_AND_ASSIGN(DnsProbeService
);
79 } // namespace chrome_browser_net
81 #endif // CHROME_BROWSER_NET_DNS_PROBE_SERVICE_H_