| OLD | NEW |
| 1 // Copyright 2016 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_SIGNIN_SIGNIN_CREATE_PROFILE_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_SIGNIN_SIGNIN_CREATE_PROFILE_HANDLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_SIGNIN_SIGNIN_CREATE_PROFILE_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_SIGNIN_SIGNIN_CREATE_PROFILE_HANDLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 void GetLocalizedValues(base::DictionaryValue* localized_strings); | 36 void GetLocalizedValues(base::DictionaryValue* localized_strings); |
| 37 | 37 |
| 38 protected: | 38 protected: |
| 39 FRIEND_TEST_ALL_PREFIXES(SigninCreateProfileHandlerTest, | 39 FRIEND_TEST_ALL_PREFIXES(SigninCreateProfileHandlerTest, |
| 40 ReturnDefaultProfileNameAndIcons); | 40 ReturnDefaultProfileNameAndIcons); |
| 41 FRIEND_TEST_ALL_PREFIXES(SigninCreateProfileHandlerTest, | 41 FRIEND_TEST_ALL_PREFIXES(SigninCreateProfileHandlerTest, |
| 42 ReturnSignedInProfiles); | 42 ReturnSignedInProfiles); |
| 43 FRIEND_TEST_ALL_PREFIXES(SigninCreateProfileHandlerTest, | 43 FRIEND_TEST_ALL_PREFIXES(SigninCreateProfileHandlerTest, |
| 44 CreateProfile); | 44 CreateProfile); |
| 45 #if defined(ENABLE_SUPERVISED_USERS) |
| 45 FRIEND_TEST_ALL_PREFIXES(SigninCreateProfileHandlerTest, | 46 FRIEND_TEST_ALL_PREFIXES(SigninCreateProfileHandlerTest, |
| 46 CreateSupervisedUser); | 47 CreateSupervisedUser); |
| 47 FRIEND_TEST_ALL_PREFIXES(SigninCreateProfileHandlerTest, | 48 FRIEND_TEST_ALL_PREFIXES(SigninCreateProfileHandlerTest, |
| 48 ImportSupervisedUser); | 49 ImportSupervisedUser); |
| 49 FRIEND_TEST_ALL_PREFIXES(SigninCreateProfileHandlerTest, | 50 FRIEND_TEST_ALL_PREFIXES(SigninCreateProfileHandlerTest, |
| 50 ImportSupervisedUserAlreadyOnDevice); | 51 ImportSupervisedUserAlreadyOnDevice); |
| 51 FRIEND_TEST_ALL_PREFIXES(SigninCreateProfileHandlerTest, | 52 FRIEND_TEST_ALL_PREFIXES(SigninCreateProfileHandlerTest, |
| 52 CustodianNotAuthenticated); | 53 CustodianNotAuthenticated); |
| 53 FRIEND_TEST_ALL_PREFIXES(SigninCreateProfileHandlerTest, | 54 FRIEND_TEST_ALL_PREFIXES(SigninCreateProfileHandlerTest, |
| 54 CustodianHasAuthError); | 55 CustodianHasAuthError); |
| 55 FRIEND_TEST_ALL_PREFIXES(SigninCreateProfileHandlerTest, | 56 FRIEND_TEST_ALL_PREFIXES(SigninCreateProfileHandlerTest, |
| 56 NotAllowedToCreateSupervisedUser); | 57 NotAllowedToCreateSupervisedUser); |
| 58 #endif |
| 57 | 59 |
| 58 // WebUIMessageHandler implementation. | 60 // WebUIMessageHandler implementation. |
| 59 void RegisterMessages() override; | 61 void RegisterMessages() override; |
| 60 | 62 |
| 61 // content::NotificationObserver implementation: | 63 // content::NotificationObserver implementation: |
| 62 void Observe(int type, | 64 void Observe(int type, |
| 63 const content::NotificationSource& source, | 65 const content::NotificationSource& source, |
| 64 const content::NotificationDetails& details) override; | 66 const content::NotificationDetails& details) override; |
| 65 | 67 |
| 66 // Represents the final profile creation status. It is used to map | 68 // Represents the final profile creation status. It is used to map |
| (...skipping 18 matching lines...) Expand all Loading... |
| 85 // Callback for the "requestDefaultProfileIcons" message. | 87 // Callback for the "requestDefaultProfileIcons" message. |
| 86 // Sends the array of default profile icon URLs to WebUI. | 88 // Sends the array of default profile icon URLs to WebUI. |
| 87 void RequestDefaultProfileIcons(const base::ListValue* args); | 89 void RequestDefaultProfileIcons(const base::ListValue* args); |
| 88 | 90 |
| 89 // Sends an object to WebUI of the form: { "name": profileName } after | 91 // Sends an object to WebUI of the form: { "name": profileName } after |
| 90 // "requestDefaultProfileIcons" is fulfilled. | 92 // "requestDefaultProfileIcons" is fulfilled. |
| 91 void SendNewProfileDefaults(); | 93 void SendNewProfileDefaults(); |
| 92 | 94 |
| 93 // Callback for the "requestSignedInProfiles" message. | 95 // Callback for the "requestSignedInProfiles" message. |
| 94 // Sends the email address of the signed-in user, or an empty string if the | 96 // Sends the email address of the signed-in user, or an empty string if the |
| 95 // user is not signed in. Also sends information about whether supervised | 97 // user is not signed in. |
| 96 // users may be created. | |
| 97 void RequestSignedInProfiles(const base::ListValue* args); | 98 void RequestSignedInProfiles(const base::ListValue* args); |
| 98 | 99 |
| 99 // Asynchronously creates and initializes a new profile. | 100 // Asynchronously creates and initializes a new profile. |
| 100 // The arguments are as follows: | 101 // The arguments are as follows: |
| 101 // 0: name (string) | 102 // 0: name (string) |
| 102 // 1: icon (string) | 103 // 1: icon (string) |
| 103 // 2: a flag stating whether we should create a profile desktop shortcut | 104 // 2: a flag stating whether we should create a profile desktop shortcut |
| 104 // (optional, boolean) | 105 // (optional, boolean) |
| 105 // 3: a flag stating whether the user should be supervised | 106 // 3: a flag stating whether the user should be supervised |
| 106 // (optional, boolean) | 107 // (optional, boolean) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 123 const std::string& supervised_user_id, | 124 const std::string& supervised_user_id, |
| 124 Profile* custodian_profile, | 125 Profile* custodian_profile, |
| 125 Profile* profile); | 126 Profile* profile); |
| 126 | 127 |
| 127 // Creates desktop shortcut and updates the UI to indicate success | 128 // Creates desktop shortcut and updates the UI to indicate success |
| 128 // when creating a profile. | 129 // when creating a profile. |
| 129 void CreateShortcutAndShowSuccess(bool create_shortcut, | 130 void CreateShortcutAndShowSuccess(bool create_shortcut, |
| 130 Profile* custodian_profile, | 131 Profile* custodian_profile, |
| 131 Profile* profile); | 132 Profile* profile); |
| 132 | 133 |
| 134 // Opens a new window for |profile|. |
| 135 virtual void OpenNewWindowForProfile(Profile* profile, |
| 136 Profile::CreateStatus status); |
| 137 |
| 138 // This callback is run after a new browser (but not the window) has been |
| 139 // created for the new profile. |
| 140 void OnBrowserReadyCallback(Profile* profile, Profile::CreateStatus status); |
| 141 |
| 133 // Updates the UI to show an error when creating a profile. | 142 // Updates the UI to show an error when creating a profile. |
| 134 void ShowProfileCreationError(Profile* profile, const base::string16& error); | 143 void ShowProfileCreationError(Profile* profile, const base::string16& error); |
| 135 | 144 |
| 136 // Updates the UI to show a non-fatal warning when creating a profile. | |
| 137 void ShowProfileCreationWarning(const base::string16& warning); | |
| 138 | |
| 139 // Records UMA histograms relevant to profile creation. | 145 // Records UMA histograms relevant to profile creation. |
| 140 void RecordProfileCreationMetrics(Profile::CreateStatus status); | 146 void RecordProfileCreationMetrics(Profile::CreateStatus status); |
| 141 | 147 |
| 142 base::string16 GetProfileCreationErrorMessageLocal() const; | 148 base::string16 GetProfileCreationErrorMessageLocal() const; |
| 143 #if defined(ENABLE_SUPERVISED_USERS) | |
| 144 // The following error messages only apply to supervised profiles. | |
| 145 base::string16 GetProfileCreateErrorMessageRemote() const; | |
| 146 base::string16 GetProfileCreateErrorMessageSignin() const; | |
| 147 #endif | |
| 148 | 149 |
| 149 base::StringValue GetWebUIListenerName(ProfileCreationStatus status) const; | 150 base::StringValue GetWebUIListenerName(ProfileCreationStatus status) const; |
| 150 | 151 |
| 151 // Used to allow canceling a profile creation (particularly a supervised-user | 152 // Used to allow canceling a profile creation (particularly a supervised-user |
| 152 // registration) in progress. Set when profile creation is begun, and | 153 // registration) in progress. Set when profile creation is begun, and |
| 153 // cleared when all the callbacks have been run and creation is complete. | 154 // cleared when all the callbacks have been run and creation is complete. |
| 154 base::FilePath profile_path_being_created_; | 155 base::FilePath profile_path_being_created_; |
| 155 | 156 |
| 156 // Used to track how long profile creation takes. | 157 // Used to track how long profile creation takes. |
| 157 base::TimeTicks profile_creation_start_time_; | 158 base::TimeTicks profile_creation_start_time_; |
| 158 | 159 |
| 159 // Indicates the type of the in progress profile creation operation. | 160 // Indicates the type of the in progress profile creation operation. |
| 160 // The value is only relevant while we are creating/importing a profile. | 161 // The value is only relevant while we are creating/importing a profile. |
| 161 ProfileCreationOperationType profile_creation_type_; | 162 ProfileCreationOperationType profile_creation_type_; |
| 162 | 163 |
| 163 // Asynchronously creates and initializes a new profile. | 164 // Asynchronously creates and initializes a new profile. |
| 164 virtual void DoCreateProfile(const base::string16& name, | 165 virtual void DoCreateProfile(const base::string16& name, |
| 165 const std::string& icon_url, | 166 const std::string& icon_url, |
| 166 bool create_shortcut, | 167 bool create_shortcut, |
| 167 const std::string& supervised_user_id, | 168 const std::string& supervised_user_id, |
| 168 Profile* custodian_profile); | 169 Profile* custodian_profile); |
| 169 | 170 |
| 170 #if defined(ENABLE_SUPERVISED_USERS) | 171 #if defined(ENABLE_SUPERVISED_USERS) |
| 172 base::string16 GetProfileCreateErrorMessageRemote() const; |
| 173 base::string16 GetProfileCreateErrorMessageSignin() const; |
| 174 |
| 171 // Extracts the supervised user ID and the custodian user profile path from | 175 // Extracts the supervised user ID and the custodian user profile path from |
| 172 // the args passed into CreateProfile. | 176 // the args passed into CreateProfile. |
| 173 bool GetSupervisedCreateProfileArgs(const base::ListValue* args, | 177 bool GetSupervisedCreateProfileArgs(const base::ListValue* args, |
| 174 std::string* supervised_user_id, | 178 std::string* supervised_user_id, |
| 175 base::FilePath* custodian_profile_path); | 179 base::FilePath* custodian_profile_path); |
| 176 | 180 |
| 177 // Callback that runs once the custodian profile has been loaded. It sets | 181 // Callback that runs once the custodian profile has been loaded. It sets |
| 178 // |profile_creation_type_| if necessary, and calls |DoCreateProfile| if the | 182 // |profile_creation_type_| if necessary, and calls |DoCreateProfile| if the |
| 179 // supervised user id specified in |args| is valid. | 183 // supervised user id specified in |args| is valid. |
| 180 void LoadCustodianProfileCallback(const base::string16& name, | 184 void LoadCustodianProfileCallback(const base::string16& name, |
| 181 const std::string& icon_url, | 185 const std::string& icon_url, |
| 182 bool create_shortcut, | 186 bool create_shortcut, |
| 183 const std::string& supervised_user_id, | 187 const std::string& supervised_user_id, |
| 184 Profile* custodian_profile, | 188 Profile* custodian_profile, |
| 185 Profile::CreateStatus status); | 189 Profile::CreateStatus status); |
| 186 | 190 |
| 187 // Cancels creation of a supervised-user profile currently in progress, as | 191 // Cancels creation of a supervised-user profile currently in progress, as |
| 188 // indicated by profile_path_being_created_, removing the object and files | 192 // indicated by profile_path_being_created_, removing the object and files |
| 189 // and canceling supervised-user registration. This is the handler for the | 193 // and canceling supervised-user registration. This is the handler for the |
| 190 // "cancelCreateProfile" message. |args| is not used. | 194 // "cancelCreateProfile" message. |args| is not used. |
| 191 void HandleCancelProfileCreation(const base::ListValue* args); | 195 void HandleCancelProfileCreation(const base::ListValue* args); |
| 192 | 196 |
| 193 // Internal implementation. This may safely be called whether profile creation | 197 // Internal implementation. This may safely be called whether profile creation |
| 194 // or registration is in progress or not. |user_initiated| should be true if | 198 // or registration is in progress or not. |user_initiated| should be true if |
| 195 // the cancellation was deliberately requested by the user, and false if it | 199 // the cancellation was deliberately requested by the user, and false if it |
| 196 // was caused implicitly, e.g. by shutting down the browser. | 200 // was caused implicitly, e.g. by shutting down the browser. |
| 197 void CancelProfileRegistration(bool user_initiated); | 201 void CancelProfileRegistration(bool user_initiated); |
| 198 | 202 |
| 203 // Returns true if profile has signed into chrome. |
| 204 bool IsAccountConnected(Profile* profile) const; |
| 205 // Returns true if profile has authentication error. |
| 206 bool HasAuthError(Profile* profile) const; |
| 207 |
| 199 // After a new supervised-user profile has been created, registers the user | 208 // After a new supervised-user profile has been created, registers the user |
| 200 // with the management server. | 209 // with the management server. |
| 201 virtual void RegisterSupervisedUser(bool create_shortcut, | 210 virtual void RegisterSupervisedUser(bool create_shortcut, |
| 202 const std::string& managed_user_id, | 211 const std::string& managed_user_id, |
| 203 Profile* custodian_profile, | 212 Profile* custodian_profile, |
| 204 Profile* new_profile); | 213 Profile* new_profile); |
| 205 | 214 |
| 206 // Called back with the result of the supervised user registration. | 215 // Called back with the result of the supervised user registration. |
| 207 void OnSupervisedUserRegistered(bool create_shortcut, | 216 void OnSupervisedUserRegistered(bool create_shortcut, |
| 208 Profile* custodian_profile, | 217 Profile* custodian_profile, |
| 209 Profile* profile, | 218 Profile* profile, |
| 210 const GoogleServiceAuthError& error); | 219 const GoogleServiceAuthError& error); |
| 211 | 220 |
| 221 // Updates the UI to show a non-fatal warning when creating a profile. |
| 222 void ShowProfileCreationWarning(const base::string16& warning); |
| 223 |
| 212 // Records UMA histograms relevant to supervised user profiles | 224 // Records UMA histograms relevant to supervised user profiles |
| 213 // creation and registration. | 225 // creation and registration. |
| 214 void RecordSupervisedProfileCreationMetrics( | 226 void RecordSupervisedProfileCreationMetrics( |
| 215 GoogleServiceAuthError::State error_state); | 227 GoogleServiceAuthError::State error_state); |
| 216 | 228 |
| 217 // Creates the supervised user with the given |supervised_user_id| if the user | 229 // Creates the supervised user with the given |supervised_user_id| if the user |
| 218 // doesn't already exist on the machine. | 230 // doesn't already exist on the machine. |
| 219 void DoCreateProfileIfPossible(const base::string16& name, | 231 void DoCreateProfileIfPossible(const base::string16& name, |
| 220 const std::string& icon_url, | 232 const std::string& icon_url, |
| 221 bool create_shortcut, | 233 bool create_shortcut, |
| 222 const std::string& supervised_user_id, | 234 const std::string& supervised_user_id, |
| 223 Profile* custodian_profile, | 235 Profile* custodian_profile, |
| 224 const base::DictionaryValue* dict); | 236 const base::DictionaryValue* dict); |
| 225 | 237 |
| 226 // Opens a new window for |profile|. | |
| 227 virtual void OpenNewWindowForProfile(Profile* profile, | |
| 228 Profile::CreateStatus status); | |
| 229 | |
| 230 // Callback for the "switchToProfile" message. Opens a new window for the | 238 // Callback for the "switchToProfile" message. Opens a new window for the |
| 231 // profile. The profile file path is passed as a string argument. | 239 // profile. The profile file path is passed as a string argument. |
| 232 void SwitchToProfile(const base::ListValue* args); | 240 void SwitchToProfile(const base::ListValue* args); |
| 233 | 241 |
| 234 std::unique_ptr<SupervisedUserRegistrationUtility> | 242 std::unique_ptr<SupervisedUserRegistrationUtility> |
| 235 supervised_user_registration_utility_; | 243 supervised_user_registration_utility_; |
| 236 #endif | 244 #endif |
| 237 | 245 |
| 238 // Returns true if profile has signed into chrome. | |
| 239 bool IsAccountConnected(Profile* profile) const; | |
| 240 // Returns true if profile has authentication error. | |
| 241 bool HasAuthError(Profile* profile) const; | |
| 242 | |
| 243 // This callback is run after a new browser (but not the window) has been | |
| 244 // created for the new profile. | |
| 245 void OnBrowserReadyCallback(Profile* profile, | |
| 246 Profile::CreateStatus status); | |
| 247 | |
| 248 content::NotificationRegistrar registrar_; | 246 content::NotificationRegistrar registrar_; |
| 249 | 247 |
| 250 base::WeakPtrFactory<SigninCreateProfileHandler> weak_ptr_factory_; | 248 base::WeakPtrFactory<SigninCreateProfileHandler> weak_ptr_factory_; |
| 251 | 249 |
| 252 private: | 250 private: |
| 253 DISALLOW_COPY_AND_ASSIGN(SigninCreateProfileHandler); | 251 DISALLOW_COPY_AND_ASSIGN(SigninCreateProfileHandler); |
| 254 }; | 252 }; |
| 255 | 253 |
| 256 #endif // CHROME_BROWSER_UI_WEBUI_SIGNIN_SIGNIN_CREATE_PROFILE_HANDLER_H_ | 254 #endif // CHROME_BROWSER_UI_WEBUI_SIGNIN_SIGNIN_CREATE_PROFILE_HANDLER_H_ |
| OLD | NEW |