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

Side by Side Diff: chrome/browser/chromeos/policy/device_local_account_policy_service.h

Issue 27548004: Cache force-installed apps/extensions in device-local accounts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Ready to reland after revert due to conflicting concurrent commit. Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
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 // Initialize the broker, loading its |store_|.
50 void Initialize();
51
52 // For the difference between |account_id| and |user_id|, see the
53 // documentation of DeviceLocalAccount.
54 const std::string& account_id() const { return account_id_; }
48 const std::string& user_id() const { return user_id_; } 55 const std::string& user_id() const { return user_id_; }
49 56
57 scoped_refptr<chromeos::DeviceLocalAccountExternalPolicyLoader>
58 extension_loader() const { return extension_loader_; }
59
50 CloudPolicyCore* core() { return &core_; } 60 CloudPolicyCore* core() { return &core_; }
51 const CloudPolicyCore* core() const { return &core_; } 61 const CloudPolicyCore* core() const { return &core_; }
52 62
53 // Establish a cloud connection for the service. 63 // Fire up the cloud connection for fetching policy for the account from the
54 void Connect(scoped_ptr<CloudPolicyClient> client); 64 // cloud if this is an enterprise-managed device.
65 void ConnectIfPossible(
66 chromeos::DeviceSettingsService* device_settings_service,
67 DeviceManagementService* device_management_service);
55 68
56 // Destroy the cloud connection, stopping policy refreshes. 69 // Destroy the cloud connection, stopping policy refreshes.
57 void Disconnect(); 70 void Disconnect();
58 71
59 // Reads the refresh delay from policy and configures the refresh scheduler. 72 // Reads the refresh delay from policy and configures the refresh scheduler.
60 void UpdateRefreshDelay(); 73 void UpdateRefreshDelay();
61 74
62 // 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
63 // empty string if the policy is not present. 76 // empty string if the policy is not present.
64 std::string GetDisplayName() const; 77 std::string GetDisplayName() const;
65 78
66 private: 79 private:
80 const std::string account_id_;
67 const std::string user_id_; 81 const std::string user_id_;
68 scoped_ptr<DeviceLocalAccountPolicyStore> store_; 82 const scoped_ptr<DeviceLocalAccountPolicyStore> store_;
83 scoped_refptr<chromeos::DeviceLocalAccountExternalPolicyLoader>
84 extension_loader_;
69 CloudPolicyCore core_; 85 CloudPolicyCore core_;
70 86
71 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyBroker); 87 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyBroker);
72 }; 88 };
73 89
74 // 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.
75 // 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
76 // 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
77 // ensure they're issued by the device owner. 93 // ensure they're issued by the device owner.
78 class DeviceLocalAccountPolicyService : public CloudPolicyStore::Observer { 94 class DeviceLocalAccountPolicyService : public CloudPolicyStore::Observer {
79 public: 95 public:
80 // Interface for interested parties to observe policy changes. 96 // Interface for interested parties to observe policy changes.
81 class Observer { 97 class Observer {
82 public: 98 public:
83 virtual ~Observer() {} 99 virtual ~Observer() {}
84 100
85 // Policy for the given |user_id| has changed. 101 // Policy for the given |user_id| has changed.
86 virtual void OnPolicyUpdated(const std::string& user_id) = 0; 102 virtual void OnPolicyUpdated(const std::string& user_id) = 0;
87 103
88 // The list of accounts has been updated. 104 // The list of accounts has been updated.
89 virtual void OnDeviceLocalAccountsChanged() = 0; 105 virtual void OnDeviceLocalAccountsChanged() = 0;
90 }; 106 };
91 107
92 DeviceLocalAccountPolicyService( 108 DeviceLocalAccountPolicyService(
93 chromeos::SessionManagerClient* session_manager_client, 109 chromeos::SessionManagerClient* session_manager_client,
94 chromeos::DeviceSettingsService* device_settings_service, 110 chromeos::DeviceSettingsService* device_settings_service,
95 chromeos::CrosSettings* cros_settings, 111 chromeos::CrosSettings* cros_settings,
96 scoped_refptr<base::SequencedTaskRunner> background_task_runner); 112 scoped_refptr<base::SequencedTaskRunner> store_background_task_runner,
113 scoped_refptr<base::SequencedTaskRunner> extension_cache_task_runner);
97 virtual ~DeviceLocalAccountPolicyService(); 114 virtual ~DeviceLocalAccountPolicyService();
98 115
99 // Initializes the cloud policy service connection. 116 // Initializes the cloud policy service connection.
100 void Connect(DeviceManagementService* device_management_service); 117 void Connect(DeviceManagementService* device_management_service);
101 118
102 // Prevents further policy fetches from the cloud. 119 // Prevents further policy fetches from the cloud.
103 void Disconnect(); 120 void Disconnect();
104 121
105 // 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|
106 // does not belong to an existing device-local account. 123 // does not belong to an existing device-local account.
107 DeviceLocalAccountPolicyBroker* GetBrokerForUser(const std::string& user_id); 124 DeviceLocalAccountPolicyBroker* GetBrokerForUser(const std::string& user_id);
108 125
109 // Indicates whether policy has been successfully fetched for the given 126 // Indicates whether policy has been successfully fetched for the given
110 // |user_id|. 127 // |user_id|.
111 bool IsPolicyAvailableForUser(const std::string& user_id); 128 bool IsPolicyAvailableForUser(const std::string& user_id);
112 129
113 void AddObserver(Observer* observer); 130 void AddObserver(Observer* observer);
114 void RemoveObserver(Observer* observer); 131 void RemoveObserver(Observer* observer);
115 132
116 // CloudPolicyStore::Observer: 133 // CloudPolicyStore::Observer:
117 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; 134 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE;
118 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE; 135 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE;
119 136
120 private: 137 private:
121 struct PolicyBrokerWrapper { 138 typedef std::map<std::string, DeviceLocalAccountPolicyBroker*>
122 PolicyBrokerWrapper(); 139 PolicyBrokerMap;
123 ~PolicyBrokerWrapper();
124 140
125 // Return the |broker|, creating it first if necessary. 141 // Returns |true| if the directory in which force-installed extensions are
126 DeviceLocalAccountPolicyBroker* GetBroker(); 142 // cached for |account_id| is busy, either because a broker that was using
143 // this directory has not shut down completely yet or because the directory is
144 // being deleted.
145 bool IsExtensionCacheDirectoryBusy(const std::string& account_id);
127 146
128 // Fire up the cloud connection for fetching policy for the account from the 147 // Starts any extension caches that are not running yet but can be started now
129 // cloud if this is an enterprise-managed device. 148 // because their cache directories are no longer busy.
130 void ConnectIfPossible(); 149 void StartExtensionCachesIfPossible();
131 150
132 // Destroy the cloud connection. 151 // Checks whether a broker exists for |account_id|. If so, starts the broker's
133 void Disconnect(); 152 // extension cache and returns |true|. Otherwise, returns |false|.
153 bool StartExtensionCacheForAccountIfPresent(const std::string& account_id);
134 154
135 // Delete the broker. 155 // Called back when any extension caches belonging to device-local accounts
136 void DeleteBroker(); 156 // that no longer exist have been removed at start-up.
157 void OnOrphanedExtensionCachesDeleted();
137 158
138 std::string user_id; 159 // Called back when the extension cache for |account_id| has been shut down.
139 std::string account_id; 160 void OnObsoleteExtensionCacheShutdown(const std::string& account_id);
140 DeviceLocalAccountPolicyService* parent;
141 DeviceLocalAccountPolicyBroker* broker;
142 scoped_refptr<base::SequencedTaskRunner> background_task_runner;
143 };
144 161
145 typedef std::map<std::string, PolicyBrokerWrapper> PolicyBrokerMap; 162 // Called back when the extension cache for |account_id| has been removed.
163 void OnObsoleteExtensionCacheDeleted(const std::string& account_id);
146 164
147 // Re-queries the list of defined device-local accounts from device settings 165 // Re-queries the list of defined device-local accounts from device settings
148 // and updates |policy_brokers_| to match that list. 166 // and updates |policy_brokers_| to match that list.
149 void UpdateAccountList(); 167 void UpdateAccountList();
150 168
151 // Calls |UpdateAccountList| if there are no previous calls pending. 169 // Calls |UpdateAccountList| if there are no previous calls pending.
152 void UpdateAccountListIfNonePending(); 170 void UpdateAccountListIfNonePending();
153 171
154 // Deletes brokers in |map| and clears it. 172 // Deletes brokers in |map| and clears it.
155 void DeleteBrokers(PolicyBrokerMap* map); 173 void DeleteBrokers(PolicyBrokerMap* map);
156 174
157 // 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.
158 DeviceLocalAccountPolicyBroker* GetBrokerForStore(CloudPolicyStore* store); 176 DeviceLocalAccountPolicyBroker* GetBrokerForStore(CloudPolicyStore* store);
159 177
160 chromeos::SessionManagerClient* session_manager_client_; 178 chromeos::SessionManagerClient* session_manager_client_;
161 chromeos::DeviceSettingsService* device_settings_service_; 179 chromeos::DeviceSettingsService* device_settings_service_;
162 chromeos::CrosSettings* cros_settings_; 180 chromeos::CrosSettings* cros_settings_;
163 181
164 DeviceManagementService* device_management_service_; 182 DeviceManagementService* device_management_service_;
165 183
166 // The device-local account policy brokers, keyed by user ID. 184 // The device-local account policy brokers, keyed by user ID.
167 PolicyBrokerMap policy_brokers_; 185 PolicyBrokerMap policy_brokers_;
168 186
187 // Whether a call to UpdateAccountList() is pending because |cros_settings_|
188 // are not trusted yet.
189 bool waiting_for_cros_settings_;
190
191 // Orphaned extension caches are removed at startup. This tracks the status of
192 // that process.
193 enum OrphanCacheDeletionState {
194 NOT_STARTED,
195 IN_PROGRESS,
196 DONE,
197 };
198 OrphanCacheDeletionState orphan_cache_deletion_state_;
199
200 // Account IDs whose extension cache directories are busy, either because a
201 // broker for the account has not shut down completely yet or because the
202 // directory is being deleted.
203 std::set<std::string> busy_extension_cache_directories_;
204
205 const scoped_refptr<base::SequencedTaskRunner> store_background_task_runner_;
206 const scoped_refptr<base::SequencedTaskRunner> extension_cache_task_runner_;
207
169 ObserverList<Observer, true> observers_; 208 ObserverList<Observer, true> observers_;
170 209
171 scoped_ptr<chromeos::CrosSettings::ObserverSubscription> 210 const scoped_ptr<chromeos::CrosSettings::ObserverSubscription>
172 local_accounts_subscription_; 211 local_accounts_subscription_;
173 212
174 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; 213 base::WeakPtrFactory<DeviceLocalAccountPolicyService> weak_factory_;
175
176 // Weak pointer factory for cros_settings_->PrepareTrustedValues() callbacks.
177 base::WeakPtrFactory<DeviceLocalAccountPolicyService>
178 cros_settings_callback_factory_;
179 214
180 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyService); 215 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyService);
181 }; 216 };
182 217
183 } // namespace policy 218 } // namespace policy
184 219
185 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_SERVICE_H_ 220 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698