Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -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 | #include "shill/default_profile.h" |
| 6 | |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame] | 7 | #include <vector> |
| 8 | |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 9 | #include <base/file_path.h> |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 10 | #include <base/string_number_conversions.h> |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 11 | #include <base/stringprintf.h> |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 12 | #include <chromeos/dbus/service_constants.h> |
| 13 | |
| 14 | #include "shill/adaptor_interfaces.h" |
| 15 | #include "shill/control_interface.h" |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 16 | #include "shill/link_monitor.h" |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 17 | #include "shill/manager.h" |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 18 | #include "shill/portal_detector.h" |
Paul Stewart | bf66761 | 2012-06-29 14:49:54 -0700 | [diff] [blame] | 19 | #include "shill/resolver.h" |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 20 | #include "shill/store_interface.h" |
Wade Guthrie | 60a3706 | 2013-04-02 11:39:09 -0700 | [diff] [blame] | 21 | #include "shill/wifi_provider.h" |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 22 | |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 23 | using base::FilePath; |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 24 | using std::string; |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame] | 25 | using std::vector; |
| 26 | |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 27 | namespace shill { |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 28 | // static |
Chris Masone | 7df0c67 | 2011-07-15 10:24:54 -0700 | [diff] [blame] | 29 | const char DefaultProfile::kDefaultId[] = "default"; |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 30 | // static |
| 31 | const char DefaultProfile::kStorageId[] = "global"; |
| 32 | // static |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 33 | const char DefaultProfile::kStorageArpGateway[] = "ArpGateway"; |
| 34 | // static |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 35 | const char DefaultProfile::kStorageCheckPortalList[] = "CheckPortalList"; |
| 36 | // static |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 37 | const char DefaultProfile::kStorageHostName[] = "HostName"; |
| 38 | // static |
Paul Stewart | 4d5efb7 | 2012-09-17 12:24:34 -0700 | [diff] [blame] | 39 | const char DefaultProfile::kStorageIgnoredDNSSearchPaths[] = |
| 40 | "IgnoredDNSSearchPaths"; |
| 41 | // static |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 42 | const char DefaultProfile::kStorageLinkMonitorTechnologies[] = |
| 43 | "LinkMonitorTechnologies"; |
| 44 | // static |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 45 | const char DefaultProfile::kStorageName[] = "Name"; |
| 46 | // static |
| 47 | const char DefaultProfile::kStorageOfflineMode[] = "OfflineMode"; |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 48 | // static |
| 49 | const char DefaultProfile::kStoragePortalURL[] = "PortalURL"; |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 50 | // static |
| 51 | const char DefaultProfile::kStoragePortalCheckInterval[] = |
| 52 | "PortalCheckInterval"; |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 53 | |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 54 | DefaultProfile::DefaultProfile(ControlInterface *control, |
Thieu Le | 5133b71 | 2013-02-19 14:47:21 -0800 | [diff] [blame] | 55 | Metrics *metrics, |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 56 | Manager *manager, |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 57 | const FilePath &storage_path, |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 58 | const string &profile_id, |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 59 | const Manager::Properties &manager_props) |
Thieu Le | 5133b71 | 2013-02-19 14:47:21 -0800 | [diff] [blame] | 60 | : Profile(control, metrics, manager, Identifier(profile_id), "", true), |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 61 | storage_path_(storage_path), |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 62 | profile_id_(profile_id), |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 63 | props_(manager_props) { |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 64 | PropertyStore *store = this->mutable_store(); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 65 | store->RegisterConstBool(flimflam::kArpGatewayProperty, |
| 66 | &manager_props.arp_gateway); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 67 | store->RegisterConstString(flimflam::kCheckPortalListProperty, |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 68 | &manager_props.check_portal_list); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 69 | store->RegisterConstString(flimflam::kCountryProperty, |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 70 | &manager_props.country); |
Paul Stewart | 4d5efb7 | 2012-09-17 12:24:34 -0700 | [diff] [blame] | 71 | store->RegisterConstString(shill::kIgnoredDNSSearchPathsProperty, |
| 72 | &manager_props.ignored_dns_search_paths); |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 73 | store->RegisterConstString(shill::kLinkMonitorTechnologiesProperty, |
| 74 | &manager_props.link_monitor_technologies); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 75 | store->RegisterConstBool(flimflam::kOfflineModeProperty, |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 76 | &manager_props.offline_mode); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 77 | store->RegisterConstString(flimflam::kPortalURLProperty, |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 78 | &manager_props.portal_url); |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 79 | store->RegisterConstInt32(shill::kPortalCheckIntervalProperty, |
| 80 | &manager_props.portal_check_interval_seconds); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | DefaultProfile::~DefaultProfile() {} |
| 84 | |
Paul Stewart | 870523b | 2012-01-11 17:00:42 -0800 | [diff] [blame] | 85 | bool DefaultProfile::LoadManagerProperties(Manager::Properties *manager_props) { |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 86 | storage()->GetBool(kStorageId, kStorageArpGateway, |
| 87 | &manager_props->arp_gateway); |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 88 | storage()->GetString(kStorageId, kStorageHostName, &manager_props->host_name); |
Paul Stewart | 870523b | 2012-01-11 17:00:42 -0800 | [diff] [blame] | 89 | storage()->GetBool(kStorageId, kStorageOfflineMode, |
| 90 | &manager_props->offline_mode); |
Paul Stewart | f555cf8 | 2012-03-15 14:42:43 -0700 | [diff] [blame] | 91 | if (!storage()->GetString(kStorageId, |
| 92 | kStorageCheckPortalList, |
| 93 | &manager_props->check_portal_list)) { |
| 94 | manager_props->check_portal_list = PortalDetector::kDefaultCheckPortalList; |
| 95 | } |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 96 | if (!storage()->GetString(kStorageId, |
Paul Stewart | 4d5efb7 | 2012-09-17 12:24:34 -0700 | [diff] [blame] | 97 | kStorageIgnoredDNSSearchPaths, |
| 98 | &manager_props->ignored_dns_search_paths)) { |
| 99 | manager_props->ignored_dns_search_paths = |
| 100 | Resolver::kDefaultIgnoredSearchList; |
| 101 | } |
| 102 | if (!storage()->GetString(kStorageId, |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 103 | kStorageLinkMonitorTechnologies, |
| 104 | &manager_props->link_monitor_technologies)) { |
| 105 | manager_props->link_monitor_technologies = |
| 106 | LinkMonitor::kDefaultLinkMonitorTechnologies; |
| 107 | } |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 108 | if (!storage()->GetString(kStorageId, kStoragePortalURL, |
| 109 | &manager_props->portal_url)) { |
| 110 | manager_props->portal_url = PortalDetector::kDefaultURL; |
| 111 | } |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 112 | std::string check_interval; |
| 113 | if (!storage()->GetString(kStorageId, kStoragePortalCheckInterval, |
| 114 | &check_interval) || |
| 115 | !base::StringToInt(check_interval, |
| 116 | &manager_props->portal_check_interval_seconds)) { |
| 117 | manager_props->portal_check_interval_seconds = |
| 118 | PortalDetector::kDefaultCheckIntervalSeconds; |
| 119 | } |
Paul Stewart | 870523b | 2012-01-11 17:00:42 -0800 | [diff] [blame] | 120 | return true; |
| 121 | } |
| 122 | |
Paul Stewart | f284a23 | 2012-05-01 10:24:37 -0700 | [diff] [blame] | 123 | bool DefaultProfile::ConfigureService(const ServiceRefPtr &service) { |
| 124 | if (Profile::ConfigureService(service)) { |
| 125 | return true; |
| 126 | } |
| 127 | if (service->technology() == Technology::kEthernet) { |
| 128 | // Ethernet services should have an affinity towards the default profile, |
| 129 | // so even if a new Ethernet service has no known configuration, accept |
| 130 | // it anyway. |
| 131 | UpdateService(service); |
Philipp Neubeck | 7917360 | 2012-11-13 21:10:09 +0100 | [diff] [blame] | 132 | service->SetProfile(this); |
Paul Stewart | f284a23 | 2012-05-01 10:24:37 -0700 | [diff] [blame] | 133 | return true; |
| 134 | } |
| 135 | return false; |
| 136 | } |
| 137 | |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 138 | bool DefaultProfile::Save() { |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 139 | storage()->SetBool(kStorageId, kStorageArpGateway, props_.arp_gateway); |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 140 | storage()->SetString(kStorageId, kStorageHostName, props_.host_name); |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 141 | storage()->SetString(kStorageId, kStorageName, GetFriendlyName()); |
| 142 | storage()->SetBool(kStorageId, kStorageOfflineMode, props_.offline_mode); |
| 143 | storage()->SetString(kStorageId, |
| 144 | kStorageCheckPortalList, |
| 145 | props_.check_portal_list); |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 146 | storage()->SetString(kStorageId, |
Paul Stewart | 4d5efb7 | 2012-09-17 12:24:34 -0700 | [diff] [blame] | 147 | kStorageIgnoredDNSSearchPaths, |
| 148 | props_.ignored_dns_search_paths); |
| 149 | storage()->SetString(kStorageId, |
Paul Stewart | 036dba0 | 2012-08-07 12:34:41 -0700 | [diff] [blame] | 150 | kStorageLinkMonitorTechnologies, |
| 151 | props_.link_monitor_technologies); |
| 152 | storage()->SetString(kStorageId, |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 153 | kStoragePortalURL, |
| 154 | props_.portal_url); |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 155 | storage()->SetString(kStorageId, |
| 156 | kStoragePortalCheckInterval, |
| 157 | base::IntToString(props_.portal_check_interval_seconds)); |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 158 | return Profile::Save(); |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Darin Petkov | e7c6ad3 | 2012-06-29 10:22:09 +0200 | [diff] [blame] | 161 | bool DefaultProfile::UpdateDevice(const DeviceRefPtr &device) { |
| 162 | return device->Save(storage()) && storage()->Flush(); |
| 163 | } |
| 164 | |
Wade Guthrie | 60a3706 | 2013-04-02 11:39:09 -0700 | [diff] [blame] | 165 | bool DefaultProfile::UpdateWiFiProvider(const WiFiProvider &wifi_provider) { |
| 166 | return wifi_provider.Save(storage()) && storage()->Flush(); |
| 167 | } |
| 168 | |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 169 | bool DefaultProfile::GetStoragePath(FilePath *path) { |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 170 | *path = storage_path_.Append(base::StringPrintf("%s.profile", |
| 171 | profile_id_.c_str())); |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 172 | return true; |
| 173 | } |
| 174 | |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 175 | } // namespace shill |