blob: f8b263bab3a4cb6ee65eb50f5faee139c8ff0c62 [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
Chris Masoneaa482372011-09-14 16:40:37 -070052bool DefaultProfile::Save(StoreInterface *storage) {
53 storage->SetString(kStorageId, kStorageName, GetFriendlyName());
54 storage->SetBool(kStorageId, kStorageOfflineMode, props_.offline_mode);
55 storage->SetString(kStorageId,
56 kStorageCheckPortalList,
57 props_.check_portal_list);
Chris Masone877ff982011-09-21 16:18:24 -070058 vector<DeviceRefPtr>::iterator it;
59 for (it = manager()->devices_begin(); it != manager()->devices_end(); ++it) {
60 if (!(*it)->Save(storage)) {
61 LOG(ERROR) << "Could not save " << (*it)->UniqueName();
62 return false;
63 }
64 }
Chris Masoneaa482372011-09-14 16:40:37 -070065 return Profile::Save(storage);
66}
67
Chris Masone2ae797d2011-08-23 20:41:00 -070068bool DefaultProfile::GetStoragePath(FilePath *path) {
69 *path = storage_path_.Append(base::StringPrintf("%s.profile", kDefaultId));
70 return true;
71}
72
Chris Masone88cbd5f2011-07-03 14:30:04 -070073} // namespace shill