OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "remoting/host/policy_hack/policy_watcher.h" | 5 #include "remoting/host/policy_hack/policy_watcher.h" |
6 | 6 |
7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/mac/foundation_util.h" |
10 #include "base/mac/scoped_cftyperef.h" | 11 #include "base/mac/scoped_cftyperef.h" |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
13 #include "base/sys_string_conversions.h" | 14 #include "base/sys_string_conversions.h" |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 | 16 |
16 namespace remoting { | 17 namespace remoting { |
17 namespace policy_hack { | 18 namespace policy_hack { |
18 | 19 |
19 // The MacOS version does not watch files because it is accepted | 20 // The MacOS version does not watch files because it is accepted |
(...skipping 29 matching lines...) Expand all Loading... |
49 base::mac::ScopedCFTypeRef<CFStringRef> policy_key( | 50 base::mac::ScopedCFTypeRef<CFStringRef> policy_key( |
50 base::SysUTF8ToCFStringRef(policy_name)); | 51 base::SysUTF8ToCFStringRef(policy_name)); |
51 Boolean valid = false; | 52 Boolean valid = false; |
52 bool allowed = CFPreferencesGetAppBooleanValue(policy_key, | 53 bool allowed = CFPreferencesGetAppBooleanValue(policy_key, |
53 policy_bundle_id, | 54 policy_bundle_id, |
54 &valid); | 55 &valid); |
55 if (valid) { | 56 if (valid) { |
56 policy.SetBoolean(policy_name, allowed); | 57 policy.SetBoolean(policy_name, allowed); |
57 } | 58 } |
58 } | 59 } |
59 // TODO(simonmorris): Read policies whose names are in kStringPolicyNames. | 60 for (int i = 0; i < kStringPolicyNamesNum; ++i) { |
| 61 const char* policy_name = kStringPolicyNames[i]; |
| 62 base::mac::ScopedCFTypeRef<CFStringRef> policy_key( |
| 63 base::SysUTF8ToCFStringRef(policy_name)); |
| 64 base::mac::ScopedCFTypeRef<CFPropertyListRef> property_list( |
| 65 CFPreferencesCopyAppValue(policy_key, policy_bundle_id)); |
| 66 if (property_list.get() != NULL) { |
| 67 CFStringRef policy_value = base::mac::CFCast<CFStringRef>( |
| 68 property_list.get()); |
| 69 if (policy_value != NULL) { |
| 70 policy.SetString(policy_name, |
| 71 base::SysCFStringRefToUTF8(policy_value)); |
| 72 } else { |
| 73 LOG(WARNING) << "Policy " << policy_name << ": value not a string."; |
| 74 } |
| 75 } |
| 76 } |
60 } | 77 } |
61 | 78 |
62 // Set policy. Policy must be set (even if it is empty) so that the | 79 // Set policy. Policy must be set (even if it is empty) so that the |
63 // default policy is picked up the first time reload is called. | 80 // default policy is picked up the first time reload is called. |
64 UpdatePolicies(&policy); | 81 UpdatePolicies(&policy); |
65 | 82 |
66 // Reschedule task. | 83 // Reschedule task. |
67 ScheduleFallbackReloadTask(); | 84 ScheduleFallbackReloadTask(); |
68 } | 85 } |
69 }; | 86 }; |
70 | 87 |
71 PolicyWatcher* PolicyWatcher::Create( | 88 PolicyWatcher* PolicyWatcher::Create( |
72 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | 89 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
73 return new PolicyWatcherMac(task_runner); | 90 return new PolicyWatcherMac(task_runner); |
74 } | 91 } |
75 | 92 |
76 } // namespace policy_hack | 93 } // namespace policy_hack |
77 } // namespace remoting | 94 } // namespace remoting |
OLD | NEW |