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[];
73 // The name of the policy for disabling PIN-less authentication.
74 static const char kHostAllowClientPairing[];
76 // The name of the policy for overriding policies, for use in testing.
77 static const char kHostDebugOverridePoliciesName[];
80 virtual void StartWatchingInternal() = 0;
81 virtual void StopWatchingInternal() = 0;
82 virtual void Reload() = 0;
84 // Used to check if the class is on the right thread.
85 bool OnPolicyWatcherThread() const;
87 // Takes the policy dictionary from the OS specific store and extracts the
89 void UpdatePolicies(const base::DictionaryValue* new_policy);
91 // Used for time-based reloads in case something goes wrong with the
92 // notification system.
93 void ScheduleFallbackReloadTask();
94 void ScheduleReloadTask(const base::TimeDelta& delay);
96 // Returns a DictionaryValue containing the default values for each policy.
97 const base::DictionaryValue& Defaults() const;
100 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
102 PolicyCallback policy_callback_;
104 scoped_ptr<base::DictionaryValue> old_policies_;
105 scoped_ptr<base::DictionaryValue> default_values_;
106 scoped_ptr<base::DictionaryValue> bad_type_values_;
108 // Allows us to cancel any inflight FileWatcher events or scheduled reloads.
109 base::WeakPtrFactory<PolicyWatcher> weak_factory_;
112 } // namespace policy_hack
113 } // namespace remoting
115 #endif // REMOTING_HOST_POLICY_HACK_POLICY_WATCHER_H_