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

Side by Side Diff: remoting/host/policy_hack/nat_policy_mac.mm

Issue 10804040: [Chromoting] Refactor the host policy watcher so that policies can easily be added. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix for Windows. Created 8 years, 5 months 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
(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/nat_policy.h"
6
7 #include <CoreFoundation/CoreFoundation.h>
8
9 #include "base/compiler_specific.h"
10 #include "base/mac/scoped_cftyperef.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/single_thread_task_runner.h"
13 #include "base/sys_string_conversions.h"
14 #include "base/values.h"
15
16 namespace remoting {
17 namespace policy_hack {
18
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
21 // applied. This will actually pick up policies every
22 // |kFallbackReloadDelayMinutes| which is sufficient for right now.
23 class NatPolicyMac : public NatPolicy {
24 public:
25 explicit NatPolicyMac(scoped_refptr<base::SingleThreadTaskRunner> task_runner)
26 : NatPolicy(task_runner) {
27 }
28
29 virtual ~NatPolicyMac() {
30 }
31
32 protected:
33 virtual void StartWatchingInternal() OVERRIDE {
34 Reload();
35 }
36
37 virtual void StopWatchingInternal() OVERRIDE {
38 }
39
40 virtual void Reload() OVERRIDE {
41 DCHECK(OnPolicyThread());
42 base::DictionaryValue policy;
43
44 CFStringRef policy_bundle_id = CFSTR("com.google.Chrome");
45 if (CFPreferencesAppSynchronize(policy_bundle_id)) {
46 base::mac::ScopedCFTypeRef<CFStringRef> policy_key(
47 base::SysUTF8ToCFStringRef(kNatPolicyName));
48 Boolean valid = false;
49 bool allowed = CFPreferencesGetAppBooleanValue(policy_key,
50 policy_bundle_id,
51 &valid);
52 if (valid) {
53 policy.SetBoolean(kNatPolicyName, allowed);
54 }
55 }
56
57 // 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.
59 UpdateNatPolicy(&policy);
60
61 // Reschedule task.
62 ScheduleFallbackReloadTask();
63 }
64 };
65
66 NatPolicy* NatPolicy::Create(
67 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
68 return new NatPolicyMac(task_runner);
69 }
70
71 } // namespace policy_hack
72 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/policy_hack/nat_policy_linux.cc ('k') | remoting/host/policy_hack/nat_policy_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698