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/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
18 #include "chrome/browser/chromeos/extensions/device_local_account_external_polic
y_loader.h" | 18 #include "chrome/browser/chromeos/extensions/device_local_account_external_polic
y_loader.h" |
19 #include "chrome/browser/chromeos/policy/device_local_account_external_data_mana
ger.h" | |
20 #include "chrome/browser/chromeos/settings/cros_settings.h" | 19 #include "chrome/browser/chromeos/settings/cros_settings.h" |
21 #include "chrome/browser/policy/cloud/cloud_policy_core.h" | 20 #include "chrome/browser/policy/cloud/cloud_policy_core.h" |
22 #include "chrome/browser/policy/cloud/cloud_policy_store.h" | 21 #include "chrome/browser/policy/cloud/cloud_policy_store.h" |
23 | 22 |
24 namespace base { | 23 namespace base { |
25 class SequencedTaskRunner; | 24 class SequencedTaskRunner; |
26 } | 25 } |
27 | 26 |
28 namespace chromeos { | 27 namespace chromeos { |
29 class DeviceSettingsService; | 28 class DeviceSettingsService; |
30 class SessionManagerClient; | 29 class SessionManagerClient; |
31 } | 30 } |
32 | 31 |
33 namespace net { | |
34 class URLRequestContextGetter; | |
35 } | |
36 | |
37 namespace policy { | 32 namespace policy { |
38 | 33 |
39 struct DeviceLocalAccount; | 34 struct DeviceLocalAccount; |
40 class DeviceLocalAccountExternalDataService; | |
41 class DeviceLocalAccountPolicyStore; | 35 class DeviceLocalAccountPolicyStore; |
42 class DeviceManagementService; | 36 class DeviceManagementService; |
43 | 37 |
44 // The main switching central that downloads, caches, refreshes, etc. policy for | 38 // The main switching central that downloads, caches, refreshes, etc. policy for |
45 // a single device-local account. | 39 // a single device-local account. |
46 class DeviceLocalAccountPolicyBroker { | 40 class DeviceLocalAccountPolicyBroker { |
47 public: | 41 public: |
48 // |task_runner| is the runner for policy refresh tasks. | 42 // |task_runner| is the runner for policy refresh tasks. |
49 DeviceLocalAccountPolicyBroker( | 43 DeviceLocalAccountPolicyBroker( |
50 const DeviceLocalAccount& account, | 44 const DeviceLocalAccount& account, |
51 scoped_ptr<DeviceLocalAccountPolicyStore> store, | 45 scoped_ptr<DeviceLocalAccountPolicyStore> store, |
52 scoped_refptr<DeviceLocalAccountExternalDataManager> | |
53 external_data_manager, | |
54 const scoped_refptr<base::SequencedTaskRunner>& task_runner); | 46 const scoped_refptr<base::SequencedTaskRunner>& task_runner); |
55 ~DeviceLocalAccountPolicyBroker(); | 47 ~DeviceLocalAccountPolicyBroker(); |
56 | 48 |
57 // Initialize the broker, loading its |store_|. | 49 // Initialize the broker, loading its |store_|. |
58 void Initialize(); | 50 void Initialize(); |
59 | 51 |
60 // For the difference between |account_id| and |user_id|, see the | 52 // For the difference between |account_id| and |user_id|, see the |
61 // documentation of DeviceLocalAccount. | 53 // documentation of DeviceLocalAccount. |
62 const std::string& account_id() const { return account_id_; } | 54 const std::string& account_id() const { return account_id_; } |
63 const std::string& user_id() const { return user_id_; } | 55 const std::string& user_id() const { return user_id_; } |
64 | 56 |
65 scoped_refptr<chromeos::DeviceLocalAccountExternalPolicyLoader> | 57 scoped_refptr<chromeos::DeviceLocalAccountExternalPolicyLoader> |
66 extension_loader() const { return extension_loader_; } | 58 extension_loader() const { return extension_loader_; } |
67 | 59 |
68 CloudPolicyCore* core() { return &core_; } | 60 CloudPolicyCore* core() { return &core_; } |
69 const CloudPolicyCore* core() const { return &core_; } | 61 const CloudPolicyCore* core() const { return &core_; } |
70 | 62 |
71 scoped_refptr<DeviceLocalAccountExternalDataManager> external_data_manager() { | |
72 return external_data_manager_; | |
73 } | |
74 | |
75 // Fire up the cloud connection for fetching policy for the account from the | 63 // Fire up the cloud connection for fetching policy for the account from the |
76 // cloud if this is an enterprise-managed device. | 64 // cloud if this is an enterprise-managed device. |
77 void ConnectIfPossible( | 65 void ConnectIfPossible( |
78 chromeos::DeviceSettingsService* device_settings_service, | 66 chromeos::DeviceSettingsService* device_settings_service, |
79 DeviceManagementService* device_management_service, | 67 DeviceManagementService* device_management_service); |
80 scoped_refptr<net::URLRequestContextGetter> request_context); | 68 |
| 69 // Destroy the cloud connection, stopping policy refreshes. |
| 70 void Disconnect(); |
81 | 71 |
82 // Reads the refresh delay from policy and configures the refresh scheduler. | 72 // Reads the refresh delay from policy and configures the refresh scheduler. |
83 void UpdateRefreshDelay(); | 73 void UpdateRefreshDelay(); |
84 | 74 |
85 // Retrieves the display name for the account as stored in policy. Returns an | 75 // Retrieves the display name for the account as stored in policy. Returns an |
86 // empty string if the policy is not present. | 76 // empty string if the policy is not present. |
87 std::string GetDisplayName() const; | 77 std::string GetDisplayName() const; |
88 | 78 |
89 private: | 79 private: |
90 const std::string account_id_; | 80 const std::string account_id_; |
91 const std::string user_id_; | 81 const std::string user_id_; |
92 const scoped_ptr<DeviceLocalAccountPolicyStore> store_; | 82 const scoped_ptr<DeviceLocalAccountPolicyStore> store_; |
93 scoped_refptr<DeviceLocalAccountExternalDataManager> external_data_manager_; | |
94 scoped_refptr<chromeos::DeviceLocalAccountExternalPolicyLoader> | 83 scoped_refptr<chromeos::DeviceLocalAccountExternalPolicyLoader> |
95 extension_loader_; | 84 extension_loader_; |
96 CloudPolicyCore core_; | 85 CloudPolicyCore core_; |
97 | 86 |
98 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyBroker); | 87 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyBroker); |
99 }; | 88 }; |
100 | 89 |
101 // Manages user policy blobs for device-local accounts present on the device. | 90 // Manages user policy blobs for device-local accounts present on the device. |
102 // The actual policy blobs are brokered by session_manager (to prevent file | 91 // The actual policy blobs are brokered by session_manager (to prevent file |
103 // manipulation), and we're making signature checks on the policy blobs to | 92 // manipulation), and we're making signature checks on the policy blobs to |
(...skipping 10 matching lines...) Expand all Loading... |
114 | 103 |
115 // The list of accounts has been updated. | 104 // The list of accounts has been updated. |
116 virtual void OnDeviceLocalAccountsChanged() = 0; | 105 virtual void OnDeviceLocalAccountsChanged() = 0; |
117 }; | 106 }; |
118 | 107 |
119 DeviceLocalAccountPolicyService( | 108 DeviceLocalAccountPolicyService( |
120 chromeos::SessionManagerClient* session_manager_client, | 109 chromeos::SessionManagerClient* session_manager_client, |
121 chromeos::DeviceSettingsService* device_settings_service, | 110 chromeos::DeviceSettingsService* device_settings_service, |
122 chromeos::CrosSettings* cros_settings, | 111 chromeos::CrosSettings* cros_settings, |
123 scoped_refptr<base::SequencedTaskRunner> store_background_task_runner, | 112 scoped_refptr<base::SequencedTaskRunner> store_background_task_runner, |
124 scoped_refptr<base::SequencedTaskRunner> extension_cache_task_runner, | 113 scoped_refptr<base::SequencedTaskRunner> extension_cache_task_runner); |
125 scoped_refptr<base::SequencedTaskRunner> | |
126 external_data_service_backend_task_runner, | |
127 scoped_refptr<base::SequencedTaskRunner> io_task_runner, | |
128 scoped_refptr<net::URLRequestContextGetter> request_context); | |
129 virtual ~DeviceLocalAccountPolicyService(); | 114 virtual ~DeviceLocalAccountPolicyService(); |
130 | 115 |
131 // Shuts down the service and prevents further policy fetches from the cloud. | |
132 void Shutdown(); | |
133 | |
134 // Initializes the cloud policy service connection. | 116 // Initializes the cloud policy service connection. |
135 void Connect(DeviceManagementService* device_management_service); | 117 void Connect(DeviceManagementService* device_management_service); |
136 | 118 |
| 119 // Prevents further policy fetches from the cloud. |
| 120 void Disconnect(); |
| 121 |
137 // Get the policy broker for a given |user_id|. Returns NULL if that |user_id| | 122 // Get the policy broker for a given |user_id|. Returns NULL if that |user_id| |
138 // does not belong to an existing device-local account. | 123 // does not belong to an existing device-local account. |
139 DeviceLocalAccountPolicyBroker* GetBrokerForUser(const std::string& user_id); | 124 DeviceLocalAccountPolicyBroker* GetBrokerForUser(const std::string& user_id); |
140 | 125 |
141 // Indicates whether policy has been successfully fetched for the given | 126 // Indicates whether policy has been successfully fetched for the given |
142 // |user_id|. | 127 // |user_id|. |
143 bool IsPolicyAvailableForUser(const std::string& user_id); | 128 bool IsPolicyAvailableForUser(const std::string& user_id); |
144 | 129 |
145 void AddObserver(Observer* observer); | 130 void AddObserver(Observer* observer); |
146 void RemoveObserver(Observer* observer); | 131 void RemoveObserver(Observer* observer); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 168 |
184 // Calls |UpdateAccountList| if there are no previous calls pending. | 169 // Calls |UpdateAccountList| if there are no previous calls pending. |
185 void UpdateAccountListIfNonePending(); | 170 void UpdateAccountListIfNonePending(); |
186 | 171 |
187 // Deletes brokers in |map| and clears it. | 172 // Deletes brokers in |map| and clears it. |
188 void DeleteBrokers(PolicyBrokerMap* map); | 173 void DeleteBrokers(PolicyBrokerMap* map); |
189 | 174 |
190 // Find the broker for a given |store|. Returns NULL if |store| is unknown. | 175 // Find the broker for a given |store|. Returns NULL if |store| is unknown. |
191 DeviceLocalAccountPolicyBroker* GetBrokerForStore(CloudPolicyStore* store); | 176 DeviceLocalAccountPolicyBroker* GetBrokerForStore(CloudPolicyStore* store); |
192 | 177 |
193 ObserverList<Observer, true> observers_; | |
194 | |
195 chromeos::SessionManagerClient* session_manager_client_; | 178 chromeos::SessionManagerClient* session_manager_client_; |
196 chromeos::DeviceSettingsService* device_settings_service_; | 179 chromeos::DeviceSettingsService* device_settings_service_; |
197 chromeos::CrosSettings* cros_settings_; | 180 chromeos::CrosSettings* cros_settings_; |
198 | 181 |
199 DeviceManagementService* device_management_service_; | 182 DeviceManagementService* device_management_service_; |
200 | 183 |
201 // The device-local account policy brokers, keyed by user ID. | 184 // The device-local account policy brokers, keyed by user ID. |
202 PolicyBrokerMap policy_brokers_; | 185 PolicyBrokerMap policy_brokers_; |
203 | 186 |
204 // Whether a call to UpdateAccountList() is pending because |cros_settings_| | 187 // Whether a call to UpdateAccountList() is pending because |cros_settings_| |
(...skipping 10 matching lines...) Expand all Loading... |
215 OrphanCacheDeletionState orphan_cache_deletion_state_; | 198 OrphanCacheDeletionState orphan_cache_deletion_state_; |
216 | 199 |
217 // Account IDs whose extension cache directories are busy, either because a | 200 // Account IDs whose extension cache directories are busy, either because a |
218 // broker for the account has not shut down completely yet or because the | 201 // broker for the account has not shut down completely yet or because the |
219 // directory is being deleted. | 202 // directory is being deleted. |
220 std::set<std::string> busy_extension_cache_directories_; | 203 std::set<std::string> busy_extension_cache_directories_; |
221 | 204 |
222 const scoped_refptr<base::SequencedTaskRunner> store_background_task_runner_; | 205 const scoped_refptr<base::SequencedTaskRunner> store_background_task_runner_; |
223 const scoped_refptr<base::SequencedTaskRunner> extension_cache_task_runner_; | 206 const scoped_refptr<base::SequencedTaskRunner> extension_cache_task_runner_; |
224 | 207 |
225 scoped_ptr<DeviceLocalAccountExternalDataService> external_data_service_; | 208 ObserverList<Observer, true> observers_; |
226 | |
227 scoped_refptr<net::URLRequestContextGetter> request_context_; | |
228 | 209 |
229 const scoped_ptr<chromeos::CrosSettings::ObserverSubscription> | 210 const scoped_ptr<chromeos::CrosSettings::ObserverSubscription> |
230 local_accounts_subscription_; | 211 local_accounts_subscription_; |
231 | 212 |
232 base::WeakPtrFactory<DeviceLocalAccountPolicyService> weak_factory_; | 213 base::WeakPtrFactory<DeviceLocalAccountPolicyService> weak_factory_; |
233 | 214 |
234 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyService); | 215 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyService); |
235 }; | 216 }; |
236 | 217 |
237 } // namespace policy | 218 } // namespace policy |
238 | 219 |
239 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_SERVICE_H_ | 220 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_SERVICE_H_ |
OLD | NEW |