Chromium Code Reviews| 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/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 21 #include "chrome/browser/chromeos/profiles/profile_helper.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_id.h" | |
| 31 #include "components/user_manager/user_manager.h" | 32 #include "components/user_manager/user_manager.h" |
| 32 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
| 33 #include "content/public/browser/user_metrics.h" | 34 #include "content/public/browser/user_metrics.h" |
| 34 #include "crypto/random.h" | 35 #include "crypto/random.h" |
| 35 #include "google_apis/gaia/google_service_auth_error.h" | 36 #include "google_apis/gaia/google_service_auth_error.h" |
| 36 | 37 |
| 37 namespace chromeos { | 38 namespace chromeos { |
| 38 | 39 |
| 39 namespace { | 40 namespace { |
| 40 | 41 |
| 41 const int kUserCreationTimeoutSeconds = 30; // 30 seconds. | 42 const int kUserCreationTimeoutSeconds = 30; // 30 seconds. |
| 42 | 43 |
| 43 bool StoreSupervisedUserFiles(const std::string& token, | 44 bool StoreSupervisedUserFiles(const std::string& token, |
| 44 const base::FilePath& base_path) { | 45 const base::FilePath& base_path) { |
| 45 if (!base::SysInfo::IsRunningOnChromeOS()) { | 46 if (!base::SysInfo::IsRunningOnChromeOS()) { |
| 46 // If running on desktop, cryptohome stub does not create home directory. | 47 // If running on desktop, cryptohome stub does not create home directory. |
| 47 base::CreateDirectory(base_path); | 48 base::CreateDirectory(base_path); |
| 48 } | 49 } |
| 49 base::FilePath token_file = base_path.Append(kSupervisedUserTokenFilename); | 50 base::FilePath token_file = base_path.Append(kSupervisedUserTokenFilename); |
| 50 int bytes = base::WriteFile(token_file, token.c_str(), token.length()); | 51 int bytes = base::WriteFile(token_file, token.c_str(), token.length()); |
| 51 return bytes >= 0; | 52 return bytes >= 0; |
| 52 } | 53 } |
| 53 | 54 |
| 54 } // namespace | 55 } // namespace |
| 55 | 56 |
| 56 SupervisedUserCreationControllerNew::SupervisedUserCreationControllerNew( | 57 SupervisedUserCreationControllerNew::SupervisedUserCreationControllerNew( |
| 57 SupervisedUserCreationControllerNew::StatusConsumer* consumer, | 58 SupervisedUserCreationControllerNew::StatusConsumer* consumer, |
| 58 const std::string& manager_id) | 59 const user_manager::UserID& manager_id) |
| 59 : SupervisedUserCreationController(consumer), | 60 : SupervisedUserCreationController(consumer), |
| 60 stage_(STAGE_INITIAL), | 61 stage_(STAGE_INITIAL), |
| 61 weak_factory_(this) { | 62 weak_factory_(this) { |
| 62 creation_context_.reset( | 63 creation_context_.reset( |
| 63 new SupervisedUserCreationControllerNew::UserCreationContext()); | 64 new SupervisedUserCreationControllerNew::UserCreationContext()); |
| 64 creation_context_->manager_id = manager_id; | 65 creation_context_->manager_id = manager_id; |
| 65 } | 66 } |
| 66 | 67 |
| 67 SupervisedUserCreationControllerNew::~SupervisedUserCreationControllerNew() {} | 68 SupervisedUserCreationControllerNew::~SupervisedUserCreationControllerNew() {} |
| 68 | 69 |
| 69 SupervisedUserCreationControllerNew::UserCreationContext:: | 70 SupervisedUserCreationControllerNew::UserCreationContext:: |
| 70 UserCreationContext() {} | 71 UserCreationContext() : manager_id(std::string(), std::string()), local_user _id(std::string(), std::string()) {} |
|
Denis Kuznetsov (DE-MUC)
2015/06/10 16:50:46
EmptyGaiaID() ?
| |
| 71 | 72 |
| 72 SupervisedUserCreationControllerNew::UserCreationContext:: | 73 SupervisedUserCreationControllerNew::UserCreationContext:: |
| 73 ~UserCreationContext() {} | 74 ~UserCreationContext() {} |
| 74 | 75 |
| 75 void SupervisedUserCreationControllerNew::SetManagerProfile( | 76 void SupervisedUserCreationControllerNew::SetManagerProfile( |
| 76 Profile* manager_profile) { | 77 Profile* manager_profile) { |
| 77 creation_context_->manager_profile = manager_profile; | 78 creation_context_->manager_profile = manager_profile; |
| 78 } | 79 } |
| 79 | 80 |
| 80 Profile* SupervisedUserCreationControllerNew::GetManagerProfile() { | 81 Profile* SupervisedUserCreationControllerNew::GetManagerProfile() { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 VLOG(1) << "Starting supervised user creation"; | 149 VLOG(1) << "Starting supervised user creation"; |
| 149 VLOG(1) << " Phase 1 : Prepare keys"; | 150 VLOG(1) << " Phase 1 : Prepare keys"; |
| 150 | 151 |
| 151 SupervisedUserManager* manager = | 152 SupervisedUserManager* manager = |
| 152 ChromeUserManager::Get()->GetSupervisedUserManager(); | 153 ChromeUserManager::Get()->GetSupervisedUserManager(); |
| 153 manager->StartCreationTransaction(creation_context_->display_name); | 154 manager->StartCreationTransaction(creation_context_->display_name); |
| 154 | 155 |
| 155 creation_context_->local_user_id = manager->GenerateUserId(); | 156 creation_context_->local_user_id = manager->GenerateUserId(); |
| 156 if (creation_context_->creation_type == NEW_USER) { | 157 if (creation_context_->creation_type == NEW_USER) { |
| 157 creation_context_->sync_user_id = | 158 creation_context_->sync_user_id = |
| 158 SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId(); | 159 SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId().GetUser Email(); |
| 159 } | 160 } |
| 160 | 161 |
| 161 manager->SetCreationTransactionUserId(creation_context_->local_user_id); | 162 manager->SetCreationTransactionUserId(creation_context_->local_user_id); |
| 162 | 163 |
| 163 stage_ = TRANSACTION_STARTED; | 164 stage_ = TRANSACTION_STARTED; |
| 164 | 165 |
| 165 manager->CreateUserRecord(creation_context_->manager_id, | 166 manager->CreateUserRecord(creation_context_->manager_id, |
| 166 creation_context_->local_user_id, | 167 creation_context_->local_user_id, |
| 167 creation_context_->sync_user_id, | 168 creation_context_->sync_user_id, |
| 168 creation_context_->display_name); | 169 creation_context_->display_name); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 SupervisedUserRegistrationInfo info(creation_context_->display_name, | 323 SupervisedUserRegistrationInfo info(creation_context_->display_name, |
| 323 creation_context_->avatar_index); | 324 creation_context_->avatar_index); |
| 324 info.master_key = creation_context_->master_key; | 325 info.master_key = creation_context_->master_key; |
| 325 info.password_signature_key = creation_context_->signature_key; | 326 info.password_signature_key = creation_context_->signature_key; |
| 326 info.password_encryption_key = creation_context_->encryption_key; | 327 info.password_encryption_key = creation_context_->encryption_key; |
| 327 | 328 |
| 328 info.password_data.MergeDictionary(&creation_context_->password_data); | 329 info.password_data.MergeDictionary(&creation_context_->password_data); |
| 329 | 330 |
| 330 // Registration utility will update user data if user already exist. | 331 // Registration utility will update user data if user already exist. |
| 331 creation_context_->registration_utility->Register( | 332 creation_context_->registration_utility->Register( |
| 332 creation_context_->sync_user_id, | 333 user_manager::UserID::FromUserEmail(creation_context_->sync_user_id), |
| 333 info, | 334 info, |
| 334 base::Bind(&SupervisedUserCreationControllerNew::RegistrationCallback, | 335 base::Bind(&SupervisedUserCreationControllerNew::RegistrationCallback, |
| 335 weak_factory_.GetWeakPtr())); | 336 weak_factory_.GetWeakPtr())); |
| 336 } | 337 } |
| 337 | 338 |
| 338 void SupervisedUserCreationControllerNew::RegistrationCallback( | 339 void SupervisedUserCreationControllerNew::RegistrationCallback( |
| 339 const GoogleServiceAuthError& error, | 340 const GoogleServiceAuthError& error, |
| 340 const std::string& token) { | 341 const std::string& token) { |
| 341 DCHECK(creation_context_); | 342 DCHECK(creation_context_); |
| 342 DCHECK_EQ(CRYPTOHOME_CREATED, stage_); | 343 DCHECK_EQ(CRYPTOHOME_CREATED, stage_); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 | 408 |
| 408 void SupervisedUserCreationControllerNew::FinishCreation() { | 409 void SupervisedUserCreationControllerNew::FinishCreation() { |
| 409 chrome::AttemptUserExit(); | 410 chrome::AttemptUserExit(); |
| 410 } | 411 } |
| 411 | 412 |
| 412 void SupervisedUserCreationControllerNew::CancelCreation() { | 413 void SupervisedUserCreationControllerNew::CancelCreation() { |
| 413 creation_context_->registration_utility.reset(); | 414 creation_context_->registration_utility.reset(); |
| 414 chrome::AttemptUserExit(); | 415 chrome::AttemptUserExit(); |
| 415 } | 416 } |
| 416 | 417 |
| 417 std::string SupervisedUserCreationControllerNew::GetSupervisedUserId() { | 418 const user_manager::UserID& SupervisedUserCreationControllerNew::GetSupervisedUs erId() const { |
| 418 DCHECK(creation_context_); | 419 DCHECK(creation_context_); |
| 419 return creation_context_->local_user_id; | 420 return creation_context_->local_user_id; |
| 420 } | 421 } |
| 421 | 422 |
| 422 } // namespace chromeos | 423 } // namespace chromeos |
| OLD | NEW |