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

Side by Side Diff: remoting/host/policy_watcher.h

Issue 891053003: Reporting a policy error after detecting mistyped policies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing... Created 5 years, 10 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
« no previous file with comments | « no previous file | remoting/host/policy_watcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #ifndef REMOTING_HOST_POLICY_WATCHER_H_ 5 #ifndef REMOTING_HOST_POLICY_WATCHER_H_
6 #define REMOTING_HOST_POLICY_WATCHER_H_ 6 #define REMOTING_HOST_POLICY_WATCHER_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/threading/non_thread_safe.h" 12 #include "base/threading/non_thread_safe.h"
13 #include "components/policy/core/common/policy_service.h" 13 #include "components/policy/core/common/policy_service.h"
14 14
15 namespace base { 15 namespace base {
16 class DictionaryValue; 16 class DictionaryValue;
17 class SingleThreadTaskRunner; 17 class SingleThreadTaskRunner;
18 } // namespace base 18 } // namespace base
19 19
20 namespace policy { 20 namespace policy {
21 class AsyncPolicyLoader; 21 class AsyncPolicyLoader;
22 class ConfigurationPolicyProvider; 22 class ConfigurationPolicyProvider;
23 class Schema;
23 class SchemaRegistry; 24 class SchemaRegistry;
24 } // namespace policy 25 } // namespace policy
25 26
26 namespace remoting { 27 namespace remoting {
27 28
28 // Watches for changes to the managed remote access host policies. 29 // Watches for changes to the managed remote access host policies.
29 class PolicyWatcher : public policy::PolicyService::Observer, 30 class PolicyWatcher : public policy::PolicyService::Observer,
30 public base::NonThreadSafe { 31 public base::NonThreadSafe {
31 public: 32 public:
32 // Called first with all policies, and subsequently with any changed policies. 33 // Called first with all policies, and subsequently with any changed policies.
33 typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)> 34 typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)>
34 PolicyUpdatedCallback; 35 PolicyUpdatedCallback;
35 36
36 // TODO(lukasza): PolicyErrorCallback never gets called by PolicyWatcher.
37 // Need to either 1) remove error-handling from PolicyWatcher or 2) add
38 // error-handling around PolicyService 2a) Add policy name/type validation via
39 // policy::Schema::Normalize. 2b) Consider exposing parsing errors from
40 // policy::ConfigDirPolicyLoader.
41
42 // Called after detecting malformed policies. 37 // Called after detecting malformed policies.
43 typedef base::Callback<void()> PolicyErrorCallback; 38 typedef base::Callback<void()> PolicyErrorCallback;
44 39
45 ~PolicyWatcher() override; 40 ~PolicyWatcher() override;
46 41
47 // This guarantees that the |policy_updated_callback| is called at least once 42 // This guarantees that the |policy_updated_callback| is called at least once
48 // with the current policies. After that, |policy_updated_callback| will be 43 // with the current policies. After that, |policy_updated_callback| will be
49 // called whenever a change to any policy is detected. It will then be called 44 // called whenever a change to any policy is detected. It will then be called
50 // only with the changed policies. 45 // only with the changed policies.
51 // 46 //
(...skipping 30 matching lines...) Expand all
82 policy::PolicyService* policy_service, 77 policy::PolicyService* policy_service,
83 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner); 78 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner);
84 79
85 private: 80 private:
86 friend class PolicyWatcherTest; 81 friend class PolicyWatcherTest;
87 82
88 // Takes the policy dictionary from the OS specific store and extracts the 83 // Takes the policy dictionary from the OS specific store and extracts the
89 // relevant policies. 84 // relevant policies.
90 void UpdatePolicies(const base::DictionaryValue* new_policy); 85 void UpdatePolicies(const base::DictionaryValue* new_policy);
91 86
87 // Gets Chromoting schema stored inside |owned_schema_registry_|.
88 const policy::Schema* GetPolicySchema() const;
89
92 // Signals policy error to the registered |PolicyErrorCallback|. 90 // Signals policy error to the registered |PolicyErrorCallback|.
93 void SignalPolicyError(); 91 void SignalPolicyError();
94 92
95 // Called whenever a transient error occurs during reading of policy files.
96 // This will increment a counter, and will trigger a call to
97 // SignalPolicyError() only after a threshold count is reached.
98 // The counter is reset whenever policy has been successfully read.
99 void SignalTransientPolicyError();
100
101 // |policy_service_task_runner| is the task runner where it is safe 93 // |policy_service_task_runner| is the task runner where it is safe
102 // to call |policy_service_| methods and where we expect to get callbacks 94 // to call |policy_service_| methods and where we expect to get callbacks
103 // from |policy_service_|. 95 // from |policy_service_|.
104 PolicyWatcher( 96 PolicyWatcher(
105 policy::PolicyService* policy_service, 97 policy::PolicyService* policy_service,
106 scoped_ptr<policy::PolicyService> owned_policy_service, 98 scoped_ptr<policy::PolicyService> owned_policy_service,
107 scoped_ptr<policy::ConfigurationPolicyProvider> owned_policy_provider, 99 scoped_ptr<policy::ConfigurationPolicyProvider> owned_policy_provider,
108 scoped_ptr<policy::SchemaRegistry> owned_schema_registry); 100 scoped_ptr<policy::SchemaRegistry> owned_schema_registry);
109 101
110 // Creates PolicyWatcher that wraps the owned |async_policy_loader| with an 102 // Creates PolicyWatcher that wraps the owned |async_policy_loader| with an
111 // appropriate PolicySchema. 103 // appropriate PolicySchema.
112 // 104 //
113 // |policy_service_task_runner| is passed through to the constructor of 105 // |policy_service_task_runner| is passed through to the constructor of
114 // PolicyWatcher. 106 // PolicyWatcher.
115 static scoped_ptr<PolicyWatcher> CreateFromPolicyLoader( 107 static scoped_ptr<PolicyWatcher> CreateFromPolicyLoader(
116 scoped_ptr<policy::AsyncPolicyLoader> async_policy_loader); 108 scoped_ptr<policy::AsyncPolicyLoader> async_policy_loader);
117 109
118 // PolicyService::Observer interface. 110 // PolicyService::Observer interface.
119 void OnPolicyUpdated(const policy::PolicyNamespace& ns, 111 void OnPolicyUpdated(const policy::PolicyNamespace& ns,
120 const policy::PolicyMap& previous, 112 const policy::PolicyMap& previous,
121 const policy::PolicyMap& current) override; 113 const policy::PolicyMap& current) override;
122 void OnPolicyServiceInitialized(policy::PolicyDomain domain) override; 114 void OnPolicyServiceInitialized(policy::PolicyDomain domain) override;
123 115
124 PolicyUpdatedCallback policy_updated_callback_; 116 PolicyUpdatedCallback policy_updated_callback_;
125 PolicyErrorCallback policy_error_callback_; 117 PolicyErrorCallback policy_error_callback_;
126 int transient_policy_error_retry_counter_;
127 118
128 scoped_ptr<base::DictionaryValue> old_policies_; 119 scoped_ptr<base::DictionaryValue> old_policies_;
129 scoped_ptr<base::DictionaryValue> default_values_; 120 scoped_ptr<base::DictionaryValue> default_values_;
130 scoped_ptr<base::DictionaryValue> bad_type_values_;
131 121
132 policy::PolicyService* policy_service_; 122 policy::PolicyService* policy_service_;
133 123
134 // Order of fields below is important to ensure destruction takes object 124 // Order of fields below is important to ensure destruction takes object
135 // dependencies into account: 125 // dependencies into account:
136 // - |owned_policy_service_| uses |owned_policy_provider_| 126 // - |owned_policy_service_| uses |owned_policy_provider_|
137 // - |owned_policy_provider_| uses |owned_schema_registry_| 127 // - |owned_policy_provider_| uses |owned_schema_registry_|
138 scoped_ptr<policy::SchemaRegistry> owned_schema_registry_; 128 scoped_ptr<policy::SchemaRegistry> owned_schema_registry_;
139 scoped_ptr<policy::ConfigurationPolicyProvider> owned_policy_provider_; 129 scoped_ptr<policy::ConfigurationPolicyProvider> owned_policy_provider_;
140 scoped_ptr<policy::PolicyService> owned_policy_service_; 130 scoped_ptr<policy::PolicyService> owned_policy_service_;
141 131
142 DISALLOW_COPY_AND_ASSIGN(PolicyWatcher); 132 DISALLOW_COPY_AND_ASSIGN(PolicyWatcher);
143 }; 133 };
144 134
145 } // namespace remoting 135 } // namespace remoting
146 136
147 #endif // REMOTING_HOST_POLICY_WATCHER_H_ 137 #endif // REMOTING_HOST_POLICY_WATCHER_H_
OLDNEW
« no previous file with comments | « no previous file | remoting/host/policy_watcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698