Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: chrome/browser/policy/configuration_policy_provider_mac.cc

Issue 4062002: Dynamic policy refresh support for the Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: s/map/list/, nits. Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/policy/configuration_policy_provider_mac.h" 5 #include "chrome/browser/policy/configuration_policy_provider_mac.h"
6 6
7 #include "base/file_util.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
8 #include "base/mac/scoped_cftyperef.h" 9 #include "base/mac/scoped_cftyperef.h"
10 #include "base/path_service.h"
9 #include "base/sys_string_conversions.h" 11 #include "base/sys_string_conversions.h"
12 #include "chrome/common/chrome_paths.h"
10 13
11 namespace policy { 14 namespace policy {
12 15
13 ConfigurationPolicyProviderMac::ConfigurationPolicyProviderMac( 16 static FilePath GetManagedPolicyPath() {
14 const StaticPolicyValueMap& policy_map) 17 // This constructs the path to the plist file in which Mac OS X stores the
15 : ConfigurationPolicyProvider(policy_map), 18 // managed preference for the application. This is undocumented and therefore
16 preferences_(new MacPreferences()) { 19 // fragile, but if it doesn't work out, FileBasedPolicyLoader has a task that
20 // polls periodically in order to reload managed preferences later even if we
21 // missed the change.
22 FilePath path;
23 if (!PathService::Get(chrome::DIR_MANAGED_PREFS, &path))
24 return FilePath();
25
26 CFBundleRef bundle(CFBundleGetMainBundle());
27 if (!bundle)
28 return FilePath();
29
30 CFStringRef bundle_id = CFBundleGetIdentifier(bundle);
31 if (!bundle_id)
32 return FilePath();
33
34 return path.Append(base::SysCFStringRefToUTF8(bundle_id) + ".plist");
17 } 35 }
18 36
19 ConfigurationPolicyProviderMac::ConfigurationPolicyProviderMac( 37 MacPreferencesPolicyLoader::MacPreferencesPolicyLoader(
20 const StaticPolicyValueMap& policy_map, MacPreferences* preferences) 38 MacPreferences* preferences,
21 : ConfigurationPolicyProvider(policy_map), preferences_(preferences) { 39 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list)
40 : FileBasedPolicyProvider::Delegate(GetManagedPolicyPath()),
41 policy_list_(policy_list),
42 preferences_(preferences) {
22 } 43 }
23 44
24 bool ConfigurationPolicyProviderMac::Provide(ConfigurationPolicyStore* store) { 45 DictionaryValue* MacPreferencesPolicyLoader::Load() {
25 const PolicyValueMap& mapping = policy_value_map(); 46 preferences_->AppSynchronize(kCFPreferencesCurrentApplication);
47 DictionaryValue* policy = new DictionaryValue;
26 48
27 for (PolicyValueMap::const_iterator current = mapping.begin(); 49 const ConfigurationPolicyProvider::PolicyDefinitionList::Entry* current;
28 current != mapping.end(); ++current) { 50 for (current = policy_list_->begin; current != policy_list_->end; ++current) {
29 base::mac::ScopedCFTypeRef<CFStringRef> name( 51 base::mac::ScopedCFTypeRef<CFStringRef> name(
30 base::SysUTF8ToCFStringRef(current->name)); 52 base::SysUTF8ToCFStringRef(current->name));
31 base::mac::ScopedCFTypeRef<CFPropertyListRef> value( 53 base::mac::ScopedCFTypeRef<CFPropertyListRef> value(
32 preferences_->CopyAppValue(name, kCFPreferencesCurrentApplication)); 54 preferences_->CopyAppValue(name, kCFPreferencesCurrentApplication));
33 if (!value.get()) 55 if (!value.get())
34 continue; 56 continue;
35 if (!preferences_->AppValueIsForced(name, kCFPreferencesCurrentApplication)) 57 if (!preferences_->AppValueIsForced(name, kCFPreferencesCurrentApplication))
36 continue; 58 continue;
37 59
38 switch (current->value_type) { 60 switch (current->value_type) {
39 case Value::TYPE_STRING: 61 case Value::TYPE_STRING:
40 if (CFGetTypeID(value) == CFStringGetTypeID()) { 62 if (CFGetTypeID(value) == CFStringGetTypeID()) {
41 std::string string_value = 63 std::string string_value =
42 base::SysCFStringRefToUTF8((CFStringRef)value.get()); 64 base::SysCFStringRefToUTF8((CFStringRef)value.get());
43 store->Apply( 65 policy->SetString(current->name, string_value);
44 current->policy_type,
45 Value::CreateStringValue(string_value));
46 } 66 }
47 break; 67 break;
48 case Value::TYPE_BOOLEAN: 68 case Value::TYPE_BOOLEAN:
49 if (CFGetTypeID(value) == CFBooleanGetTypeID()) { 69 if (CFGetTypeID(value) == CFBooleanGetTypeID()) {
50 bool bool_value = CFBooleanGetValue((CFBooleanRef)value.get()); 70 bool bool_value = CFBooleanGetValue((CFBooleanRef)value.get());
51 store->Apply(current->policy_type, 71 policy->SetBoolean(current->name, bool_value);
52 Value::CreateBooleanValue(bool_value));
53 } 72 }
54 break; 73 break;
55 case Value::TYPE_INTEGER: 74 case Value::TYPE_INTEGER:
56 if (CFGetTypeID(value) == CFNumberGetTypeID()) { 75 if (CFGetTypeID(value) == CFNumberGetTypeID()) {
57 int int_value; 76 int int_value;
58 bool cast = CFNumberGetValue((CFNumberRef)value.get(), 77 bool cast = CFNumberGetValue((CFNumberRef)value.get(),
59 kCFNumberIntType, 78 kCFNumberIntType,
60 &int_value); 79 &int_value);
61 if (cast) 80 if (cast)
62 store->Apply(current->policy_type, 81 policy->SetInteger(current->name, int_value);
63 Value::CreateIntegerValue(int_value));
64 } 82 }
65 break; 83 break;
66 case Value::TYPE_LIST: 84 case Value::TYPE_LIST:
67 if (CFGetTypeID(value) == CFArrayGetTypeID()) { 85 if (CFGetTypeID(value) == CFArrayGetTypeID()) {
68 scoped_ptr<ListValue> list_value(new ListValue); 86 scoped_ptr<ListValue> list_value(new ListValue);
69 bool valid_array = true; 87 bool valid_array = true;
70 CFArrayRef array_value = (CFArrayRef)value.get(); 88 CFArrayRef array_value = (CFArrayRef)value.get();
71 for (CFIndex i = 0; i < CFArrayGetCount(array_value); ++i) { 89 for (CFIndex i = 0; i < CFArrayGetCount(array_value); ++i) {
72 // For now we assume that all values are strings. 90 // For now we assume that all values are strings.
73 CFStringRef array_string = 91 CFStringRef array_string =
74 (CFStringRef)CFArrayGetValueAtIndex(array_value, i); 92 (CFStringRef)CFArrayGetValueAtIndex(array_value, i);
75 if (CFGetTypeID(array_string) == CFStringGetTypeID()) { 93 if (CFGetTypeID(array_string) == CFStringGetTypeID()) {
76 std::string array_string_value = 94 std::string array_string_value =
77 base::SysCFStringRefToUTF8(array_string); 95 base::SysCFStringRefToUTF8(array_string);
78 list_value->Append(Value::CreateStringValue(array_string_value)); 96 list_value->Append(Value::CreateStringValue(array_string_value));
79 } else { 97 } else {
80 valid_array = false; 98 valid_array = false;
81 } 99 }
82 } 100 }
83 if (valid_array) 101 if (valid_array)
84 store->Apply(current->policy_type, list_value.release()); 102 policy->Set(current->name, list_value.release());
85 } 103 }
86 break; 104 break;
87 default: 105 default:
88 NOTREACHED(); 106 NOTREACHED();
89 return false;
90 } 107 }
91 } 108 }
92 109
93 return true; 110 return policy;
111 }
112
113 base::Time MacPreferencesPolicyLoader::GetLastModification() {
114 base::PlatformFileInfo file_info;
115 if (!file_util::GetFileInfo(config_file_path(), &file_info) ||
116 file_info.is_directory) {
117 return base::Time();
118 }
119
120 return file_info.last_modified;
121 }
122
123 ConfigurationPolicyProviderMac::ConfigurationPolicyProviderMac(
124 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list)
125 : FileBasedPolicyProvider(policy_list,
126 new MacPreferencesPolicyLoader(new MacPreferences, policy_list)) {
127 }
128
129 ConfigurationPolicyProviderMac::ConfigurationPolicyProviderMac(
130 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list,
131 MacPreferences* preferences)
132 : FileBasedPolicyProvider(policy_list,
133 new MacPreferencesPolicyLoader(preferences, policy_list)) {
94 } 134 }
95 135
96 } // namespace policy 136 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698