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

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

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 years, 8 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 | « remoting/host/pam_authorization_factory_posix.cc ('k') | 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 <memory>
9
8 #include "base/callback.h" 10 #include "base/callback.h"
9 #include "base/macros.h" 11 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/threading/non_thread_safe.h" 13 #include "base/threading/non_thread_safe.h"
13 #include "components/policy/core/common/policy_service.h" 14 #include "components/policy/core/common/policy_service.h"
14 15
15 namespace base { 16 namespace base {
16 class DictionaryValue; 17 class DictionaryValue;
17 class SingleThreadTaskRunner; 18 class SingleThreadTaskRunner;
18 } // namespace base 19 } // namespace base
19 20
20 namespace policy { 21 namespace policy {
21 class AsyncPolicyLoader; 22 class AsyncPolicyLoader;
22 class ConfigurationPolicyProvider; 23 class ConfigurationPolicyProvider;
23 class Schema; 24 class Schema;
24 class SchemaRegistry; 25 class SchemaRegistry;
25 } // namespace policy 26 } // namespace policy
26 27
27 namespace remoting { 28 namespace remoting {
28 29
29 // Watches for changes to the managed remote access host policies. 30 // Watches for changes to the managed remote access host policies.
30 class PolicyWatcher : public policy::PolicyService::Observer, 31 class PolicyWatcher : public policy::PolicyService::Observer,
31 public base::NonThreadSafe { 32 public base::NonThreadSafe {
32 public: 33 public:
33 // Called first with all policies, and subsequently with any changed policies. 34 // Called first with all policies, and subsequently with any changed policies.
34 typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)> 35 typedef base::Callback<void(std::unique_ptr<base::DictionaryValue>)>
35 PolicyUpdatedCallback; 36 PolicyUpdatedCallback;
36 37
37 // Called after detecting malformed policies. 38 // Called after detecting malformed policies.
38 typedef base::Callback<void()> PolicyErrorCallback; 39 typedef base::Callback<void()> PolicyErrorCallback;
39 40
40 ~PolicyWatcher() override; 41 ~PolicyWatcher() override;
41 42
42 // This guarantees that the |policy_updated_callback| is called at least once 43 // This guarantees that the |policy_updated_callback| is called at least once
43 // with the current policies. After that, |policy_updated_callback| will be 44 // with the current policies. After that, |policy_updated_callback| will be
44 // called whenever a change to any policy is detected. It will then be called 45 // called whenever a change to any policy is detected. It will then be called
(...skipping 21 matching lines...) Expand all
66 // When |policy_service| is null, then |file_task_runner| is used for reading 67 // When |policy_service| is null, then |file_task_runner| is used for reading
67 // the policy from files / registry / preferences (which are blocking 68 // the policy from files / registry / preferences (which are blocking
68 // operations). |file_task_runner| should be of TYPE_IO type. 69 // operations). |file_task_runner| should be of TYPE_IO type.
69 // 70 //
70 // When |policy_service| is specified then |file_task_runner| argument is 71 // When |policy_service| is specified then |file_task_runner| argument is
71 // ignored and 1) BrowserThread::UI is used for PolicyUpdatedCallback and 72 // ignored and 1) BrowserThread::UI is used for PolicyUpdatedCallback and
72 // PolicyErrorCallback and 2) BrowserThread::FILE is used for reading the 73 // PolicyErrorCallback and 2) BrowserThread::FILE is used for reading the
73 // policy from files / registry / preferences (although (2) is just an 74 // policy from files / registry / preferences (although (2) is just an
74 // implementation detail and should likely be ignored outside of 75 // implementation detail and should likely be ignored outside of
75 // PolicyWatcher). 76 // PolicyWatcher).
76 static scoped_ptr<PolicyWatcher> Create( 77 static std::unique_ptr<PolicyWatcher> Create(
77 policy::PolicyService* policy_service, 78 policy::PolicyService* policy_service,
78 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner); 79 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner);
79 80
80 private: 81 private:
81 friend class PolicyWatcherTest; 82 friend class PolicyWatcherTest;
82 83
83 // Gets Chromoting schema stored inside |owned_schema_registry_|. 84 // Gets Chromoting schema stored inside |owned_schema_registry_|.
84 const policy::Schema* GetPolicySchema() const; 85 const policy::Schema* GetPolicySchema() const;
85 86
86 // Simplifying wrapper around Schema::Normalize. 87 // Simplifying wrapper around Schema::Normalize.
87 // - Returns false if |dict| is invalid (i.e. contains mistyped policy 88 // - Returns false if |dict| is invalid (i.e. contains mistyped policy
88 // values). 89 // values).
89 // - Returns true if |dict| was valid or got normalized. 90 // - Returns true if |dict| was valid or got normalized.
90 bool NormalizePolicies(base::DictionaryValue* dict); 91 bool NormalizePolicies(base::DictionaryValue* dict);
91 92
92 // Stores |new_policies| into |old_policies_|. Returns dictionary with items 93 // Stores |new_policies| into |old_policies_|. Returns dictionary with items
93 // from |new_policies| that are different from the old |old_policies_|. 94 // from |new_policies| that are different from the old |old_policies_|.
94 scoped_ptr<base::DictionaryValue> StoreNewAndReturnChangedPolicies( 95 std::unique_ptr<base::DictionaryValue> StoreNewAndReturnChangedPolicies(
95 scoped_ptr<base::DictionaryValue> new_policies); 96 std::unique_ptr<base::DictionaryValue> new_policies);
96 97
97 // Signals policy error to the registered |PolicyErrorCallback|. 98 // Signals policy error to the registered |PolicyErrorCallback|.
98 void SignalPolicyError(); 99 void SignalPolicyError();
99 100
100 // |policy_service_task_runner| is the task runner where it is safe 101 // |policy_service_task_runner| is the task runner where it is safe
101 // to call |policy_service_| methods and where we expect to get callbacks 102 // to call |policy_service_| methods and where we expect to get callbacks
102 // from |policy_service_|. 103 // from |policy_service_|.
103 PolicyWatcher( 104 PolicyWatcher(policy::PolicyService* policy_service,
104 policy::PolicyService* policy_service, 105 std::unique_ptr<policy::PolicyService> owned_policy_service,
105 scoped_ptr<policy::PolicyService> owned_policy_service, 106 std::unique_ptr<policy::ConfigurationPolicyProvider>
106 scoped_ptr<policy::ConfigurationPolicyProvider> owned_policy_provider, 107 owned_policy_provider,
107 scoped_ptr<policy::SchemaRegistry> owned_schema_registry); 108 std::unique_ptr<policy::SchemaRegistry> owned_schema_registry);
108 109
109 // Creates PolicyWatcher that wraps the owned |async_policy_loader| with an 110 // Creates PolicyWatcher that wraps the owned |async_policy_loader| with an
110 // appropriate PolicySchema. 111 // appropriate PolicySchema.
111 // 112 //
112 // |policy_service_task_runner| is passed through to the constructor of 113 // |policy_service_task_runner| is passed through to the constructor of
113 // PolicyWatcher. 114 // PolicyWatcher.
114 static scoped_ptr<PolicyWatcher> CreateFromPolicyLoader( 115 static std::unique_ptr<PolicyWatcher> CreateFromPolicyLoader(
115 scoped_ptr<policy::AsyncPolicyLoader> async_policy_loader); 116 std::unique_ptr<policy::AsyncPolicyLoader> async_policy_loader);
116 117
117 // PolicyService::Observer interface. 118 // PolicyService::Observer interface.
118 void OnPolicyUpdated(const policy::PolicyNamespace& ns, 119 void OnPolicyUpdated(const policy::PolicyNamespace& ns,
119 const policy::PolicyMap& previous, 120 const policy::PolicyMap& previous,
120 const policy::PolicyMap& current) override; 121 const policy::PolicyMap& current) override;
121 void OnPolicyServiceInitialized(policy::PolicyDomain domain) override; 122 void OnPolicyServiceInitialized(policy::PolicyDomain domain) override;
122 123
123 PolicyUpdatedCallback policy_updated_callback_; 124 PolicyUpdatedCallback policy_updated_callback_;
124 PolicyErrorCallback policy_error_callback_; 125 PolicyErrorCallback policy_error_callback_;
125 126
126 scoped_ptr<base::DictionaryValue> old_policies_; 127 std::unique_ptr<base::DictionaryValue> old_policies_;
127 scoped_ptr<base::DictionaryValue> default_values_; 128 std::unique_ptr<base::DictionaryValue> default_values_;
128 129
129 policy::PolicyService* policy_service_; 130 policy::PolicyService* policy_service_;
130 131
131 // Order of fields below is important to ensure destruction takes object 132 // Order of fields below is important to ensure destruction takes object
132 // dependencies into account: 133 // dependencies into account:
133 // - |owned_policy_service_| uses |owned_policy_provider_| 134 // - |owned_policy_service_| uses |owned_policy_provider_|
134 // - |owned_policy_provider_| uses |owned_schema_registry_| 135 // - |owned_policy_provider_| uses |owned_schema_registry_|
135 scoped_ptr<policy::SchemaRegistry> owned_schema_registry_; 136 std::unique_ptr<policy::SchemaRegistry> owned_schema_registry_;
136 scoped_ptr<policy::ConfigurationPolicyProvider> owned_policy_provider_; 137 std::unique_ptr<policy::ConfigurationPolicyProvider> owned_policy_provider_;
137 scoped_ptr<policy::PolicyService> owned_policy_service_; 138 std::unique_ptr<policy::PolicyService> owned_policy_service_;
138 139
139 DISALLOW_COPY_AND_ASSIGN(PolicyWatcher); 140 DISALLOW_COPY_AND_ASSIGN(PolicyWatcher);
140 }; 141 };
141 142
142 } // namespace remoting 143 } // namespace remoting
143 144
144 #endif // REMOTING_HOST_POLICY_WATCHER_H_ 145 #endif // REMOTING_HOST_POLICY_WATCHER_H_
OLDNEW
« no previous file with comments | « remoting/host/pam_authorization_factory_posix.cc ('k') | remoting/host/policy_watcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698