blob: 8c567126d60876c6add7db116d8ef010fb4a1ff6 [file] [log] [blame]
Paul Stewartbf667612012-06-29 14:49:54 -07001// Copyright (c) 2012 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
5#ifndef SHILL_RESOLVER_
6#define SHILL_RESOLVER_
7
Hristo Stefanoved2c28c2011-11-29 15:37:30 -08008#include <string>
9#include <vector>
10
Paul Stewartb6063942011-08-05 10:17:29 -070011#include <base/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 Stewartbf667612012-06-29 14:49:54 -070023 enum TimeoutParameters {
24 kDefaultTimeout,
25 kShortTimeout
26 };
27
28 // The default comma-separated list of technologies for which short
29 // DNS timeouts should be enabled.
30 static const char kDefaultShortTimeoutTechnologies[];
31
Paul Stewart0d2ada32011-08-09 17:01:57 -070032 virtual ~Resolver();
33
Paul Stewartb6063942011-08-05 10:17:29 -070034 // Since this is a singleton, use Resolver::GetInstance()->Foo()
35 static Resolver *GetInstance();
36
Paul Stewartdd60e452011-08-08 11:38:36 -070037 virtual void set_path(const FilePath &path) { path_ = path; }
Paul Stewartb6063942011-08-05 10:17:29 -070038
Paul Stewartbf667612012-06-29 14:49:54 -070039 // Set the default domain name service parameters, given an ipconfig entry.
40 virtual bool SetDNSFromIPConfig(const IPConfigRefPtr &ipconfig,
41 TimeoutParameters timeout);
Paul Stewartdd60e452011-08-08 11:38:36 -070042
Paul Stewartbf667612012-06-29 14:49:54 -070043 // Set the default domain name service parameters, given an ipconfig entry.
Paul Stewartdd60e452011-08-08 11:38:36 -070044 virtual bool SetDNSFromLists(const std::vector<std::string> &dns_servers,
Paul Stewartbf667612012-06-29 14:49:54 -070045 const std::vector<std::string> &domain_search,
46 TimeoutParameters timeout);
Paul Stewartb6063942011-08-05 10:17:29 -070047
Paul Stewartbf667612012-06-29 14:49:54 -070048 // Remove any created domain name service file.
Paul Stewartdd60e452011-08-08 11:38:36 -070049 virtual bool ClearDNS();
Paul Stewartb6063942011-08-05 10:17:29 -070050
Paul Stewart0d2ada32011-08-09 17:01:57 -070051 protected:
Paul Stewartb6063942011-08-05 10:17:29 -070052 Resolver();
Paul Stewart0d2ada32011-08-09 17:01:57 -070053
54 private:
55 friend struct base::DefaultLazyInstanceTraits<Resolver>;
56 friend class ResolverTest;
Paul Stewartb6063942011-08-05 10:17:29 -070057
Paul Stewartbf667612012-06-29 14:49:54 -070058 static const char kDefaultTimeoutOptions[];
59 static const char kShortTimeoutOptions[];
60
Paul Stewartb6063942011-08-05 10:17:29 -070061 FilePath path_;
62
63 DISALLOW_COPY_AND_ASSIGN(Resolver);
64};
65
66} // namespace shill
67
68#endif // SHILL_RESOLVER_