Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS 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 | #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> |
| 10 | #include <base/stringprintf.h> |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 11 | #include <chromeos/dbus/service_constants.h> |
| 12 | |
| 13 | #include "shill/adaptor_interfaces.h" |
| 14 | #include "shill/control_interface.h" |
| 15 | #include "shill/manager.h" |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 16 | #include "shill/store_interface.h" |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 17 | |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame] | 18 | using std::vector; |
| 19 | |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 20 | namespace shill { |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 21 | // static |
Chris Masone | 7df0c67 | 2011-07-15 10:24:54 -0700 | [diff] [blame] | 22 | const char DefaultProfile::kDefaultId[] = "default"; |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 23 | // static |
| 24 | const char DefaultProfile::kStorageId[] = "global"; |
| 25 | // static |
| 26 | const char DefaultProfile::kStorageCheckPortalList[] = "CheckPortalList"; |
| 27 | // static |
| 28 | const char DefaultProfile::kStorageName[] = "Name"; |
| 29 | // static |
| 30 | const char DefaultProfile::kStorageOfflineMode[] = "OfflineMode"; |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 31 | |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 32 | DefaultProfile::DefaultProfile(ControlInterface *control, |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 33 | Manager *manager, |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 34 | const FilePath &storage_path, |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 35 | const Manager::Properties &manager_props) |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 36 | : Profile(control, manager, Identifier(kDefaultId), "", true), |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 37 | storage_path_(storage_path), |
| 38 | props_(manager_props) { |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 39 | PropertyStore *store = this->mutable_store(); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 40 | store->RegisterConstString(flimflam::kCheckPortalListProperty, |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 41 | &manager_props.check_portal_list); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 42 | store->RegisterConstString(flimflam::kCountryProperty, |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 43 | &manager_props.country); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 44 | store->RegisterConstBool(flimflam::kOfflineModeProperty, |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 45 | &manager_props.offline_mode); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 46 | store->RegisterConstString(flimflam::kPortalURLProperty, |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 47 | &manager_props.portal_url); |
| 48 | } |
| 49 | |
| 50 | DefaultProfile::~DefaultProfile() {} |
| 51 | |
Paul Stewart | 870523b | 2012-01-11 17:00:42 -0800 | [diff] [blame^] | 52 | bool DefaultProfile::LoadManagerProperties(Manager::Properties *manager_props) { |
| 53 | storage()->GetBool(kStorageId, kStorageOfflineMode, |
| 54 | &manager_props->offline_mode); |
| 55 | storage()->GetString(kStorageId, |
| 56 | kStorageCheckPortalList, |
| 57 | &manager_props->check_portal_list); |
| 58 | return true; |
| 59 | } |
| 60 | |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 61 | bool DefaultProfile::Save() { |
| 62 | storage()->SetString(kStorageId, kStorageName, GetFriendlyName()); |
| 63 | storage()->SetBool(kStorageId, kStorageOfflineMode, props_.offline_mode); |
| 64 | storage()->SetString(kStorageId, |
| 65 | kStorageCheckPortalList, |
| 66 | props_.check_portal_list); |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame] | 67 | vector<DeviceRefPtr>::iterator it; |
| 68 | for (it = manager()->devices_begin(); it != manager()->devices_end(); ++it) { |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 69 | if (!(*it)->Save(storage())) { |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame] | 70 | LOG(ERROR) << "Could not save " << (*it)->UniqueName(); |
| 71 | return false; |
| 72 | } |
| 73 | } |
Chris Masone | b9c0059 | 2011-10-06 13:10:39 -0700 | [diff] [blame] | 74 | return Profile::Save(); |
Chris Masone | aa48237 | 2011-09-14 16:40:37 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 77 | bool DefaultProfile::GetStoragePath(FilePath *path) { |
| 78 | *path = storage_path_.Append(base::StringPrintf("%s.profile", kDefaultId)); |
| 79 | return true; |
| 80 | } |
| 81 | |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 82 | } // namespace shill |