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

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: default to not setting 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
12 namespace remoting { 16 namespace remoting {
13 namespace policy_hack { 17 namespace policy_hack {
14 18
19 // The MacOS version does not watch files (because there is potentially 9
20 // files to watch in three different locations) and 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.
15 class NatPolicyMac : public NatPolicy { 24 class NatPolicyMac : public NatPolicy {
16 public: 25 public:
17 explicit NatPolicyMac(base::MessageLoopProxy* message_loop_proxy) 26 explicit NatPolicyMac(base::MessageLoopProxy* message_loop_proxy)
18 : NatPolicy(message_loop_proxy) { 27 : NatPolicy(message_loop_proxy) {
19 } 28 }
20 29
21 virtual ~NatPolicyMac() { 30 virtual ~NatPolicyMac() {
22 } 31 }
23 32
33 protected:
24 virtual void StartWatchingInternal() OVERRIDE { 34 virtual void StartWatchingInternal() OVERRIDE {
25 scoped_ptr<base::DictionaryValue> new_policy(new base::DictionaryValue()); 35 Reload();
26 UpdateNatPolicy(new_policy.get());
27 } 36 }
28 37
29 virtual void StopWatchingInternal() OVERRIDE { 38 virtual void StopWatchingInternal() OVERRIDE {
30 } 39 }
31 40
32 virtual void Reload() OVERRIDE { 41 virtual void Reload() OVERRIDE {
42 DCHECK(OnPolicyThread());
43 // Since policy could be set for any of these browsers, assume the most
44 // restrictive. Log if there is policy conflict.
45 struct {
46 Boolean is_valid;
47 Boolean is_allowed;
48 CFStringRef bundle_id;
49 } policies[3] = {
50 { false, true, CFSTR("com.google.Chrome") },
51 { false, true, CFSTR("com.chromium.Chromium") },
52 { false, true, CFSTR("com.google.Chrome.canary") }
53 };
54 base::mac::ScopedCFTypeRef<CFStringRef> policy_key(
55 base::SysUTF8ToCFStringRef(kNatPolicyName));
56 bool is_allowed = true;
57 bool is_valid = false;
58
59 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(policies); ++i) {
awong 2011/08/25 21:32:05 :-/ Would it be worth promoting this struct decla
60 if (CFPreferencesAppSynchronize(policies[i].bundle_id)) {
61 policies[i].is_allowed = CFPreferencesGetAppBooleanValue(
62 policy_key,
63 policies[i].bundle_id,
64 &policies[i].is_valid);
65 if (policies[i].is_valid) {
66 is_allowed &= policies[i].is_allowed;
67 is_valid |= policies[i].is_valid;
68 }
69 }
70 }
71
72 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(policies); ++i) {
73 if (policies[i].is_valid && policies[i].is_allowed != is_allowed) {
74 LOG(WARNING) << base::SysCFStringRefToUTF8(policies[i].bundle_id)
75 << " has conflicting policy value -> "
76 << is_allowed
77 << " != "
78 << static_cast<bool>(policies[i].is_allowed);
awong 2011/08/25 21:32:05 Should also explicitly list what state we actually
79 }
80 }
81
82 // Only set policy if a valid policy was found.
83 if (is_valid) {
84 base::DictionaryValue policy;
85 policy.SetBoolean(kNatPolicyName, is_allowed);
86 UpdateNatPolicy(&policy);
87 }
88 ScheduleFallbackReloadTask();
33 } 89 }
34 }; 90 };
35 91
36 NatPolicy* NatPolicy::Create(base::MessageLoopProxy* message_loop_proxy) { 92 NatPolicy* NatPolicy::Create(base::MessageLoopProxy* message_loop_proxy) {
37 return new NatPolicyMac(message_loop_proxy); 93 return new NatPolicyMac(message_loop_proxy);
38 } 94 }
39 95
40 } // namespace policy_hack 96 } // namespace policy_hack
41 } // namespace remoting 97 } // 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