shill: Add option to push profiles on shill startup

When re-started after a user has logged in (say, due to a crash), we need a
way to tell shill to load the logged in user's profile. Normally, you would
do this by having the respawning entity (upstart, usually) to re-send a dbus-
message to load a profile.

Due to the machinations of how process tracking works, it's sometimes better
to do the startup and profile load in a single step. Hence, this new option
similar to flimflam.

BUG=chromium-os:23492
TEST=none

Change-Id: I2f66ebd726fa678468b4ad01a57c21ebf42784aa
Reviewed-on: https://gerrit.chromium.org/gerrit/12179
Tested-by: Gaurav Shah <gauravsh@chromium.org>
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Ready: Gaurav Shah <gauravsh@chromium.org>
diff --git a/manager.cc b/manager.cc
index d7824ac..0d197e4 100644
--- a/manager.cc
+++ b/manager.cc
@@ -117,14 +117,7 @@
   CHECK(file_util::CreateDirectory(run_path_)) << run_path_.value();
   Resolver::GetInstance()->set_path(run_path_.Append("resolv.conf"));
 
-  CHECK(file_util::CreateDirectory(storage_path_)) << storage_path_.value();
-
-  profiles_.push_back(new DefaultProfile(control_interface_,
-                                         this,
-                                         storage_path_,
-                                         props_));
-  CHECK(profiles_[0]->InitStorage(glib_, Profile::kCreateOrOpenExisting, NULL));
-
+  InitializeProfiles();
   running_ = true;
   adaptor_->UpdateRunning();
   device_info_.Start();
@@ -150,6 +143,21 @@
   device_info_.Stop();
 }
 
+void Manager::InitializeProfiles() {
+  DCHECK(profiles_.empty());
+  // The default profile must go first on the stack.
+  CHECK(file_util::CreateDirectory(storage_path_)) << storage_path_.value();
+  profiles_.push_back(new DefaultProfile(control_interface_,
+                                         this,
+                                         storage_path_,
+                                         props_));
+  CHECK(profiles_[0]->InitStorage(glib_, Profile::kCreateOrOpenExisting, NULL));
+  Error error;
+  for (vector<string>::iterator it = startup_profiles_.begin();
+       it != startup_profiles_.end(); ++it)
+    PushProfile(*it, &error);
+}
+
 void Manager::CreateProfile(const string &name, Error *error) {
   Profile::Identifier ident;
   if (!Profile::ParseIdentifier(name, &ident)) {