OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 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. | |
4 | |
5 #ifndef CHROME_BROWSER_NET_DNS_PROBE_RUNNER_H | |
6 #define CHROME_BROWSER_NET_DNS_PROBE_RUNNER_H | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/bind.h" | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/memory/weak_ptr.h" | |
12 | |
13 namespace net { | |
14 class DnsClient; | |
15 class DnsResponse; | |
16 class DnsTransaction; | |
17 } | |
18 | |
19 namespace chrome_browser_net { | |
20 | |
21 // Runs DNS probes using a single DnsClient and evaluates the responses. | |
22 // (Currently requests A records for google.com and expects at least one IP | |
23 // address in the response.) | |
24 // Used by DnsProbeService to probe the system and public DNS configurations. | |
25 class DnsProbeRunner { | |
26 public: | |
27 enum Result { | |
28 UNKNOWN, | |
29 CORRECT, // Response contains at least one A record | |
30 INCORRECT, // Response claimed success but included no A records | |
31 FAILING, // Response included an error or was malformed | |
32 UNREACHABLE // No response received (timeout, network unreachable, etc.) | |
33 }; | |
34 | |
35 typedef base::Callback<void(Result)> ProbeCallback; | |
36 | |
37 DnsProbeRunner(); | |
38 ~DnsProbeRunner(); | |
39 | |
40 // Starts a probe using the client specified with SetClient, which must have | |
41 // been called before RunProbe. |callback| will be called asynchronously | |
42 // with the result (even if it is known instantly). | |
szym
2013/06/13 20:50:48
Maybe add comment that must not be called again un
Deprecated (see juliatuttle)
2013/06/18 19:36:37
Done.
| |
43 void RunProbe(const ProbeCallback& callback); | |
44 | |
45 // Sets the DnsClient that will be used for DNS probes sent by this runner. | |
46 // Must be called before RunProbe; can be called repeatedly, including during | |
47 // a probe. (It will not, of course, affect the in-flight probe.) | |
48 void SetClient(scoped_ptr<net::DnsClient> client); | |
49 | |
50 // Returns true if a probe is running. Guaranteed to return true after | |
51 // RunProbe returns, and false during and after the callback. | |
52 bool IsRunning() const; | |
53 | |
54 private: | |
55 void OnTransactionComplete(net::DnsTransaction* transaction, | |
56 int net_error, | |
57 const net::DnsResponse* response); | |
58 void CallCallback(Result result); | |
59 | |
60 base::WeakPtrFactory<DnsProbeRunner> weak_factory_; | |
61 scoped_ptr<net::DnsClient> client_; | |
62 ProbeCallback callback_; | |
63 scoped_ptr<net::DnsTransaction> transaction_; | |
64 | |
65 DISALLOW_COPY_AND_ASSIGN(DnsProbeRunner); | |
66 }; | |
67 | |
68 } // namespace chrome_browser_net | |
69 | |
70 #endif // CHROME_BROWSER_NET_DNS_PROBE_RUNNER_H | |
OLD | NEW |