shill: profile: Mark invalid profiles as corrupted and ignore

If we fail to open a profile due to a failure in loading
the keyfile store, move the broken file out of the way, since
we will never be able to load this file in later attempts.
In situations where this is the default profile, this will
allow us to start up successfully the next time.

BUG=chromium-os:33822
TEST=Unit tests + manual (copy default.profile from the bug
and ensure shill restarts itself and moves the corrupted
profile out of the way.)

Change-Id: Ia3b7716b36b52c559193f6f6e28c9b185a77c01e
Reviewed-on: https://gerrit.chromium.org/gerrit/31374
Commit-Ready: Paul Stewart <pstew@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/profile.cc b/profile.cc
index 52746b7..95b8956 100644
--- a/profile.cc
+++ b/profile.cc
@@ -87,6 +87,12 @@
     Error::PopulateAndLog(error, Error::kInternalError,
         base::StringPrintf("Could not open profile storage for %s:%s",
                            name_.user.c_str(), name_.identifier.c_str()));
+    if (already_exists) {
+      // The profile contents is corrupt, or we do not have access to
+      // this file.  Move this file out of the way so a future open attempt
+      // will succeed, assuming the failure reason was the former.
+      storage->MarkAsCorrupted();
+    }
     return false;
   }
   if (!already_exists) {