| 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/supervised/supervised_user_creation_cont
roller_new.h" | 5 #include "chrome/browser/chromeos/login/supervised/supervised_user_creation_cont
roller_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" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/sys_info.h" | 13 #include "base/sys_info.h" |
| 14 #include "base/task_runner_util.h" | 14 #include "base/task_runner_util.h" |
| 15 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/chromeos/login/auth/mount_manager.h" | 17 #include "chrome/browser/chromeos/login/auth/mount_manager.h" |
| 18 #include "chrome/browser/chromeos/login/supervised/supervised_user_authenticatio
n.h" | 18 #include "chrome/browser/chromeos/login/supervised/supervised_user_authenticatio
n.h" |
| 19 #include "chrome/browser/chromeos/login/supervised/supervised_user_constants.h" | 19 #include "chrome/browser/chromeos/login/supervised/supervised_user_constants.h" |
| 20 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
| 20 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" | 21 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" |
| 21 #include "chrome/browser/chromeos/login/users/user_manager.h" | |
| 22 #include "chrome/browser/lifetime/application_lifetime.h" | 22 #include "chrome/browser/lifetime/application_lifetime.h" |
| 23 #include "chrome/browser/sync/profile_sync_service.h" | 23 #include "chrome/browser/sync/profile_sync_service.h" |
| 24 #include "chrome/browser/sync/profile_sync_service_factory.h" | 24 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 25 #include "chromeos/cryptohome/cryptohome_parameters.h" | 25 #include "chromeos/cryptohome/cryptohome_parameters.h" |
| 26 #include "chromeos/dbus/dbus_thread_manager.h" | 26 #include "chromeos/dbus/dbus_thread_manager.h" |
| 27 #include "chromeos/dbus/session_manager_client.h" | 27 #include "chromeos/dbus/session_manager_client.h" |
| 28 #include "chromeos/login/auth/key.h" | 28 #include "chromeos/login/auth/key.h" |
| 29 #include "chromeos/login/auth/user_context.h" | 29 #include "chromeos/login/auth/user_context.h" |
| 30 #include "components/user_manager/user.h" | 30 #include "components/user_manager/user.h" |
| 31 #include "components/user_manager/user_manager.h" |
| 31 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
| 32 #include "content/public/browser/user_metrics.h" | 33 #include "content/public/browser/user_metrics.h" |
| 33 #include "crypto/random.h" | 34 #include "crypto/random.h" |
| 34 #include "google_apis/gaia/google_service_auth_error.h" | 35 #include "google_apis/gaia/google_service_auth_error.h" |
| 35 | 36 |
| 36 namespace chromeos { | 37 namespace chromeos { |
| 37 | 38 |
| 38 namespace { | 39 namespace { |
| 39 | 40 |
| 40 const int kUserCreationTimeoutSeconds = 30; // 30 seconds. | 41 const int kUserCreationTimeoutSeconds = 30; // 30 seconds. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 StartCreationImpl(); | 142 StartCreationImpl(); |
| 142 } | 143 } |
| 143 | 144 |
| 144 void SupervisedUserCreationControllerNew::StartCreationImpl() { | 145 void SupervisedUserCreationControllerNew::StartCreationImpl() { |
| 145 DCHECK(creation_context_); | 146 DCHECK(creation_context_); |
| 146 DCHECK_EQ(STAGE_INITIAL, stage_); | 147 DCHECK_EQ(STAGE_INITIAL, stage_); |
| 147 VLOG(1) << "Starting supervised user creation"; | 148 VLOG(1) << "Starting supervised user creation"; |
| 148 VLOG(1) << " Phase 1 : Prepare keys"; | 149 VLOG(1) << " Phase 1 : Prepare keys"; |
| 149 | 150 |
| 150 SupervisedUserManager* manager = | 151 SupervisedUserManager* manager = |
| 151 UserManager::Get()->GetSupervisedUserManager(); | 152 ChromeUserManager::Get()->GetSupervisedUserManager(); |
| 152 manager->StartCreationTransaction(creation_context_->display_name); | 153 manager->StartCreationTransaction(creation_context_->display_name); |
| 153 | 154 |
| 154 creation_context_->local_user_id = manager->GenerateUserId(); | 155 creation_context_->local_user_id = manager->GenerateUserId(); |
| 155 if (creation_context_->creation_type == NEW_USER) { | 156 if (creation_context_->creation_type == NEW_USER) { |
| 156 creation_context_->sync_user_id = | 157 creation_context_->sync_user_id = |
| 157 SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId(); | 158 SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId(); |
| 158 } | 159 } |
| 159 | 160 |
| 160 manager->SetCreationTransactionUserId(creation_context_->local_user_id); | 161 manager->SetCreationTransactionUserId(creation_context_->local_user_id); |
| 161 | 162 |
| 162 stage_ = TRANSACTION_STARTED; | 163 stage_ = TRANSACTION_STARTED; |
| 163 | 164 |
| 164 manager->CreateUserRecord(creation_context_->manager_id, | 165 manager->CreateUserRecord(creation_context_->manager_id, |
| 165 creation_context_->local_user_id, | 166 creation_context_->local_user_id, |
| 166 creation_context_->sync_user_id, | 167 creation_context_->sync_user_id, |
| 167 creation_context_->display_name); | 168 creation_context_->display_name); |
| 168 | 169 |
| 169 SupervisedUserAuthentication* authentication = | 170 SupervisedUserAuthentication* authentication = |
| 170 UserManager::Get()->GetSupervisedUserManager()->GetAuthentication(); | 171 ChromeUserManager::Get()->GetSupervisedUserManager()->GetAuthentication(); |
| 171 | 172 |
| 172 // When importing M35+ users we need only to store data, for all other cases | 173 // When importing M35+ users we need only to store data, for all other cases |
| 173 // we need to create some keys. | 174 // we need to create some keys. |
| 174 if (creation_context_->creation_type != USER_IMPORT_NEW) { | 175 if (creation_context_->creation_type != USER_IMPORT_NEW) { |
| 175 // Of all required keys old imported users have only master key. | 176 // Of all required keys old imported users have only master key. |
| 176 // Otherwise they are the same as newly created users in terms of keys. | 177 // Otherwise they are the same as newly created users in terms of keys. |
| 177 if (creation_context_->creation_type == NEW_USER) { | 178 if (creation_context_->creation_type == NEW_USER) { |
| 178 creation_context_->master_key = authentication->GenerateMasterKey(); | 179 creation_context_->master_key = authentication->GenerateMasterKey(); |
| 179 } | 180 } |
| 180 | 181 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 DCHECK_EQ(DASHBOARD_CREATED, stage_); | 362 DCHECK_EQ(DASHBOARD_CREATED, stage_); |
| 362 | 363 |
| 363 if (!success) { | 364 if (!success) { |
| 364 stage_ = STAGE_ERROR; | 365 stage_ = STAGE_ERROR; |
| 365 if (consumer_) | 366 if (consumer_) |
| 366 consumer_->OnCreationError(TOKEN_WRITE_FAILED); | 367 consumer_->OnCreationError(TOKEN_WRITE_FAILED); |
| 367 return; | 368 return; |
| 368 } | 369 } |
| 369 // Assume that new token is valid. It will be automatically invalidated if | 370 // Assume that new token is valid. It will be automatically invalidated if |
| 370 // sync service fails to use it. | 371 // sync service fails to use it. |
| 371 UserManager::Get()->SaveUserOAuthStatus( | 372 user_manager::UserManager::Get()->SaveUserOAuthStatus( |
| 372 creation_context_->local_user_id, | 373 creation_context_->local_user_id, |
| 373 user_manager::User::OAUTH2_TOKEN_STATUS_VALID); | 374 user_manager::User::OAUTH2_TOKEN_STATUS_VALID); |
| 374 | 375 |
| 375 stage_ = TOKEN_WRITTEN; | 376 stage_ = TOKEN_WRITTEN; |
| 376 | 377 |
| 377 timeout_timer_.Stop(); | 378 timeout_timer_.Stop(); |
| 378 UserManager::Get()->GetSupervisedUserManager()->CommitCreationTransaction(); | 379 ChromeUserManager::Get() |
| 380 ->GetSupervisedUserManager() |
| 381 ->CommitCreationTransaction(); |
| 379 content::RecordAction( | 382 content::RecordAction( |
| 380 base::UserMetricsAction("ManagedMode_LocallyManagedUserCreated")); | 383 base::UserMetricsAction("ManagedMode_LocallyManagedUserCreated")); |
| 381 | 384 |
| 382 stage_ = TRANSACTION_COMMITTED; | 385 stage_ = TRANSACTION_COMMITTED; |
| 383 | 386 |
| 384 if (consumer_) | 387 if (consumer_) |
| 385 consumer_->OnCreationSuccess(); | 388 consumer_->OnCreationSuccess(); |
| 386 } | 389 } |
| 387 | 390 |
| 388 void SupervisedUserCreationControllerNew::CreationTimedOut() { | 391 void SupervisedUserCreationControllerNew::CreationTimedOut() { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 399 creation_context_->registration_utility.reset(); | 402 creation_context_->registration_utility.reset(); |
| 400 chrome::AttemptUserExit(); | 403 chrome::AttemptUserExit(); |
| 401 } | 404 } |
| 402 | 405 |
| 403 std::string SupervisedUserCreationControllerNew::GetSupervisedUserId() { | 406 std::string SupervisedUserCreationControllerNew::GetSupervisedUserId() { |
| 404 DCHECK(creation_context_); | 407 DCHECK(creation_context_); |
| 405 return creation_context_->local_user_id; | 408 return creation_context_->local_user_id; |
| 406 } | 409 } |
| 407 | 410 |
| 408 } // namespace chromeos | 411 } // namespace chromeos |
| OLD | NEW |