blob: 285a23498948d9729b4d9b0f20078074b3c02e79 [file] [log] [blame]
mukesh agrawal23ac6b72013-01-31 18:52:37 -08001// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
Paul Stewartb6063942011-08-05 10:17:29 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Ben Chanc45688b2014-07-02 23:50:45 -07005#ifndef SHILL_RESOLVER_H_
6#define SHILL_RESOLVER_H_
Paul Stewartb6063942011-08-05 10:17:29 -07007
Hristo Stefanoved2c28c2011-11-29 15:37:30 -08008#include <string>
9#include <vector>
10
Ben Chana0ddf462014-02-06 11:32:42 -080011#include <base/files/file_path.h>
Paul Stewart0d2ada32011-08-09 17:01:57 -070012#include <base/lazy_instance.h>
Paul Stewartb6063942011-08-05 10:17:29 -070013#include <base/memory/ref_counted.h>
Paul Stewartb6063942011-08-05 10:17:29 -070014
15#include "shill/refptr_types.h"
16
17namespace shill {
18
19// This provides a static function for dumping the DNS information out
20// of an ipconfig into a "resolv.conf" formatted file.
21class Resolver {
22 public:
Paul Stewart4d5efb72012-09-17 12:24:34 -070023 // The default comma-separated list of search-list prefixes that
24 // should be ignored when writing out a DNS configuration. These
25 // are usually preconfigured by a DHCP server and are not of real
26 // value to the user. This will release DNS bandwidth for searches
27 // we expect will have a better chance of getting what the user is
28 // looking for.
29 static const char kDefaultIgnoredSearchList[];
30
Paul Stewart0d2ada32011-08-09 17:01:57 -070031 virtual ~Resolver();
32
mukesh agrawalf407d592013-07-31 11:37:57 -070033 // Since this is a singleton, use Resolver::GetInstance()->Foo().
Paul Stewart1a212a62015-06-16 13:13:10 -070034 static Resolver* GetInstance();
Paul Stewartb6063942011-08-05 10:17:29 -070035
Paul Stewart1a212a62015-06-16 13:13:10 -070036 virtual void set_path(const base::FilePath& path) { path_ = path; }
Paul Stewartb6063942011-08-05 10:17:29 -070037
Paul Stewart6f65c0b2012-09-11 14:57:32 -070038 // Install domain name service parameters, given a list of
mukesh agrawal23ac6b72013-01-31 18:52:37 -080039 // DNS servers in |dns_servers|, and a list of DNS search suffixes in
40 // |domain_search|.
Paul Stewart1a212a62015-06-16 13:13:10 -070041 virtual bool SetDNSFromLists(const std::vector<std::string>& dns_servers,
42 const std::vector<std::string>& domain_search);
Paul Stewartb6063942011-08-05 10:17:29 -070043
Paul Stewartbf667612012-06-29 14:49:54 -070044 // Remove any created domain name service file.
Paul Stewartdd60e452011-08-08 11:38:36 -070045 virtual bool ClearDNS();
Paul Stewartb6063942011-08-05 10:17:29 -070046
Paul Stewart4d5efb72012-09-17 12:24:34 -070047 // Sets the list of ignored DNS search suffixes. This list will be used
48 // to filter the domain_search parameter of later SetDNSFromLists() calls.
49 virtual void set_ignored_search_list(
Paul Stewart1a212a62015-06-16 13:13:10 -070050 const std::vector<std::string>& ignored_list) {
Paul Stewart4d5efb72012-09-17 12:24:34 -070051 ignored_search_list_ = ignored_list;
52 }
53
Paul Stewart0d2ada32011-08-09 17:01:57 -070054 protected:
Paul Stewartb6063942011-08-05 10:17:29 -070055 Resolver();
Paul Stewart0d2ada32011-08-09 17:01:57 -070056
57 private:
58 friend struct base::DefaultLazyInstanceTraits<Resolver>;
59 friend class ResolverTest;
Paul Stewartb6063942011-08-05 10:17:29 -070060
Albert Chaulk0e1cdea2013-02-27 15:32:55 -080061 base::FilePath path_;
Paul Stewart4d5efb72012-09-17 12:24:34 -070062 std::vector<std::string> ignored_search_list_;
Paul Stewartb6063942011-08-05 10:17:29 -070063
64 DISALLOW_COPY_AND_ASSIGN(Resolver);
65};
66
67} // namespace shill
68
Ben Chanc45688b2014-07-02 23:50:45 -070069#endif // SHILL_RESOLVER_H_