summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpastarmovj@chromium.org <pastarmovj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-03 15:38:50 +0000
committerpastarmovj@chromium.org <pastarmovj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-03 15:38:50 +0000
commitf7b73adeff4efc43d7e596db442be2be6037fe6a (patch)
tree9211acaa21ea66a7e3103133f3f42acd557189df
parent1b1d870bca786ef6df42e119099b60c633361860 (diff)
downloadchromium_src-f7b73adeff4efc43d7e596db442be2be6037fe6a.zip
chromium_src-f7b73adeff4efc43d7e596db442be2be6037fe6a.tar.gz
chromium_src-f7b73adeff4efc43d7e596db442be2be6037fe6a.tar.bz2
This policy is directly read from the registry instead through the local_store because it is used much earlier in the life cycle of all chrome processes and local_store is only available in the browser process and loaded much later.
The option is implemented with minimal intrusion on the existing start-up process and only overrides any command line parameter or default setting that might be in place. BUG=49601 TEST=Manual. Set the policy in windows and it should be equivalent to using the --user-data-dir option. Review URL: http://codereview.chromium.org/6286048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73623 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/chrome_main.cc42
-rw-r--r--chrome/app/policy/policy_templates.json12
-rw-r--r--chrome/chrome_dll.gypi1
3 files changed, 54 insertions, 1 deletions
diff --git a/chrome/app/chrome_main.cc b/chrome/app/chrome_main.cc
index 1613049..45b60f0 100644
--- a/chrome/app/chrome_main.cc
+++ b/chrome/app/chrome_main.cc
@@ -46,6 +46,8 @@
#include <atlapp.h>
#include <malloc.h>
#include <new.h>
+#include "base/win/registry.h"
+#include "policy/policy_constants.h"
#include "sandbox/src/sandbox.h"
#include "tools/memory_watcher/memory_watcher.h"
#endif
@@ -515,6 +517,43 @@ void HandleHelpSwitches(const CommandLine& command_line) {
#endif // OS_POSIX
+#if defined(OS_WIN)
+// Checks if the registry key exists in the given hive and expands any
+// environment variables in the string.
+bool LoadUserDataDirPolicyFromRegistry(HKEY hive, FilePath* user_data_dir) {
+ std::wstring key_name = UTF8ToWide(policy::key::kUserDataDir);
+ std::wstring value;
+
+ base::win::RegKey hklm_policy_key(hive, policy::kRegistrySubKey, KEY_READ);
+ if (hklm_policy_key.ReadValue(key_name.c_str(), &value) == ERROR_SUCCESS) {
+ // Try to expand the env variables if not possible fallback to no expansion.
+ DWORD expanded_len = ::ExpandEnvironmentStrings(value.c_str(), NULL, 0);
+ if (expanded_len) {
+ scoped_array<WCHAR> expanded_value(new WCHAR[expanded_len]);
+ ::ExpandEnvironmentStrings(value.c_str(),
+ expanded_value.get(), expanded_len);
+ *user_data_dir = FilePath::FromWStringHack(expanded_value.get());
+ } else {
+ *user_data_dir = FilePath::FromWStringHack(value);
+ }
+ return true;
+ }
+ return false;
+}
+#endif // OS_WIN
+
+// Checks if the UserDataDir policy has been set and returns its value in the
+// |user_data_dir| parameter. If no policy is set the parameter is not changed.
+void CheckUserDataDirPolicy(FilePath* user_data_dir) {
+#if defined(OS_WIN)
+ // Policy from the HKLM hive has precedence over HKCU so if we have one here
+ // we don't have to try to load HKCU.
+ if (LoadUserDataDirPolicyFromRegistry(HKEY_LOCAL_MACHINE, user_data_dir))
+ return;
+ LoadUserDataDirPolicyFromRegistry(HKEY_CURRENT_USER, user_data_dir);
+#endif
+}
+
// We dispatch to a process-type-specific FooMain() based on a command-line
// flag. This struct is used to build a table of (flag, main function) pairs.
struct MainFunction {
@@ -740,8 +779,9 @@ int ChromeMain(int argc, char** argv) {
chrome::RegisterPathProvider();
// Notice a user data directory override if any
- const FilePath user_data_dir =
+ FilePath user_data_dir =
command_line.GetSwitchValuePath(switches::kUserDataDir);
+ CheckUserDataDirPolicy(&user_data_dir);
if (!user_data_dir.empty())
CHECK(PathService::Override(chrome::DIR_USER_DATA, user_data_dir));
diff --git a/chrome/app/policy/policy_templates.json b/chrome/app/policy/policy_templates.json
index 4fc6b18..5901600 100644
--- a/chrome/app/policy/policy_templates.json
+++ b/chrome/app/policy/policy_templates.json
@@ -379,6 +379,18 @@
If you enable this setting, users cannot change or override this setting in <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph>.''',
},
{
+ 'name': 'UserDataDir',
+ 'type': 'string',
+ 'supported_on': ['chrome.win:11-'],
+ 'features': {'dynamic_refresh': 0},
+ 'example_value': '${user_home}\Chrome',
+ 'caption': '''Set user data directory''',
+ 'desc': '''Configures the directory that <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph> will use for storing user data.
+
+ If you set this policy, <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph> will use the provided directory regardless whether the user has specified the '--user-data-dir' flag or not.''',
+ 'label': '''Set user data directory''',
+ },
+ {
'name': 'Proxy',
'type': 'group',
'caption': '''Proxy server''',
diff --git a/chrome/chrome_dll.gypi b/chrome/chrome_dll.gypi
index 6578075..e7741e7 100644
--- a/chrome/chrome_dll.gypi
+++ b/chrome/chrome_dll.gypi
@@ -69,6 +69,7 @@
},
'dependencies': [
'<@(chromium_dependencies)',
+ 'policy'
],
'conditions': [
['OS=="win"', {