Chromium Code Reviews| Index: chrome/browser/policy/policy_loader_mac.cc |
| diff --git a/chrome/browser/policy/configuration_policy_provider_mac.cc b/chrome/browser/policy/policy_loader_mac.cc |
| similarity index 76% |
| rename from chrome/browser/policy/configuration_policy_provider_mac.cc |
| rename to chrome/browser/policy/policy_loader_mac.cc |
| index 046bc42109503f7a866cb3baf91e46cb58778ed1..4bba91f874244b685a31c9a34bc27c53a731c577 100644 |
| --- a/chrome/browser/policy/configuration_policy_provider_mac.cc |
| +++ b/chrome/browser/policy/policy_loader_mac.cc |
| @@ -2,11 +2,10 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "chrome/browser/policy/configuration_policy_provider_mac.h" |
| +#include "chrome/browser/policy/policy_loader_mac.h" |
| #include <string> |
| -#include "base/file_path.h" |
| #include "base/file_util.h" |
| #include "base/mac/foundation_util.h" |
| #include "base/mac/scoped_cftyperef.h" |
| @@ -30,7 +29,7 @@ namespace { |
| FilePath GetManagedPolicyPath() { |
| // This constructs the path to the plist file in which Mac OS X stores the |
| // managed preference for the application. This is undocumented and therefore |
| - // fragile, but if it doesn't work out, FileBasedPolicyLoader has a task that |
| + // fragile, but if it doesn't work out, AsyncPolicyLoader has a task that |
| // polls periodically in order to reload managed preferences later even if we |
| // missed the change. |
| FilePath path; |
| @@ -54,7 +53,7 @@ FilePath GetManagedPolicyPath() { |
| void DictionaryEntryToValue(const void* key, const void* value, void* context) { |
| if (CFStringRef cf_key = CFCast<CFStringRef>(key)) { |
| base::Value* converted = |
| - MacPreferencesPolicyProviderDelegate::CreateValueFromProperty( |
| + MacPolicyLoader::CreateValueFromProperty( |
| static_cast<CFPropertyListRef>(value)); |
| if (converted) { |
| const std::string string = base::SysCFStringRefToUTF8(cf_key); |
| @@ -68,7 +67,7 @@ void DictionaryEntryToValue(const void* key, const void* value, void* context) { |
| // in |context|. |
| void ArrayEntryToValue(const void* value, void* context) { |
| base::Value* converted = |
| - MacPreferencesPolicyProviderDelegate::CreateValueFromProperty( |
| + MacPolicyLoader::CreateValueFromProperty( |
| static_cast<CFPropertyListRef>(value)); |
| if (converted) |
| static_cast<base::ListValue *>(context)->Append(converted); |
| @@ -76,16 +75,28 @@ void ArrayEntryToValue(const void* value, void* context) { |
| } // namespace |
| -MacPreferencesPolicyProviderDelegate::MacPreferencesPolicyProviderDelegate( |
| - MacPreferences* preferences, |
| - const PolicyDefinitionList* policy_list) |
| - : FileBasedPolicyProvider::ProviderDelegate(GetManagedPolicyPath()), |
| - policy_list_(policy_list), |
| - preferences_(preferences) {} |
| +MacPolicyLoader::MacPolicyLoader(const PolicyDefinitionList* policy_list, |
| + MacPreferences* preferences) |
| + : policy_list_(policy_list), |
| + preferences_(preferences), |
| + managed_policy_path_(GetManagedPolicyPath()) {} |
| -MacPreferencesPolicyProviderDelegate::~MacPreferencesPolicyProviderDelegate() {} |
| +MacPolicyLoader::~MacPolicyLoader() {} |
| -scoped_ptr<PolicyBundle> MacPreferencesPolicyProviderDelegate::Load() { |
| +// static |
| +AsyncPolicyProvider* MacPolicyLoader::CreateProvider( |
| + const PolicyDefinitionList* policy_list) { |
| + MacPolicyLoader* loader = |
| + new MacPolicyLoader(policy_list, new MacPreferences()); |
| + return new AsyncPolicyProvider(policy_list, loader); |
|
Mattias Nissler (ping if slow)
2012/06/04 09:19:02
It seems this function will look pretty much the s
Joao da Silva
2012/06/04 17:55:14
Right, I think even CreateLoader() would be a very
|
| +} |
| + |
| +void MacPolicyLoader::InitOnFile() { |
| + if (!managed_policy_path_.empty()) |
| + WatchPath(managed_policy_path_); |
| +} |
| + |
| +scoped_ptr<PolicyBundle> MacPolicyLoader::Load() { |
| preferences_->AppSynchronize(kCFPreferencesCurrentApplication); |
| scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); |
| PolicyMap& chrome_policy = bundle->Get(POLICY_DOMAIN_CHROME, std::string()); |
| @@ -111,9 +122,9 @@ scoped_ptr<PolicyBundle> MacPreferencesPolicyProviderDelegate::Load() { |
| return bundle.Pass(); |
| } |
| -base::Time MacPreferencesPolicyProviderDelegate::GetLastModification() { |
| +base::Time MacPolicyLoader::LastModificationTime() { |
| base::PlatformFileInfo file_info; |
| - if (!file_util::GetFileInfo(config_file_path(), &file_info) || |
| + if (!file_util::GetFileInfo(managed_policy_path_, &file_info) || |
| file_info.is_directory) { |
| return base::Time(); |
| } |
| @@ -122,7 +133,7 @@ base::Time MacPreferencesPolicyProviderDelegate::GetLastModification() { |
| } |
| // static |
| -base::Value* MacPreferencesPolicyProviderDelegate::CreateValueFromProperty( |
| +base::Value* MacPolicyLoader::CreateValueFromProperty( |
| CFPropertyListRef property) { |
| if (CFCast<CFNullRef>(property)) |
| return base::Value::CreateNullValue(); |
| @@ -165,19 +176,4 @@ base::Value* MacPreferencesPolicyProviderDelegate::CreateValueFromProperty( |
| return NULL; |
| } |
| -ConfigurationPolicyProviderMac::ConfigurationPolicyProviderMac( |
| - const PolicyDefinitionList* policy_list) |
| - : FileBasedPolicyProvider( |
| - policy_list, |
| - new MacPreferencesPolicyProviderDelegate(new MacPreferences(), |
| - policy_list)) {} |
| - |
| -ConfigurationPolicyProviderMac::ConfigurationPolicyProviderMac( |
| - const PolicyDefinitionList* policy_list, |
| - MacPreferences* preferences) |
| - : FileBasedPolicyProvider( |
| - policy_list, |
| - new MacPreferencesPolicyProviderDelegate(preferences, |
| - policy_list)) {} |
| - |
| } // namespace policy |