Upstream version 9.37.197.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / login / managed / managed_user_creation_controller_old.h
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_MANAGED_MANAGED_USER_CREATION_CONTROLLER_OLD_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_MANAGED_MANAGED_USER_CREATION_CONTROLLER_OLD_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/managed/managed_user_authenticator.h"
17 #include "chrome/browser/chromeos/login/managed/managed_user_creation_controller.h"
18 #include "chrome/browser/supervised_user/supervised_user_registration_utility.h"
19
20 class Profile;
21
22 namespace chromeos {
23
24 // LMU Creation process:
25 // 0. Manager is logged in
26 // 1. Generate ID for new LMU
27 // 2. Start "transaction" in Local State.
28 // 3. Create local cryptohome (errors could arise)
29 // 4. Create user in cloud (errors could arise)
30 // 5. Store cloud token in cryptohome (actually, error could arise).
31 // 6. Mark "transaction" as completed.
32 // 7. End manager session.
33 class ManagedUserCreationControllerOld
34     : public ManagedUserCreationController,
35       ManagedUserAuthenticator::AuthStatusConsumer {
36  public:
37   // All UI initialization is deferred till Init() call.
38   // |Consumer| is not owned by controller, and it is expected that it wouldn't
39   // be deleted before ManagedUserCreationControllerOld.
40   ManagedUserCreationControllerOld(StatusConsumer* consumer,
41                                    const std::string& manager_id);
42
43   virtual ~ManagedUserCreationControllerOld();
44
45   // Set up controller for creating new supervised user with |display_name|,
46   // |password| and avatar indexed by |avatar_index|. StartCreation() have to
47   // be called to actually start creating user.
48   virtual void StartCreation(const base::string16& display_name,
49                              const std::string& password,
50                              int avatar_index) OVERRIDE;
51
52   // Configures and initiates importing existing supervised user to this device.
53   // Existing user is identified by |sync_id|, has |display_name|, |password|,
54   // |avatar_index|. The master key for cryptohome is a |master_key|.
55   virtual void StartImport(const base::string16& display_name,
56                            const std::string& password,
57                            int avatar_index,
58                            const std::string& sync_id,
59                            const std::string& master_key) OVERRIDE;
60
61   // Not implemented in this class.
62   virtual void StartImport(const base::string16& display_name,
63                            int avatar_index,
64                            const std::string& sync_id,
65                            const std::string& master_key,
66                            const base::DictionaryValue* password_data,
67                            const std::string& encryption_key,
68                            const std::string& signature_key) OVERRIDE;
69
70   virtual void SetManagerProfile(Profile* manager_profile) OVERRIDE;
71   virtual Profile* GetManagerProfile() OVERRIDE;
72
73   virtual void CancelCreation() OVERRIDE;
74   virtual void FinishCreation() OVERRIDE;
75   virtual std::string GetManagedUserId() OVERRIDE;
76
77  private:
78   // Indicates if we create new user, or import an existing one.
79   enum CreationType { NEW_USER, USER_IMPORT, };
80
81   // Contains information necessary for new user creation.
82   struct UserCreationContext {
83     UserCreationContext();
84     ~UserCreationContext();
85
86     base::string16 display_name;
87     int avatar_index;
88     std::string manager_id;
89     std::string local_user_id;  // Used to identify cryptohome.
90     std::string sync_user_id;   // Used to identify user in manager's sync data.
91     std::string password;
92     std::string mount_hash;
93     std::string master_key;
94     bool token_acquired;
95     std::string token;
96     bool token_succesfully_written;
97     CreationType creation_type;
98     base::DictionaryValue password_data;
99     Profile* manager_profile;
100     scoped_ptr<SupervisedUserRegistrationUtility> registration_utility;
101   };
102
103   void StartCreation();
104
105   // ManagedUserAuthenticator::StatusConsumer overrides.
106   virtual void OnAuthenticationFailure(
107       ManagedUserAuthenticator::AuthState error) OVERRIDE;
108   virtual void OnMountSuccess(const std::string& mount_hash) OVERRIDE;
109   virtual void OnAddKeySuccess() OVERRIDE;
110
111   void CreationTimedOut();
112   void RegistrationCallback(const GoogleServiceAuthError& error,
113                             const std::string& token);
114
115   void TokenFetched(const std::string& token);
116
117   // Completion callback for StoreManagedUserFiles method.
118   // Called on the UI thread.
119   void OnManagedUserFilesStored(bool success);
120
121   scoped_refptr<ManagedUserAuthenticator> authenticator_;
122
123   // Creation context. Not null while creating new LMU.
124   scoped_ptr<UserCreationContext> creation_context_;
125
126   // Timer for showing warning if creation process takes too long.
127   base::OneShotTimer<ManagedUserCreationControllerOld> timeout_timer_;
128
129   // Factory of callbacks.
130   base::WeakPtrFactory<ManagedUserCreationControllerOld> weak_factory_;
131
132   DISALLOW_COPY_AND_ASSIGN(ManagedUserCreationControllerOld);
133 };
134
135 }  // namespace chromeos
136
137 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_MANAGED_MANAGED_USER_CREATION_CONTROLLER_OLD_H_