Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: chrome/browser/ui/webui/signin/signin_create_profile_handler.h

Issue 1630903002: material design user manager with create profile flow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed the comments Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_CREATE_PROFILE_HANDLER_H_ 5 #ifndef CHROME_BROWSER_UI_WEBUI_SIGNIN_SIGNIN_CREATE_PROFILE_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_CREATE_PROFILE_HANDLER_H_ 6 #define CHROME_BROWSER_UI_WEBUI_SIGNIN_SIGNIN_CREATE_PROFILE_HANDLER_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/profiles/profile_window.h" 12 #include "chrome/browser/profiles/profile_window.h"
13 #include "chrome/browser/ui/host_desktop.h" 13 #include "chrome/browser/ui/host_desktop.h"
14 #include "chrome/browser/ui/webui/options/options_ui.h" 14 #include "content/public/browser/web_ui_message_handler.h"
15 #include "google_apis/gaia/google_service_auth_error.h" 15 #include "google_apis/gaia/google_service_auth_error.h"
16 16
17 17
18 namespace base { 18 namespace base {
19 class DictionaryValue; 19 class DictionaryValue;
20 class ListValue; 20 class ListValue;
21 } 21 }
22 22
23 #if defined(ENABLE_SUPERVISED_USERS) 23 #if defined(ENABLE_SUPERVISED_USERS)
24 class SupervisedUserRegistrationUtility; 24 class SupervisedUserRegistrationUtility;
25 #endif 25 #endif
26 26
27 namespace options { 27 // Handler for the 'create profile' page.
28 class SigninCreateProfileHandler: public content::WebUIMessageHandler {
29 public:
30 SigninCreateProfileHandler();
31 ~SigninCreateProfileHandler() override;
28 32
29 // Handler for the 'create profile' overlay. 33 void GetLocalizedValues(base::DictionaryValue* localized_strings);
30 class CreateProfileHandler: public OptionsPageUIHandler {
31 public:
32 CreateProfileHandler();
33 ~CreateProfileHandler() override;
34 34
35 // OptionsPageUIHandler implementation. 35 private:
36 void GetLocalizedValues(base::DictionaryValue* localized_strings) override;
37
38 // WebUIMessageHandler implementation. 36 // WebUIMessageHandler implementation.
39 void RegisterMessages() override; 37 void RegisterMessages() override;
40
41 private:
42 // Represents the final profile creation status. It is used to map 38 // Represents the final profile creation status. It is used to map
43 // the status to the javascript method to be called. 39 // the status to the javascript method to be called.
44 enum ProfileCreationStatus { 40 enum ProfileCreationStatus {
45 PROFILE_CREATION_SUCCESS, 41 PROFILE_CREATION_SUCCESS,
46 PROFILE_CREATION_ERROR, 42 PROFILE_CREATION_ERROR,
47 }; 43 };
48 44
49 // Represents the type of the in progress profile creation operation. 45 // Represents the type of the in progress profile creation operation.
50 // It is used to map the type of the profile creation operation to the 46 // It is used to map the type of the profile creation operation to the
51 // correct UMA metric name. 47 // correct UMA metric name.
52 enum ProfileCreationOperationType { 48 enum ProfileCreationOperationType {
53 #if defined(ENABLE_SUPERVISED_USERS) 49 #if defined(ENABLE_SUPERVISED_USERS)
54 SUPERVISED_PROFILE_CREATION, 50 SUPERVISED_PROFILE_CREATION,
55 SUPERVISED_PROFILE_IMPORT, 51 SUPERVISED_PROFILE_IMPORT,
56 #endif 52 #endif
57 NON_SUPERVISED_PROFILE_CREATION, 53 NON_SUPERVISED_PROFILE_CREATION,
58 NO_CREATION_IN_PROGRESS 54 NO_CREATION_IN_PROGRESS
59 }; 55 };
60 56
57 // Callback for the "requestDefaultProfileIcons" message.
58 // Sends the array of default profile icon URLs to WebUI.
59 void RequestDefaultProfileIcons(const base::ListValue* args);
60
61 // Callback for the "requestSignedInProfiles" message.
62 // Sends the email address of the signed-in user, or an empty string if the
63 // user is not signed in. Also sends information about whether supervised
64 // users may be created.
65 void RequestSignedInProfiles(const base::ListValue* args);
66
61 // Asynchronously creates and initializes a new profile. 67 // Asynchronously creates and initializes a new profile.
62 // The arguments are as follows: 68 // The arguments are as follows:
63 // 0: name (string) 69 // 0: name (string)
64 // 1: icon (string) 70 // 1: icon (string)
65 // 2: a flag stating whether we should create a profile desktop shortcut 71 // 2: a flag stating whether we should create a profile desktop shortcut
66 // (optional, boolean) 72 // (optional, boolean)
67 // 3: a flag stating whether the user should be supervised 73 // 3: a flag stating whether the user should be supervised
68 // (optional, boolean) 74 // (optional, boolean)
69 // 4: a string representing the supervised user ID. 75 // 4: a string representing the supervised user ID.
76 // 5: a string representing the supervisor profile path.
70 void CreateProfile(const base::ListValue* args); 77 void CreateProfile(const base::ListValue* args);
71 78
72 // If a local error occurs during profile creation, then show an appropriate 79 // If a local error occurs during profile creation, then show an appropriate
73 // error message. However, if profile creation succeeded and the 80 // error message. However, if profile creation succeeded and the
74 // profile being created/imported is a supervised user profile, 81 // profile being created/imported is a supervised user profile,
75 // then proceed with the registration step. Otherwise, update the UI 82 // then proceed with the registration step. Otherwise, update the UI
76 // as the final task after a new profile has been created. 83 // as the final task after a new profile has been created.
77 void OnProfileCreated(bool create_shortcut, 84 void OnProfileCreated(bool create_shortcut,
78 chrome::HostDesktopType desktop_type, 85 chrome::HostDesktopType desktop_type,
79 const std::string& supervised_user_id, 86 const std::string& supervised_user_id,
87 Profile* supervisor_profile,
80 Profile* profile, 88 Profile* profile,
81 Profile::CreateStatus status); 89 Profile::CreateStatus status);
82 90
83 void HandleProfileCreationSuccess(bool create_shortcut, 91 void HandleProfileCreationSuccess(bool create_shortcut,
84 chrome::HostDesktopType desktop_type, 92 chrome::HostDesktopType desktop_type,
85 const std::string& supervised_user_id, 93 const std::string& supervised_user_id,
94 Profile* supervisor_profile,
86 Profile* profile); 95 Profile* profile);
87 96
88 // Creates desktop shortcut and updates the UI to indicate success 97 // Creates desktop shortcut and updates the UI to indicate success
89 // when creating a profile. 98 // when creating a profile.
90 void CreateShortcutAndShowSuccess(bool create_shortcut, 99 void CreateShortcutAndShowSuccess(bool create_shortcut,
91 chrome::HostDesktopType desktop_type, 100 chrome::HostDesktopType desktop_type,
92 Profile* profile); 101 Profile* profile);
93 102
94 // Updates the UI to show an error when creating a profile. 103 // Updates the UI to show an error when creating a profile.
95 void ShowProfileCreationError(Profile* profile, const base::string16& error); 104 void ShowProfileCreationError(Profile* profile, const base::string16& error);
96 105
97 // Updates the UI to show a non-fatal warning when creating a profile. 106 // Updates the UI to show a non-fatal warning when creating a profile.
98 void ShowProfileCreationWarning(const base::string16& warning); 107 void ShowProfileCreationWarning(const base::string16& warning);
99 108
100 // Records UMA histograms relevant to profile creation. 109 // Records UMA histograms relevant to profile creation.
101 void RecordProfileCreationMetrics(Profile::CreateStatus status); 110 void RecordProfileCreationMetrics(Profile::CreateStatus status);
102 111
103 base::string16 GetProfileCreationErrorMessageLocal() const; 112 base::string16 GetProfileCreationErrorMessageLocal() const;
104 #if defined(ENABLE_SUPERVISED_USERS) 113 #if defined(ENABLE_SUPERVISED_USERS)
105 // The following error messages only apply to supervised profiles. 114 // The following error messages only apply to supervised profiles.
106 base::string16 GetProfileCreationErrorMessageRemote() const; 115 base::string16 GetProfileCreateErrorMessageRemote() const;
107 base::string16 GetProfileCreationErrorMessageSignin() const; 116 base::string16 GetProfileCreateErrorMessageSignin() const;
108 #endif 117 #endif
109 118
110 std::string GetJavascriptMethodName(ProfileCreationStatus status) const; 119 std::string GetJavascriptMethodName(ProfileCreationStatus status) const;
111 120
112 // Used to allow cancelling a profile creation (particularly a supervised-user 121 // Used to allow cancelling a profile creation (particularly a supervised-user
113 // registration) in progress. Set when profile creation is begun, and 122 // registration) in progress. Set when profile creation is begun, and
114 // cleared when all the callbacks have been run and creation is complete. 123 // cleared when all the callbacks have been run and creation is complete.
115 base::FilePath profile_path_being_created_; 124 base::FilePath profile_path_being_created_;
116 125
117 // Used to track how long profile creation takes. 126 // Used to track how long profile creation takes.
118 base::TimeTicks profile_creation_start_time_; 127 base::TimeTicks profile_creation_start_time_;
119 128
120 // Indicates the type of the in progress profile creation operation. 129 // Indicates the type of the in progress profile creation operation.
121 // The value is only relevant while we are creating/importing a profile. 130 // The value is only relevant while we are creating/importing a profile.
122 ProfileCreationOperationType profile_creation_type_; 131 ProfileCreationOperationType profile_creation_type_;
123 132
133 // Asynchronously creates and initializes a new profile.
134 void DoCreateProfile(const base::string16& name,
135 const std::string& icon_url,
136 bool create_shortcut,
137 const std::string& supervised_user_id,
138 Profile* supervisor_profile);
139
124 #if defined(ENABLE_SUPERVISED_USERS) 140 #if defined(ENABLE_SUPERVISED_USERS)
125 // Extracts the supervised user ID from the args passed into CreateProfile, 141 // Extracts the supervised user ID and the supervisor user profile path from
126 // sets |profile_creation_type_| if necessary, and returns true if the 142 // the args passed into CreateProfile.
127 // supervised user id specified in |args| are valid. 143 bool GetSupervisedCreateProfileArgs(const base::ListValue* args,
128 bool ProcessSupervisedCreateProfileArgs(const base::ListValue* args, 144 std::string* supervised_user_id,
129 std::string* supervised_user_id); 145 base::FilePath* supervisor_profile_path);
146
147 // Callback that runs once the supervisor profile has been loaded. It sets
148 // |profile_creation_type_| if necessary, and calls |DoCreateProfile| if the
149 // supervised user id specified in |args| is valid.
150 void LoadSupervisorProfileCallback(const base::string16& name,
151 const std::string& icon_url,
152 bool create_shortcut,
153 const std::string& supervised_user_id,
154 Profile* supervisor_profile,
155 Profile::CreateStatus status);
130 156
131 // Cancels creation of a supervised-user profile currently in progress, as 157 // Cancels creation of a supervised-user profile currently in progress, as
132 // indicated by profile_path_being_created_, removing the object and files 158 // indicated by profile_path_being_created_, removing the object and files
133 // and canceling supervised-user registration. This is the handler for the 159 // and canceling supervised-user registration. This is the handler for the
134 // "cancelCreateProfile" message. |args| is not used. 160 // "cancelCreateProfile" message. |args| is not used.
135 void HandleCancelProfileCreation(const base::ListValue* args); 161 void HandleCancelProfileCreation(const base::ListValue* args);
136 162
137 // Internal implementation. This may safely be called whether profile creation 163 // Internal implementation. This may safely be called whether profile creation
138 // or registration is in progress or not. |user_initiated| should be true if 164 // or registration is in progress or not. |user_initiated| should be true if
139 // the cancellation was deliberately requested by the user, and false if it 165 // the cancellation was deliberately requested by the user, and false if it
140 // was caused implicitly, e.g. by shutting down the browser. 166 // was caused implicitly, e.g. by shutting down the browser.
141 void CancelProfileRegistration(bool user_initiated); 167 void CancelProfileRegistration(bool user_initiated);
142 168
143 // After a new supervised-user profile has been created, registers the user 169 // After a new supervised-user profile has been created, registers the user
144 // with the management server. 170 // with the management server.
145 void RegisterSupervisedUser(bool create_shortcut, 171 void RegisterSupervisedUser(bool create_shortcut,
146 chrome::HostDesktopType desktop_type, 172 chrome::HostDesktopType desktop_type,
147 const std::string& managed_user_id, 173 const std::string& managed_user_id,
174 Profile* supervisor_profile,
148 Profile* new_profile); 175 Profile* new_profile);
149 176
150 // Called back with the result of the supervised user registration. 177 // Called back with the result of the supervised user registration.
151 void OnSupervisedUserRegistered(bool create_shortcut, 178 void OnSupervisedUserRegistered(bool create_shortcut,
152 chrome::HostDesktopType desktop_type, 179 chrome::HostDesktopType desktop_type,
153 Profile* profile, 180 Profile* profile,
154 const GoogleServiceAuthError& error); 181 const GoogleServiceAuthError& error);
155 182
156 // Records UMA histograms relevant to supervised user profiles 183 // Records UMA histograms relevant to supervised user profiles
157 // creation and registration. 184 // creation and registration.
158 void RecordSupervisedProfileCreationMetrics( 185 void RecordSupervisedProfileCreationMetrics(
159 GoogleServiceAuthError::State error_state); 186 GoogleServiceAuthError::State error_state);
160 187
161 bool IsValidExistingSupervisedUserId( 188 void DoCreateProfileIfPossible(
162 const std::string& existing_supervised_user_id) const; 189 const base::string16& name,
190 const std::string& icon_url,
191 bool create_shortcut,
192 const std::string& supervised_user_id,
193 Profile* supervisor_profile,
194 const base::DictionaryValue* dict);
163 195
164 scoped_ptr<SupervisedUserRegistrationUtility> 196 scoped_ptr<SupervisedUserRegistrationUtility>
165 supervised_user_registration_utility_; 197 supervised_user_registration_utility_;
166 #endif 198 #endif
167 199
168 base::WeakPtrFactory<CreateProfileHandler> weak_ptr_factory_; 200 base::WeakPtrFactory<SigninCreateProfileHandler> weak_ptr_factory_;
169 201
170 DISALLOW_COPY_AND_ASSIGN(CreateProfileHandler); 202 DISALLOW_COPY_AND_ASSIGN(SigninCreateProfileHandler);
171 }; 203 };
172 204
173 } // namespace options 205 #endif // CHROME_BROWSER_UI_WEBUI_SIGNIN_SIGNIN_CREATE_PROFILE_HANDLER_H_
174
175 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CREATE_PROFILE_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698