shill; Create Error::LogMessage utility routine

This combines a LOG(ERROR) with an error->Populate().  It has
the downside of having the error originate from error.cc, as
opposed to the orignal call site of the error, so readers of
the log need to rely on the content of the error message to
tell where the error came from.

BUG=chromium-os:22426
TEST=Rerun unit tests, look at all error messages

Change-Id: I9ccd5385db7c4eda34eb242abd02c57c899d161c
Reviewed-on: https://gerrit.chromium.org/gerrit/11098
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/profile.cc b/profile.cc
index d87bbf2..7ba3aef 100644
--- a/profile.cc
+++ b/profile.cc
@@ -61,13 +61,9 @@
                           Error *error) {
   FilePath final_path;
   if (!GetStoragePath(&final_path)) {
-    const string kMessage =
+    Error::PopulateAndLog(error, Error::kInvalidArguments,
         base::StringPrintf("Could not set up profile storage for %s:%s",
-                           name_.user.c_str(), name_.identifier.c_str());
-    LOG(ERROR) << kMessage;
-    if (error) {
-      error->Populate(Error::kInvalidArguments, kMessage);
-    }
+                           name_.user.c_str(), name_.identifier.c_str()));
     return false;
   }
   scoped_ptr<KeyFileStore> storage(new KeyFileStore(glib));
@@ -75,33 +71,21 @@
   bool already_exists = storage->IsNonEmpty();
   if (!already_exists && storage_option != kCreateNew &&
       storage_option != kCreateOrOpenExisting) {
-    const string kMessage =
+    Error::PopulateAndLog(error, Error::kNotFound,
         base::StringPrintf("Profile storage for %s:%s does not already exist",
-                           name_.user.c_str(), name_.identifier.c_str());
-    LOG(ERROR) << kMessage;
-    if (error) {
-      error->Populate(Error::kNotFound, kMessage);
-    }
+                           name_.user.c_str(), name_.identifier.c_str()));
     return false;
   } else if (already_exists && storage_option != kOpenExisting &&
              storage_option != kCreateOrOpenExisting) {
-    const string kMessage =
+    Error::PopulateAndLog(error, Error::kAlreadyExists,
         base::StringPrintf("Profile storage for %s:%s already exists",
-                           name_.user.c_str(), name_.identifier.c_str());
-    LOG(ERROR) << kMessage;
-    if (error) {
-      error->Populate(Error::kAlreadyExists, kMessage);
-    }
+                           name_.user.c_str(), name_.identifier.c_str()));
     return false;
   }
   if (!storage->Open()) {
-    const string kMessage =
+    Error::PopulateAndLog(error, Error::kInternalError,
         base::StringPrintf("Could not open profile storage for %s:%s",
-                           name_.user.c_str(), name_.identifier.c_str());
-    LOG(ERROR) << kMessage;
-    if (error) {
-      error->Populate(Error::kInternalError, kMessage);
-    }
+                           name_.user.c_str(), name_.identifier.c_str()));
     return false;
   }
   if (!already_exists) {