Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7945)

Unified Diff: chrome/common/switch_utils.cc

Issue 174253002: Initialize chrome::DIR_USER_DATA early on for service processes, etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move utility functions into related files. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« chrome/common/switch_utils.h ('K') | « chrome/common/switch_utils.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/switch_utils.cc
diff --git a/chrome/common/switch_utils.cc b/chrome/common/switch_utils.cc
index 3b65b81ba171d4ed6f21b7a90614f05a620f04e1..aeb37ebec6f46b6d29aeb4598fe09b40cc428e46 100644
--- a/chrome/common/switch_utils.cc
+++ b/chrome/common/switch_utils.cc
@@ -5,8 +5,29 @@
#include "chrome/common/switch_utils.h"
#include "base/basictypes.h"
+#include "base/files/file_path.h"
+#include "base/lazy_instance.h"
+#include "base/path_service.h"
+#include "base/strings/string_util.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/common/chrome_paths_internal.h"
#include "chrome/common/chrome_switches.h"
+#if defined(OS_LINUX)
+#include "base/environment.h"
+#endif
+
+#if defined(OS_MACOSX) || defined(OS_WIN)
+#include "chrome/browser/policy/policy_path_parser.h"
+#endif
+
+namespace {
+
+static base::LazyInstance<base::FilePath>::Leaky
Vitaly Buka (NO REVIEWS) 2014/02/21 23:11:33 FilePath is simple structure. I guess it's OK to h
msw 2014/02/21 23:38:30 Done.
+ g_invalid_specified_user_data_dir = LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
namespace switches {
// Switches enumerated here will be removed when a background instance of
@@ -29,4 +50,51 @@ void RemoveSwitchesForAutostart(
switch_list->erase(kSwitchesToRemoveOnAutorestart[i]);
}
+void InitializeUserDataDir() {
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ base::FilePath user_data_dir =
+ command_line->GetSwitchValuePath(switches::kUserDataDir);
+ std::string process_type =
+ command_line->GetSwitchValueASCII(switches::kProcessType);
+
+#if defined(OS_LINUX)
+ // On Linux, Chrome does not support running multiple copies under different
+ // DISPLAYs, so the profile directory can be specified in the environment to
+ // support the virtual desktop use-case.
+ if (user_data_dir.empty()) {
+ std::string user_data_dir_string;
+ scoped_ptr<base::Environment> environment(base::Environment::Create());
+ if (environment->GetVar("CHROME_USER_DATA_DIR", &user_data_dir_string) &&
+ IsStringUTF8(user_data_dir_string)) {
+ user_data_dir = base::FilePath::FromUTF8Unsafe(user_data_dir_string);
+ }
+ }
+#endif
+#if defined(OS_MACOSX) || defined(OS_WIN)
+ policy::path_parser::CheckUserDataDirPolicy(&user_data_dir);
+#endif
+
+ const bool specified_directory_was_invalid = !user_data_dir.empty() &&
+ !PathService::OverrideAndCreateIfNeeded(chrome::DIR_USER_DATA,
+ user_data_dir, chrome::ProcessNeedsProfileDir(process_type));
+ // Save inaccessible or invalid paths so the user may be prompted later.
+ if (specified_directory_was_invalid)
+ g_invalid_specified_user_data_dir.Get() = user_data_dir;
+
+ // Getting the user data directory can fail if the directory isn't creatable.
+ // ProcessSingleton needs a real user data directory on Mac/Linux, so it's
+ // better to fail here than fail mysteriously elsewhere.
+ CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir))
+ << "Must be able to get user data directory!";
+
+ // Append the fallback user data directory to the commandline. Otherwise,
+ // child or service processes will attempt to use the invalid directory.
+ if (specified_directory_was_invalid)
+ command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
+}
+
+const base::FilePath& GetInvalidSpecifiedUserDataDir() {
+ return g_invalid_specified_user_data_dir.Get();
+}
+
} // namespace switches
« chrome/common/switch_utils.h ('K') | « chrome/common/switch_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698