shill: Implement CreateProfile, PushProfile, PopProfile

Collateral fixes: Profiles now create a header at the beginning
of the file, and this feature is plumbed down through key_file_store
and glib.  InitStorage can be configured to fail if the profile
already exists/doesn't yet exist.

BUG=chromium-os:22221
TEST=New unit tests

Change-Id: Ie7c2d0dee97891b7850cec75b74052fce77eee8f
Reviewed-on: https://gerrit.chromium.org/gerrit/10884
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Reviewed-by: Darin Petkov <petkov@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/manager.h b/manager.h
index 3a9482b..9a3e56d 100644
--- a/manager.h
+++ b/manager.h
@@ -54,8 +54,6 @@
   void Stop();
 
   // Pushes |profile| onto stack of managed profiles.
-  // TODO(someone): CreateProfile and PushProfile should be implemented
-  // using this.
   void AdoptProfile(const ProfileRefPtr &profile);
 
   const ProfileRefPtr &ActiveProfile();
@@ -80,6 +78,14 @@
   void RequestScan(const std::string &technology, Error *error);
   std::string GetTechnologyOrder();
   void SetTechnologyOrder(const std::string &order, Error *error);
+  // Create a profile.  This does not affect the profile stack.
+  void CreateProfile(const std::string &name, Error *error);
+  // Pushes existing profile with name |name| onto stack of managed profiles.
+  void PushProfile(const std::string &name, Error *error);
+  // Pops profile named |name| off the top of the stack of managed profiles.
+  void PopProfile(const std::string &name, Error *error);
+  // Remove the active profile.
+  void PopAnyProfile(Error *error);
 
   virtual DeviceInfo *device_info() { return &device_info_; }
   PropertyStore *mutable_store() { return &store_; }
@@ -93,6 +99,7 @@
  private:
   friend class ManagerAdaptorInterface;
   friend class ManagerTest;
+  FRIEND_TEST(ManagerTest, PushPopProfile);
   FRIEND_TEST(ManagerTest, SortServices);
 
   static const char kManagerErrorNoDevice[];
@@ -116,6 +123,7 @@
       Strings(Manager::*get)(void),
       void(Manager::*set)(const Strings&, Error *));
 
+  void PopProfileInternal();
   bool OrderServices(ServiceRefPtr a, ServiceRefPtr b);
   void SortServices();
 
@@ -126,6 +134,8 @@
   DeviceInfo device_info_;
   ModemInfo modem_info_;
   bool running_;
+  // Used to facilitate unit tests which can't use RPC.
+  bool connect_profiles_to_rpc_;
   std::vector<DeviceRefPtr> devices_;
   // We store Services in a vector, because we want to keep them sorted.
   std::vector<ServiceRefPtr> services_;