| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/pref_service.h" | 5 #include "chrome/browser/pref_service.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 #include <string> | 8 #include <string> | 
| 9 | 9 | 
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" | 
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" | 
| 12 #include "base/histogram.h" | 12 #include "base/histogram.h" | 
| 13 #include "base/logging.h" | 13 #include "base/logging.h" | 
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" | 
|  | 15 #include "base/path_service.h" | 
| 15 #include "base/stl_util-inl.h" | 16 #include "base/stl_util-inl.h" | 
| 16 #include "base/string_util.h" | 17 #include "base/string_util.h" | 
| 17 #include "base/sys_string_conversions.h" | 18 #include "base/sys_string_conversions.h" | 
| 18 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" | 
| 19 #include "build/build_config.h" | 20 #include "build/build_config.h" | 
| 20 #include "chrome/browser/chrome_thread.h" | 21 #include "chrome/browser/chrome_thread.h" | 
| 21 | 22 | 
| 22 #if defined(OS_WIN) | 23 #if defined(OS_WIN) | 
| 23 #include "chrome/browser/configuration_policy_provider_win.h" | 24 #include "chrome/browser/configuration_policy_provider_win.h" | 
| 24 #elif defined(OS_MACOSX) | 25 #elif defined(OS_MACOSX) | 
| 25 #include "chrome/browser/configuration_policy_provider_mac.h" | 26 #include "chrome/browser/configuration_policy_provider_mac.h" | 
| 26 #elif defined(OS_POSIX) | 27 #elif defined(OS_POSIX) | 
|  | 28 #include "chrome/browser/config_dir_policy_provider.h" | 
|  | 29 #endif | 
| 27 #include "chrome/browser/dummy_configuration_policy_provider.h" | 30 #include "chrome/browser/dummy_configuration_policy_provider.h" | 
| 28 #endif |  | 
| 29 | 31 | 
| 30 #include "chrome/browser/configuration_policy_pref_store.h" | 32 #include "chrome/browser/configuration_policy_pref_store.h" | 
|  | 33 #include "chrome/common/chrome_paths.h" | 
| 31 #include "chrome/common/json_pref_store.h" | 34 #include "chrome/common/json_pref_store.h" | 
| 32 #include "chrome/common/notification_service.h" | 35 #include "chrome/common/notification_service.h" | 
| 33 #include "grit/chromium_strings.h" | 36 #include "grit/chromium_strings.h" | 
| 34 #include "grit/generated_resources.h" | 37 #include "grit/generated_resources.h" | 
| 35 | 38 | 
| 36 namespace { | 39 namespace { | 
| 37 | 40 | 
| 38 // A helper function for RegisterLocalized*Pref that creates a Value* based on | 41 // A helper function for RegisterLocalized*Pref that creates a Value* based on | 
| 39 // the string value in the locale dll.  Because we control the values in a | 42 // the string value in the locale dll.  Because we control the values in a | 
| 40 // locale dll, this should always return a Value of the appropriate type. | 43 // locale dll, this should always return a Value of the appropriate type. | 
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 87 }  // namespace | 90 }  // namespace | 
| 88 | 91 | 
| 89 PrefService* PrefService::CreatePrefService(const FilePath& pref_filename) { | 92 PrefService* PrefService::CreatePrefService(const FilePath& pref_filename) { | 
| 90   PrefStore* managed_prefs = NULL; | 93   PrefStore* managed_prefs = NULL; | 
| 91   PrefStore* local_prefs = new JsonPrefStore( | 94   PrefStore* local_prefs = new JsonPrefStore( | 
| 92       pref_filename, | 95       pref_filename, | 
| 93       ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)); | 96       ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)); | 
| 94   PrefStore* recommended_prefs = NULL; | 97   PrefStore* recommended_prefs = NULL; | 
| 95 | 98 | 
| 96   ConfigurationPolicyProvider* managed_prefs_provider = NULL; | 99   ConfigurationPolicyProvider* managed_prefs_provider = NULL; | 
|  | 100   ConfigurationPolicyProvider* recommended_prefs_provider = NULL; | 
|  | 101 | 
| 97 #if defined(OS_WIN) | 102 #if defined(OS_WIN) | 
| 98   managed_prefs_provider = new ConfigurationPolicyProviderWin(); | 103   managed_prefs_provider = new ConfigurationPolicyProviderWin(); | 
|  | 104   recommended_prefs_provider = new DummyConfigurationPolicyProvider(); | 
| 99 #elif defined(OS_MACOSX) | 105 #elif defined(OS_MACOSX) | 
| 100   managed_prefs_provider = new ConfigurationPolicyProviderMac(); | 106   managed_prefs_provider = new ConfigurationPolicyProviderMac(); | 
|  | 107   recommended_prefs_provider = new DummyConfigurationPolicyProvider(); | 
| 101 #elif defined(OS_POSIX) | 108 #elif defined(OS_POSIX) | 
| 102   // TODO(markusheintz): Will be replaced by the Linux implementation. | 109   FilePath config_dir_path; | 
| 103   managed_prefs_provider = new DummyConfigurationPolicyProvider(); | 110   if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { | 
|  | 111     managed_prefs_provider = new ConfigDirPolicyProvider( | 
|  | 112         config_dir_path.Append(FILE_PATH_LITERAL("managed"))); | 
|  | 113     recommended_prefs_provider = new ConfigDirPolicyProvider( | 
|  | 114         config_dir_path.Append(FILE_PATH_LITERAL("recommended"))); | 
|  | 115   } else { | 
|  | 116     managed_prefs_provider = new DummyConfigurationPolicyProvider(); | 
|  | 117     recommended_prefs_provider = new DummyConfigurationPolicyProvider(); | 
|  | 118   } | 
| 104 #endif | 119 #endif | 
| 105 | 120 | 
| 106   // The ConfigurationPolicyPrefStore take the ownership of the passed | 121   // The ConfigurationPolicyPrefStore takes ownership of the passed | 
| 107   // |provider|. | 122   // |provider|. | 
| 108   managed_prefs = new ConfigurationPolicyPrefStore( | 123   managed_prefs = new ConfigurationPolicyPrefStore( | 
| 109       CommandLine::ForCurrentProcess(), | 124       CommandLine::ForCurrentProcess(), | 
| 110       managed_prefs_provider); | 125       managed_prefs_provider); | 
|  | 126   recommended_prefs = new ConfigurationPolicyPrefStore( | 
|  | 127       CommandLine::ForCurrentProcess(), | 
|  | 128       recommended_prefs_provider); | 
| 111 | 129 | 
| 112   // The PrefValueStore takes to ownership of the parameters. | 130   // The PrefValueStore takes to ownership of the parameters. | 
| 113   PrefValueStore* value_store = new PrefValueStore( | 131   PrefValueStore* value_store = new PrefValueStore( | 
| 114       managed_prefs, | 132       managed_prefs, | 
| 115       local_prefs, | 133       local_prefs, | 
| 116       recommended_prefs); | 134       recommended_prefs); | 
| 117   return new PrefService(value_store); | 135   return new PrefService(value_store); | 
| 118 } | 136 } | 
| 119 | 137 | 
| 120 PrefService::PrefService(PrefValueStore* pref_value_store) | 138 PrefService::PrefService(PrefValueStore* pref_value_store) | 
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 787 | 805 | 
| 788 bool PrefService::Preference::IsDefaultValue() const { | 806 bool PrefService::Preference::IsDefaultValue() const { | 
| 789   DCHECK(default_value_.get()); | 807   DCHECK(default_value_.get()); | 
| 790   return default_value_->Equals(GetValue()); | 808   return default_value_->Equals(GetValue()); | 
| 791 } | 809 } | 
| 792 | 810 | 
| 793 bool PrefService::Preference::IsManaged() const { | 811 bool PrefService::Preference::IsManaged() const { | 
| 794   return pref_value_store_->PrefValueIsManaged(name_.c_str()); | 812   return pref_value_store_->PrefValueIsManaged(name_.c_str()); | 
| 795 } | 813 } | 
| 796 | 814 | 
| OLD | NEW | 
|---|