| 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/managed_mode/managed_user_registration_utility.h" | 5 #include "chrome/browser/managed_mode/managed_user_registration_utility.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 } | 221 } |
| 222 | 222 |
| 223 void ManagedUserRegistrationUtilityImpl::Register( | 223 void ManagedUserRegistrationUtilityImpl::Register( |
| 224 const std::string& managed_user_id, | 224 const std::string& managed_user_id, |
| 225 const ManagedUserRegistrationInfo& info, | 225 const ManagedUserRegistrationInfo& info, |
| 226 const RegistrationCallback& callback) { | 226 const RegistrationCallback& callback) { |
| 227 DCHECK(pending_managed_user_id_.empty()); | 227 DCHECK(pending_managed_user_id_.empty()); |
| 228 callback_ = callback; | 228 callback_ = callback; |
| 229 pending_managed_user_id_ = managed_user_id; | 229 pending_managed_user_id_ = managed_user_id; |
| 230 | 230 |
| 231 bool need_password_update = !info.password_data.empty(); |
| 231 const base::DictionaryValue* dict = | 232 const base::DictionaryValue* dict = |
| 232 prefs_->GetDictionary(prefs::kManagedUsers); | 233 prefs_->GetDictionary(prefs::kManagedUsers); |
| 233 is_existing_managed_user_ = dict->HasKey(managed_user_id); | 234 is_existing_managed_user_ = dict->HasKey(managed_user_id); |
| 234 if (!is_existing_managed_user_) { | 235 if (!is_existing_managed_user_) { |
| 235 managed_user_sync_service_->AddManagedUser(pending_managed_user_id_, | 236 managed_user_sync_service_->AddManagedUser(pending_managed_user_id_, |
| 236 base::UTF16ToUTF8(info.name), | 237 base::UTF16ToUTF8(info.name), |
| 237 info.master_key, | 238 info.master_key, |
| 238 info.password_signature_key, | 239 info.password_signature_key, |
| 239 info.password_encryption_key, | 240 info.password_encryption_key, |
| 240 info.avatar_index); | 241 info.avatar_index); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 258 if (keys_need_update) { | 259 if (keys_need_update) { |
| 259 managed_user_sync_service_->UpdateManagedUser( | 260 managed_user_sync_service_->UpdateManagedUser( |
| 260 pending_managed_user_id_, | 261 pending_managed_user_id_, |
| 261 base::UTF16ToUTF8(info.name), | 262 base::UTF16ToUTF8(info.name), |
| 262 info.master_key, | 263 info.master_key, |
| 263 info.password_signature_key, | 264 info.password_signature_key, |
| 264 info.password_encryption_key, | 265 info.password_encryption_key, |
| 265 info.avatar_index); | 266 info.avatar_index); |
| 266 } else { | 267 } else { |
| 267 // The user already exists and does not need to be updated. | 268 // The user already exists and does not need to be updated. |
| 269 need_password_update = false; |
| 268 OnManagedUserAcknowledged(managed_user_id); | 270 OnManagedUserAcknowledged(managed_user_id); |
| 269 } | 271 } |
| 270 avatar_updated_ = | 272 avatar_updated_ = |
| 271 managed_user_sync_service_->UpdateManagedUserAvatarIfNeeded( | 273 managed_user_sync_service_->UpdateManagedUserAvatarIfNeeded( |
| 272 managed_user_id, | 274 managed_user_id, |
| 273 info.avatar_index); | 275 info.avatar_index); |
| 274 } | 276 } |
| 275 #if defined(OS_CHROMEOS) | 277 #if defined(OS_CHROMEOS) |
| 276 const char* kAvatarKey = managed_users::kChromeOSAvatarIndex; | 278 const char* kAvatarKey = managed_users::kChromeOSAvatarIndex; |
| 277 #else | 279 #else |
| 278 const char* kAvatarKey = managed_users::kChromeAvatarIndex; | 280 const char* kAvatarKey = managed_users::kChromeAvatarIndex; |
| 279 #endif | 281 #endif |
| 280 managed_user_shared_settings_service_->SetValue( | 282 managed_user_shared_settings_service_->SetValue( |
| 281 pending_managed_user_id_, kAvatarKey, | 283 pending_managed_user_id_, kAvatarKey, |
| 282 base::FundamentalValue(info.avatar_index)); | 284 base::FundamentalValue(info.avatar_index)); |
| 283 if (!info.password_data.empty()) { | 285 if (need_password_update) { |
| 284 password_update_.reset(new ManagedUserSharedSettingsUpdate( | 286 password_update_.reset(new ManagedUserSharedSettingsUpdate( |
| 285 managed_user_shared_settings_service_, | 287 managed_user_shared_settings_service_, |
| 286 pending_managed_user_id_, | 288 pending_managed_user_id_, |
| 287 managed_users::kChromeOSPasswordData, | 289 managed_users::kChromeOSPasswordData, |
| 288 scoped_ptr<base::Value>(info.password_data.DeepCopy()), | 290 scoped_ptr<base::Value>(info.password_data.DeepCopy()), |
| 289 base::Bind( | 291 base::Bind( |
| 290 &ManagedUserRegistrationUtilityImpl::OnPasswordChangeAcknowledged, | 292 &ManagedUserRegistrationUtilityImpl::OnPasswordChangeAcknowledged, |
| 291 weak_ptr_factory_.GetWeakPtr()))); | 293 weak_ptr_factory_.GetWeakPtr()))); |
| 292 } | 294 } |
| 293 | 295 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 pending_managed_user_id_); | 393 pending_managed_user_id_); |
| 392 } | 394 } |
| 393 } | 395 } |
| 394 | 396 |
| 395 if (run_callback) | 397 if (run_callback) |
| 396 callback_.Run(error, pending_managed_user_token_); | 398 callback_.Run(error, pending_managed_user_token_); |
| 397 callback_.Reset(); | 399 callback_.Reset(); |
| 398 } | 400 } |
| 399 | 401 |
| 400 } // namespace | 402 } // namespace |
| OLD | NEW |