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 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SUPERVISED_SUPERVISED_USER_CREATION_CONTROLLER_H_ 6#define CHROME_BROWSER_CHROMEOS_LOGIN_SUPERVISED_SUPERVISED_USER_CREATION_CONTROLLER_H_ 7 8#include <string> 9 10#include "base/files/file_path.h" 11#include "base/memory/scoped_ptr.h" 12#include "base/memory/weak_ptr.h" 13#include "base/strings/string16.h" 14#include "base/timer/timer.h" 15#include "base/values.h" 16#include "chrome/browser/chromeos/login/supervised/supervised_user_authenticator.h" 17#include "chrome/browser/supervised_user/supervised_user_registration_utility.h" 18 19class Profile; 20 21namespace chromeos { 22 23class SupervisedUserCreationController { 24 public: 25 // This constant is used to indicate that user does not have one of default 26 // avatars: either he has no chromeos avatar at all, or has an external 27 // image as an avatar. 28 static const int kDummyAvatarIndex; 29 30 enum ErrorCode { 31 NO_ERROR, 32 CRYPTOHOME_NO_MOUNT, 33 CRYPTOHOME_FAILED_MOUNT, 34 CRYPTOHOME_FAILED_TPM, 35 CLOUD_SERVER_ERROR, 36 TOKEN_WRITE_FAILED, 37 }; 38 39 class StatusConsumer { 40 public: 41 virtual ~StatusConsumer(); 42 43 virtual void OnCreationError(ErrorCode code) = 0; 44 virtual void OnLongCreationWarning() = 0; 45 virtual void OnCreationTimeout() = 0; 46 virtual void OnCreationSuccess() = 0; 47 }; 48 49 // All UI initialization is deferred till Init() call. 50 // |Consumer| is not owned by controller, and it is expected that it wouldn't 51 // be deleted before SupervisedUserCreationController. 52 explicit SupervisedUserCreationController(StatusConsumer* consumer); 53 virtual ~SupervisedUserCreationController(); 54 55 // Returns the current supervised user controller if it has been created. 56 static SupervisedUserCreationController* current_controller() { 57 return current_controller_; 58 } 59 60 // Set up controller for creating new supervised user with |display_name|, 61 // |password| and avatar indexed by |avatar_index|. StartCreation() have to 62 // be called to actually start creating user. 63 virtual void StartCreation(const base::string16& display_name, 64 const std::string& password, 65 int avatar_index) = 0; 66 67 // Configures and initiates importing existing supervised user to this device. 68 // Existing user is identified by |sync_id|, has |display_name|, |password|, 69 // |avatar_index|. The master key for cryptohome is a |master_key|. 70 virtual void StartImport(const base::string16& display_name, 71 const std::string& password, 72 int avatar_index, 73 const std::string& sync_id, 74 const std::string& master_key) = 0; 75 76 // Configures and initiates importing existing supervised user to this device. 77 // Existing user is identified by |sync_id|, has |display_name|, 78 // |avatar_index|. The master key for cryptohome is a |master_key|. The user 79 // has password specified in |password_data| and 80 // |encryption_key|/|signature_key| for cryptohome. 81 virtual void StartImport(const base::string16& display_name, 82 int avatar_index, 83 const std::string& sync_id, 84 const std::string& master_key, 85 const base::DictionaryValue* password_data, 86 const std::string& encryption_key, 87 const std::string& signature_key) = 0; 88 89 virtual void SetManagerProfile(Profile* manager_profile) = 0; 90 virtual Profile* GetManagerProfile() = 0; 91 virtual void CancelCreation() = 0; 92 virtual void FinishCreation() = 0; 93 virtual std::string GetSupervisedUserId() = 0; 94 95 protected: 96 // Pointer to the current instance of the controller to be used by 97 // automation tests. 98 static SupervisedUserCreationController* current_controller_; 99 100 StatusConsumer* consumer_; 101 102 private: 103 DISALLOW_COPY_AND_ASSIGN(SupervisedUserCreationController); 104}; 105 106} // namespace chromeos 107 108#endif // CHROME_BROWSER_CHROMEOS_LOGIN_SUPERVISED_SUPERVISED_USER_CREATION_CONTROLLER_H_ 109