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

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

Issue 13270005: Display DNS probe results. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix FilePath initalization on Windows Created 7 years, 7 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_NET_DNS_PROBE_SERVICE_H_ 5 #ifndef CHROME_BROWSER_NET_DNS_PROBE_SERVICE_H_
6 #define CHROME_BROWSER_NET_DNS_PROBE_SERVICE_H_ 6 #define CHROME_BROWSER_NET_DNS_PROBE_SERVICE_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/bind.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
12 #include "base/time.h" 13 #include "base/time.h"
13 #include "chrome/browser/net/dns_probe_job.h" 14 #include "chrome/browser/net/dns_probe_job.h"
14 #include "chrome/common/net/net_error_info.h" 15 #include "chrome/common/net/net_error_info.h"
15 #include "net/base/network_change_notifier.h"
16 16
17 namespace net { 17 namespace net {
18 struct DnsConfig; 18 struct DnsConfig;
19 } 19 }
20 20
21 namespace chrome_browser_net { 21 namespace chrome_browser_net {
22 22
23 class DnsProbeService : public net::NetworkChangeNotifier::IPAddressObserver { 23 class DnsProbeService {
24 public: 24 public:
25 typedef base::Callback<void(chrome_common_net::DnsProbeResult result)> 25 class JobFactory {
26 public:
27 JobFactory() { }
28 virtual ~JobFactory() { }
mmenke 2013/05/28 18:20:13 nit: Google C++ style guide says not to use a spa
Deprecated (see juliatuttle) 2013/06/05 21:01:47 Done.
29 virtual scoped_ptr<DnsProbeJob> CreateSystemJob(
30 const DnsProbeJob::CallbackType& job_callback) = 0;
31 virtual scoped_ptr<DnsProbeJob> CreatePublicJob(
32 const DnsProbeJob::CallbackType& job_callback) = 0;
33
34 private:
35 DISALLOW_COPY_AND_ASSIGN(JobFactory);
36 };
37
38 typedef base::Callback<void(chrome_common_net::DnsProbeStatus result)>
26 CallbackType; 39 CallbackType;
27 40
28 DnsProbeService(); 41 DnsProbeService() { }
29 virtual ~DnsProbeService(); 42 virtual ~DnsProbeService() { }
mmenke 2013/05/28 18:20:13 nit: Google C++ style guide says not to use a spa
Deprecated (see juliatuttle) 2013/06/05 21:01:47 Done.
30 43
31 void ProbeDns(const CallbackType& callback); 44 static DnsProbeService* CreateDefault();
45 static DnsProbeService* CreateDefaultWithJobFactory(
46 scoped_ptr<JobFactory> job_factory);
32 47
33 // NetworkChangeNotifier::IPAddressObserver implementation: 48 virtual void ProbeDns(const CallbackType& callback) = 0;
34 virtual void OnIPAddressChanged() OVERRIDE; 49 virtual void ExpireResultForTesting() { }
mmenke 2013/05/28 18:20:13 nit: Google C++ style guide says not to use a spa
Deprecated (see juliatuttle) 2013/06/05 21:01:47 Done.
35
36 protected:
37 // This can be called by tests to pretend the cached reuslt has expired.
38 void ExpireResults();
39
40 private:
41 enum State {
42 STATE_NO_RESULTS,
43 STATE_PROBE_RUNNING,
44 STATE_RESULTS_CACHED,
45 };
46
47 void StartProbes();
48 void OnProbesComplete();
49 void CallCallbacks();
50
51 void OnProbeJobComplete(DnsProbeJob* job, DnsProbeJob::Result result);
52 chrome_common_net::DnsProbeResult EvaluateResults() const;
53 void HistogramProbes() const;
54
55 // These are expected to be overridden by tests to return mock jobs.
56 virtual scoped_ptr<DnsProbeJob> CreateSystemProbeJob(
57 const DnsProbeJob::CallbackType& job_callback);
58 virtual scoped_ptr<DnsProbeJob> CreatePublicProbeJob(
59 const DnsProbeJob::CallbackType& job_callback);
60
61 scoped_ptr<DnsProbeJob> CreateProbeJob(
62 const net::DnsConfig& dns_config,
63 const DnsProbeJob::CallbackType& job_callback);
64 void GetSystemDnsConfig(net::DnsConfig* config);
65 void GetPublicDnsConfig(net::DnsConfig* config);
66 bool ResultsExpired();
67
68 scoped_ptr<DnsProbeJob> system_job_;
69 scoped_ptr<DnsProbeJob> public_job_;
70 DnsProbeJob::Result system_result_;
71 DnsProbeJob::Result public_result_;
72 std::vector<CallbackType> callbacks_;
73 State state_;
74 chrome_common_net::DnsProbeResult result_;
75 base::Time probe_start_time_;
76 // How many DNS request attempts the probe jobs will make before giving up
77 // (Overrides the attempts field in the system DnsConfig.)
78 const int dns_attempts_;
79 // How many nameservers the system config has.
80 int system_nameserver_count_;
81 // Whether the only system nameserver is 127.0.0.1.
82 bool system_is_localhost_;
83 50
84 DISALLOW_COPY_AND_ASSIGN(DnsProbeService); 51 DISALLOW_COPY_AND_ASSIGN(DnsProbeService);
85 }; 52 };
86 53
87 } // namespace chrome_browser_net 54 } // namespace chrome_browser_net
88 55
89 #endif // CHROME_BROWSER_NET_DNS_PROBE_SERVICE_H_ 56 #endif // CHROME_BROWSER_NET_DNS_PROBE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698