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

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

Issue 7748027: Remoting host policy for mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updated with ajwong suggestions Created 9 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/plugin/policy_hack/nat_policy.h" 5 #include "remoting/host/plugin/policy_hack/nat_policy.h"
6 6
7 #include <CoreFoundation/CoreFoundation.h>
8
7 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/mac/scoped_cftyperef.h"
8 #include "base/message_loop_proxy.h" 11 #include "base/message_loop_proxy.h"
9 #include "base/scoped_ptr.h" 12 #include "base/scoped_ptr.h"
13 #include "base/sys_string_conversions.h"
10 #include "base/values.h" 14 #include "base/values.h"
11 15
16 namespace {
17
18 struct BundledAppPolicy {
19 Boolean is_valid;
20 Boolean is_allowed;
21 CFStringRef bundle_id;
22 };
23
24 }
25
12 namespace remoting { 26 namespace remoting {
13 namespace policy_hack { 27 namespace policy_hack {
14 28
29 // The MacOS version does not watch files (because there is potentially 9
30 // files to watch in three different locations) and because it is accepted
31 // practice on the Mac that the user must logout/login for policies to be
32 // applied. This will actually pick up policies every
33 // |kFallbackReloadDelayMinutes| which is sufficient for right now.
15 class NatPolicyMac : public NatPolicy { 34 class NatPolicyMac : public NatPolicy {
16 public: 35 public:
17 explicit NatPolicyMac(base::MessageLoopProxy* message_loop_proxy) 36 explicit NatPolicyMac(base::MessageLoopProxy* message_loop_proxy)
18 : NatPolicy(message_loop_proxy) { 37 : NatPolicy(message_loop_proxy) {
19 } 38 }
20 39
21 virtual ~NatPolicyMac() { 40 virtual ~NatPolicyMac() {
22 } 41 }
23 42
43 protected:
24 virtual void StartWatchingInternal() OVERRIDE { 44 virtual void StartWatchingInternal() OVERRIDE {
25 scoped_ptr<base::DictionaryValue> new_policy(new base::DictionaryValue()); 45 Reload();
26 UpdateNatPolicy(new_policy.get());
27 } 46 }
28 47
29 virtual void StopWatchingInternal() OVERRIDE { 48 virtual void StopWatchingInternal() OVERRIDE {
30 } 49 }
31 50
32 virtual void Reload() OVERRIDE { 51 virtual void Reload() OVERRIDE {
52 DCHECK(OnPolicyThread());
53
54 // Since policy could be set for any of these browsers, assume the most
55 // restrictive.
56 BundledAppPolicy policies[3] = {
57 { false, true, CFSTR("com.google.Chrome") },
58 { false, true, CFSTR("com.chromium.Chromium") },
59 { false, true, CFSTR("com.google.Chrome.canary") }
60 };
61 base::DictionaryValue policy;
62 base::mac::ScopedCFTypeRef<CFStringRef> policy_key(
63 base::SysUTF8ToCFStringRef(kNatPolicyName));
64 bool is_allowed = true;
65 bool is_valid = false;
66 CFStringRef bundle_setting_policy = NULL;
67 for (size_t i = 0; i < arraysize(policies); ++i) {
68 if (CFPreferencesAppSynchronize(policies[i].bundle_id)) {
69 policies[i].is_allowed = CFPreferencesGetAppBooleanValue(
70 policy_key,
71 policies[i].bundle_id,
72 &policies[i].is_valid);
73 if (policies[i].is_valid) {
74 is_allowed &= policies[i].is_allowed;
75 if (!is_allowed && bundle_setting_policy == NULL) {
76 bundle_setting_policy = policies[i].bundle_id;
77 }
78 is_valid = true;
79 }
80 }
81 }
82
83 // Only set policy if a valid policy was found.
84 if (is_valid) {
85 policy.SetBoolean(kNatPolicyName, is_allowed);
86
87 // Log if there is policy conflict.
88 for (size_t i = 0; i < arraysize(policies); ++i) {
89 if (policies[i].is_valid && policies[i].is_allowed != is_allowed) {
90 LOG(WARNING) << base::SysCFStringRefToUTF8(policies[i].bundle_id)
91 << ":" << kNatPolicyName
92 << "(" << (policies[i].is_allowed ? "true" : "false")
93 << ") is being overridden by "
94 << base::SysCFStringRefToUTF8(bundle_setting_policy)
95 << ":" << kNatPolicyName
96 << "(" << (is_allowed ? "true" : "false") << ")";
97 }
98 }
99 }
100
101 // Set policy. Policy must be set (even if it is empty) so that the
102 // default policy is picked up the first time reload is called.
103 UpdateNatPolicy(&policy);
104
105 // Reschedule task.
106 ScheduleFallbackReloadTask();
33 } 107 }
34 }; 108 };
35 109
36 NatPolicy* NatPolicy::Create(base::MessageLoopProxy* message_loop_proxy) { 110 NatPolicy* NatPolicy::Create(base::MessageLoopProxy* message_loop_proxy) {
37 return new NatPolicyMac(message_loop_proxy); 111 return new NatPolicyMac(message_loop_proxy);
38 } 112 }
39 113
40 } // namespace policy_hack 114 } // namespace policy_hack
41 } // namespace remoting 115 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698