blob: 04d105f8365e8a15484e58f4f0b5d8ee77e84d29 [file] [log] [blame]
Chris Masone88cbd5f2011-07-03 14:30:04 -07001// 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 Masone877ff982011-09-21 16:18:24 -07007#include <vector>
8
Chris Masone2ae797d2011-08-23 20:41:00 -07009#include <base/file_path.h>
10#include <base/stringprintf.h>
Chris Masone88cbd5f2011-07-03 14:30:04 -070011#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 Masoneaa482372011-09-14 16:40:37 -070016#include "shill/store_interface.h"
Chris Masone88cbd5f2011-07-03 14:30:04 -070017
Chris Masone877ff982011-09-21 16:18:24 -070018using std::vector;
19
Chris Masone88cbd5f2011-07-03 14:30:04 -070020namespace shill {
Chris Masoneaa482372011-09-14 16:40:37 -070021// static
Chris Masone7df0c672011-07-15 10:24:54 -070022const char DefaultProfile::kDefaultId[] = "default";
Chris Masoneaa482372011-09-14 16:40:37 -070023// static
24const char DefaultProfile::kStorageId[] = "global";
25// static
26const char DefaultProfile::kStorageCheckPortalList[] = "CheckPortalList";
27// static
28const char DefaultProfile::kStorageName[] = "Name";
29// static
30const char DefaultProfile::kStorageOfflineMode[] = "OfflineMode";
Chris Masone88cbd5f2011-07-03 14:30:04 -070031
Chris Masone2ae797d2011-08-23 20:41:00 -070032DefaultProfile::DefaultProfile(ControlInterface *control,
Chris Masone6791a432011-07-12 13:23:19 -070033 Manager *manager,
Chris Masone2ae797d2011-08-23 20:41:00 -070034 const FilePath &storage_path,
Chris Masone88cbd5f2011-07-03 14:30:04 -070035 const Manager::Properties &manager_props)
Chris Masone9d779932011-08-25 16:33:41 -070036 : Profile(control, manager, Identifier(kDefaultId), "", true),
Chris Masoneaa482372011-09-14 16:40:37 -070037 storage_path_(storage_path),
38 props_(manager_props) {
mukesh agrawalde29fa82011-09-16 16:16:36 -070039 PropertyStore *store = this->mutable_store();
Paul Stewartac4ac002011-08-26 12:04:26 -070040 store->RegisterConstString(flimflam::kCheckPortalListProperty,
Chris Masone88cbd5f2011-07-03 14:30:04 -070041 &manager_props.check_portal_list);
Paul Stewartac4ac002011-08-26 12:04:26 -070042 store->RegisterConstString(flimflam::kCountryProperty,
Chris Masone88cbd5f2011-07-03 14:30:04 -070043 &manager_props.country);
Paul Stewartac4ac002011-08-26 12:04:26 -070044 store->RegisterConstBool(flimflam::kOfflineModeProperty,
Chris Masone88cbd5f2011-07-03 14:30:04 -070045 &manager_props.offline_mode);
Paul Stewartac4ac002011-08-26 12:04:26 -070046 store->RegisterConstString(flimflam::kPortalURLProperty,
Chris Masone88cbd5f2011-07-03 14:30:04 -070047 &manager_props.portal_url);
48}
49
50DefaultProfile::~DefaultProfile() {}
51
Paul Stewart870523b2012-01-11 17:00:42 -080052bool 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 Masoneb9c00592011-10-06 13:10:39 -070061bool 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 Masone877ff982011-09-21 16:18:24 -070067 vector<DeviceRefPtr>::iterator it;
68 for (it = manager()->devices_begin(); it != manager()->devices_end(); ++it) {
Chris Masoneb9c00592011-10-06 13:10:39 -070069 if (!(*it)->Save(storage())) {
Chris Masone877ff982011-09-21 16:18:24 -070070 LOG(ERROR) << "Could not save " << (*it)->UniqueName();
71 return false;
72 }
73 }
Chris Masoneb9c00592011-10-06 13:10:39 -070074 return Profile::Save();
Chris Masoneaa482372011-09-14 16:40:37 -070075}
76
Chris Masone2ae797d2011-08-23 20:41:00 -070077bool DefaultProfile::GetStoragePath(FilePath *path) {
78 *path = storage_path_.Append(base::StringPrintf("%s.profile", kDefaultId));
79 return true;
80}
81
Chris Masone88cbd5f2011-07-03 14:30:04 -070082} // namespace shill