| 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 <string> | 10 #include <string> |
| 10 | 11 |
| 11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 16 #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" |
| 17 #include "chrome/browser/chromeos/settings/cros_settings.h" | 19 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 18 #include "chrome/browser/policy/cloud/cloud_policy_core.h" | 20 #include "chrome/browser/policy/cloud/cloud_policy_core.h" |
| 19 #include "chrome/browser/policy/cloud/cloud_policy_store.h" | 21 #include "chrome/browser/policy/cloud/cloud_policy_store.h" |
| 20 | 22 |
| 21 namespace base { | 23 namespace base { |
| 22 class SequencedTaskRunner; | 24 class SequencedTaskRunner; |
| 23 } | 25 } |
| 24 | 26 |
| 25 namespace chromeos { | 27 namespace chromeos { |
| 26 class CrosSettings; | |
| 27 class DeviceSettingsService; | 28 class DeviceSettingsService; |
| 28 class SessionManagerClient; | 29 class SessionManagerClient; |
| 29 } | 30 } |
| 30 | 31 |
| 31 namespace policy { | 32 namespace policy { |
| 32 | 33 |
| 33 class CloudPolicyClient; | 34 struct DeviceLocalAccount; |
| 34 class DeviceLocalAccountPolicyStore; | 35 class DeviceLocalAccountPolicyStore; |
| 35 class DeviceManagementService; | 36 class DeviceManagementService; |
| 36 | 37 |
| 37 // The main switching central that downloads, caches, refreshes, etc. policy for | 38 // The main switching central that downloads, caches, refreshes, etc. policy for |
| 38 // a single device-local account. | 39 // a single device-local account. |
| 39 class DeviceLocalAccountPolicyBroker { | 40 class DeviceLocalAccountPolicyBroker { |
| 40 public: | 41 public: |
| 41 // |task_runner| is the runner for policy refresh tasks. | 42 // |task_runner| is the runner for policy refresh tasks. |
| 42 explicit DeviceLocalAccountPolicyBroker( | 43 DeviceLocalAccountPolicyBroker( |
| 43 const std::string& user_id, | 44 const DeviceLocalAccount& account, |
| 44 scoped_ptr<DeviceLocalAccountPolicyStore> store, | 45 scoped_ptr<DeviceLocalAccountPolicyStore> store, |
| 45 const scoped_refptr<base::SequencedTaskRunner>& task_runner); | 46 const scoped_refptr<base::SequencedTaskRunner>& task_runner); |
| 46 ~DeviceLocalAccountPolicyBroker(); | 47 ~DeviceLocalAccountPolicyBroker(); |
| 47 | 48 |
| 49 // For the difference between |account_id| and |user_id|, see the |
| 50 // documentation of DeviceLocalAccount. |
| 51 const std::string& account_id() const { return account_id_; } |
| 48 const std::string& user_id() const { return user_id_; } | 52 const std::string& user_id() const { return user_id_; } |
| 49 | 53 |
| 54 scoped_refptr<chromeos::DeviceLocalAccountExternalPolicyLoader> |
| 55 extension_loader() const { return extension_loader_; } |
| 56 |
| 50 CloudPolicyCore* core() { return &core_; } | 57 CloudPolicyCore* core() { return &core_; } |
| 51 const CloudPolicyCore* core() const { return &core_; } | 58 const CloudPolicyCore* core() const { return &core_; } |
| 52 | 59 |
| 53 // Establish a cloud connection for the service. | 60 // Fire up the cloud connection for fetching policy for the account from the |
| 54 void Connect(scoped_ptr<CloudPolicyClient> client); | 61 // cloud if this is an enterprise-managed device. |
| 62 void ConnectIfPossible( |
| 63 chromeos::DeviceSettingsService* device_settings_service, |
| 64 DeviceManagementService* device_management_service); |
| 55 | 65 |
| 56 // Destroy the cloud connection, stopping policy refreshes. | 66 // Destroy the cloud connection, stopping policy refreshes. |
| 57 void Disconnect(); | 67 void Disconnect(); |
| 58 | 68 |
| 59 // Reads the refresh delay from policy and configures the refresh scheduler. | 69 // Reads the refresh delay from policy and configures the refresh scheduler. |
| 60 void UpdateRefreshDelay(); | 70 void UpdateRefreshDelay(); |
| 61 | 71 |
| 62 // Retrieves the display name for the account as stored in policy. Returns an | 72 // Retrieves the display name for the account as stored in policy. Returns an |
| 63 // empty string if the policy is not present. | 73 // empty string if the policy is not present. |
| 64 std::string GetDisplayName() const; | 74 std::string GetDisplayName() const; |
| 65 | 75 |
| 66 private: | 76 private: |
| 77 const std::string account_id_; |
| 67 const std::string user_id_; | 78 const std::string user_id_; |
| 68 scoped_ptr<DeviceLocalAccountPolicyStore> store_; | 79 const scoped_ptr<DeviceLocalAccountPolicyStore> store_; |
| 80 scoped_refptr<chromeos::DeviceLocalAccountExternalPolicyLoader> |
| 81 extension_loader_; |
| 69 CloudPolicyCore core_; | 82 CloudPolicyCore core_; |
| 70 | 83 |
| 71 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyBroker); | 84 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyBroker); |
| 72 }; | 85 }; |
| 73 | 86 |
| 74 // Manages user policy blobs for device-local accounts present on the device. | 87 // Manages user policy blobs for device-local accounts present on the device. |
| 75 // The actual policy blobs are brokered by session_manager (to prevent file | 88 // The actual policy blobs are brokered by session_manager (to prevent file |
| 76 // manipulation), and we're making signature checks on the policy blobs to | 89 // manipulation), and we're making signature checks on the policy blobs to |
| 77 // ensure they're issued by the device owner. | 90 // ensure they're issued by the device owner. |
| 78 class DeviceLocalAccountPolicyService : public CloudPolicyStore::Observer { | 91 class DeviceLocalAccountPolicyService : public CloudPolicyStore::Observer { |
| 79 public: | 92 public: |
| 80 // Interface for interested parties to observe policy changes. | 93 // Interface for interested parties to observe policy changes. |
| 81 class Observer { | 94 class Observer { |
| 82 public: | 95 public: |
| 83 virtual ~Observer() {} | 96 virtual ~Observer() {} |
| 84 | 97 |
| 85 // Policy for the given |user_id| has changed. | 98 // Policy for the given |user_id| has changed. |
| 86 virtual void OnPolicyUpdated(const std::string& user_id) = 0; | 99 virtual void OnPolicyUpdated(const std::string& user_id) = 0; |
| 87 | 100 |
| 88 // The list of accounts has been updated. | 101 // The list of accounts has been updated. |
| 89 virtual void OnDeviceLocalAccountsChanged() = 0; | 102 virtual void OnDeviceLocalAccountsChanged() = 0; |
| 90 }; | 103 }; |
| 91 | 104 |
| 92 DeviceLocalAccountPolicyService( | 105 DeviceLocalAccountPolicyService( |
| 93 chromeos::SessionManagerClient* session_manager_client, | 106 chromeos::SessionManagerClient* session_manager_client, |
| 94 chromeos::DeviceSettingsService* device_settings_service, | 107 chromeos::DeviceSettingsService* device_settings_service, |
| 95 chromeos::CrosSettings* cros_settings); | 108 chromeos::CrosSettings* cros_settings, |
| 109 scoped_refptr<base::SequencedTaskRunner> extension_cache_task_runner); |
| 96 virtual ~DeviceLocalAccountPolicyService(); | 110 virtual ~DeviceLocalAccountPolicyService(); |
| 97 | 111 |
| 98 // Initializes the cloud policy service connection. | 112 // Initializes the cloud policy service connection. |
| 99 void Connect(DeviceManagementService* device_management_service); | 113 void Connect(DeviceManagementService* device_management_service); |
| 100 | 114 |
| 101 // Prevents further policy fetches from the cloud. | 115 // Prevents further policy fetches from the cloud. |
| 102 void Disconnect(); | 116 void Disconnect(); |
| 103 | 117 |
| 104 // Get the policy broker for a given |user_id|. Returns NULL if that |user_id| | 118 // Get the policy broker for a given |user_id|. Returns NULL if that |user_id| |
| 105 // does not belong to an existing device-local account. | 119 // does not belong to an existing device-local account. |
| 106 DeviceLocalAccountPolicyBroker* GetBrokerForUser(const std::string& user_id); | 120 DeviceLocalAccountPolicyBroker* GetBrokerForUser(const std::string& user_id); |
| 107 | 121 |
| 108 // Indicates whether policy has been successfully fetched for the given | 122 // Indicates whether policy has been successfully fetched for the given |
| 109 // |user_id|. | 123 // |user_id|. |
| 110 bool IsPolicyAvailableForUser(const std::string& user_id); | 124 bool IsPolicyAvailableForUser(const std::string& user_id); |
| 111 | 125 |
| 112 void AddObserver(Observer* observer); | 126 void AddObserver(Observer* observer); |
| 113 void RemoveObserver(Observer* observer); | 127 void RemoveObserver(Observer* observer); |
| 114 | 128 |
| 115 // CloudPolicyStore::Observer: | 129 // CloudPolicyStore::Observer: |
| 116 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; | 130 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; |
| 117 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE; | 131 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE; |
| 118 | 132 |
| 119 private: | 133 private: |
| 120 struct PolicyBrokerWrapper { | 134 typedef std::map<std::string, DeviceLocalAccountPolicyBroker*> |
| 121 PolicyBrokerWrapper(); | 135 PolicyBrokerMap; |
| 122 | 136 |
| 123 // Return the |broker|, creating it first if necessary. | 137 // Returns |true| if the directory in which force-installed extensions are |
| 124 DeviceLocalAccountPolicyBroker* GetBroker(); | 138 // cached for |account_id| is busy, either because a broker that was using |
| 139 // this directory has not shut down completely yet or because the directory is |
| 140 // being deleted. |
| 141 bool IsExtensionCacheDirectoryBusy(const std::string& account_id); |
| 125 | 142 |
| 126 // Fire up the cloud connection for fetching policy for the account from the | 143 // Starts any extension caches that are not running yet but can be started now |
| 127 // cloud if this is an enterprise-managed device. | 144 // because their cache directories are no longer busy. |
| 128 void ConnectIfPossible(); | 145 void StartExtensionCachesIfPossible(); |
| 129 | 146 |
| 130 // Destroy the cloud connection. | 147 // Checks whether a broker exists for |account_id|. If so, starts the broker's |
| 131 void Disconnect(); | 148 // extension cache and returns |true|. Otherwise, returns |false|. |
| 149 bool StartExtensionCacheForAccountIfPresent(const std::string& account_id); |
| 132 | 150 |
| 133 // Delete the broker. | 151 // Called back when any extension caches belonging to device-local accounts |
| 134 void DeleteBroker(); | 152 // that no longer exist have been removed at start-up. |
| 153 void OnOrphanedExtensionCachesDeleted(); |
| 135 | 154 |
| 136 std::string user_id; | 155 // Called back when the extension cache for |account_id| has been shut down. |
| 137 std::string account_id; | 156 void OnObsoleteExtensionCacheShutdown(const std::string& account_id); |
| 138 DeviceLocalAccountPolicyService* parent; | |
| 139 DeviceLocalAccountPolicyBroker* broker; | |
| 140 }; | |
| 141 | 157 |
| 142 typedef std::map<std::string, PolicyBrokerWrapper> PolicyBrokerMap; | 158 // Called back when the extension cache for |account_id| has been removed. |
| 159 void OnObsoleteExtensionCacheDeleted(const std::string& account_id); |
| 143 | 160 |
| 144 // Re-queries the list of defined device-local accounts from device settings | 161 // Re-queries the list of defined device-local accounts from device settings |
| 145 // and updates |policy_brokers_| to match that list. | 162 // and updates |policy_brokers_| to match that list. |
| 146 void UpdateAccountList(); | 163 void UpdateAccountList(); |
| 147 | 164 |
| 148 // Calls |UpdateAccountList| if there are no previous calls pending. | 165 // Calls |UpdateAccountList| if there are no previous calls pending. |
| 149 void UpdateAccountListIfNonePending(); | 166 void UpdateAccountListIfNonePending(); |
| 150 | 167 |
| 151 // Deletes brokers in |map| and clears it. | 168 // Deletes brokers in |map| and clears it. |
| 152 void DeleteBrokers(PolicyBrokerMap* map); | 169 void DeleteBrokers(PolicyBrokerMap* map); |
| 153 | 170 |
| 154 // Find the broker for a given |store|. Returns NULL if |store| is unknown. | 171 // Find the broker for a given |store|. Returns NULL if |store| is unknown. |
| 155 DeviceLocalAccountPolicyBroker* GetBrokerForStore(CloudPolicyStore* store); | 172 DeviceLocalAccountPolicyBroker* GetBrokerForStore(CloudPolicyStore* store); |
| 156 | 173 |
| 157 chromeos::SessionManagerClient* session_manager_client_; | 174 chromeos::SessionManagerClient* session_manager_client_; |
| 158 chromeos::DeviceSettingsService* device_settings_service_; | 175 chromeos::DeviceSettingsService* device_settings_service_; |
| 159 chromeos::CrosSettings* cros_settings_; | 176 chromeos::CrosSettings* cros_settings_; |
| 160 | 177 |
| 161 DeviceManagementService* device_management_service_; | 178 DeviceManagementService* device_management_service_; |
| 162 | 179 |
| 163 // The device-local account policy brokers, keyed by user ID. | 180 // The device-local account policy brokers, keyed by user ID. |
| 164 PolicyBrokerMap policy_brokers_; | 181 PolicyBrokerMap policy_brokers_; |
| 165 | 182 |
| 183 // Whether a call to UpdateAccountList() is pending because |cros_settings_| |
| 184 // are not trusted yet. |
| 185 bool waiting_for_cros_settings_; |
| 186 |
| 187 // Orphaned extension caches are removed at startup. This tracks the status of |
| 188 // that process. |
| 189 enum OrphanCacheDeletionState { |
| 190 NOT_STARTED, |
| 191 IN_PROGRESS, |
| 192 DONE, |
| 193 }; |
| 194 OrphanCacheDeletionState orphan_cache_deletion_state_; |
| 195 |
| 196 // Account IDs whose extension cache directories are busy, either because a |
| 197 // broker for the account has not shut down completely yet or because the |
| 198 // directory is being deleted. |
| 199 std::set<std::string> busy_extension_cache_directories_; |
| 200 |
| 201 // Background task runner on which all extension caches and cache directory |
| 202 // removal tasks run. |
| 203 const scoped_refptr<base::SequencedTaskRunner> extension_cache_task_runner_; |
| 204 |
| 166 ObserverList<Observer, true> observers_; | 205 ObserverList<Observer, true> observers_; |
| 167 | 206 |
| 168 scoped_ptr<chromeos::CrosSettings::ObserverSubscription> | 207 const scoped_ptr<chromeos::CrosSettings::ObserverSubscription> |
| 169 local_accounts_subscription_; | 208 local_accounts_subscription_; |
| 170 | 209 |
| 171 // Weak pointer factory for cros_settings_->PrepareTrustedValues() callbacks. | 210 base::WeakPtrFactory<DeviceLocalAccountPolicyService> weak_factory_; |
| 172 base::WeakPtrFactory<DeviceLocalAccountPolicyService> | |
| 173 cros_settings_callback_factory_; | |
| 174 | 211 |
| 175 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyService); | 212 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyService); |
| 176 }; | 213 }; |
| 177 | 214 |
| 178 } // namespace policy | 215 } // namespace policy |
| 179 | 216 |
| 180 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_SERVICE_H_ | 217 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_SERVICE_H_ |
| OLD | NEW |