| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/login/managed/managed_user_creation_controller
_new.h" | 5 #include "chrome/browser/chromeos/login/managed/managed_user_creation_controller
_new.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/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 | 138 |
| 139 StartCreationImpl(); | 139 StartCreationImpl(); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void ManagedUserCreationControllerNew::StartCreationImpl() { | 142 void ManagedUserCreationControllerNew::StartCreationImpl() { |
| 143 DCHECK(creation_context_); | 143 DCHECK(creation_context_); |
| 144 DCHECK_EQ(STAGE_INITIAL, stage_); | 144 DCHECK_EQ(STAGE_INITIAL, stage_); |
| 145 VLOG(1) << "Starting supervised user creation"; | 145 VLOG(1) << "Starting supervised user creation"; |
| 146 VLOG(1) << " Phase 1 : Prepare keys"; | 146 VLOG(1) << " Phase 1 : Prepare keys"; |
| 147 | 147 |
| 148 SupervisedUserManager* manager = | 148 SupervisedUserManager* manager = GetUserManager()->GetSupervisedUserManager(); |
| 149 UserManager::Get()->GetSupervisedUserManager(); | |
| 150 manager->StartCreationTransaction(creation_context_->display_name); | 149 manager->StartCreationTransaction(creation_context_->display_name); |
| 151 | 150 |
| 152 creation_context_->local_user_id = manager->GenerateUserId(); | 151 creation_context_->local_user_id = manager->GenerateUserId(); |
| 153 if (creation_context_->creation_type == NEW_USER) { | 152 if (creation_context_->creation_type == NEW_USER) { |
| 154 creation_context_->sync_user_id = | 153 creation_context_->sync_user_id = |
| 155 SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId(); | 154 SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId(); |
| 156 } | 155 } |
| 157 | 156 |
| 158 manager->SetCreationTransactionUserId(creation_context_->local_user_id); | 157 manager->SetCreationTransactionUserId(creation_context_->local_user_id); |
| 159 | 158 |
| 160 stage_ = TRANSACTION_STARTED; | 159 stage_ = TRANSACTION_STARTED; |
| 161 | 160 |
| 162 manager->CreateUserRecord(creation_context_->manager_id, | 161 manager->CreateUserRecord(creation_context_->manager_id, |
| 163 creation_context_->local_user_id, | 162 creation_context_->local_user_id, |
| 164 creation_context_->sync_user_id, | 163 creation_context_->sync_user_id, |
| 165 creation_context_->display_name); | 164 creation_context_->display_name); |
| 166 | 165 |
| 167 SupervisedUserAuthentication* authentication = | 166 SupervisedUserAuthentication* authentication = |
| 168 UserManager::Get()->GetSupervisedUserManager()->GetAuthentication(); | 167 GetUserManager()->GetSupervisedUserManager()->GetAuthentication(); |
| 169 | 168 |
| 170 // When importing M35+ users we need only to store data, for all other cases | 169 // When importing M35+ users we need only to store data, for all other cases |
| 171 // we need to create some keys. | 170 // we need to create some keys. |
| 172 if (creation_context_->creation_type != USER_IMPORT_NEW) { | 171 if (creation_context_->creation_type != USER_IMPORT_NEW) { |
| 173 // Of all required keys old imported users have only master key. | 172 // Of all required keys old imported users have only master key. |
| 174 // Otherwise they are the same as newly created users in terms of keys. | 173 // Otherwise they are the same as newly created users in terms of keys. |
| 175 if (creation_context_->creation_type == NEW_USER) { | 174 if (creation_context_->creation_type == NEW_USER) { |
| 176 creation_context_->master_key = authentication->GenerateMasterKey(); | 175 creation_context_->master_key = authentication->GenerateMasterKey(); |
| 177 } | 176 } |
| 178 | 177 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 DCHECK_EQ(DASHBOARD_CREATED, stage_); | 355 DCHECK_EQ(DASHBOARD_CREATED, stage_); |
| 357 | 356 |
| 358 if (!success) { | 357 if (!success) { |
| 359 stage_ = STAGE_ERROR; | 358 stage_ = STAGE_ERROR; |
| 360 if (consumer_) | 359 if (consumer_) |
| 361 consumer_->OnCreationError(TOKEN_WRITE_FAILED); | 360 consumer_->OnCreationError(TOKEN_WRITE_FAILED); |
| 362 return; | 361 return; |
| 363 } | 362 } |
| 364 // Assume that new token is valid. It will be automatically invalidated if | 363 // Assume that new token is valid. It will be automatically invalidated if |
| 365 // sync service fails to use it. | 364 // sync service fails to use it. |
| 366 UserManager::Get()->SaveUserOAuthStatus(creation_context_->local_user_id, | 365 GetUserManager()->SaveUserOAuthStatus(creation_context_->local_user_id, |
| 367 User::OAUTH2_TOKEN_STATUS_VALID); | 366 User::OAUTH2_TOKEN_STATUS_VALID); |
| 368 | 367 |
| 369 stage_ = TOKEN_WRITTEN; | 368 stage_ = TOKEN_WRITTEN; |
| 370 | 369 |
| 371 timeout_timer_.Stop(); | 370 timeout_timer_.Stop(); |
| 372 UserManager::Get()->GetSupervisedUserManager()->CommitCreationTransaction(); | 371 GetUserManager()->GetSupervisedUserManager()->CommitCreationTransaction(); |
| 373 content::RecordAction( | 372 content::RecordAction( |
| 374 base::UserMetricsAction("ManagedMode_LocallyManagedUserCreated")); | 373 base::UserMetricsAction("ManagedMode_LocallyManagedUserCreated")); |
| 375 | 374 |
| 376 stage_ = TRANSACTION_COMMITTED; | 375 stage_ = TRANSACTION_COMMITTED; |
| 377 | 376 |
| 378 if (consumer_) | 377 if (consumer_) |
| 379 consumer_->OnCreationSuccess(); | 378 consumer_->OnCreationSuccess(); |
| 380 } | 379 } |
| 381 | 380 |
| 382 void ManagedUserCreationControllerNew::CreationTimedOut() { | 381 void ManagedUserCreationControllerNew::CreationTimedOut() { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 393 creation_context_->registration_utility.reset(); | 392 creation_context_->registration_utility.reset(); |
| 394 chrome::AttemptUserExit(); | 393 chrome::AttemptUserExit(); |
| 395 } | 394 } |
| 396 | 395 |
| 397 std::string ManagedUserCreationControllerNew::GetManagedUserId() { | 396 std::string ManagedUserCreationControllerNew::GetManagedUserId() { |
| 398 DCHECK(creation_context_); | 397 DCHECK(creation_context_); |
| 399 return creation_context_->local_user_id; | 398 return creation_context_->local_user_id; |
| 400 } | 399 } |
| 401 | 400 |
| 402 } // namespace chromeos | 401 } // namespace chromeos |
| OLD | NEW |