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

Side by Side Diff: chrome/browser/chromeos/policy/cloud_external_data_policy_observer.cc

Issue 1165323004: We should use UserID object to identify users instead of username. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
OLDNEW
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 <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 20 matching lines...) Expand all
31 #include "content/public/browser/notification_source.h" 31 #include "content/public/browser/notification_source.h"
32 32
33 namespace policy { 33 namespace policy {
34 34
35 // Helper class that observes a policy for a logged-in user, notifying the 35 // Helper class that observes a policy for a logged-in user, notifying the
36 // |parent_| whenever the external data reference for this user changes. 36 // |parent_| whenever the external data reference for this user changes.
37 class CloudExternalDataPolicyObserver::PolicyServiceObserver 37 class CloudExternalDataPolicyObserver::PolicyServiceObserver
38 : public PolicyService::Observer { 38 : public PolicyService::Observer {
39 public: 39 public:
40 PolicyServiceObserver(CloudExternalDataPolicyObserver* parent, 40 PolicyServiceObserver(CloudExternalDataPolicyObserver* parent,
41 const std::string& user_id, 41 const user_manager::UserID& user_id,
42 PolicyService* policy_service); 42 PolicyService* policy_service);
43 ~PolicyServiceObserver() override; 43 ~PolicyServiceObserver() override;
44 44
45 // PolicyService::Observer: 45 // PolicyService::Observer:
46 void OnPolicyUpdated(const PolicyNamespace& ns, 46 void OnPolicyUpdated(const PolicyNamespace& ns,
47 const PolicyMap& previous, 47 const PolicyMap& previous,
48 const PolicyMap& current) override; 48 const PolicyMap& current) override;
49 49
50 private: 50 private:
51 CloudExternalDataPolicyObserver* parent_; 51 CloudExternalDataPolicyObserver* parent_;
52 const std::string user_id_; 52 const user_manager::UserID user_id_;
53 PolicyService* policy_service_; 53 PolicyService* policy_service_;
54 54
55 DISALLOW_COPY_AND_ASSIGN(PolicyServiceObserver); 55 DISALLOW_COPY_AND_ASSIGN(PolicyServiceObserver);
56 }; 56 };
57 57
58 CloudExternalDataPolicyObserver::PolicyServiceObserver::PolicyServiceObserver( 58 CloudExternalDataPolicyObserver::PolicyServiceObserver::PolicyServiceObserver(
59 CloudExternalDataPolicyObserver* parent, 59 CloudExternalDataPolicyObserver* parent,
60 const std::string& user_id, 60 const user_manager::UserID& user_id,
61 PolicyService* policy_service) 61 PolicyService* policy_service)
62 : parent_(parent), 62 : parent_(parent),
63 user_id_(user_id), 63 user_id_(user_id),
64 policy_service_(policy_service) { 64 policy_service_(policy_service) {
65 policy_service_->AddObserver(POLICY_DOMAIN_CHROME, this); 65 policy_service_->AddObserver(POLICY_DOMAIN_CHROME, this);
66 66
67 if (!IsDeviceLocalAccountUser(user_id, NULL)) { 67 if (!IsDeviceLocalAccountUser(user_id, NULL)) {
68 // Notify |parent_| if the external data reference for |user_id_| is set 68 // Notify |parent_| if the external data reference for |user_id_| is set
69 // during login. This is omitted for device-local accounts because their 69 // during login. This is omitted for device-local accounts because their
70 // policy is available before login and the external data reference will 70 // policy is available before login and the external data reference will
(...skipping 24 matching lines...) Expand all
95 (previous_entry && current_entry && 95 (previous_entry && current_entry &&
96 !previous_entry->Equals(*current_entry))) { 96 !previous_entry->Equals(*current_entry))) {
97 // Notify |parent_| if the external data reference for |user_id_| has 97 // Notify |parent_| if the external data reference for |user_id_| has
98 // changed. 98 // changed.
99 parent_->HandleExternalDataPolicyUpdate(user_id_, current_entry); 99 parent_->HandleExternalDataPolicyUpdate(user_id_, current_entry);
100 } 100 }
101 } 101 }
102 102
103 void CloudExternalDataPolicyObserver::Delegate::OnExternalDataSet( 103 void CloudExternalDataPolicyObserver::Delegate::OnExternalDataSet(
104 const std::string& policy, 104 const std::string& policy,
105 const std::string& user_id) { 105 const user_manager::UserID& user_id) {
106 } 106 }
107 107
108 void CloudExternalDataPolicyObserver::Delegate::OnExternalDataCleared( 108 void CloudExternalDataPolicyObserver::Delegate::OnExternalDataCleared(
109 const std::string& policy, 109 const std::string& policy,
110 const std::string& user_id) { 110 const user_manager::UserID& user_id) {
111 } 111 }
112 112
113 void CloudExternalDataPolicyObserver::Delegate::OnExternalDataFetched( 113 void CloudExternalDataPolicyObserver::Delegate::OnExternalDataFetched(
114 const std::string& policy, 114 const std::string& policy,
115 const std::string& user_id, 115 const user_manager::UserID& user_id,
116 scoped_ptr<std::string> data) { 116 scoped_ptr<std::string> data) {
117 } 117 }
118 118
119 CloudExternalDataPolicyObserver::Delegate::~Delegate() { 119 CloudExternalDataPolicyObserver::Delegate::~Delegate() {
120 } 120 }
121 121
122 CloudExternalDataPolicyObserver::CloudExternalDataPolicyObserver( 122 CloudExternalDataPolicyObserver::CloudExternalDataPolicyObserver(
123 chromeos::CrosSettings* cros_settings, 123 chromeos::CrosSettings* cros_settings,
124 DeviceLocalAccountPolicyService* device_local_account_policy_service, 124 DeviceLocalAccountPolicyService* device_local_account_policy_service,
125 const std::string& policy, 125 const std::string& policy,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 } 168 }
169 Profile* profile = content::Details<Profile>(details).ptr(); 169 Profile* profile = content::Details<Profile>(details).ptr();
170 170
171 const user_manager::User* user = 171 const user_manager::User* user =
172 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); 172 chromeos::ProfileHelper::Get()->GetUserByProfile(profile);
173 if (!user) { 173 if (!user) {
174 NOTREACHED(); 174 NOTREACHED();
175 return; 175 return;
176 } 176 }
177 177
178 const std::string& user_id = user->email(); 178 const user_manager::UserID& user_id = user->GetUserID();
179 if (ContainsKey(logged_in_user_observers_, user_id)) { 179 if (ContainsKey(logged_in_user_observers_, user_id)) {
180 NOTREACHED(); 180 NOTREACHED();
181 return; 181 return;
182 } 182 }
183 183
184 ProfilePolicyConnector* policy_connector = 184 ProfilePolicyConnector* policy_connector =
185 ProfilePolicyConnectorFactory::GetForBrowserContext(profile); 185 ProfilePolicyConnectorFactory::GetForBrowserContext(profile);
186 logged_in_user_observers_[user_id] = make_linked_ptr( 186 logged_in_user_observers_[user_id] = make_linked_ptr(
187 new PolicyServiceObserver(this, 187 new PolicyServiceObserver(this,
188 user_id, 188 user_id,
189 policy_connector->policy_service())); 189 policy_connector->policy_service()));
190 } 190 }
191 191
192 void CloudExternalDataPolicyObserver::OnPolicyUpdated( 192 void CloudExternalDataPolicyObserver::OnPolicyUpdated(
193 const std::string& user_id) { 193 const user_manager::UserID& user_id) {
194 if (ContainsKey(logged_in_user_observers_, user_id)) { 194 if (ContainsKey(logged_in_user_observers_, user_id)) {
195 // When a device-local account is logged in, a policy change triggers both 195 // When a device-local account is logged in, a policy change triggers both
196 // OnPolicyUpdated() and PolicyServiceObserver::OnPolicyUpdated(). Ignore 196 // OnPolicyUpdated() and PolicyServiceObserver::OnPolicyUpdated(). Ignore
197 // the former so that the policy change is handled only once. 197 // the former so that the policy change is handled only once.
198 return; 198 return;
199 } 199 }
200 200
201 if (!device_local_account_policy_service_) { 201 if (!device_local_account_policy_service_) {
202 NOTREACHED(); 202 NOTREACHED();
203 return; 203 return;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 // Schedule a callback if device policy has not yet been verified. 245 // Schedule a callback if device policy has not yet been verified.
246 if (chromeos::CrosSettingsProvider::TRUSTED != 246 if (chromeos::CrosSettingsProvider::TRUSTED !=
247 cros_settings_->PrepareTrustedValues(base::Bind( 247 cros_settings_->PrepareTrustedValues(base::Bind(
248 &CloudExternalDataPolicyObserver::RetrieveDeviceLocalAccounts, 248 &CloudExternalDataPolicyObserver::RetrieveDeviceLocalAccounts,
249 weak_factory_.GetWeakPtr()))) { 249 weak_factory_.GetWeakPtr()))) {
250 return; 250 return;
251 } 251 }
252 252
253 std::vector<DeviceLocalAccount> device_local_account_list = 253 std::vector<DeviceLocalAccount> device_local_account_list =
254 policy::GetDeviceLocalAccounts(cros_settings_); 254 policy::GetDeviceLocalAccounts(cros_settings_);
255 std::set<std::string> device_local_accounts; 255 std::set<user_manager::UserID> device_local_accounts;
256 for (std::vector<DeviceLocalAccount>::const_iterator it = 256 for (std::vector<DeviceLocalAccount>::const_iterator it =
257 device_local_account_list.begin(); 257 device_local_account_list.begin();
258 it != device_local_account_list.end(); ++it) { 258 it != device_local_account_list.end(); ++it) {
259 device_local_accounts.insert(it->user_id); 259 device_local_accounts.insert(it->user_id);
260 } 260 }
261 261
262 for (DeviceLocalAccountEntryMap::iterator it = 262 for (DeviceLocalAccountEntryMap::iterator it =
263 device_local_account_entries_.begin(); 263 device_local_account_entries_.begin();
264 it != device_local_account_entries_.end(); ) { 264 it != device_local_account_entries_.end(); ) {
265 if (!ContainsKey(device_local_accounts, it->first)) { 265 if (!ContainsKey(device_local_accounts, it->first)) {
266 const std::string user_id = it->first; 266 const user_manager::UserID user_id = it->first;
267 it->second.DeleteOwnedMembers(); 267 it->second.DeleteOwnedMembers();
268 device_local_account_entries_.erase(it++); 268 device_local_account_entries_.erase(it++);
269 // When a device-local account whose external data reference was set is 269 // When a device-local account whose external data reference was set is
270 // removed, emit a notification that the external data reference has been 270 // removed, emit a notification that the external data reference has been
271 // cleared. 271 // cleared.
272 HandleExternalDataPolicyUpdate(user_id, NULL); 272 HandleExternalDataPolicyUpdate(user_id, NULL);
273 } else { 273 } else {
274 ++it; 274 ++it;
275 } 275 }
276 } 276 }
277 277
278 for (std::set<std::string>::const_iterator it = device_local_accounts.begin(); 278 for (std::set<user_manager::UserID>::const_iterator it = device_local_accounts .begin();
279 it != device_local_accounts.end(); ++it) { 279 it != device_local_accounts.end(); ++it) {
280 OnPolicyUpdated(*it); 280 OnPolicyUpdated(*it);
281 } 281 }
282 } 282 }
283 283
284 void CloudExternalDataPolicyObserver::HandleExternalDataPolicyUpdate( 284 void CloudExternalDataPolicyObserver::HandleExternalDataPolicyUpdate(
285 const std::string& user_id, 285 const user_manager::UserID& user_id,
286 const PolicyMap::Entry* entry) { 286 const PolicyMap::Entry* entry) {
287 if (!entry) { 287 if (!entry) {
288 delegate_->OnExternalDataCleared(policy_, user_id); 288 delegate_->OnExternalDataCleared(policy_, user_id);
289 fetch_weak_ptrs_.erase(user_id); 289 fetch_weak_ptrs_.erase(user_id);
290 return; 290 return;
291 } 291 }
292 292
293 delegate_->OnExternalDataSet(policy_, user_id); 293 delegate_->OnExternalDataSet(policy_, user_id);
294 294
295 linked_ptr<WeakPtrFactory>& weak_ptr_factory = fetch_weak_ptrs_[user_id]; 295 linked_ptr<WeakPtrFactory>& weak_ptr_factory = fetch_weak_ptrs_[user_id];
296 weak_ptr_factory.reset(new WeakPtrFactory(this)); 296 weak_ptr_factory.reset(new WeakPtrFactory(this));
297 if (entry->external_data_fetcher) { 297 if (entry->external_data_fetcher) {
298 entry->external_data_fetcher->Fetch(base::Bind( 298 entry->external_data_fetcher->Fetch(base::Bind(
299 &CloudExternalDataPolicyObserver::OnExternalDataFetched, 299 &CloudExternalDataPolicyObserver::OnExternalDataFetched,
300 weak_ptr_factory->GetWeakPtr(), 300 weak_ptr_factory->GetWeakPtr(),
301 user_id)); 301 user_id));
302 } else { 302 } else {
303 NOTREACHED(); 303 NOTREACHED();
304 } 304 }
305 } 305 }
306 306
307 void CloudExternalDataPolicyObserver::OnExternalDataFetched( 307 void CloudExternalDataPolicyObserver::OnExternalDataFetched(
308 const std::string& user_id, 308 const user_manager::UserID& user_id,
309 scoped_ptr<std::string> data) { 309 scoped_ptr<std::string> data) {
310 FetchWeakPtrMap::iterator it = fetch_weak_ptrs_.find(user_id); 310 FetchWeakPtrMap::iterator it = fetch_weak_ptrs_.find(user_id);
311 DCHECK(it != fetch_weak_ptrs_.end()); 311 DCHECK(it != fetch_weak_ptrs_.end());
312 fetch_weak_ptrs_.erase(it); 312 fetch_weak_ptrs_.erase(it);
313 delegate_->OnExternalDataFetched(policy_, user_id, data.Pass()); 313 delegate_->OnExternalDataFetched(policy_, user_id, data.Pass());
314 } 314 }
315 315
316 } // namespace policy 316 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698