Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: chrome/browser/net/dns_probe_runner.h

Issue 13270005: Display DNS probe results. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Don't break DnsProbe histograms Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 // Used in histograms; add new entries at the bottom, and don't remove any.
28 enum Result {
29 UNKNOWN,
30 CORRECT, // Response contains at least one A record.
31 INCORRECT, // Response claimed success but included no A records.
32 FAILING, // Response included an error or was malformed.
33 UNREACHABLE // No response received (timeout, network unreachable, etc.).
34 };
35
36 DnsProbeRunner();
37 ~DnsProbeRunner();
38
39 // Starts a probe using the client specified with SetClient, which must have
40 // been called before RunProbe. |callback| will be called asynchronously
41 // when the result is ready, even if it is ready synchronously. Must not
42 // be called again until the callback is called, but may be called during the
43 // callback.
44 void RunProbe(const base::Closure& callback);
45
46 // Sets the DnsClient that will be used for DNS probes sent by this runner.
47 // Must be called before RunProbe; can be called repeatedly, including during
48 // a probe. It will not affect an in-flight probe, if one is running.
49 void SetClient(scoped_ptr<net::DnsClient> client);
50
51 // Returns true if a probe is running. Guaranteed to return true after
52 // RunProbe returns, and false during and after the callback.
53 bool IsRunning() const;
54
55 // Returns the result of the last probe.
56 Result result() const { return result_; }
57
58 private:
59 void OnTransactionComplete(net::DnsTransaction* transaction,
60 int net_error,
61 const net::DnsResponse* response);
62 void CallCallback();
63
64 base::WeakPtrFactory<DnsProbeRunner> weak_factory_;
65 scoped_ptr<net::DnsClient> client_;
66 base::Closure callback_;
67 scoped_ptr<net::DnsTransaction> transaction_;
68 Result result_;
69
70 DISALLOW_COPY_AND_ASSIGN(DnsProbeRunner);
71 };
72
73 } // namespace chrome_browser_net
74
75 #endif // CHROME_BROWSER_NET_DNS_PROBE_RUNNER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698