| 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..4e6c2f16859697d90d381da0777e9143e1ea991e 100644
|
| --- a/chrome/browser/policy/configuration_policy_provider_mac.cc
|
| +++ b/chrome/browser/policy/policy_loader_mac.cc
|
| @@ -2,11 +2,12 @@
|
| // 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/bind.h"
|
| +#include "base/bind_helpers.h"
|
| #include "base/file_util.h"
|
| #include "base/mac/foundation_util.h"
|
| #include "base/mac/scoped_cftyperef.h"
|
| @@ -30,7 +31,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 +55,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(
|
| + PolicyLoaderMac::CreateValueFromProperty(
|
| static_cast<CFPropertyListRef>(value));
|
| if (converted) {
|
| const std::string string = base::SysCFStringRefToUTF8(cf_key);
|
| @@ -68,7 +69,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(
|
| + PolicyLoaderMac::CreateValueFromProperty(
|
| static_cast<CFPropertyListRef>(value));
|
| if (converted)
|
| static_cast<base::ListValue *>(context)->Append(converted);
|
| @@ -76,16 +77,23 @@ 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) {}
|
| +PolicyLoaderMac::PolicyLoaderMac(const PolicyDefinitionList* policy_list,
|
| + MacPreferences* preferences)
|
| + : policy_list_(policy_list),
|
| + preferences_(preferences),
|
| + managed_policy_path_(GetManagedPolicyPath()) {}
|
|
|
| -MacPreferencesPolicyProviderDelegate::~MacPreferencesPolicyProviderDelegate() {}
|
| +PolicyLoaderMac::~PolicyLoaderMac() {}
|
|
|
| -scoped_ptr<PolicyBundle> MacPreferencesPolicyProviderDelegate::Load() {
|
| +void PolicyLoaderMac::InitOnFile() {
|
| + if (!managed_policy_path_.empty()) {
|
| + watcher_.Watch(
|
| + managed_policy_path_,
|
| + base::Bind(&PolicyLoaderMac::OnFileUpdated, base::Unretained(this)));
|
| + }
|
| +}
|
| +
|
| +scoped_ptr<PolicyBundle> PolicyLoaderMac::Load() {
|
| preferences_->AppSynchronize(kCFPreferencesCurrentApplication);
|
| scoped_ptr<PolicyBundle> bundle(new PolicyBundle());
|
| PolicyMap& chrome_policy = bundle->Get(POLICY_DOMAIN_CHROME, std::string());
|
| @@ -111,9 +119,9 @@ scoped_ptr<PolicyBundle> MacPreferencesPolicyProviderDelegate::Load() {
|
| return bundle.Pass();
|
| }
|
|
|
| -base::Time MacPreferencesPolicyProviderDelegate::GetLastModification() {
|
| +base::Time PolicyLoaderMac::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 +130,7 @@ base::Time MacPreferencesPolicyProviderDelegate::GetLastModification() {
|
| }
|
|
|
| // static
|
| -base::Value* MacPreferencesPolicyProviderDelegate::CreateValueFromProperty(
|
| +base::Value* PolicyLoaderMac::CreateValueFromProperty(
|
| CFPropertyListRef property) {
|
| if (CFCast<CFNullRef>(property))
|
| return base::Value::CreateNullValue();
|
| @@ -165,19 +173,9 @@ 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)) {}
|
| +void PolicyLoaderMac::OnFileUpdated(const FilePath& path, bool error) {
|
| + if (!error)
|
| + Reload(false);
|
| +}
|
|
|
| } // namespace policy
|
|
|