| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/app/chrome_main.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/file_path.h" | |
| 9 #include "base/logging.h" | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/utf_string_conversions.h" | |
| 12 #include "base/win/registry.h" | |
| 13 #include "chrome/browser/policy/policy_path_parser.h" | |
| 14 #include "chrome/common/chrome_switches.h" | |
| 15 #include "policy/policy_constants.h" | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 // Checks if the registry key exists in the given hive and expands any | |
| 20 // variables in the string. | |
| 21 bool LoadUserDataDirPolicyFromRegistry(HKEY hive, | |
| 22 const std::wstring& key_name, | |
| 23 FilePath* user_data_dir) { | |
| 24 std::wstring value; | |
| 25 | |
| 26 base::win::RegKey hklm_policy_key(hive, policy::kRegistrySubKey, KEY_READ); | |
| 27 if (hklm_policy_key.ReadValue(key_name.c_str(), &value) == ERROR_SUCCESS) { | |
| 28 *user_data_dir = FilePath(policy::path_parser::ExpandPathVariables(value)); | |
| 29 return true; | |
| 30 } | |
| 31 return false; | |
| 32 } | |
| 33 | |
| 34 } // namespace | |
| 35 | |
| 36 namespace chrome_main { | |
| 37 | |
| 38 void CheckUserDataDirPolicy(FilePath* user_data_dir) { | |
| 39 DCHECK(user_data_dir); | |
| 40 // We are running as Chrome Frame if we were invoked with user-data-dir, | |
| 41 // chrome-frame, and automation-channel switches. | |
| 42 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 43 const bool is_chrome_frame = | |
| 44 !user_data_dir->empty() && | |
| 45 command_line->HasSwitch(switches::kChromeFrame) && | |
| 46 command_line->HasSwitch(switches::kAutomationClientChannelID); | |
| 47 | |
| 48 // In the case of Chrome Frame, the last path component of the user-data-dir | |
| 49 // provided on the command line must be preserved since it is specific to | |
| 50 // CF's host. | |
| 51 FilePath cf_host_dir; | |
| 52 if (is_chrome_frame) | |
| 53 cf_host_dir = user_data_dir->BaseName(); | |
| 54 | |
| 55 // Policy from the HKLM hive has precedence over HKCU so if we have one here | |
| 56 // we don't have to try to load HKCU. | |
| 57 const char* key_name_ascii = (is_chrome_frame ? policy::key::kGCFUserDataDir : | |
| 58 policy::key::kUserDataDir); | |
| 59 std::wstring key_name(ASCIIToWide(key_name_ascii)); | |
| 60 if (LoadUserDataDirPolicyFromRegistry(HKEY_LOCAL_MACHINE, key_name, | |
| 61 user_data_dir) || | |
| 62 LoadUserDataDirPolicyFromRegistry(HKEY_CURRENT_USER, key_name, | |
| 63 user_data_dir)) { | |
| 64 // A Group Policy value was loaded. Append the Chrome Frame host directory | |
| 65 // if relevant. | |
| 66 if (is_chrome_frame) | |
| 67 *user_data_dir = user_data_dir->Append(cf_host_dir); | |
| 68 } | |
| 69 } | |
| 70 | |
| 71 } // namespace chrome_main | |
| OLD | NEW |