| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/install_static/user_data_dir.h" | 5 #include "chrome/install_static/user_data_dir.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <assert.h> | 8 #include <assert.h> |
| 9 | 9 |
| 10 #include "chrome/install_static/install_details.h" | 10 #include "chrome/install_static/install_details.h" |
| 11 #include "chrome/install_static/install_util.h" | 11 #include "chrome/install_static/install_util.h" |
| 12 #include "chrome/install_static/policy_path_parser.h" | 12 #include "chrome/install_static/policy_path_parser.h" |
| 13 #include "chrome_elf/nt_registry/nt_registry.h" | 13 #include "chrome_elf/nt_registry/nt_registry.h" |
| 14 | 14 |
| 15 namespace install_static { | 15 namespace install_static { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 std::wstring* g_user_data_dir; | |
| 20 std::wstring* g_invalid_user_data_dir; | |
| 21 | |
| 22 // Retrieves a registry policy for the user data directory from the registry, if | 19 // Retrieves a registry policy for the user data directory from the registry, if |
| 23 // one is set. If there's none set in either HKLM or HKCU, |user_data_dir| will | 20 // one is set. If there's none set in either HKLM or HKCU, |user_data_dir| will |
| 24 // be unmodified. | 21 // be unmodified. |
| 25 void GetUserDataDirFromRegistryPolicyIfSet(const InstallConstants& mode, | 22 void GetUserDataDirFromRegistryPolicyIfSet(const InstallConstants& mode, |
| 26 std::wstring* user_data_dir) { | 23 std::wstring* user_data_dir) { |
| 27 assert(user_data_dir); | 24 assert(user_data_dir); |
| 28 std::wstring policies_path = L"SOFTWARE\\Policies\\"; | 25 std::wstring policies_path = L"SOFTWARE\\Policies\\"; |
| 29 AppendChromeInstallSubDirectory(mode, false /* !include_suffix */, | 26 AppendChromeInstallSubDirectory(mode, false /* !include_suffix */, |
| 30 &policies_path); | 27 &policies_path); |
| 31 | 28 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 48 } | 45 } |
| 49 } | 46 } |
| 50 | 47 |
| 51 std::wstring MakeAbsoluteFilePath(const std::wstring& input) { | 48 std::wstring MakeAbsoluteFilePath(const std::wstring& input) { |
| 52 wchar_t file_path[MAX_PATH]; | 49 wchar_t file_path[MAX_PATH]; |
| 53 if (!_wfullpath(file_path, input.c_str(), _countof(file_path))) | 50 if (!_wfullpath(file_path, input.c_str(), _countof(file_path))) |
| 54 return std::wstring(); | 51 return std::wstring(); |
| 55 return file_path; | 52 return file_path; |
| 56 } | 53 } |
| 57 | 54 |
| 58 // The same as GetUserDataDirectory(), but directly queries the global command | 55 // The same as DeriveUserDataDirectoryImpl(), but directly queries the global |
| 59 // line object for the --user-data-dir flag. This is the more commonly used | 56 // command line object for the --user-data-dir flag. This is the more commonly |
| 60 // function, where GetUserDataDirectory() is used primiarily for testing. | 57 // used function, where DeriveUserDataDirectoryImpl() is used primiarily for |
| 58 // testing. |
| 61 bool GetUserDataDirectoryUsingProcessCommandLine( | 59 bool GetUserDataDirectoryUsingProcessCommandLine( |
| 62 const InstallConstants& mode, | 60 const InstallConstants& mode, |
| 63 std::wstring* result, | 61 std::wstring* result, |
| 64 std::wstring* invalid_supplied_directory) { | 62 std::wstring* invalid_supplied_directory) { |
| 65 return GetUserDataDirectoryImpl( | 63 return DeriveUserDataDirectoryImpl( |
| 66 GetSwitchValueFromCommandLine(::GetCommandLine(), kUserDataDirSwitch), | 64 GetSwitchValueFromCommandLine(::GetCommandLine(), kUserDataDirSwitch), |
| 67 mode, result, invalid_supplied_directory); | 65 mode, result, invalid_supplied_directory); |
| 68 } | 66 } |
| 69 | 67 |
| 70 // Populates |result| with the default User Data directory for the current | 68 // Populates |result| with the default User Data directory for the current |
| 71 // user. Returns false if all attempts at locating a User Data directory fail. | 69 // user. Returns false if all attempts at locating a User Data directory fail. |
| 72 // TODO(ananta) | 70 // TODO(ananta) |
| 73 // http://crbug.com/604923 | 71 // http://crbug.com/604923 |
| 74 // Unify this with the Browser Distribution code. | 72 // Unify this with the Browser Distribution code. |
| 75 bool GetDefaultUserDataDirectory(const InstallConstants& mode, | 73 bool GetDefaultUserDataDirectory(const InstallConstants& mode, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 94 if ((*result)[result->length() - 1] != L'\\') | 92 if ((*result)[result->length() - 1] != L'\\') |
| 95 result->push_back(L'\\'); | 93 result->push_back(L'\\'); |
| 96 AppendChromeInstallSubDirectory(mode, true /* include_suffix */, result); | 94 AppendChromeInstallSubDirectory(mode, true /* include_suffix */, result); |
| 97 result->push_back(L'\\'); | 95 result->push_back(L'\\'); |
| 98 result->append(L"User Data"); | 96 result->append(L"User Data"); |
| 99 return true; | 97 return true; |
| 100 } | 98 } |
| 101 | 99 |
| 102 } // namespace | 100 } // namespace |
| 103 | 101 |
| 104 bool GetUserDataDirectoryImpl( | 102 bool DeriveUserDataDirectoryImpl( |
| 105 const std::wstring& user_data_dir_from_command_line, | 103 const std::wstring& user_data_dir_from_command_line, |
| 106 const InstallConstants& mode, | 104 const InstallConstants& mode, |
| 107 std::wstring* result, | 105 std::wstring* result, |
| 108 std::wstring* invalid_supplied_directory) { | 106 std::wstring* invalid_supplied_directory) { |
| 109 std::wstring user_data_dir = user_data_dir_from_command_line; | 107 std::wstring user_data_dir = user_data_dir_from_command_line; |
| 110 | 108 |
| 111 GetUserDataDirFromRegistryPolicyIfSet(mode, &user_data_dir); | 109 GetUserDataDirFromRegistryPolicyIfSet(mode, &user_data_dir); |
| 112 | 110 |
| 113 // On Windows, trailing separators leave Chrome in a bad state. See | 111 // On Windows, trailing separators leave Chrome in a bad state. See |
| 114 // crbug.com/464616. | 112 // crbug.com/464616. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 128 // don't as this function is used to initialize crash reporting, so | 126 // don't as this function is used to initialize crash reporting, so |
| 129 // we would get no report of this failure. | 127 // we would get no report of this failure. |
| 130 assert(got_valid_directory); | 128 assert(got_valid_directory); |
| 131 if (!got_valid_directory) | 129 if (!got_valid_directory) |
| 132 return false; | 130 return false; |
| 133 | 131 |
| 134 *result = MakeAbsoluteFilePath(user_data_dir); | 132 *result = MakeAbsoluteFilePath(user_data_dir); |
| 135 return true; | 133 return true; |
| 136 } | 134 } |
| 137 | 135 |
| 138 bool GetUserDataDirectory(std::wstring* user_data_dir, | 136 bool DeriveUserDataDirectory(const InstallConstants& mode, |
| 139 std::wstring* invalid_user_data_dir) { | 137 std::wstring* user_data_dir, |
| 140 if (!g_user_data_dir) { | 138 std::wstring* invalid_user_data_dir) { |
| 141 g_user_data_dir = new std::wstring(); | 139 return GetUserDataDirectoryUsingProcessCommandLine(mode, user_data_dir, |
| 142 g_invalid_user_data_dir = new std::wstring(); | 140 invalid_user_data_dir); |
| 143 if (!GetUserDataDirectoryUsingProcessCommandLine( | |
| 144 InstallDetails::Get().mode(), g_user_data_dir, | |
| 145 g_invalid_user_data_dir)) { | |
| 146 return false; | |
| 147 } | |
| 148 assert(!g_user_data_dir->empty()); | |
| 149 } | |
| 150 *user_data_dir = *g_user_data_dir; | |
| 151 if (invalid_user_data_dir) | |
| 152 *invalid_user_data_dir = *g_invalid_user_data_dir; | |
| 153 return true; | |
| 154 } | 141 } |
| 155 | 142 |
| 156 } // namespace install_static | 143 } // namespace install_static |
| OLD | NEW |