Paul Stewart | bf66761 | 2012-06-29 14:49:54 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Paul Stewart | b606394 | 2011-08-05 10:17:29 -0700 | [diff] [blame] | 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 SHILL_RESOLVER_ |
| 6 | #define SHILL_RESOLVER_ |
| 7 | |
Hristo Stefanov | ed2c28c | 2011-11-29 15:37:30 -0800 | [diff] [blame] | 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
Paul Stewart | b606394 | 2011-08-05 10:17:29 -0700 | [diff] [blame] | 11 | #include <base/file_path.h> |
Paul Stewart | 0d2ada3 | 2011-08-09 17:01:57 -0700 | [diff] [blame] | 12 | #include <base/lazy_instance.h> |
Paul Stewart | b606394 | 2011-08-05 10:17:29 -0700 | [diff] [blame] | 13 | #include <base/memory/ref_counted.h> |
Paul Stewart | b606394 | 2011-08-05 10:17:29 -0700 | [diff] [blame] | 14 | |
| 15 | #include "shill/refptr_types.h" |
| 16 | |
| 17 | namespace shill { |
| 18 | |
| 19 | // This provides a static function for dumping the DNS information out |
| 20 | // of an ipconfig into a "resolv.conf" formatted file. |
| 21 | class Resolver { |
| 22 | public: |
Paul Stewart | bf66761 | 2012-06-29 14:49:54 -0700 | [diff] [blame] | 23 | 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 Stewart | 0d2ada3 | 2011-08-09 17:01:57 -0700 | [diff] [blame] | 32 | virtual ~Resolver(); |
| 33 | |
Paul Stewart | b606394 | 2011-08-05 10:17:29 -0700 | [diff] [blame] | 34 | // Since this is a singleton, use Resolver::GetInstance()->Foo() |
| 35 | static Resolver *GetInstance(); |
| 36 | |
Paul Stewart | dd60e45 | 2011-08-08 11:38:36 -0700 | [diff] [blame] | 37 | virtual void set_path(const FilePath &path) { path_ = path; } |
Paul Stewart | b606394 | 2011-08-05 10:17:29 -0700 | [diff] [blame] | 38 | |
Paul Stewart | bf66761 | 2012-06-29 14:49:54 -0700 | [diff] [blame] | 39 | // Set the default domain name service parameters, given an ipconfig entry. |
| 40 | virtual bool SetDNSFromIPConfig(const IPConfigRefPtr &ipconfig, |
| 41 | TimeoutParameters timeout); |
Paul Stewart | dd60e45 | 2011-08-08 11:38:36 -0700 | [diff] [blame] | 42 | |
Paul Stewart | bf66761 | 2012-06-29 14:49:54 -0700 | [diff] [blame] | 43 | // Set the default domain name service parameters, given an ipconfig entry. |
Paul Stewart | dd60e45 | 2011-08-08 11:38:36 -0700 | [diff] [blame] | 44 | virtual bool SetDNSFromLists(const std::vector<std::string> &dns_servers, |
Paul Stewart | bf66761 | 2012-06-29 14:49:54 -0700 | [diff] [blame] | 45 | const std::vector<std::string> &domain_search, |
| 46 | TimeoutParameters timeout); |
Paul Stewart | b606394 | 2011-08-05 10:17:29 -0700 | [diff] [blame] | 47 | |
Paul Stewart | bf66761 | 2012-06-29 14:49:54 -0700 | [diff] [blame] | 48 | // Remove any created domain name service file. |
Paul Stewart | dd60e45 | 2011-08-08 11:38:36 -0700 | [diff] [blame] | 49 | virtual bool ClearDNS(); |
Paul Stewart | b606394 | 2011-08-05 10:17:29 -0700 | [diff] [blame] | 50 | |
Paul Stewart | 0d2ada3 | 2011-08-09 17:01:57 -0700 | [diff] [blame] | 51 | protected: |
Paul Stewart | b606394 | 2011-08-05 10:17:29 -0700 | [diff] [blame] | 52 | Resolver(); |
Paul Stewart | 0d2ada3 | 2011-08-09 17:01:57 -0700 | [diff] [blame] | 53 | |
| 54 | private: |
| 55 | friend struct base::DefaultLazyInstanceTraits<Resolver>; |
| 56 | friend class ResolverTest; |
Paul Stewart | b606394 | 2011-08-05 10:17:29 -0700 | [diff] [blame] | 57 | |
Paul Stewart | bf66761 | 2012-06-29 14:49:54 -0700 | [diff] [blame] | 58 | static const char kDefaultTimeoutOptions[]; |
| 59 | static const char kShortTimeoutOptions[]; |
| 60 | |
Paul Stewart | b606394 | 2011-08-05 10:17:29 -0700 | [diff] [blame] | 61 | FilePath path_; |
| 62 | |
| 63 | DISALLOW_COPY_AND_ASSIGN(Resolver); |
| 64 | }; |
| 65 | |
| 66 | } // namespace shill |
| 67 | |
| 68 | #endif // SHILL_RESOLVER_ |