OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "chrome/browser/chromeos/policy/cloud_external_data_policy_observer.h" | 5 #include "chrome/browser/chromeos/policy/cloud_external_data_policy_observer.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 140 |
141 device_local_accounts_subscription_ = cros_settings_->AddSettingsObserver( | 141 device_local_accounts_subscription_ = cros_settings_->AddSettingsObserver( |
142 chromeos::kAccountsPrefDeviceLocalAccounts, | 142 chromeos::kAccountsPrefDeviceLocalAccounts, |
143 base::Bind(&CloudExternalDataPolicyObserver::RetrieveDeviceLocalAccounts, | 143 base::Bind(&CloudExternalDataPolicyObserver::RetrieveDeviceLocalAccounts, |
144 base::Unretained(this))); | 144 base::Unretained(this))); |
145 } | 145 } |
146 | 146 |
147 CloudExternalDataPolicyObserver::~CloudExternalDataPolicyObserver() { | 147 CloudExternalDataPolicyObserver::~CloudExternalDataPolicyObserver() { |
148 if (device_local_account_policy_service_) | 148 if (device_local_account_policy_service_) |
149 device_local_account_policy_service_->RemoveObserver(this); | 149 device_local_account_policy_service_->RemoveObserver(this); |
150 for (DeviceLocalAccountEntryMap::iterator it = | |
151 device_local_account_entries_.begin(); | |
152 it != device_local_account_entries_.end(); ++it) { | |
153 it->second.DeleteOwnedMembers(); | |
154 } | |
155 device_local_account_entries_.clear(); | 150 device_local_account_entries_.clear(); |
156 } | 151 } |
157 | 152 |
158 void CloudExternalDataPolicyObserver::Init() { | 153 void CloudExternalDataPolicyObserver::Init() { |
159 RetrieveDeviceLocalAccounts(); | 154 RetrieveDeviceLocalAccounts(); |
160 } | 155 } |
161 | 156 |
162 void CloudExternalDataPolicyObserver::Observe( | 157 void CloudExternalDataPolicyObserver::Observe( |
163 int type, | 158 int type, |
164 const content::NotificationSource& source, | 159 const content::NotificationSource& source, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 // finds out about |user_id| and creates a |broker| for it. | 209 // finds out about |user_id| and creates a |broker| for it. |
215 return; | 210 return; |
216 } | 211 } |
217 | 212 |
218 const PolicyMap::Entry* entry = | 213 const PolicyMap::Entry* entry = |
219 broker->core()->store()->policy_map().Get(policy_); | 214 broker->core()->store()->policy_map().Get(policy_); |
220 if (!entry) { | 215 if (!entry) { |
221 DeviceLocalAccountEntryMap::iterator it = | 216 DeviceLocalAccountEntryMap::iterator it = |
222 device_local_account_entries_.find(user_id); | 217 device_local_account_entries_.find(user_id); |
223 if (it != device_local_account_entries_.end()) { | 218 if (it != device_local_account_entries_.end()) { |
224 it->second.DeleteOwnedMembers(); | |
225 device_local_account_entries_.erase(it); | 219 device_local_account_entries_.erase(it); |
226 HandleExternalDataPolicyUpdate(user_id, NULL); | 220 HandleExternalDataPolicyUpdate(user_id, NULL); |
227 } | 221 } |
228 return; | 222 return; |
229 } | 223 } |
230 | 224 |
231 PolicyMap::Entry& map_entry = device_local_account_entries_[user_id]; | 225 PolicyMap::Entry& map_entry = device_local_account_entries_[user_id]; |
232 if (map_entry.Equals(*entry)) | 226 if (map_entry.Equals(*entry)) |
233 return; | 227 return; |
234 | 228 |
235 map_entry.DeleteOwnedMembers(); | 229 map_entry = entry->DeepCopy(); |
236 map_entry = *entry->DeepCopy(); | |
237 HandleExternalDataPolicyUpdate(user_id, entry); | 230 HandleExternalDataPolicyUpdate(user_id, entry); |
238 } | 231 } |
239 | 232 |
240 void CloudExternalDataPolicyObserver::OnDeviceLocalAccountsChanged() { | 233 void CloudExternalDataPolicyObserver::OnDeviceLocalAccountsChanged() { |
241 // No action needed here, changes to the list of device-local accounts get | 234 // No action needed here, changes to the list of device-local accounts get |
242 // handled via the kAccountsPrefDeviceLocalAccounts device setting observer. | 235 // handled via the kAccountsPrefDeviceLocalAccounts device setting observer. |
243 } | 236 } |
244 | 237 |
245 void CloudExternalDataPolicyObserver::RetrieveDeviceLocalAccounts() { | 238 void CloudExternalDataPolicyObserver::RetrieveDeviceLocalAccounts() { |
246 // Schedule a callback if device policy has not yet been verified. | 239 // Schedule a callback if device policy has not yet been verified. |
(...skipping 11 matching lines...) Expand all Loading... |
258 device_local_account_list.begin(); | 251 device_local_account_list.begin(); |
259 it != device_local_account_list.end(); ++it) { | 252 it != device_local_account_list.end(); ++it) { |
260 device_local_accounts.insert(it->user_id); | 253 device_local_accounts.insert(it->user_id); |
261 } | 254 } |
262 | 255 |
263 for (DeviceLocalAccountEntryMap::iterator it = | 256 for (DeviceLocalAccountEntryMap::iterator it = |
264 device_local_account_entries_.begin(); | 257 device_local_account_entries_.begin(); |
265 it != device_local_account_entries_.end(); ) { | 258 it != device_local_account_entries_.end(); ) { |
266 if (!ContainsKey(device_local_accounts, it->first)) { | 259 if (!ContainsKey(device_local_accounts, it->first)) { |
267 const std::string user_id = it->first; | 260 const std::string user_id = it->first; |
268 it->second.DeleteOwnedMembers(); | |
269 device_local_account_entries_.erase(it++); | 261 device_local_account_entries_.erase(it++); |
270 // When a device-local account whose external data reference was set is | 262 // When a device-local account whose external data reference was set is |
271 // removed, emit a notification that the external data reference has been | 263 // removed, emit a notification that the external data reference has been |
272 // cleared. | 264 // cleared. |
273 HandleExternalDataPolicyUpdate(user_id, NULL); | 265 HandleExternalDataPolicyUpdate(user_id, NULL); |
274 } else { | 266 } else { |
275 ++it; | 267 ++it; |
276 } | 268 } |
277 } | 269 } |
278 | 270 |
(...skipping 29 matching lines...) Expand all Loading... |
308 void CloudExternalDataPolicyObserver::OnExternalDataFetched( | 300 void CloudExternalDataPolicyObserver::OnExternalDataFetched( |
309 const std::string& user_id, | 301 const std::string& user_id, |
310 std::unique_ptr<std::string> data) { | 302 std::unique_ptr<std::string> data) { |
311 FetchWeakPtrMap::iterator it = fetch_weak_ptrs_.find(user_id); | 303 FetchWeakPtrMap::iterator it = fetch_weak_ptrs_.find(user_id); |
312 DCHECK(it != fetch_weak_ptrs_.end()); | 304 DCHECK(it != fetch_weak_ptrs_.end()); |
313 fetch_weak_ptrs_.erase(it); | 305 fetch_weak_ptrs_.erase(it); |
314 delegate_->OnExternalDataFetched(policy_, user_id, std::move(data)); | 306 delegate_->OnExternalDataFetched(policy_, user_id, std::move(data)); |
315 } | 307 } |
316 | 308 |
317 } // namespace policy | 309 } // namespace policy |
OLD | NEW |