Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / net / dns_probe_service.h
blob16efecf4e50bd9f4a3ffdac78c1f2bba4d55f3bc
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_
8 #include <vector>
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"
18 namespace net {
19 class DnsClient;
20 struct DnsConfig;
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 {
31 public:
32 typedef base::Callback<void(error_page::DnsProbeStatus result)>
33 ProbeCallback;
35 DnsProbeService();
36 ~DnsProbeService() override;
38 virtual void ProbeDns(const ProbeCallback& callback);
40 // NetworkChangeNotifier::DNSObserver implementation:
41 void OnDNSChanged() override;
42 void OnInitialDNSConfigRead() override;
44 void SetSystemClientForTesting(scoped_ptr<net::DnsClient> system_client);
45 void SetPublicClientForTesting(scoped_ptr<net::DnsClient> public_client);
46 void ClearCachedResultForTesting();
48 private:
49 enum State {
50 STATE_NO_RESULT,
51 STATE_PROBE_RUNNING,
52 STATE_RESULT_CACHED,
55 void SetSystemClientToCurrentConfig();
56 void SetPublicClientToGooglePublicDns();
58 // Starts a probe (runs system and public probes).
59 void StartProbes();
60 void OnProbeComplete();
61 // Calls all |pending_callbacks_| with the |cached_result_|.
62 void CallCallbacks();
63 // Clears a cached probe result.
64 void ClearCachedResult();
66 bool CachedResultIsExpired() const;
68 State state_;
69 std::vector<ProbeCallback> pending_callbacks_;
70 base::Time probe_start_time_;
71 error_page::DnsProbeStatus cached_result_;
73 // DnsProbeRunners for the system DNS configuration and a public DNS server.
74 DnsProbeRunner system_runner_;
75 DnsProbeRunner public_runner_;
77 DISALLOW_COPY_AND_ASSIGN(DnsProbeService);
80 } // namespace chrome_browser_net
82 #endif // CHROME_BROWSER_NET_DNS_PROBE_SERVICE_H_