Re-land "[shill] Provide a cmd line toggle between flimflam and shill storage dirs"

This is so that we can easily switch to (and away from) using
the flimflam profile dir (and user profile dirs) when we start shill.

BUG=chromium-os:17253
TEST=unit

Change-Id: I0264162665607bb180688428c4640e42383ae355
Reviewed-on: http://gerrit.chromium.org/gerrit/6568
Reviewed-by: Chris Masone <cmasone@chromium.org>
Tested-by: Chris Masone <cmasone@chromium.org>
diff --git a/profile.cc b/profile.cc
index ef5182b..d0bcd77 100644
--- a/profile.cc
+++ b/profile.cc
@@ -26,17 +26,16 @@
 
 namespace shill {
 
-const char Profile::kGlobalStorageDir[] = "/var/cache/flimflam";
-const char Profile::kUserStorageDirFormat[] = "/home/%s/user/flimflam";
-
 Profile::Profile(ControlInterface *control_interface,
                  GLib *glib,
                  Manager *manager,
                  const Identifier &name,
+                 const string &user_storage_format,
                  bool connect_to_rpc)
     : manager_(manager),
       name_(name),
-      storage_(glib) {
+      storage_(glib),
+      storage_format_(user_storage_format) {
   if (connect_to_rpc)
     adaptor_.reset(control_interface->CreateProfileAdaptor(this));
 
@@ -150,14 +149,15 @@
   return true;
 }
 
-bool Profile::GetStoragePath(const Identifier &identifier, FilePath *path) {
-  FilePath dir(
-      identifier.user.empty() ?
-      kGlobalStorageDir :
-      base::StringPrintf(kUserStorageDirFormat, identifier.user.c_str()));
+bool Profile::GetStoragePath(FilePath *path) {
+  if (name_.user.empty()) {
+    LOG(ERROR) << "Non-default profiles cannot be stored globally.";
+    return false;
+  }
+  FilePath dir(base::StringPrintf(storage_format_.c_str(), name_.user.c_str()));
   // TODO(petkov): Validate the directory permissions, etc.
   *path = dir.Append(base::StringPrintf("%s.profile",
-                                        identifier.identifier.c_str()));
+                                        name_.identifier.c_str()));
   return true;
 }