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

Side by Side Diff: chrome/browser/policy/policy_path_parser_win.cc

Issue 1986823002: Reset user data directory and disk cache directory after downgrade. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/policy/policy_path_parser_mac.mm ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/browser/policy/policy_path_parser.h" 5 #include "chrome/browser/policy/policy_path_parser.h"
6 6
7 #include <shlobj.h> 7 #include <shlobj.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <wtsapi32.h> 9 #include <wtsapi32.h>
10 10
11 #include <memory> 11 #include <memory>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/win/registry.h" 15 #include "base/win/registry.h"
16 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
17 #include "policy/policy_constants.h" 17 #include "policy/policy_constants.h"
18 18
19 namespace { 19 namespace {
20 20
21 // Checks if the key exists in the given hive and expands any string variables. 21 // Checks if the key exists in the given hive and expands any string variables.
22 bool LoadUserDataDirPolicyFromRegistry(HKEY hive, base::FilePath* dir) { 22 bool LoadUserDataDirPolicyFromRegistry(HKEY hive,
23 const char* key_name_str,
24 base::FilePath* dir) {
23 base::string16 value; 25 base::string16 value;
24 base::string16 key_name(base::ASCIIToUTF16(policy::key::kUserDataDir)); 26 base::string16 key_name(base::ASCIIToUTF16(key_name_str));
25 base::win::RegKey key(hive, policy::kRegistryChromePolicyKey, KEY_READ); 27 base::win::RegKey key(hive, policy::kRegistryChromePolicyKey, KEY_READ);
26 if (key.ReadValue(key_name.c_str(), &value) == ERROR_SUCCESS) { 28 if (key.ReadValue(key_name.c_str(), &value) == ERROR_SUCCESS) {
27 *dir = base::FilePath(policy::path_parser::ExpandPathVariables(value)); 29 *dir = base::FilePath(policy::path_parser::ExpandPathVariables(value));
28 return true; 30 return true;
29 } 31 }
30 return false; 32 return false;
31 } 33 }
32 34
33 const WCHAR* kMachineNamePolicyVarName = L"${machine_name}"; 35 const WCHAR* kMachineNamePolicyVarName = L"${machine_name}";
34 const WCHAR* kUserNamePolicyVarName = L"${user_name}"; 36 const WCHAR* kUserNamePolicyVarName = L"${user_name}";
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 // TODO(pastarmovj): Consider reorganizing this code once there are even more 142 // TODO(pastarmovj): Consider reorganizing this code once there are even more
141 // variables to be supported. The search for the var and its replacement can 143 // variables to be supported. The search for the var and its replacement can
142 // be extracted as common functionality. 144 // be extracted as common functionality.
143 145
144 return result; 146 return result;
145 } 147 }
146 148
147 void CheckUserDataDirPolicy(base::FilePath* user_data_dir) { 149 void CheckUserDataDirPolicy(base::FilePath* user_data_dir) {
148 DCHECK(user_data_dir); 150 DCHECK(user_data_dir);
149 // Policy from the HKLM hive has precedence over HKCU. 151 // Policy from the HKLM hive has precedence over HKCU.
150 if (!LoadUserDataDirPolicyFromRegistry(HKEY_LOCAL_MACHINE, user_data_dir)) 152 if (!LoadUserDataDirPolicyFromRegistry(HKEY_LOCAL_MACHINE, key::kUserDataDir,
151 LoadUserDataDirPolicyFromRegistry(HKEY_CURRENT_USER, user_data_dir); 153 user_data_dir)) {
154 LoadUserDataDirPolicyFromRegistry(HKEY_CURRENT_USER, key::kUserDataDir,
155 user_data_dir);
156 }
157 }
158
159 void CheckDiskCacheDirPolicy(base::FilePath* disk_cache_dir) {
160 DCHECK(disk_cache_dir);
161 if (!LoadUserDataDirPolicyFromRegistry(HKEY_LOCAL_MACHINE, key::kDiskCacheDir,
162 disk_cache_dir)) {
163 LoadUserDataDirPolicyFromRegistry(HKEY_CURRENT_USER, key::kDiskCacheDir,
164 disk_cache_dir);
165 }
152 } 166 }
153 167
154 } // namespace path_parser 168 } // namespace path_parser
155 169
156 } // namespace policy 170 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_path_parser_mac.mm ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698