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

Side by Side Diff: net/dns/dns_config_service_posix.h

Issue 7518028: DnsConfigService and a posix implementation (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: CloseResState applies to OS_LINUX only Created 9 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « net/dns/dns_config_service.cc ('k') | net/dns/dns_config_service_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 NET_DNS_DNS_CONFIG_SERVICE_POSIX_H_
6 #define NET_DNS_DNS_CONFIG_SERVICE_POSIX_H_
7 #pragma once
8
9 #include <resolv.h>
10
11 #include "base/compiler_specific.h"
12 #include "base/files/file_path_watcher.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/observer_list.h"
15 #include "base/scoped_ptr.h"
16 #include "base/threading/non_thread_safe.h"
17 #include "net/base/net_export.h"
18 #include "net/dns/dns_config_service.h"
19
20 namespace net {
21
22 class NET_EXPORT_PRIVATE DnsConfigServicePosix
23 : public NON_EXPORTED_BASE(DnsConfigService),
24 public NON_EXPORTED_BASE(base::NonThreadSafe) {
25 public:
26 class ResolverLib;
27 class FilePathWatcherShim;
28 class FilePathWatcherFactory;
29 class WatcherDelegate;
30
31 DnsConfigServicePosix();
32 virtual ~DnsConfigServicePosix();
33
34 virtual void AddObserver(Observer* observer) OVERRIDE;
35 virtual void RemoveObserver(Observer* observer) OVERRIDE;
36 virtual void Watch() OVERRIDE;
37
38 // Takes ownership of |lib|. Must be set before Watch.
39 void set_resolver_lib(ResolverLib* lib) {
40 DCHECK(!watcher_delegate_.get());
41 resolver_lib_.reset(lib);
42 }
43
44 // Takes ownership of |factory|. Must be set before Watch.
45 void set_watcher_factory(FilePathWatcherFactory* factory) {
46 DCHECK(!watcher_delegate_.get());
47 watcher_factory_.reset(factory);
48 }
49
50 private:
51 void OnConfigRead(const DnsConfig& config);
52
53 // Configure a FilePathWatcher and install watcher_delegate_. Executed each
54 // time FilePathWatcher fails.
55 void StartWatch();
56
57 DnsConfig dns_config_;
58 // True after first OnConfigChanged, that is, dns_config_ is valid.
59 bool have_config_;
60
61 scoped_ptr<ResolverLib> resolver_lib_;
62 scoped_ptr<FilePathWatcherFactory> watcher_factory_;
63 scoped_ptr<FilePathWatcherShim> resolv_file_watcher_;
64 scoped_refptr<WatcherDelegate> watcher_delegate_;
65 ObserverList<Observer> observers_;
66
67 DISALLOW_COPY_AND_ASSIGN(DnsConfigServicePosix);
68 };
69
70
71 // Allows mocking res_ninit.
72 class NET_EXPORT_PRIVATE DnsConfigServicePosix::ResolverLib
73 : public NON_EXPORTED_BASE(base::NonThreadSafe) {
74 public:
75 ResolverLib() {}
76 virtual ~ResolverLib() {}
77 virtual int ninit(res_state statp);
78 virtual void nclose(res_state statp);
79 private:
80 DISALLOW_COPY_AND_ASSIGN(ResolverLib);
81 };
82
83 // Allows mocking FilePathWatcher
84 class NET_EXPORT_PRIVATE DnsConfigServicePosix::FilePathWatcherShim
85 : public NON_EXPORTED_BASE(base::NonThreadSafe) {
86 public:
87 FilePathWatcherShim();
88 virtual ~FilePathWatcherShim();
89
90 virtual bool Watch(
91 const FilePath& path,
92 base::files::FilePathWatcher::Delegate* delegate) WARN_UNUSED_RESULT;
93 private:
94 scoped_ptr<base::files::FilePathWatcher> watcher_;
95 DISALLOW_COPY_AND_ASSIGN(FilePathWatcherShim);
96 };
97
98 class NET_EXPORT_PRIVATE DnsConfigServicePosix::FilePathWatcherFactory
99 : public NON_EXPORTED_BASE(base::NonThreadSafe) {
100 public:
101 FilePathWatcherFactory() {}
102 virtual ~FilePathWatcherFactory() {}
103 virtual FilePathWatcherShim* CreateFilePathWatcher();
104 private:
105 DISALLOW_COPY_AND_ASSIGN(FilePathWatcherFactory);
106 };
107
108 // Fills in |dns_config| from |res|. Exposed for tests.
109 bool NET_EXPORT_PRIVATE ConvertResToConfig(const struct __res_state& res,
110 DnsConfig* dns_config);
111
112 } // namespace net
113
114 #endif // NET_DNS_DNS_CONFIG_SERVICE_POSIX_H_
115
OLDNEW
« no previous file with comments | « net/dns/dns_config_service.cc ('k') | net/dns/dns_config_service_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698