OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/common/switch_utils.h" | 5 #include "chrome/common/switch_utils.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/files/file_path.h" | |
9 #include "base/lazy_instance.h" | |
10 #include "base/path_service.h" | |
11 #include "base/strings/string_util.h" | |
12 #include "chrome/common/chrome_paths.h" | |
13 #include "chrome/common/chrome_paths_internal.h" | |
8 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
9 | 15 |
16 #if defined(OS_LINUX) | |
17 #include "base/environment.h" | |
18 #endif | |
19 | |
20 #if defined(OS_MACOSX) || defined(OS_WIN) | |
21 #include "chrome/browser/policy/policy_path_parser.h" | |
22 #endif | |
23 | |
24 namespace { | |
25 | |
26 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.
| |
27 g_invalid_specified_user_data_dir = LAZY_INSTANCE_INITIALIZER; | |
28 | |
29 } // namespace | |
30 | |
10 namespace switches { | 31 namespace switches { |
11 | 32 |
12 // Switches enumerated here will be removed when a background instance of | 33 // Switches enumerated here will be removed when a background instance of |
13 // Chrome restarts itself. If your key is designed to only be used once, | 34 // Chrome restarts itself. If your key is designed to only be used once, |
14 // or if it does not make sense when restarting a background instance to | 35 // or if it does not make sense when restarting a background instance to |
15 // pick up an automatic update, be sure to add it to this list. | 36 // pick up an automatic update, be sure to add it to this list. |
16 const char* const kSwitchesToRemoveOnAutorestart[] = { | 37 const char* const kSwitchesToRemoveOnAutorestart[] = { |
17 switches::kApp, | 38 switches::kApp, |
18 switches::kAppId, | 39 switches::kAppId, |
19 switches::kForceFirstRun, | 40 switches::kForceFirstRun, |
20 switches::kMakeDefaultBrowser, | 41 switches::kMakeDefaultBrowser, |
21 switches::kNoStartupWindow, | 42 switches::kNoStartupWindow, |
22 switches::kRestoreLastSession, | 43 switches::kRestoreLastSession, |
23 switches::kShowAppList, | 44 switches::kShowAppList, |
24 }; | 45 }; |
25 | 46 |
26 void RemoveSwitchesForAutostart( | 47 void RemoveSwitchesForAutostart( |
27 std::map<std::string, CommandLine::StringType>* switch_list) { | 48 std::map<std::string, CommandLine::StringType>* switch_list) { |
28 for (size_t i = 0; i < arraysize(kSwitchesToRemoveOnAutorestart); ++i) | 49 for (size_t i = 0; i < arraysize(kSwitchesToRemoveOnAutorestart); ++i) |
29 switch_list->erase(kSwitchesToRemoveOnAutorestart[i]); | 50 switch_list->erase(kSwitchesToRemoveOnAutorestart[i]); |
30 } | 51 } |
31 | 52 |
53 void InitializeUserDataDir() { | |
54 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
55 base::FilePath user_data_dir = | |
56 command_line->GetSwitchValuePath(switches::kUserDataDir); | |
57 std::string process_type = | |
58 command_line->GetSwitchValueASCII(switches::kProcessType); | |
59 | |
60 #if defined(OS_LINUX) | |
61 // On Linux, Chrome does not support running multiple copies under different | |
62 // DISPLAYs, so the profile directory can be specified in the environment to | |
63 // support the virtual desktop use-case. | |
64 if (user_data_dir.empty()) { | |
65 std::string user_data_dir_string; | |
66 scoped_ptr<base::Environment> environment(base::Environment::Create()); | |
67 if (environment->GetVar("CHROME_USER_DATA_DIR", &user_data_dir_string) && | |
68 IsStringUTF8(user_data_dir_string)) { | |
69 user_data_dir = base::FilePath::FromUTF8Unsafe(user_data_dir_string); | |
70 } | |
71 } | |
72 #endif | |
73 #if defined(OS_MACOSX) || defined(OS_WIN) | |
74 policy::path_parser::CheckUserDataDirPolicy(&user_data_dir); | |
75 #endif | |
76 | |
77 const bool specified_directory_was_invalid = !user_data_dir.empty() && | |
78 !PathService::OverrideAndCreateIfNeeded(chrome::DIR_USER_DATA, | |
79 user_data_dir, chrome::ProcessNeedsProfileDir(process_type)); | |
80 // Save inaccessible or invalid paths so the user may be prompted later. | |
81 if (specified_directory_was_invalid) | |
82 g_invalid_specified_user_data_dir.Get() = user_data_dir; | |
83 | |
84 // Getting the user data directory can fail if the directory isn't creatable. | |
85 // ProcessSingleton needs a real user data directory on Mac/Linux, so it's | |
86 // better to fail here than fail mysteriously elsewhere. | |
87 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) | |
88 << "Must be able to get user data directory!"; | |
89 | |
90 // Append the fallback user data directory to the commandline. Otherwise, | |
91 // child or service processes will attempt to use the invalid directory. | |
92 if (specified_directory_was_invalid) | |
93 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir); | |
94 } | |
95 | |
96 const base::FilePath& GetInvalidSpecifiedUserDataDir() { | |
97 return g_invalid_specified_user_data_dir.Get(); | |
98 } | |
99 | |
32 } // namespace switches | 100 } // namespace switches |
OLD | NEW |