1 // Copyright 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.
5 #ifndef CHROME_BROWSER_NET_DNS_PROBE_RUNNER_H_
6 #define CHROME_BROWSER_NET_DNS_PROBE_RUNNER_H_
8 #include "base/basictypes.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
19 namespace chrome_browser_net
{
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
{
27 static const char* kKnownGoodHostname
;
29 // Used in histograms; add new entries at the bottom, and don't remove any.
32 CORRECT
, // Response contains at least one A record.
33 INCORRECT
, // Response claimed success but included no A records.
34 FAILING
, // Response included an error or was malformed.
35 UNREACHABLE
// No response received (timeout, network unreachable, etc.).
41 // Sets the DnsClient that will be used for DNS probes sent by this runner.
42 // Must be called before RunProbe; can be called repeatedly, including during
43 // a probe. It will not affect an in-flight probe, if one is running.
44 void SetClient(scoped_ptr
<net::DnsClient
> client
);
46 // Starts a probe using the client specified with SetClient, which must have
47 // been called before RunProbe. |callback| will be called asynchronously
48 // when the result is ready, even if it is ready synchronously. Must not
49 // be called again until the callback is called, but may be called during the
51 void RunProbe(const base::Closure
& callback
);
53 // Returns true if a probe is running. Guaranteed to return true after
54 // RunProbe returns, and false during and after the callback.
55 bool IsRunning() const;
57 // Returns the result of the last probe.
58 Result
result() const { return result_
; }
61 void OnTransactionComplete(net::DnsTransaction
* transaction
,
63 const net::DnsResponse
* response
);
66 scoped_ptr
<net::DnsClient
> client_
;
68 // The callback passed to |RunProbe|. Cleared right before calling the
70 base::Closure callback_
;
72 // The transaction started in |RunProbe| for the DNS probe. Reset once the
73 // results have been examined.
74 scoped_ptr
<net::DnsTransaction
> transaction_
;
78 base::WeakPtrFactory
<DnsProbeRunner
> weak_factory_
;
80 DISALLOW_COPY_AND_ASSIGN(DnsProbeRunner
);
83 } // namespace chrome_browser_net
85 #endif // CHROME_BROWSER_NET_DNS_PROBE_RUNNER_H_