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"
11 #include "components/policy/core/common/policy_service.h"
14 class SingleThreadTaskRunner;
20 namespace policy_hack {
22 // Watches for changes to the managed remote access host policies.
23 // If StartWatching() has been called, then before this object can be deleted,
24 // StopWatching() have completed (the provided |done| event must be signaled).
27 // Called first with all policies, and subsequently with any changed policies.
28 typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)>
31 explicit PolicyWatcher(
32 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
33 virtual ~PolicyWatcher();
35 // This guarantees that the |policy_callback| is called at least once with
36 // the current policies. After that, |policy_callback| will be called
37 // whenever a change to any policy is detected. It will then be called only
38 // with the changed policies.
39 virtual void StartWatching(const PolicyCallback& policy_callback);
41 // Should be called after StartWatching() before the object is deleted. Calls
42 // should wait for |stopped_callback| to be called before deleting it.
43 virtual void StopWatching(const base::Closure& stopped_callback);
45 // Implemented by each platform. |task_runner| should be an IO message loop.
46 // |policy_service| is currently only used on ChromeOS. The caller must
47 // ensure that |policy_service| remains valid for the lifetime of
49 static scoped_ptr<PolicyWatcher> Create(
50 policy::PolicyService* policy_service,
51 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
53 // The name of the NAT traversal policy.
54 static const char kNatPolicyName[];
56 // The name of the policy for requiring 2-factor authentication.
57 static const char kHostRequireTwoFactorPolicyName[];
59 // The name of the host domain policy.
60 static const char kHostDomainPolicyName[];
62 // The name of the username policy. This policy is ignored on Windows.
63 // This policy is currently considered 'internal only' and so is not
64 // documented in policy_templates.json.
65 static const char kHostMatchUsernamePolicyName[];
67 // The name of the policy that controls the host talkgadget prefix.
68 static const char kHostTalkGadgetPrefixPolicyName[];
70 // The name of the policy for requiring curtain-mode.
71 static const char kHostRequireCurtainPolicyName[];
73 // The names of the policies for token authentication URLs.
74 static const char kHostTokenUrlPolicyName[];
75 static const char kHostTokenValidationUrlPolicyName[];
76 static const char kHostTokenValidationCertIssuerPolicyName[];
78 // The name of the policy for disabling PIN-less authentication.
79 static const char kHostAllowClientPairing[];
81 // The name of the policy for disabling gnubbyd forwarding.
82 static const char kHostAllowGnubbyAuthPolicyName[];
84 // The name of the policy for allowing use of relay servers.
85 static const char kRelayPolicyName[];
87 // The name of the policy that restricts the range of host UDP ports.
88 static const char kUdpPortRangePolicyName[];
90 // The name of the policy for overriding policies, for use in testing.
91 static const char kHostDebugOverridePoliciesName[];
94 virtual void StartWatchingInternal() = 0;
95 virtual void StopWatchingInternal() = 0;
96 virtual void Reload() = 0;
98 // Used to check if the class is on the right thread.
99 bool OnPolicyWatcherThread() const;
101 // Takes the policy dictionary from the OS specific store and extracts the
102 // relevant policies.
103 void UpdatePolicies(const base::DictionaryValue* new_policy);
105 // Used for time-based reloads in case something goes wrong with the
106 // notification system.
107 void ScheduleFallbackReloadTask();
108 void ScheduleReloadTask(const base::TimeDelta& delay);
110 // Returns a DictionaryValue containing the default values for each policy.
111 const base::DictionaryValue& Defaults() const;
114 void StopWatchingOnPolicyWatcherThread();
115 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
117 PolicyCallback policy_callback_;
119 scoped_ptr<base::DictionaryValue> old_policies_;
120 scoped_ptr<base::DictionaryValue> default_values_;
121 scoped_ptr<base::DictionaryValue> bad_type_values_;
123 // Allows us to cancel any inflight FileWatcher events or scheduled reloads.
124 base::WeakPtrFactory<PolicyWatcher> weak_factory_;
127 } // namespace policy_hack
128 } // namespace remoting
130 #endif // REMOTING_HOST_POLICY_HACK_POLICY_WATCHER_H_