OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_SERVICE_H_ |
6 #define CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_SERVICE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_SERVICE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/callback_forward.h" | |
13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
14 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
17 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
18 #include "base/observer_list.h" | 19 #include "base/observer_list.h" |
19 #include "chrome/browser/chromeos/extensions/device_local_account_external_polic y_loader.h" | 20 #include "chrome/browser/chromeos/extensions/device_local_account_external_polic y_loader.h" |
20 #include "chrome/browser/chromeos/policy/device_local_account_external_data_mana ger.h" | 21 #include "chrome/browser/chromeos/policy/device_local_account_external_data_mana ger.h" |
21 #include "chrome/browser/chromeos/settings/cros_settings.h" | 22 #include "chrome/browser/chromeos/settings/cros_settings.h" |
22 #include "components/policy/core/common/cloud/cloud_policy_core.h" | 23 #include "components/policy/core/common/cloud/cloud_policy_core.h" |
23 #include "components/policy/core/common/cloud/cloud_policy_store.h" | 24 #include "components/policy/core/common/cloud/cloud_policy_store.h" |
25 #include "components/policy/core/common/cloud/component_cloud_policy_service.h" | |
24 | 26 |
25 namespace base { | 27 namespace base { |
26 class SequencedTaskRunner; | 28 class SequencedTaskRunner; |
27 } | 29 } |
28 | 30 |
29 namespace chromeos { | 31 namespace chromeos { |
30 class DeviceSettingsService; | 32 class DeviceSettingsService; |
31 class SessionManagerClient; | 33 class SessionManagerClient; |
32 } | 34 } |
33 | 35 |
34 namespace net { | 36 namespace net { |
35 class URLRequestContextGetter; | 37 class URLRequestContextGetter; |
36 } | 38 } |
37 | 39 |
38 namespace policy { | 40 namespace policy { |
39 | 41 |
42 class ComponentCloudPolicyService; | |
bartfab (slow)
2014/06/20 09:44:23
You include the header for ComponentCloudPolicySer
Joao da Silva
2014/06/20 15:36:08
Done.
| |
40 struct DeviceLocalAccount; | 43 struct DeviceLocalAccount; |
41 class DeviceLocalAccountExternalDataService; | 44 class DeviceLocalAccountExternalDataService; |
42 class DeviceLocalAccountPolicyStore; | 45 class DeviceLocalAccountPolicyStore; |
43 class DeviceManagementService; | 46 class DeviceManagementService; |
47 class SchemaRegistryService; | |
44 | 48 |
45 // The main switching central that downloads, caches, refreshes, etc. policy for | 49 // The main switching central that downloads, caches, refreshes, etc. policy for |
46 // a single device-local account. | 50 // a single device-local account. |
47 class DeviceLocalAccountPolicyBroker { | 51 class DeviceLocalAccountPolicyBroker |
52 : public CloudPolicyStore::Observer, | |
53 public ComponentCloudPolicyService::Delegate { | |
48 public: | 54 public: |
55 // |policy_update_callback| can be invoked to notify observers that the policy | |
bartfab (slow)
2014/06/20 09:44:23
Nit: "can" sounds like it may or may not be invoke
Joao da Silva
2014/06/20 15:36:08
Done.
| |
56 // for |account| has been updated. | |
49 // |task_runner| is the runner for policy refresh tasks. | 57 // |task_runner| is the runner for policy refresh tasks. |
50 DeviceLocalAccountPolicyBroker( | 58 DeviceLocalAccountPolicyBroker( |
51 const DeviceLocalAccount& account, | 59 const DeviceLocalAccount& account, |
52 const base::FilePath& component_policy_cache_path, | 60 const base::FilePath& component_policy_cache_path, |
53 scoped_ptr<DeviceLocalAccountPolicyStore> store, | 61 scoped_ptr<DeviceLocalAccountPolicyStore> store, |
54 scoped_refptr<DeviceLocalAccountExternalDataManager> | 62 scoped_refptr<DeviceLocalAccountExternalDataManager> |
55 external_data_manager, | 63 external_data_manager, |
64 const base::Closure& policy_updated_callback, | |
56 const scoped_refptr<base::SequencedTaskRunner>& task_runner); | 65 const scoped_refptr<base::SequencedTaskRunner>& task_runner); |
57 ~DeviceLocalAccountPolicyBroker(); | 66 virtual ~DeviceLocalAccountPolicyBroker(); |
58 | 67 |
59 // Initialize the broker, loading its |store_|. | 68 // Initialize the broker, loading its |store_|. |
60 void Initialize(); | 69 void Initialize(); |
61 | 70 |
71 // Called by the SchemaRegistryServiceFactory to tell the broker that its | |
72 // SchemaRegistryService is going to shutdown soon. This is only called if | |
bartfab (slow)
2014/06/20 09:44:23
Nit: s/shutdown/shut down/
Joao da Silva
2014/06/20 15:36:08
Obsolete
| |
73 // release_schema_registry() was used before. | |
74 void OnSchemaRegistryShutdown(); | |
75 | |
62 // For the difference between |account_id| and |user_id|, see the | 76 // For the difference between |account_id| and |user_id|, see the |
63 // documentation of DeviceLocalAccount. | 77 // documentation of DeviceLocalAccount. |
64 const std::string& account_id() const { return account_id_; } | 78 const std::string& account_id() const { return account_id_; } |
65 const std::string& user_id() const { return user_id_; } | 79 const std::string& user_id() const { return user_id_; } |
66 | 80 |
67 scoped_refptr<chromeos::DeviceLocalAccountExternalPolicyLoader> | 81 scoped_refptr<chromeos::DeviceLocalAccountExternalPolicyLoader> |
68 extension_loader() const { return extension_loader_; } | 82 extension_loader() const { return extension_loader_; } |
69 | 83 |
70 CloudPolicyCore* core() { return &core_; } | 84 CloudPolicyCore* core() { return &core_; } |
71 const CloudPolicyCore* core() const { return &core_; } | 85 const CloudPolicyCore* core() const { return &core_; } |
72 | 86 |
73 scoped_refptr<DeviceLocalAccountExternalDataManager> external_data_manager() { | 87 scoped_refptr<DeviceLocalAccountExternalDataManager> external_data_manager() { |
74 return external_data_manager_; | 88 return external_data_manager_; |
75 } | 89 } |
76 | 90 |
91 ComponentCloudPolicyService* component_policy_service() const { | |
92 return component_policy_service_.get(); | |
93 } | |
94 | |
95 // The broker creates a SchemaRegistryService before a Profile is created | |
96 // for this account (if ever). This method allows the | |
97 // SchemaRegistryServiceFactory to obtain the SchemaRegistryService that was | |
98 // created for the account. | |
99 scoped_ptr<SchemaRegistryService> release_schema_registry(); | |
bartfab (slow)
2014/06/20 09:44:23
1: This should be hacker_style(). It is not a simp
Joao da Silva
2014/06/20 15:36:07
Obsolete
| |
100 | |
77 // Fire up the cloud connection for fetching policy for the account from the | 101 // Fire up the cloud connection for fetching policy for the account from the |
78 // cloud if this is an enterprise-managed device. | 102 // cloud if this is an enterprise-managed device. |
79 void ConnectIfPossible( | 103 void ConnectIfPossible( |
80 chromeos::DeviceSettingsService* device_settings_service, | 104 chromeos::DeviceSettingsService* device_settings_service, |
81 DeviceManagementService* device_management_service, | 105 DeviceManagementService* device_management_service, |
82 scoped_refptr<net::URLRequestContextGetter> request_context); | 106 scoped_refptr<net::URLRequestContextGetter> request_context); |
83 | 107 |
84 // Reads the refresh delay from policy and configures the refresh scheduler. | 108 // Reads the refresh delay from policy and configures the refresh scheduler. |
85 void UpdateRefreshDelay(); | 109 void UpdateRefreshDelay(); |
86 | 110 |
87 // Retrieves the display name for the account as stored in policy. Returns an | 111 // Retrieves the display name for the account as stored in policy. Returns an |
88 // empty string if the policy is not present. | 112 // empty string if the policy is not present. |
89 std::string GetDisplayName() const; | 113 std::string GetDisplayName() const; |
90 | 114 |
91 // Returns a directory where component policy for this account can be cached. | 115 // CloudPolicyStore::Observer: |
92 // The DeviceLocalAccountPolicyService takes care of cleaning up caches of | 116 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; |
93 // accounts that have been removed. | 117 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE; |
94 base::FilePath GetComponentPolicyCachePath() const; | 118 |
119 // ComponentCloudPolicyService::Delegate: | |
120 virtual void OnComponentCloudPolicyUpdated() OVERRIDE; | |
95 | 121 |
96 private: | 122 private: |
123 void CreateComponentCloudPolicyService( | |
124 const scoped_refptr<net::URLRequestContextGetter>& request_context); | |
125 | |
97 const std::string account_id_; | 126 const std::string account_id_; |
98 const std::string user_id_; | 127 const std::string user_id_; |
99 const base::FilePath component_policy_cache_path_; | 128 const base::FilePath component_policy_cache_path_; |
129 scoped_ptr<SchemaRegistryService> schema_registry_; | |
100 const scoped_ptr<DeviceLocalAccountPolicyStore> store_; | 130 const scoped_ptr<DeviceLocalAccountPolicyStore> store_; |
101 scoped_refptr<DeviceLocalAccountExternalDataManager> external_data_manager_; | 131 scoped_refptr<DeviceLocalAccountExternalDataManager> external_data_manager_; |
102 scoped_refptr<chromeos::DeviceLocalAccountExternalPolicyLoader> | 132 scoped_refptr<chromeos::DeviceLocalAccountExternalPolicyLoader> |
103 extension_loader_; | 133 extension_loader_; |
104 CloudPolicyCore core_; | 134 CloudPolicyCore core_; |
135 scoped_ptr<ComponentCloudPolicyService> component_policy_service_; | |
136 base::Closure policy_update_callback_; | |
bartfab (slow)
2014/06/20 09:44:23
Since you have a base::Closure member, you will ne
Joao da Silva
2014/06/20 15:36:07
Done.
| |
105 | 137 |
106 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyBroker); | 138 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyBroker); |
107 }; | 139 }; |
108 | 140 |
109 // Manages user policy blobs for device-local accounts present on the device. | 141 // Manages user policy blobs for device-local accounts present on the device. |
110 // The actual policy blobs are brokered by session_manager (to prevent file | 142 // The actual policy blobs are brokered by session_manager (to prevent file |
111 // manipulation), and we're making signature checks on the policy blobs to | 143 // manipulation), and we're making signature checks on the policy blobs to |
112 // ensure they're issued by the device owner. | 144 // ensure they're issued by the device owner. |
113 class DeviceLocalAccountPolicyService : public CloudPolicyStore::Observer { | 145 class DeviceLocalAccountPolicyService { |
114 public: | 146 public: |
115 // Interface for interested parties to observe policy changes. | 147 // Interface for interested parties to observe policy changes. |
116 class Observer { | 148 class Observer { |
117 public: | 149 public: |
118 virtual ~Observer() {} | 150 virtual ~Observer() {} |
119 | 151 |
120 // Policy for the given |user_id| has changed. | 152 // Policy for the given |user_id| has changed. |
121 virtual void OnPolicyUpdated(const std::string& user_id) = 0; | 153 virtual void OnPolicyUpdated(const std::string& user_id) = 0; |
122 | 154 |
123 // The list of accounts has been updated. | 155 // The list of accounts has been updated. |
124 virtual void OnDeviceLocalAccountsChanged() = 0; | 156 virtual void OnDeviceLocalAccountsChanged() = 0; |
125 | |
126 // The given |broker| is about to be destroyed. | |
127 virtual void OnBrokerShutdown(DeviceLocalAccountPolicyBroker* broker) {} | |
128 }; | 157 }; |
129 | 158 |
130 DeviceLocalAccountPolicyService( | 159 DeviceLocalAccountPolicyService( |
131 chromeos::SessionManagerClient* session_manager_client, | 160 chromeos::SessionManagerClient* session_manager_client, |
132 chromeos::DeviceSettingsService* device_settings_service, | 161 chromeos::DeviceSettingsService* device_settings_service, |
133 chromeos::CrosSettings* cros_settings, | 162 chromeos::CrosSettings* cros_settings, |
134 scoped_refptr<base::SequencedTaskRunner> store_background_task_runner, | 163 scoped_refptr<base::SequencedTaskRunner> store_background_task_runner, |
135 scoped_refptr<base::SequencedTaskRunner> extension_cache_task_runner, | 164 scoped_refptr<base::SequencedTaskRunner> extension_cache_task_runner, |
136 scoped_refptr<base::SequencedTaskRunner> | 165 scoped_refptr<base::SequencedTaskRunner> |
137 external_data_service_backend_task_runner, | 166 external_data_service_backend_task_runner, |
138 scoped_refptr<base::SequencedTaskRunner> io_task_runner, | 167 scoped_refptr<base::SequencedTaskRunner> io_task_runner, |
139 scoped_refptr<net::URLRequestContextGetter> request_context); | 168 scoped_refptr<net::URLRequestContextGetter> request_context); |
140 virtual ~DeviceLocalAccountPolicyService(); | 169 virtual ~DeviceLocalAccountPolicyService(); |
141 | 170 |
142 // Shuts down the service and prevents further policy fetches from the cloud. | 171 // Shuts down the service and prevents further policy fetches from the cloud. |
143 void Shutdown(); | 172 void Shutdown(); |
144 | 173 |
145 // Initializes the cloud policy service connection. | 174 // Initializes the cloud policy service connection. |
146 void Connect(DeviceManagementService* device_management_service); | 175 void Connect(DeviceManagementService* device_management_service); |
147 | 176 |
148 // Get the policy broker for a given |user_id|. Returns NULL if that |user_id| | 177 // Get the policy broker for a given |user_id|. Returns NULL if that |user_id| |
149 // does not belong to an existing device-local account. | 178 // does not belong to an existing device-local account. |
150 DeviceLocalAccountPolicyBroker* GetBrokerForUser(const std::string& user_id); | 179 DeviceLocalAccountPolicyBroker* GetBrokerForUser(const std::string& user_id); |
151 | 180 |
152 // Indicates whether policy has been successfully fetched for the given | 181 // Indicates whether policy has been successfully fetched for the given |
153 // |user_id|. | 182 // |user_id|. |
154 bool IsPolicyAvailableForUser(const std::string& user_id); | 183 bool IsPolicyAvailableForUser(const std::string& user_id); |
155 | 184 |
156 scoped_refptr<net::URLRequestContextGetter> request_context() const; | |
157 | |
158 void AddObserver(Observer* observer); | 185 void AddObserver(Observer* observer); |
159 void RemoveObserver(Observer* observer); | 186 void RemoveObserver(Observer* observer); |
160 | 187 |
161 // CloudPolicyStore::Observer: | |
162 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; | |
163 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE; | |
164 | |
165 private: | 188 private: |
166 typedef std::map<std::string, DeviceLocalAccountPolicyBroker*> | 189 typedef std::map<std::string, DeviceLocalAccountPolicyBroker*> |
167 PolicyBrokerMap; | 190 PolicyBrokerMap; |
168 | 191 |
169 // Returns |true| if the directory in which force-installed extensions are | 192 // Returns |true| if the directory in which force-installed extensions are |
170 // cached for |account_id| is busy, either because a broker that was using | 193 // cached for |account_id| is busy, either because a broker that was using |
171 // this directory has not shut down completely yet or because the directory is | 194 // this directory has not shut down completely yet or because the directory is |
172 // being deleted. | 195 // being deleted. |
173 bool IsExtensionCacheDirectoryBusy(const std::string& account_id); | 196 bool IsExtensionCacheDirectoryBusy(const std::string& account_id); |
174 | 197 |
(...skipping 21 matching lines...) Expand all Loading... | |
196 | 219 |
197 // Calls |UpdateAccountList| if there are no previous calls pending. | 220 // Calls |UpdateAccountList| if there are no previous calls pending. |
198 void UpdateAccountListIfNonePending(); | 221 void UpdateAccountListIfNonePending(); |
199 | 222 |
200 // Deletes brokers in |map| and clears it. | 223 // Deletes brokers in |map| and clears it. |
201 void DeleteBrokers(PolicyBrokerMap* map); | 224 void DeleteBrokers(PolicyBrokerMap* map); |
202 | 225 |
203 // Find the broker for a given |store|. Returns NULL if |store| is unknown. | 226 // Find the broker for a given |store|. Returns NULL if |store| is unknown. |
204 DeviceLocalAccountPolicyBroker* GetBrokerForStore(CloudPolicyStore* store); | 227 DeviceLocalAccountPolicyBroker* GetBrokerForStore(CloudPolicyStore* store); |
205 | 228 |
229 // Notifies the |observers_| that the policy for |user_id| has changed. | |
230 void NotifyPolicyUpdated(const std::string& user_id); | |
231 | |
206 ObserverList<Observer, true> observers_; | 232 ObserverList<Observer, true> observers_; |
207 | 233 |
208 chromeos::SessionManagerClient* session_manager_client_; | 234 chromeos::SessionManagerClient* session_manager_client_; |
209 chromeos::DeviceSettingsService* device_settings_service_; | 235 chromeos::DeviceSettingsService* device_settings_service_; |
210 chromeos::CrosSettings* cros_settings_; | 236 chromeos::CrosSettings* cros_settings_; |
211 | 237 |
212 DeviceManagementService* device_management_service_; | 238 DeviceManagementService* device_management_service_; |
213 | 239 |
214 // The device-local account policy brokers, keyed by user ID. | 240 // The device-local account policy brokers, keyed by user ID. |
215 PolicyBrokerMap policy_brokers_; | 241 PolicyBrokerMap policy_brokers_; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 base::FilePath component_policy_cache_root_; | 273 base::FilePath component_policy_cache_root_; |
248 | 274 |
249 base::WeakPtrFactory<DeviceLocalAccountPolicyService> weak_factory_; | 275 base::WeakPtrFactory<DeviceLocalAccountPolicyService> weak_factory_; |
250 | 276 |
251 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyService); | 277 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyService); |
252 }; | 278 }; |
253 | 279 |
254 } // namespace policy | 280 } // namespace policy |
255 | 281 |
256 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_SERVICE_H_ | 282 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_SERVICE_H_ |
OLD | NEW |