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