[shill] Save profile specific data

BUG=chromium-os:17253
TEST=unit

Change-Id: I1ae28e1f42f4c0bf132cb28df9f334dfa1ca6795
Reviewed-on: http://gerrit.chromium.org/gerrit/7831
Reviewed-by: Darin Petkov <petkov@chromium.org>
Tested-by: Chris Masone <cmasone@chromium.org>
diff --git a/default_profile.cc b/default_profile.cc
index 59e56c5..feb41d4 100644
--- a/default_profile.cc
+++ b/default_profile.cc
@@ -11,16 +11,27 @@
 #include "shill/adaptor_interfaces.h"
 #include "shill/control_interface.h"
 #include "shill/manager.h"
+#include "shill/store_interface.h"
 
 namespace shill {
+// static
 const char DefaultProfile::kDefaultId[] = "default";
+// static
+const char DefaultProfile::kStorageId[] = "global";
+// static
+const char DefaultProfile::kStorageCheckPortalList[] = "CheckPortalList";
+// static
+const char DefaultProfile::kStorageName[] = "Name";
+// static
+const char DefaultProfile::kStorageOfflineMode[] = "OfflineMode";
 
 DefaultProfile::DefaultProfile(ControlInterface *control,
                                Manager *manager,
                                const FilePath &storage_path,
                                const Manager::Properties &manager_props)
     : Profile(control, manager, Identifier(kDefaultId), "", true),
-      storage_path_(storage_path) {
+      storage_path_(storage_path),
+      props_(manager_props) {
   PropertyStore *store = this->store();
   store->RegisterConstString(flimflam::kCheckPortalListProperty,
                              &manager_props.check_portal_list);
@@ -34,6 +45,15 @@
 
 DefaultProfile::~DefaultProfile() {}
 
+bool DefaultProfile::Save(StoreInterface *storage) {
+  storage->SetString(kStorageId, kStorageName, GetFriendlyName());
+  storage->SetBool(kStorageId, kStorageOfflineMode, props_.offline_mode);
+  storage->SetString(kStorageId,
+                     kStorageCheckPortalList,
+                     props_.check_portal_list);
+  return Profile::Save(storage);
+}
+
 bool DefaultProfile::GetStoragePath(FilePath *path) {
   *path = storage_path_.Append(base::StringPrintf("%s.profile", kDefaultId));
   return true;
diff --git a/default_profile.h b/default_profile.h
index 803c444..59a75c3 100644
--- a/default_profile.h
+++ b/default_profile.h
@@ -10,6 +10,7 @@
 
 #include <base/file_path.h>
 #include <base/memory/scoped_ptr.h>
+#include <gtest/gtest_prod.h>  // for FRIEND_TEST
 
 #include "shill/manager.h"
 #include "shill/profile.h"
@@ -29,6 +30,8 @@
                  const Manager::Properties &manager_props);
   virtual ~DefaultProfile();
 
+  virtual bool Save(StoreInterface *storage);
+
   // Sets |path| to the persistent store file path for the default, global
   // profile. Returns true on success, and false if unable to determine an
   // appropriate file location.
@@ -37,9 +40,16 @@
   virtual bool GetStoragePath(FilePath *path);
 
  private:
+  FRIEND_TEST(DefaultProfileTest, Save);
+
   static const char kDefaultId[];
+  static const char kStorageId[];
+  static const char kStorageCheckPortalList[];
+  static const char kStorageName[];
+  static const char kStorageOfflineMode[];
 
   const FilePath storage_path_;
+  const Manager::Properties &props_;
 
   DISALLOW_COPY_AND_ASSIGN(DefaultProfile);
 };
diff --git a/default_profile_unittest.cc b/default_profile_unittest.cc
index 5fb188e..e819185 100644
--- a/default_profile_unittest.cc
+++ b/default_profile_unittest.cc
@@ -13,11 +13,13 @@
 
 #include "shill/manager.h"
 #include "shill/mock_control.h"
+#include "shill/mock_store.h"
 #include "shill/property_store_unittest.h"
 
 using std::map;
 using std::string;
 using ::testing::_;
+using ::testing::Return;
 
 namespace shill {
 
@@ -67,6 +69,23 @@
   }
 }
 
+TEST_F(DefaultProfileTest, Save) {
+  MockStore storage;
+  EXPECT_CALL(storage, SetString(DefaultProfile::kStorageId,
+                                 DefaultProfile::kStorageName,
+                                 DefaultProfile::kDefaultId))
+      .WillOnce(Return(true));
+  EXPECT_CALL(storage, SetString(DefaultProfile::kStorageId,
+                                 DefaultProfile::kStorageCheckPortalList,
+                                 ""))
+      .WillOnce(Return(true));
+  EXPECT_CALL(storage, SetBool(DefaultProfile::kStorageId,
+                               DefaultProfile::kStorageOfflineMode,
+                               false))
+      .WillOnce(Return(true));
+  ASSERT_TRUE(profile_->Save(&storage));
+}
+
 TEST_F(DefaultProfileTest, GetStoragePath) {
   FilePath path;
   EXPECT_TRUE(profile_->GetStoragePath(&path));
diff --git a/profile.cc b/profile.cc
index 3fa0ed1..f905797 100644
--- a/profile.cc
+++ b/profile.cc
@@ -155,7 +155,6 @@
 }
 
 bool Profile::Save(StoreInterface *storage) {
-  // TODO(cmasone): Persist other profile info to disk.
   return SaveServices(storage);
 }
 
@@ -185,8 +184,8 @@
 }
 
 void Profile::HelpRegisterDerivedStrings(const string &name,
-                                     Strings(Profile::*get)(void),
-                                     bool(Profile::*set)(const Strings&)) {
+                                         Strings(Profile::*get)(void),
+                                         bool(Profile::*set)(const Strings&)) {
   store_.RegisterDerivedStrings(
       name,
       StringsAccessor(new CustomAccessor<Profile, Strings>(this, get, set)));