| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "remoting/host/policy_hack/policy_watcher.h" | |
| 6 | |
| 7 #include <CoreFoundation/CoreFoundation.h> | |
| 8 | |
| 9 #include "base/compiler_specific.h" | |
| 10 #include "base/mac/foundation_util.h" | |
| 11 #include "base/mac/scoped_cftyperef.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/single_thread_task_runner.h" | |
| 14 #include "base/strings/sys_string_conversions.h" | |
| 15 #include "base/values.h" | |
| 16 | |
| 17 namespace remoting { | |
| 18 namespace policy_hack { | |
| 19 | |
| 20 // The MacOS version does not watch files because it is accepted | |
| 21 // practice on the Mac that the user must logout/login for policies to be | |
| 22 // applied. This will actually pick up policies every | |
| 23 // |kFallbackReloadDelayMinutes| which is sufficient for right now. | |
| 24 class PolicyWatcherMac : public PolicyWatcher { | |
| 25 public: | |
| 26 explicit PolicyWatcherMac( | |
| 27 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | |
| 28 : PolicyWatcher(task_runner) { | |
| 29 } | |
| 30 | |
| 31 ~PolicyWatcherMac() override {} | |
| 32 | |
| 33 protected: | |
| 34 void StartWatchingInternal() override { Reload(); } | |
| 35 | |
| 36 void StopWatchingInternal() override {} | |
| 37 | |
| 38 void Reload() override { | |
| 39 DCHECK(OnPolicyWatcherThread()); | |
| 40 base::DictionaryValue policy; | |
| 41 | |
| 42 CFStringRef policy_bundle_id = CFSTR("com.google.Chrome"); | |
| 43 if (CFPreferencesAppSynchronize(policy_bundle_id)) { | |
| 44 for (base::DictionaryValue::Iterator i(Defaults()); | |
| 45 !i.IsAtEnd(); i.Advance()) { | |
| 46 const std::string& policy_name = i.key(); | |
| 47 base::ScopedCFTypeRef<CFStringRef> policy_key( | |
| 48 base::SysUTF8ToCFStringRef(policy_name)); | |
| 49 | |
| 50 if (i.value().GetType() == base::DictionaryValue::TYPE_BOOLEAN) { | |
| 51 Boolean valid = false; | |
| 52 bool value = CFPreferencesGetAppBooleanValue(policy_key, | |
| 53 policy_bundle_id, | |
| 54 &valid); | |
| 55 if (valid) { | |
| 56 policy.SetBoolean(policy_name, value); | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 if (i.value().GetType() == base::DictionaryValue::TYPE_STRING) { | |
| 61 base::ScopedCFTypeRef<CFPropertyListRef> property_list( | |
| 62 CFPreferencesCopyAppValue(policy_key, policy_bundle_id)); | |
| 63 if (property_list.get() != NULL) { | |
| 64 CFStringRef policy_value = base::mac::CFCast<CFStringRef>( | |
| 65 property_list.get()); | |
| 66 if (policy_value != NULL) { | |
| 67 policy.SetString(policy_name, | |
| 68 base::SysCFStringRefToUTF8(policy_value)); | |
| 69 } | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 // Set policy. Policy must be set (even if it is empty) so that the | |
| 77 // default policy is picked up the first time reload is called. | |
| 78 UpdatePolicies(&policy); | |
| 79 | |
| 80 // Reschedule task. | |
| 81 ScheduleFallbackReloadTask(); | |
| 82 } | |
| 83 }; | |
| 84 | |
| 85 scoped_ptr<PolicyWatcher> PolicyWatcher::Create( | |
| 86 policy::PolicyService* policy_service, | |
| 87 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | |
| 88 return make_scoped_ptr(new PolicyWatcherMac(task_runner)); | |
| 89 } | |
| 90 | |
| 91 } // namespace policy_hack | |
| 92 } // namespace remoting | |
| OLD | NEW |