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.
5 #ifndef REMOTING_HOST_POLICY_HACK_POLICY_WATCHER_H_
6 #define REMOTING_HOST_POLICY_HACK_POLICY_WATCHER_H_
8 #include "base/callback.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/values.h"
13 class SingleThreadTaskRunner
;
19 namespace policy_hack
{
21 // Watches for changes to the managed remote access host policies.
22 // If StartWatching() has been called, then before this object can be deleted,
23 // StopWatching() have completed (the provided |done| event must be signaled).
26 // Called first with all policies, and subsequently with any changed policies.
27 typedef base::Callback
<void(scoped_ptr
<base::DictionaryValue
>)>
30 explicit PolicyWatcher(
31 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner
);
32 virtual ~PolicyWatcher();
34 // This guarantees that the |policy_callback| is called at least once with
35 // the current policies. After that, |policy_callback| will be called
36 // whenever a change to any policy is detected. It will then be called only
37 // with the changed policies.
38 virtual void StartWatching(const PolicyCallback
& policy_callback
);
40 // Should be called after StartWatching() before the object is deleted. Calls
41 // just wait for |done| to be signaled before deleting the object.
42 virtual void StopWatching(base::WaitableEvent
* done
);
44 // Implemented by each platform. This message loop should be an IO message
46 static PolicyWatcher
* Create(
47 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner
);
49 // The name of the NAT traversal policy.
50 static const char kNatPolicyName
[];
52 // The name of the policy for requiring 2-factor authentication.
53 static const char kHostRequireTwoFactorPolicyName
[];
55 // The name of the host domain policy.
56 static const char kHostDomainPolicyName
[];
58 // The name of the username policy. This policy is ignored on Windows.
59 // This policy is currently considered 'internal only' and so is not
60 // documented in policy_templates.json.
61 static const char kHostMatchUsernamePolicyName
[];
63 // The name of the policy that controls the host talkgadget prefix.
64 static const char kHostTalkGadgetPrefixPolicyName
[];
66 // The name of the policy for requiring curtain-mode.
67 static const char kHostRequireCurtainPolicyName
[];
69 // The names of the policies for token authentication URLs.
70 static const char kHostTokenUrlPolicyName
[];
71 static const char kHostTokenValidationUrlPolicyName
[];
72 static const char kHostTokenValidationCertIssuerPolicyName
[];
74 // The name of the policy for disabling PIN-less authentication.
75 static const char kHostAllowClientPairing
[];
77 // The name of the policy for disabling gnubbyd forwarding.
78 static const char kHostAllowGnubbyAuthPolicyName
[];
80 // The name of the policy for allowing use of relay servers.
81 static const char kRelayPolicyName
[];
83 // The name of the policy that restricts the range of host UDP ports.
84 static const char kUdpPortRangePolicyName
[];
86 // The name of the policy for overriding policies, for use in testing.
87 static const char kHostDebugOverridePoliciesName
[];
90 virtual void StartWatchingInternal() = 0;
91 virtual void StopWatchingInternal() = 0;
92 virtual void Reload() = 0;
94 // Used to check if the class is on the right thread.
95 bool OnPolicyWatcherThread() const;
97 // Takes the policy dictionary from the OS specific store and extracts the
99 void UpdatePolicies(const base::DictionaryValue
* new_policy
);
101 // Used for time-based reloads in case something goes wrong with the
102 // notification system.
103 void ScheduleFallbackReloadTask();
104 void ScheduleReloadTask(const base::TimeDelta
& delay
);
106 // Returns a DictionaryValue containing the default values for each policy.
107 const base::DictionaryValue
& Defaults() const;
110 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
112 PolicyCallback policy_callback_
;
114 scoped_ptr
<base::DictionaryValue
> old_policies_
;
115 scoped_ptr
<base::DictionaryValue
> default_values_
;
116 scoped_ptr
<base::DictionaryValue
> bad_type_values_
;
118 // Allows us to cancel any inflight FileWatcher events or scheduled reloads.
119 base::WeakPtrFactory
<PolicyWatcher
> weak_factory_
;
122 } // namespace policy_hack
123 } // namespace remoting
125 #endif // REMOTING_HOST_POLICY_HACK_POLICY_WATCHER_H_