[ExtensionToolbarMac] Restrict action button drags to the container's bounds
[chromium-blink-merge.git] / chrome / browser / net / dns_probe_service.h
blob37a294a25aa6e5874a264b272f884eca00c6b7c5
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(chrome_common_net::DnsProbeStatus result)>
33 ProbeCallback;
35 DnsProbeService();
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();
47 private:
48 enum State {
49 STATE_NO_RESULT,
50 STATE_PROBE_RUNNING,
51 STATE_RESULT_CACHED,
54 void SetSystemClientToCurrentConfig();
55 void SetPublicClientToGooglePublicDns();
57 // Starts a probe (runs system and public probes).
58 void StartProbes();
59 void OnProbeComplete();
60 // Calls all |pending_callbacks_| with the |cached_result_|.
61 void CallCallbacks();
62 // Clears a cached probe result.
63 void ClearCachedResult();
65 bool CachedResultIsExpired() const;
67 State state_;
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_