blob: 27607e1fcdbacb977de94b4f65ed0053e1f8b321 [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
Paul Stewartd32f4842012-01-11 16:08:13 -080028const char DefaultProfile::kStorageHostName[] = "HostName";
29// static
Chris Masoneaa482372011-09-14 16:40:37 -070030const char DefaultProfile::kStorageName[] = "Name";
31// static
32const char DefaultProfile::kStorageOfflineMode[] = "OfflineMode";
Chris Masone88cbd5f2011-07-03 14:30:04 -070033
Chris Masone2ae797d2011-08-23 20:41:00 -070034DefaultProfile::DefaultProfile(ControlInterface *control,
Chris Masone6791a432011-07-12 13:23:19 -070035 Manager *manager,
Chris Masone2ae797d2011-08-23 20:41:00 -070036 const FilePath &storage_path,
Chris Masone88cbd5f2011-07-03 14:30:04 -070037 const Manager::Properties &manager_props)
Chris Masone9d779932011-08-25 16:33:41 -070038 : Profile(control, manager, Identifier(kDefaultId), "", true),
Chris Masoneaa482372011-09-14 16:40:37 -070039 storage_path_(storage_path),
40 props_(manager_props) {
mukesh agrawalde29fa82011-09-16 16:16:36 -070041 PropertyStore *store = this->mutable_store();
Paul Stewartac4ac002011-08-26 12:04:26 -070042 store->RegisterConstString(flimflam::kCheckPortalListProperty,
Chris Masone88cbd5f2011-07-03 14:30:04 -070043 &manager_props.check_portal_list);
Paul Stewartac4ac002011-08-26 12:04:26 -070044 store->RegisterConstString(flimflam::kCountryProperty,
Chris Masone88cbd5f2011-07-03 14:30:04 -070045 &manager_props.country);
Paul Stewartac4ac002011-08-26 12:04:26 -070046 store->RegisterConstBool(flimflam::kOfflineModeProperty,
Chris Masone88cbd5f2011-07-03 14:30:04 -070047 &manager_props.offline_mode);
Paul Stewartac4ac002011-08-26 12:04:26 -070048 store->RegisterConstString(flimflam::kPortalURLProperty,
Chris Masone88cbd5f2011-07-03 14:30:04 -070049 &manager_props.portal_url);
50}
51
52DefaultProfile::~DefaultProfile() {}
53
Paul Stewart870523b2012-01-11 17:00:42 -080054bool DefaultProfile::LoadManagerProperties(Manager::Properties *manager_props) {
Paul Stewartd32f4842012-01-11 16:08:13 -080055 storage()->GetString(kStorageId, kStorageHostName, &manager_props->host_name);
Paul Stewart870523b2012-01-11 17:00:42 -080056 storage()->GetBool(kStorageId, kStorageOfflineMode,
57 &manager_props->offline_mode);
58 storage()->GetString(kStorageId,
59 kStorageCheckPortalList,
60 &manager_props->check_portal_list);
61 return true;
62}
63
Chris Masoneb9c00592011-10-06 13:10:39 -070064bool DefaultProfile::Save() {
Paul Stewartd32f4842012-01-11 16:08:13 -080065 storage()->SetString(kStorageId, kStorageHostName, props_.host_name);
Chris Masoneb9c00592011-10-06 13:10:39 -070066 storage()->SetString(kStorageId, kStorageName, GetFriendlyName());
67 storage()->SetBool(kStorageId, kStorageOfflineMode, props_.offline_mode);
68 storage()->SetString(kStorageId,
69 kStorageCheckPortalList,
70 props_.check_portal_list);
Chris Masone877ff982011-09-21 16:18:24 -070071 vector<DeviceRefPtr>::iterator it;
72 for (it = manager()->devices_begin(); it != manager()->devices_end(); ++it) {
Chris Masoneb9c00592011-10-06 13:10:39 -070073 if (!(*it)->Save(storage())) {
Chris Masone877ff982011-09-21 16:18:24 -070074 LOG(ERROR) << "Could not save " << (*it)->UniqueName();
75 return false;
76 }
77 }
Chris Masoneb9c00592011-10-06 13:10:39 -070078 return Profile::Save();
Chris Masoneaa482372011-09-14 16:40:37 -070079}
80
Chris Masone2ae797d2011-08-23 20:41:00 -070081bool DefaultProfile::GetStoragePath(FilePath *path) {
82 *path = storage_path_.Append(base::StringPrintf("%s.profile", kDefaultId));
83 return true;
84}
85
Chris Masone88cbd5f2011-07-03 14:30:04 -070086} // namespace shill