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

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

Powered by Google App Engine
This is Rietveld 408576698