| 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/nat_policy.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/scoped_cftyperef.h" | 10 #include "base/mac/scoped_cftyperef.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 | 15 |
| 16 namespace remoting { | 16 namespace remoting { |
| 17 namespace policy_hack { | 17 namespace policy_hack { |
| 18 | 18 |
| 19 // The MacOS version does not watch files because it is accepted | 19 // The MacOS version does not watch files because it is accepted |
| 20 // practice on the Mac that the user must logout/login for policies to be | 20 // practice on the Mac that the user must logout/login for policies to be |
| 21 // applied. This will actually pick up policies every | 21 // applied. This will actually pick up policies every |
| 22 // |kFallbackReloadDelayMinutes| which is sufficient for right now. | 22 // |kFallbackReloadDelayMinutes| which is sufficient for right now. |
| 23 class NatPolicyMac : public NatPolicy { | 23 class PolicyWatcherMac : public PolicyWatcher { |
| 24 public: | 24 public: |
| 25 explicit NatPolicyMac(scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 25 explicit PolicyWatcherMac( |
| 26 : NatPolicy(task_runner) { | 26 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 27 : PolicyWatcher(task_runner) { |
| 27 } | 28 } |
| 28 | 29 |
| 29 virtual ~NatPolicyMac() { | 30 virtual ~PolicyWatcherMac() { |
| 30 } | 31 } |
| 31 | 32 |
| 32 protected: | 33 protected: |
| 33 virtual void StartWatchingInternal() OVERRIDE { | 34 virtual void StartWatchingInternal() OVERRIDE { |
| 34 Reload(); | 35 Reload(); |
| 35 } | 36 } |
| 36 | 37 |
| 37 virtual void StopWatchingInternal() OVERRIDE { | 38 virtual void StopWatchingInternal() OVERRIDE { |
| 38 } | 39 } |
| 39 | 40 |
| 40 virtual void Reload() OVERRIDE { | 41 virtual void Reload() OVERRIDE { |
| 41 DCHECK(OnPolicyThread()); | 42 DCHECK(OnPolicyWatcherThread()); |
| 42 base::DictionaryValue policy; | 43 base::DictionaryValue policy; |
| 43 | 44 |
| 44 CFStringRef policy_bundle_id = CFSTR("com.google.Chrome"); | 45 CFStringRef policy_bundle_id = CFSTR("com.google.Chrome"); |
| 45 if (CFPreferencesAppSynchronize(policy_bundle_id)) { | 46 if (CFPreferencesAppSynchronize(policy_bundle_id)) { |
| 46 base::mac::ScopedCFTypeRef<CFStringRef> policy_key( | 47 for (int i = 0; i < kBooleanPolicyNamesNum; ++i) { |
| 47 base::SysUTF8ToCFStringRef(kNatPolicyName)); | 48 const char* policy_name = kBooleanPolicyNames[i]; |
| 48 Boolean valid = false; | 49 base::mac::ScopedCFTypeRef<CFStringRef> policy_key( |
| 49 bool allowed = CFPreferencesGetAppBooleanValue(policy_key, | 50 base::SysUTF8ToCFStringRef(policy_name)); |
| 50 policy_bundle_id, | 51 Boolean valid = false; |
| 51 &valid); | 52 bool allowed = CFPreferencesGetAppBooleanValue(policy_key, |
| 52 if (valid) { | 53 policy_bundle_id, |
| 53 policy.SetBoolean(kNatPolicyName, allowed); | 54 &valid); |
| 55 if (valid) { |
| 56 policy.SetBoolean(policy_name, allowed); |
| 57 } |
| 54 } | 58 } |
| 55 } | 59 } |
| 56 | 60 |
| 57 // Set policy. Policy must be set (even if it is empty) so that the | 61 // Set policy. Policy must be set (even if it is empty) so that the |
| 58 // default policy is picked up the first time reload is called. | 62 // default policy is picked up the first time reload is called. |
| 59 UpdateNatPolicy(&policy); | 63 UpdatePolicies(&policy); |
| 60 | 64 |
| 61 // Reschedule task. | 65 // Reschedule task. |
| 62 ScheduleFallbackReloadTask(); | 66 ScheduleFallbackReloadTask(); |
| 63 } | 67 } |
| 64 }; | 68 }; |
| 65 | 69 |
| 66 NatPolicy* NatPolicy::Create( | 70 PolicyWatcher* PolicyWatcher::Create( |
| 67 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | 71 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
| 68 return new NatPolicyMac(task_runner); | 72 return new PolicyWatcherMac(task_runner); |
| 69 } | 73 } |
| 70 | 74 |
| 71 } // namespace policy_hack | 75 } // namespace policy_hack |
| 72 } // namespace remoting | 76 } // namespace remoting |
| OLD | NEW |