| 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 #include "chrome/browser/ui/webui/options/create_profile_handler.h" | 5 #include "chrome/browser/ui/webui/signin/signin_create_profile_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string> |
| 9 #include <vector> |
| 8 | 10 |
| 9 #include "base/bind.h" | 11 #include "base/bind.h" |
| 10 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 11 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 12 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 13 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/task_runner_util.h" |
| 18 #include "base/threading/thread_restrictions.h" |
| 14 #include "base/value_conversions.h" | 19 #include "base/value_conversions.h" |
| 15 #include "base/values.h" | 20 #include "base/values.h" |
| 16 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 22 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 18 #include "chrome/browser/profiles/profile_manager.h" | 23 #include "chrome/browser/profiles/profile_manager.h" |
| 19 #include "chrome/browser/profiles/profile_metrics.h" | 24 #include "chrome/browser/profiles/profile_metrics.h" |
| 20 #include "chrome/browser/profiles/profiles_state.h" | 25 #include "chrome/browser/profiles/profiles_state.h" |
| 26 #include "chrome/browser/signin/signin_manager_factory.h" |
| 21 #include "chrome/browser/sync/profile_sync_service_factory.h" | 27 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 22 #include "chrome/browser/ui/webui/options/options_handlers_helper.h" | 28 #include "chrome/browser/ui/webui/options/options_handlers_helper.h" |
| 23 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/common/url_constants.h" |
| 24 #include "chrome/grit/generated_resources.h" | 31 #include "chrome/grit/generated_resources.h" |
| 25 #include "components/browser_sync/browser/profile_sync_service.h" | 32 #include "components/browser_sync/browser/profile_sync_service.h" |
| 33 #include "components/strings/grit/components_strings.h" |
| 34 #include "content/public/browser/browser_thread.h" |
| 26 #include "content/public/browser/web_ui.h" | 35 #include "content/public/browser/web_ui.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
| 28 | 37 |
| 29 #if defined(ENABLE_SUPERVISED_USERS) | 38 #if defined(ENABLE_SUPERVISED_USERS) |
| 30 #include "chrome/browser/supervised_user/legacy/supervised_user_registration_uti
lity.h" | 39 #include "chrome/browser/supervised_user/legacy/supervised_user_registration_uti
lity.h" |
| 31 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service.h" | 40 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service.h" |
| 32 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service_fac
tory.h" | 41 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service_fac
tory.h" |
| 33 #include "chrome/browser/supervised_user/supervised_user_service.h" | 42 #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 34 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | 43 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
| 35 #endif | 44 #endif |
| 36 | 45 |
| 37 namespace options { | 46 SigninCreateProfileHandler::SigninCreateProfileHandler() |
| 47 : profile_creation_type_(NO_CREATION_IN_PROGRESS), |
| 48 weak_ptr_factory_(this) {} |
| 38 | 49 |
| 39 CreateProfileHandler::CreateProfileHandler() | 50 SigninCreateProfileHandler::~SigninCreateProfileHandler() { |
| 40 : profile_creation_type_(NO_CREATION_IN_PROGRESS), | |
| 41 weak_ptr_factory_(this) { | |
| 42 } | |
| 43 | |
| 44 CreateProfileHandler::~CreateProfileHandler() { | |
| 45 #if defined(ENABLE_SUPERVISED_USERS) | 51 #if defined(ENABLE_SUPERVISED_USERS) |
| 46 // Cancellation is only supported for supervised users. | 52 // Cancellation is only supported for supervised users. |
| 47 CancelProfileRegistration(false); | 53 CancelProfileRegistration(false); |
| 48 #endif | 54 #endif |
| 49 } | 55 } |
| 50 | 56 |
| 51 void CreateProfileHandler::GetLocalizedValues( | 57 void SigninCreateProfileHandler::GetLocalizedValues( |
| 52 base::DictionaryValue* localized_strings) { | 58 base::DictionaryValue* localized_strings) { |
| 59 localized_strings->SetString( |
| 60 "manageProfilesSupervisedSignedInLabel", |
| 61 l10n_util::GetStringUTF16( |
| 62 IDS_PROFILES_CREATE_SUPERVISED_MULTI_SIGNED_IN_LABEL)); |
| 63 localized_strings->SetString( |
| 64 "manageProfilesSupervisedNotSignedIn", |
| 65 l10n_util::GetStringUTF16( |
| 66 IDS_PROFILES_CREATE_SUPERVISED_NOT_SIGNED_IN_HTML)); |
| 67 localized_strings->SetString("createProfileConfirm", |
| 68 l10n_util::GetStringUTF16(IDS_SAVE)); |
| 69 localized_strings->SetString("learnMore", |
| 70 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); |
| 71 localized_strings->SetString( |
| 72 "createProfileTitle", |
| 73 l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_TITLE)); |
| 74 |
| 75 localized_strings->SetString( |
| 76 "supervisedUserLearnMoreTitle", |
| 77 l10n_util::GetStringUTF16(IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_TITLE)); |
| 78 localized_strings->SetString( |
| 79 "supervisedUserLearnMoreDone", |
| 80 l10n_util::GetStringUTF16( |
| 81 IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_DONE_BUTTON)); |
| 82 localized_strings->SetString( |
| 83 "supervisedUserLearnMoreText", |
| 84 l10n_util::GetStringFUTF16( |
| 85 IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_TEXT, |
| 86 base::ASCIIToUTF16( |
| 87 chrome::kLegacySupervisedUserManagementDisplayURL))); |
| 53 } | 88 } |
| 54 | 89 |
| 55 void CreateProfileHandler::RegisterMessages() { | 90 void SigninCreateProfileHandler::RegisterMessages() { |
| 56 #if defined(ENABLE_SUPERVISED_USERS) | 91 #if defined(ENABLE_SUPERVISED_USERS) |
| 57 // Cancellation is only supported for supervised users. | 92 // Cancellation is only supported for supervised users. |
| 58 web_ui()->RegisterMessageCallback( | 93 web_ui()->RegisterMessageCallback( |
| 59 "cancelCreateProfile", | 94 "cancelCreateProfile", |
| 60 base::Bind(&CreateProfileHandler::HandleCancelProfileCreation, | 95 base::Bind(&SigninCreateProfileHandler::HandleCancelProfileCreation, |
| 61 base::Unretained(this))); | 96 base::Unretained(this))); |
| 62 #endif | 97 #endif |
| 63 web_ui()->RegisterMessageCallback( | 98 web_ui()->RegisterMessageCallback( |
| 64 "createProfile", | 99 "createProfile", base::Bind(&SigninCreateProfileHandler::CreateProfile, |
| 65 base::Bind(&CreateProfileHandler::CreateProfile, | 100 base::Unretained(this))); |
| 101 |
| 102 web_ui()->RegisterMessageCallback( |
| 103 "requestDefaultProfileIcons", |
| 104 base::Bind(&SigninCreateProfileHandler::RequestDefaultProfileIcons, |
| 105 base::Unretained(this))); |
| 106 |
| 107 web_ui()->RegisterMessageCallback( |
| 108 "requestSignedInProfiles", |
| 109 base::Bind(&SigninCreateProfileHandler::RequestSignedInProfiles, |
| 66 base::Unretained(this))); | 110 base::Unretained(this))); |
| 67 } | 111 } |
| 68 | 112 |
| 69 void CreateProfileHandler::CreateProfile(const base::ListValue* args) { | 113 void SigninCreateProfileHandler::RequestDefaultProfileIcons( |
| 70 #if defined(ENABLE_SUPERVISED_USERS) | 114 const base::ListValue* args) { |
| 71 // This handler could have been called for a supervised user, for example | 115 base::ListValue image_url_list; |
| 72 // because the user fiddled with the web inspector. Silently return. | |
| 73 if (Profile::FromWebUI(web_ui())->IsSupervised()) | |
| 74 return; | |
| 75 #endif | |
| 76 | 116 |
| 117 // Add the default avatar icons. |
| 118 size_t placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex(); |
| 119 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount() && |
| 120 i != placeholder_avatar_index; |
| 121 i++) { |
| 122 std::string url = profiles::GetDefaultAvatarIconUrl(i); |
| 123 image_url_list.AppendString(url); |
| 124 } |
| 125 |
| 126 web_ui()->CallJavascriptFunction("signin.ProfileApi.updateAvailableIcons", |
| 127 image_url_list); |
| 128 } |
| 129 |
| 130 void SigninCreateProfileHandler::RequestSignedInProfiles( |
| 131 const base::ListValue* args) { |
| 132 base::ListValue user_info_list; |
| 133 ProfileInfoCache& cache = |
| 134 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 135 std::vector<ProfileAttributesEntry*> entries = |
| 136 cache.GetAllProfilesAttributes(); |
| 137 for (auto& entry : entries) { |
| 138 base::string16 username = entry->GetUserName(); |
| 139 if (username.empty()) |
| 140 continue; |
| 141 base::string16 profile_path = entry->GetPath().AsUTF16Unsafe(); |
| 142 base::DictionaryValue* user_info = new base::DictionaryValue(); |
| 143 user_info->SetString("username", username); |
| 144 user_info->SetString("profilePath", profile_path); |
| 145 |
| 146 user_info_list.Append(user_info); |
| 147 } |
| 148 web_ui()->CallJavascriptFunction("signin.ProfileApi.updateSignedInUsers", |
| 149 user_info_list); |
| 150 } |
| 151 |
| 152 void SigninCreateProfileHandler::CreateProfile(const base::ListValue* args) { |
| 77 if (!profiles::IsMultipleProfilesEnabled()) | 153 if (!profiles::IsMultipleProfilesEnabled()) |
| 78 return; | 154 return; |
| 79 | 155 |
| 80 // We can have only one in progress profile creation | 156 // We can have only one in progress profile creation |
| 81 // at any given moment, if new ones are initiated just | 157 // at any given moment, if new ones are initiated just |
| 82 // ignore them until we are done with the old one. | 158 // ignore them until we are done with the old one. |
| 83 if (profile_creation_type_ != NO_CREATION_IN_PROGRESS) | 159 if (profile_creation_type_ != NO_CREATION_IN_PROGRESS) |
| 84 return; | 160 return; |
| 85 | 161 |
| 86 profile_creation_type_ = NON_SUPERVISED_PROFILE_CREATION; | 162 profile_creation_type_ = NON_SUPERVISED_PROFILE_CREATION; |
| 87 | 163 |
| 88 DCHECK(profile_path_being_created_.empty()); | 164 DCHECK(profile_path_being_created_.empty()); |
| 89 profile_creation_start_time_ = base::TimeTicks::Now(); | 165 profile_creation_start_time_ = base::TimeTicks::Now(); |
| 90 | 166 |
| 91 base::string16 name; | 167 base::string16 name; |
| 92 std::string icon_url; | 168 std::string icon_url; |
| 93 bool create_shortcut = false; | 169 bool create_shortcut = false; |
| 94 if (args->GetString(0, &name) && args->GetString(1, &icon_url)) { | 170 if (args->GetString(0, &name) && args->GetString(1, &icon_url)) { |
| 95 DCHECK(base::IsStringASCII(icon_url)); | 171 DCHECK(base::IsStringASCII(icon_url)); |
| 96 base::TrimWhitespace(name, base::TRIM_ALL, &name); | 172 base::TrimWhitespace(name, base::TRIM_ALL, &name); |
| 97 CHECK(!name.empty()); | 173 CHECK(!name.empty()); |
| 98 #ifndef NDEBUG | 174 #ifndef NDEBUG |
| 99 size_t icon_index; | 175 size_t icon_index; |
| 100 DCHECK(profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index)); | 176 DCHECK(profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index)); |
| 101 #endif | 177 #endif |
| 102 args->GetBoolean(2, &create_shortcut); | 178 args->GetBoolean(2, &create_shortcut); |
| 103 } | 179 } |
| 180 #if defined(ENABLE_SUPERVISED_USERS) |
| 104 std::string supervised_user_id; | 181 std::string supervised_user_id; |
| 105 #if defined(ENABLE_SUPERVISED_USERS) | 182 base::FilePath supervisor_profile_path; |
| 106 if (!ProcessSupervisedCreateProfileArgs(args, &supervised_user_id)) | 183 if (GetSupervisedCreateProfileArgs(args, &supervised_user_id, |
| 107 return; | 184 &supervisor_profile_path)) { |
| 185 // Load supervisor profile. |
| 186 g_browser_process->profile_manager()->CreateProfileAsync( |
| 187 supervisor_profile_path, |
| 188 base::Bind(&SigninCreateProfileHandler::LoadSupervisorProfileCallback, |
| 189 weak_ptr_factory_.GetWeakPtr(), name, icon_url, |
| 190 create_shortcut, supervised_user_id), |
| 191 base::string16(), std::string(), std::string()); |
| 192 } else { |
| 193 DoCreateProfile(name, icon_url, create_shortcut, std::string(), nullptr); |
| 194 } |
| 195 #else |
| 196 DoCreateProfile(name, icon_url, create_shortcut, std::string(), nullptr); |
| 108 #endif | 197 #endif |
| 198 } |
| 109 | 199 |
| 200 void SigninCreateProfileHandler::DoCreateProfile( |
| 201 const base::string16& name, |
| 202 const std::string& icon_url, |
| 203 bool create_shortcut, |
| 204 const std::string& supervised_user_id, |
| 205 Profile* supervisor_profile) { |
| 110 ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_DIALOG); | 206 ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_DIALOG); |
| 111 | 207 |
| 112 profile_path_being_created_ = ProfileManager::CreateMultiProfileAsync( | 208 profile_path_being_created_ = ProfileManager::CreateMultiProfileAsync( |
| 113 name, icon_url, | 209 name, icon_url, |
| 114 base::Bind(&CreateProfileHandler::OnProfileCreated, | 210 base::Bind(&SigninCreateProfileHandler::OnProfileCreated, |
| 115 weak_ptr_factory_.GetWeakPtr(), | 211 weak_ptr_factory_.GetWeakPtr(), create_shortcut, |
| 116 create_shortcut, | 212 options::helper::GetDesktopType(web_ui()), supervised_user_id, |
| 117 helper::GetDesktopType(web_ui()), | 213 supervisor_profile), |
| 118 supervised_user_id), | |
| 119 supervised_user_id); | 214 supervised_user_id); |
| 120 } | 215 } |
| 121 | 216 |
| 122 void CreateProfileHandler::OnProfileCreated( | 217 void SigninCreateProfileHandler::OnProfileCreated( |
| 123 bool create_shortcut, | 218 bool create_shortcut, |
| 124 chrome::HostDesktopType desktop_type, | 219 chrome::HostDesktopType desktop_type, |
| 125 const std::string& supervised_user_id, | 220 const std::string& supervised_user_id, |
| 221 Profile* supervisor_profile, |
| 126 Profile* profile, | 222 Profile* profile, |
| 127 Profile::CreateStatus status) { | 223 Profile::CreateStatus status) { |
| 128 if (status != Profile::CREATE_STATUS_CREATED) | 224 if (status != Profile::CREATE_STATUS_CREATED) |
| 129 RecordProfileCreationMetrics(status); | 225 RecordProfileCreationMetrics(status); |
| 130 | 226 |
| 131 switch (status) { | 227 switch (status) { |
| 132 case Profile::CREATE_STATUS_LOCAL_FAIL: { | 228 case Profile::CREATE_STATUS_LOCAL_FAIL: { |
| 133 ShowProfileCreationError(profile, GetProfileCreationErrorMessageLocal()); | 229 ShowProfileCreationError(profile, GetProfileCreationErrorMessageLocal()); |
| 134 break; | 230 break; |
| 135 } | 231 } |
| 136 case Profile::CREATE_STATUS_CREATED: { | 232 case Profile::CREATE_STATUS_CREATED: { |
| 137 // Do nothing for an intermediate status. | 233 // Do nothing for an intermediate status. |
| 138 break; | 234 break; |
| 139 } | 235 } |
| 140 case Profile::CREATE_STATUS_INITIALIZED: { | 236 case Profile::CREATE_STATUS_INITIALIZED: { |
| 141 HandleProfileCreationSuccess(create_shortcut, desktop_type, | 237 HandleProfileCreationSuccess(create_shortcut, desktop_type, |
| 142 supervised_user_id, profile); | 238 supervised_user_id, supervisor_profile, |
| 239 profile); |
| 143 break; | 240 break; |
| 144 } | 241 } |
| 145 // User-initiated cancellation is handled in CancelProfileRegistration and | 242 // User-initiated cancellation is handled in CancelProfileRegistration and |
| 146 // does not call this callback. | 243 // does not call this callback. |
| 147 case Profile::CREATE_STATUS_CANCELED: | 244 case Profile::CREATE_STATUS_CANCELED: |
| 148 // Supervised user registration errors are handled in | 245 // Supervised user registration errors are handled in |
| 149 // OnSupervisedUserRegistered(). | 246 // OnSupervisedUserRegistered(). |
| 150 case Profile::CREATE_STATUS_REMOTE_FAIL: | 247 case Profile::CREATE_STATUS_REMOTE_FAIL: |
| 151 case Profile::MAX_CREATE_STATUS: { | 248 case Profile::MAX_CREATE_STATUS: { |
| 152 NOTREACHED(); | 249 NOTREACHED(); |
| 153 break; | 250 break; |
| 154 } | 251 } |
| 155 } | 252 } |
| 156 } | 253 } |
| 157 | 254 |
| 158 void CreateProfileHandler::HandleProfileCreationSuccess( | 255 void SigninCreateProfileHandler::HandleProfileCreationSuccess( |
| 159 bool create_shortcut, | 256 bool create_shortcut, |
| 160 chrome::HostDesktopType desktop_type, | 257 chrome::HostDesktopType desktop_type, |
| 161 const std::string& supervised_user_id, | 258 const std::string& supervised_user_id, |
| 259 Profile* supervisor_profile, |
| 162 Profile* profile) { | 260 Profile* profile) { |
| 163 switch (profile_creation_type_) { | 261 switch (profile_creation_type_) { |
| 164 case NON_SUPERVISED_PROFILE_CREATION: { | 262 case NON_SUPERVISED_PROFILE_CREATION: { |
| 165 DCHECK(supervised_user_id.empty()); | 263 DCHECK(supervised_user_id.empty()); |
| 166 CreateShortcutAndShowSuccess(create_shortcut, desktop_type, profile); | 264 CreateShortcutAndShowSuccess(create_shortcut, desktop_type, profile); |
| 167 break; | 265 break; |
| 168 } | 266 } |
| 169 #if defined(ENABLE_SUPERVISED_USERS) | 267 #if defined(ENABLE_SUPERVISED_USERS) |
| 170 case SUPERVISED_PROFILE_CREATION: | 268 case SUPERVISED_PROFILE_CREATION: |
| 171 case SUPERVISED_PROFILE_IMPORT: | 269 case SUPERVISED_PROFILE_IMPORT: |
| 172 RegisterSupervisedUser(create_shortcut, desktop_type, | 270 RegisterSupervisedUser(create_shortcut, desktop_type, supervised_user_id, |
| 173 supervised_user_id, profile); | 271 supervisor_profile, profile); |
| 174 break; | 272 break; |
| 175 #endif | 273 #endif |
| 176 case NO_CREATION_IN_PROGRESS: | 274 case NO_CREATION_IN_PROGRESS: |
| 177 NOTREACHED(); | 275 NOTREACHED(); |
| 178 break; | 276 break; |
| 179 } | 277 } |
| 180 } | 278 } |
| 181 | 279 |
| 182 void CreateProfileHandler::CreateShortcutAndShowSuccess( | 280 void SigninCreateProfileHandler::CreateShortcutAndShowSuccess( |
| 183 bool create_shortcut, | 281 bool create_shortcut, |
| 184 chrome::HostDesktopType desktop_type, | 282 chrome::HostDesktopType desktop_type, |
| 185 Profile* profile) { | 283 Profile* profile) { |
| 186 if (create_shortcut) { | 284 if (create_shortcut) { |
| 187 ProfileShortcutManager* shortcut_manager = | 285 ProfileShortcutManager* shortcut_manager = |
| 188 g_browser_process->profile_manager()->profile_shortcut_manager(); | 286 g_browser_process->profile_manager()->profile_shortcut_manager(); |
| 189 | 287 |
| 190 if (shortcut_manager) | 288 if (shortcut_manager) |
| 191 shortcut_manager->CreateProfileShortcut(profile->GetPath()); | 289 shortcut_manager->CreateProfileShortcut(profile->GetPath()); |
| 192 } | 290 } |
| 193 | 291 |
| 194 DCHECK_EQ(profile_path_being_created_.value(), profile->GetPath().value()); | 292 DCHECK_EQ(profile_path_being_created_.value(), profile->GetPath().value()); |
| 195 profile_path_being_created_.clear(); | 293 profile_path_being_created_.clear(); |
| 196 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); | 294 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); |
| 197 base::DictionaryValue dict; | 295 base::DictionaryValue dict; |
| 198 dict.SetString("name", | 296 dict.SetString("name", profile->GetPrefs()->GetString(prefs::kProfileName)); |
| 199 profile->GetPrefs()->GetString(prefs::kProfileName)); | |
| 200 dict.Set("filePath", base::CreateFilePathValue(profile->GetPath())); | 297 dict.Set("filePath", base::CreateFilePathValue(profile->GetPath())); |
| 201 #if defined(ENABLE_SUPERVISED_USERS) | 298 #if defined(ENABLE_SUPERVISED_USERS) |
| 202 bool is_supervised = | 299 bool is_supervised = profile_creation_type_ == SUPERVISED_PROFILE_CREATION || |
| 203 profile_creation_type_ == SUPERVISED_PROFILE_CREATION || | 300 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT; |
| 204 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT; | |
| 205 dict.SetBoolean("isSupervised", is_supervised); | 301 dict.SetBoolean("isSupervised", is_supervised); |
| 206 #endif | 302 #endif |
| 207 web_ui()->CallJavascriptFunction( | 303 web_ui()->CallJavascriptFunction( |
| 208 GetJavascriptMethodName(PROFILE_CREATION_SUCCESS), dict); | 304 GetJavascriptMethodName(PROFILE_CREATION_SUCCESS), dict); |
| 209 | 305 |
| 210 // If the new profile is a supervised user, instead of opening a new window | 306 // If the new profile is a supervised user, instead of opening a new window |
| 211 // right away, a confirmation overlay will be shown by JS from the creation | 307 // right away, a confirmation overlay will be shown by JS from the creation |
| 212 // dialog. If we are importing an existing supervised profile or creating a | 308 // dialog. If we are importing an existing supervised profile or creating a |
| 213 // new non-supervised user profile we don't show any confirmation, so open | 309 // new non-supervised user profile we don't show any confirmation, so open |
| 214 // the new window now. | 310 // the new window now. |
| 215 bool should_open_new_window = true; | 311 bool should_open_new_window = true; |
| 216 #if defined(ENABLE_SUPERVISED_USERS) | 312 #if defined(ENABLE_SUPERVISED_USERS) |
| 217 if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION) | 313 if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION) |
| 218 should_open_new_window = false; | 314 should_open_new_window = false; |
| 219 #endif | 315 #endif |
| 220 | 316 |
| 221 if (should_open_new_window) { | 317 if (should_open_new_window) { |
| 222 // Opening the new window must be the last action, after all callbacks | 318 // Opening the new window must be the last action, after all callbacks |
| 223 // have been run, to give them a chance to initialize the profile. | 319 // have been run, to give them a chance to initialize the profile. |
| 224 helper::OpenNewWindowForProfile(desktop_type, | 320 options::helper::OpenNewWindowForProfile( |
| 225 profile, | 321 desktop_type, profile, Profile::CREATE_STATUS_INITIALIZED); |
| 226 Profile::CREATE_STATUS_INITIALIZED); | |
| 227 } | 322 } |
| 228 profile_creation_type_ = NO_CREATION_IN_PROGRESS; | 323 profile_creation_type_ = NO_CREATION_IN_PROGRESS; |
| 229 } | 324 } |
| 230 | 325 |
| 231 void CreateProfileHandler::ShowProfileCreationError( | 326 void SigninCreateProfileHandler::ShowProfileCreationError( |
| 232 Profile* profile, | 327 Profile* profile, |
| 233 const base::string16& error) { | 328 const base::string16& error) { |
| 234 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); | 329 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); |
| 235 profile_creation_type_ = NO_CREATION_IN_PROGRESS; | 330 profile_creation_type_ = NO_CREATION_IN_PROGRESS; |
| 236 profile_path_being_created_.clear(); | 331 profile_path_being_created_.clear(); |
| 237 web_ui()->CallJavascriptFunction( | 332 web_ui()->CallJavascriptFunction( |
| 238 GetJavascriptMethodName(PROFILE_CREATION_ERROR), | 333 GetJavascriptMethodName(PROFILE_CREATION_ERROR), |
| 239 base::StringValue(error)); | 334 base::StringValue(error)); |
| 240 // The ProfileManager calls us back with a NULL profile in some cases. | 335 // The ProfileManager calls us back with a NULL profile in some cases. |
| 241 if (profile) | 336 if (profile) |
| 242 helper::DeleteProfileAtPath(profile->GetPath(), web_ui()); | 337 options::helper::DeleteProfileAtPath(profile->GetPath(), web_ui()); |
| 243 } | 338 } |
| 244 | 339 |
| 245 void CreateProfileHandler::RecordProfileCreationMetrics( | 340 void SigninCreateProfileHandler::RecordProfileCreationMetrics( |
| 246 Profile::CreateStatus status) { | 341 Profile::CreateStatus status) { |
| 247 UMA_HISTOGRAM_ENUMERATION("Profile.CreateResult", | 342 UMA_HISTOGRAM_ENUMERATION("Profile.CreateResult", status, |
| 248 status, | |
| 249 Profile::MAX_CREATE_STATUS); | 343 Profile::MAX_CREATE_STATUS); |
| 250 UMA_HISTOGRAM_MEDIUM_TIMES( | 344 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 251 "Profile.CreateTimeNoTimeout", | 345 "Profile.CreateTimeNoTimeout", |
| 252 base::TimeTicks::Now() - profile_creation_start_time_); | 346 base::TimeTicks::Now() - profile_creation_start_time_); |
| 253 } | 347 } |
| 254 | 348 |
| 255 base::string16 CreateProfileHandler::GetProfileCreationErrorMessageLocal() | 349 base::string16 SigninCreateProfileHandler::GetProfileCreationErrorMessageLocal() |
| 256 const { | 350 const { |
| 257 int message_id = IDS_PROFILES_CREATE_LOCAL_ERROR; | 351 int message_id = IDS_PROFILES_CREATE_LOCAL_ERROR; |
| 258 #if defined(ENABLE_SUPERVISED_USERS) | 352 #if defined(ENABLE_SUPERVISED_USERS) |
| 259 // Local errors can occur during supervised profile import. | 353 // Local errors can occur during supervised profile import. |
| 260 if (profile_creation_type_ == SUPERVISED_PROFILE_IMPORT) | 354 if (profile_creation_type_ == SUPERVISED_PROFILE_IMPORT) |
| 261 message_id = IDS_LEGACY_SUPERVISED_USER_IMPORT_LOCAL_ERROR; | 355 message_id = IDS_LEGACY_SUPERVISED_USER_IMPORT_LOCAL_ERROR; |
| 262 #endif | 356 #endif |
| 263 return l10n_util::GetStringUTF16(message_id); | 357 return l10n_util::GetStringUTF16(message_id); |
| 264 } | 358 } |
| 265 | 359 |
| 266 #if defined(ENABLE_SUPERVISED_USERS) | 360 #if defined(ENABLE_SUPERVISED_USERS) |
| 267 base::string16 CreateProfileHandler::GetProfileCreationErrorMessageRemote() | 361 base::string16 SigninCreateProfileHandler::GetProfileCreateErrorMessageRemote() |
| 268 const { | 362 const { |
| 269 return l10n_util::GetStringUTF16( | 363 return l10n_util::GetStringUTF16( |
| 270 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ? | 364 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT |
| 271 IDS_LEGACY_SUPERVISED_USER_IMPORT_REMOTE_ERROR : | 365 ? IDS_LEGACY_SUPERVISED_USER_IMPORT_REMOTE_ERROR |
| 272 IDS_PROFILES_CREATE_REMOTE_ERROR); | 366 : IDS_PROFILES_CREATE_REMOTE_ERROR); |
| 273 } | 367 } |
| 274 | 368 |
| 275 base::string16 CreateProfileHandler::GetProfileCreationErrorMessageSignin() | 369 base::string16 SigninCreateProfileHandler::GetProfileCreateErrorMessageSignin() |
| 276 const { | 370 const { |
| 277 return l10n_util::GetStringUTF16( | 371 return l10n_util::GetStringUTF16( |
| 278 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ? | 372 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT |
| 279 IDS_LEGACY_SUPERVISED_USER_IMPORT_SIGN_IN_ERROR : | 373 ? IDS_LEGACY_SUPERVISED_USER_IMPORT_SIGN_IN_ERROR |
| 280 IDS_PROFILES_CREATE_SIGN_IN_ERROR); | 374 : IDS_PROFILES_CREATE_SIGN_IN_ERROR); |
| 281 } | 375 } |
| 282 #endif | 376 #endif |
| 283 | 377 |
| 284 std::string CreateProfileHandler::GetJavascriptMethodName( | 378 std::string SigninCreateProfileHandler::GetJavascriptMethodName( |
| 285 ProfileCreationStatus status) const { | 379 ProfileCreationStatus status) const { |
| 286 switch (profile_creation_type_) { | 380 switch (profile_creation_type_) { |
| 287 #if defined(ENABLE_SUPERVISED_USERS) | 381 #if defined(ENABLE_SUPERVISED_USERS) |
| 288 case SUPERVISED_PROFILE_IMPORT: | 382 case SUPERVISED_PROFILE_IMPORT: |
| 289 switch (status) { | 383 switch (status) { |
| 290 case PROFILE_CREATION_SUCCESS: | 384 case PROFILE_CREATION_SUCCESS: |
| 291 return "BrowserOptions.showSupervisedUserImportSuccess"; | 385 return "BrowserOptions.showSupervisedUserImportSuccess"; |
| 292 case PROFILE_CREATION_ERROR: | 386 case PROFILE_CREATION_ERROR: |
| 293 return "BrowserOptions.showSupervisedUserImportError"; | 387 return "BrowserOptions.showSupervisedUserImportError"; |
| 294 } | 388 } |
| 295 break; | 389 break; |
| 296 #endif | 390 #endif |
| 297 default: | 391 default: |
| 298 switch (status) { | 392 switch (status) { |
| 299 case PROFILE_CREATION_SUCCESS: | 393 case PROFILE_CREATION_SUCCESS: |
| 300 return "BrowserOptions.showCreateProfileSuccess"; | 394 return "signin.ProfileApi.onCreateProfileSuccess"; |
| 301 case PROFILE_CREATION_ERROR: | 395 case PROFILE_CREATION_ERROR: |
| 302 return "BrowserOptions.showCreateProfileError"; | 396 return "signin.ProfileApi.onCreateProfileError"; |
| 303 } | 397 } |
| 304 break; | 398 break; |
| 305 } | 399 } |
| 306 | 400 |
| 307 NOTREACHED(); | 401 NOTREACHED(); |
| 308 return std::string(); | 402 return std::string(); |
| 309 } | 403 } |
| 310 | 404 |
| 311 #if defined(ENABLE_SUPERVISED_USERS) | 405 #if defined(ENABLE_SUPERVISED_USERS) |
| 312 bool CreateProfileHandler::ProcessSupervisedCreateProfileArgs( | 406 bool SigninCreateProfileHandler::GetSupervisedCreateProfileArgs( |
| 313 const base::ListValue* args, std::string* supervised_user_id) { | 407 const base::ListValue* args, |
| 408 std::string* supervised_user_id, |
| 409 base::FilePath* supervisor_profile_path) { |
| 314 bool supervised_user = false; | 410 bool supervised_user = false; |
| 315 if (args->GetSize() >= 5) { | 411 DCHECK(args->GetBoolean(3, &supervised_user)); |
| 316 bool success = args->GetBoolean(3, &supervised_user); | 412 DCHECK(args->GetString(4, supervised_user_id)); |
| 317 DCHECK(success); | 413 if (supervised_user) { |
| 414 const base::Value* path_value; |
| 415 DCHECK(args->Get(5, &path_value)); |
| 416 DCHECK(base::GetValueAsFilePath(*path_value, supervisor_profile_path)); |
| 417 } |
| 418 return supervised_user && !supervisor_profile_path->empty(); |
| 419 } |
| 318 | 420 |
| 319 success = args->GetString(4, supervised_user_id); | 421 void SigninCreateProfileHandler::LoadSupervisorProfileCallback( |
| 320 DCHECK(success); | 422 const base::string16& name, |
| 423 const std::string& icon_url, |
| 424 bool create_shortcut, |
| 425 const std::string& supervised_user_id, |
| 426 Profile* supervisor_profile, |
| 427 Profile::CreateStatus status) { |
| 428 // This method gets called once before with Profile::CREATE_STATUS_CREATED. |
| 429 switch (status) { |
| 430 case Profile::CREATE_STATUS_LOCAL_FAIL: { |
| 431 // TODO(mahmadi): see if a better error message is required here. |
| 432 ShowProfileCreationError(nullptr, GetProfileCreationErrorMessageLocal()); |
| 433 break; |
| 434 } |
| 435 case Profile::CREATE_STATUS_CREATED: { |
| 436 // Ignore the intermediate status. |
| 437 break; |
| 438 } |
| 439 case Profile::CREATE_STATUS_INITIALIZED: { |
| 440 // We are only interested in Profile::CREATE_STATUS_INITIALIZED when |
| 441 // everything is ready. |
| 442 // TODO(mahmadi): display proper error message to the user. |
| 443 PrefService* prefs = supervisor_profile->GetPrefs(); |
| 444 if (!prefs->GetBoolean(prefs::kSupervisedUserCreationAllowed)) |
| 445 return; |
| 446 |
| 447 if (!supervised_user_id.empty()) { |
| 448 profile_creation_type_ = SUPERVISED_PROFILE_IMPORT; |
| 449 |
| 450 SupervisedUserSyncService* supervised_user_sync_service = |
| 451 SupervisedUserSyncServiceFactory::GetForProfile(supervisor_profile); |
| 452 if (supervised_user_sync_service) { |
| 453 supervised_user_sync_service->GetSupervisedUsersAsync(base::Bind( |
| 454 &SigninCreateProfileHandler::DoCreateProfileIfPossible, |
| 455 weak_ptr_factory_.GetWeakPtr(), name, icon_url, create_shortcut, |
| 456 supervised_user_id, supervisor_profile)); |
| 457 } |
| 458 } else { |
| 459 profile_creation_type_ = SUPERVISED_PROFILE_CREATION; |
| 460 std::string new_supervised_user_id = |
| 461 SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId(); |
| 462 |
| 463 // If sync is not yet fully initialized, the creation may take extra |
| 464 // time, so show a message. Import doesn't wait for an acknowledgment, |
| 465 // so it won't have the same potential delay. |
| 466 ProfileSyncService* sync_service = |
| 467 ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| 468 supervisor_profile); |
| 469 ProfileSyncService::SyncStatusSummary status = |
| 470 sync_service->QuerySyncStatusSummary(); |
| 471 if (status == ProfileSyncService::DATATYPES_NOT_INITIALIZED) { |
| 472 ShowProfileCreationWarning(l10n_util::GetStringUTF16( |
| 473 IDS_PROFILES_CREATE_SUPERVISED_JUST_SIGNED_IN)); |
| 474 } |
| 475 |
| 476 DoCreateProfile(name, icon_url, create_shortcut, new_supervised_user_id, |
| 477 supervisor_profile); |
| 478 } |
| 479 break; |
| 480 } |
| 481 case Profile::CREATE_STATUS_CANCELED: |
| 482 case Profile::CREATE_STATUS_REMOTE_FAIL: |
| 483 case Profile::MAX_CREATE_STATUS: { |
| 484 NOTREACHED(); |
| 485 break; |
| 486 } |
| 487 } |
| 488 } |
| 489 |
| 490 void SigninCreateProfileHandler::DoCreateProfileIfPossible( |
| 491 const base::string16& name, |
| 492 const std::string& icon_url, |
| 493 bool create_shortcut, |
| 494 const std::string& supervised_user_id, |
| 495 Profile* supervisor_profile, |
| 496 const base::DictionaryValue* dict) { |
| 497 DCHECK(dict); |
| 498 if (!dict->HasKey(supervised_user_id)) |
| 499 return; |
| 500 |
| 501 // Check if this supervised user already exists on this machine. |
| 502 ProfileInfoCache& cache = |
| 503 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 504 std::vector<ProfileAttributesEntry*> entries = |
| 505 cache.GetAllProfilesAttributes(); |
| 506 for (auto& entry : entries) { |
| 507 if (supervised_user_id == entry->GetSupervisedUserId()) { |
| 508 // TODO(mahmadi): see whether we need a more specific error message here. |
| 509 ShowProfileCreationError(nullptr, GetProfileCreationErrorMessageLocal()); |
| 510 return; |
| 511 } |
| 321 } | 512 } |
| 322 | 513 |
| 323 if (supervised_user) { | 514 DoCreateProfile(name, icon_url, create_shortcut, supervised_user_id, |
| 324 if (!IsValidExistingSupervisedUserId(*supervised_user_id)) | 515 supervisor_profile); |
| 325 return false; | |
| 326 | |
| 327 profile_creation_type_ = SUPERVISED_PROFILE_IMPORT; | |
| 328 if (supervised_user_id->empty()) { | |
| 329 profile_creation_type_ = SUPERVISED_PROFILE_CREATION; | |
| 330 *supervised_user_id = | |
| 331 SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId(); | |
| 332 | |
| 333 // If sync is not yet fully initialized, the creation may take extra time, | |
| 334 // so show a message. Import doesn't wait for an acknowledgment, so it | |
| 335 // won't have the same potential delay. | |
| 336 ProfileSyncService* sync_service = | |
| 337 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | |
| 338 Profile::FromWebUI(web_ui())); | |
| 339 ProfileSyncService::SyncStatusSummary status = | |
| 340 sync_service->QuerySyncStatusSummary(); | |
| 341 if (status == ProfileSyncService::DATATYPES_NOT_INITIALIZED) { | |
| 342 ShowProfileCreationWarning(l10n_util::GetStringUTF16( | |
| 343 IDS_PROFILES_CREATE_SUPERVISED_JUST_SIGNED_IN)); | |
| 344 } | |
| 345 } | |
| 346 } | |
| 347 return true; | |
| 348 } | 516 } |
| 349 | 517 |
| 350 void CreateProfileHandler::HandleCancelProfileCreation( | 518 void SigninCreateProfileHandler::HandleCancelProfileCreation( |
| 351 const base::ListValue* args) { | 519 const base::ListValue* args) { |
| 352 CancelProfileRegistration(true); | 520 CancelProfileRegistration(true); |
| 353 } | 521 } |
| 354 | 522 |
| 355 // Non-supervised user creation cannot be canceled. (Creating a non-supervised | 523 // Non-supervised user creation cannot be canceled. (Creating a non-supervised |
| 356 // profile shouldn't take significant time, and it can easily be deleted | 524 // profile shouldn't take significant time, and it can easily be deleted |
| 357 // afterward.) | 525 // afterward.) |
| 358 void CreateProfileHandler::CancelProfileRegistration(bool user_initiated) { | 526 void SigninCreateProfileHandler::CancelProfileRegistration( |
| 527 bool user_initiated) { |
| 359 if (profile_path_being_created_.empty()) | 528 if (profile_path_being_created_.empty()) |
| 360 return; | 529 return; |
| 361 | 530 |
| 362 ProfileManager* manager = g_browser_process->profile_manager(); | 531 ProfileManager* manager = g_browser_process->profile_manager(); |
| 363 Profile* new_profile = manager->GetProfileByPath(profile_path_being_created_); | 532 Profile* new_profile = manager->GetProfileByPath(profile_path_being_created_); |
| 364 if (!new_profile || !new_profile->IsSupervised()) | 533 if (!new_profile || !new_profile->IsSupervised()) |
| 365 return; | 534 return; |
| 366 | 535 |
| 367 DCHECK(supervised_user_registration_utility_.get()); | 536 DCHECK(supervised_user_registration_utility_.get()); |
| 368 supervised_user_registration_utility_.reset(); | 537 supervised_user_registration_utility_.reset(); |
| 369 | 538 |
| 370 if (user_initiated) { | 539 if (user_initiated) { |
| 371 UMA_HISTOGRAM_MEDIUM_TIMES( | 540 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 372 "Profile.CreateTimeCanceledNoTimeout", | 541 "Profile.CreateTimeCanceledNoTimeout", |
| 373 base::TimeTicks::Now() - profile_creation_start_time_); | 542 base::TimeTicks::Now() - profile_creation_start_time_); |
| 374 RecordProfileCreationMetrics(Profile::CREATE_STATUS_CANCELED); | 543 RecordProfileCreationMetrics(Profile::CREATE_STATUS_CANCELED); |
| 375 } | 544 } |
| 376 | 545 |
| 377 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); | 546 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); |
| 378 profile_creation_type_ = NO_CREATION_IN_PROGRESS; | 547 profile_creation_type_ = NO_CREATION_IN_PROGRESS; |
| 379 | 548 |
| 380 // Cancelling registration means the callback passed into | 549 // Canceling registration means the callback passed into |
| 381 // RegisterAndInitSync() won't be called, so the cleanup must be done here. | 550 // RegisterAndInitSync() won't be called, so the cleanup must be done here. |
| 382 profile_path_being_created_.clear(); | 551 profile_path_being_created_.clear(); |
| 383 helper::DeleteProfileAtPath(new_profile->GetPath(), web_ui()); | 552 options::helper::DeleteProfileAtPath(new_profile->GetPath(), web_ui()); |
| 384 } | 553 } |
| 385 | 554 |
| 386 void CreateProfileHandler::RegisterSupervisedUser( | 555 void SigninCreateProfileHandler::RegisterSupervisedUser( |
| 387 bool create_shortcut, | 556 bool create_shortcut, |
| 388 chrome::HostDesktopType desktop_type, | 557 chrome::HostDesktopType desktop_type, |
| 389 const std::string& supervised_user_id, | 558 const std::string& supervised_user_id, |
| 559 Profile* supervisor_profile, |
| 390 Profile* new_profile) { | 560 Profile* new_profile) { |
| 391 DCHECK_EQ(profile_path_being_created_.value(), | 561 DCHECK_EQ(profile_path_being_created_.value(), |
| 392 new_profile->GetPath().value()); | 562 new_profile->GetPath().value()); |
| 393 | 563 |
| 394 SupervisedUserService* supervised_user_service = | 564 SupervisedUserService* supervised_user_service = |
| 395 SupervisedUserServiceFactory::GetForProfile(new_profile); | 565 SupervisedUserServiceFactory::GetForProfile(new_profile); |
| 396 | 566 |
| 397 // Register the supervised user using the profile of the custodian. | 567 // Register the supervised user using the profile of the custodian. |
| 398 supervised_user_registration_utility_ = | 568 supervised_user_registration_utility_ = |
| 399 SupervisedUserRegistrationUtility::Create(Profile::FromWebUI(web_ui())); | 569 SupervisedUserRegistrationUtility::Create(supervisor_profile); |
| 400 supervised_user_service->RegisterAndInitSync( | 570 supervised_user_service->RegisterAndInitSync( |
| 401 supervised_user_registration_utility_.get(), | 571 supervised_user_registration_utility_.get(), supervisor_profile, |
| 402 Profile::FromWebUI(web_ui()), | |
| 403 supervised_user_id, | 572 supervised_user_id, |
| 404 base::Bind(&CreateProfileHandler::OnSupervisedUserRegistered, | 573 base::Bind(&SigninCreateProfileHandler::OnSupervisedUserRegistered, |
| 405 weak_ptr_factory_.GetWeakPtr(), | 574 weak_ptr_factory_.GetWeakPtr(), create_shortcut, desktop_type, |
| 406 create_shortcut, | |
| 407 desktop_type, | |
| 408 new_profile)); | 575 new_profile)); |
| 409 } | 576 } |
| 410 | 577 |
| 411 void CreateProfileHandler::OnSupervisedUserRegistered( | 578 void SigninCreateProfileHandler::OnSupervisedUserRegistered( |
| 412 bool create_shortcut, | 579 bool create_shortcut, |
| 413 chrome::HostDesktopType desktop_type, | 580 chrome::HostDesktopType desktop_type, |
| 414 Profile* profile, | 581 Profile* profile, |
| 415 const GoogleServiceAuthError& error) { | 582 const GoogleServiceAuthError& error) { |
| 416 GoogleServiceAuthError::State state = error.state(); | 583 GoogleServiceAuthError::State state = error.state(); |
| 417 RecordSupervisedProfileCreationMetrics(state); | 584 RecordSupervisedProfileCreationMetrics(state); |
| 418 if (state == GoogleServiceAuthError::NONE) { | 585 if (state == GoogleServiceAuthError::NONE) { |
| 419 CreateShortcutAndShowSuccess(create_shortcut, desktop_type, profile); | 586 CreateShortcutAndShowSuccess(create_shortcut, desktop_type, profile); |
| 420 return; | 587 return; |
| 421 } | 588 } |
| 422 | 589 |
| 423 base::string16 error_msg; | 590 base::string16 error_msg; |
| 424 if (state == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || | 591 if (state == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || |
| 425 state == GoogleServiceAuthError::USER_NOT_SIGNED_UP || | 592 state == GoogleServiceAuthError::USER_NOT_SIGNED_UP || |
| 426 state == GoogleServiceAuthError::ACCOUNT_DELETED || | 593 state == GoogleServiceAuthError::ACCOUNT_DELETED || |
| 427 state == GoogleServiceAuthError::ACCOUNT_DISABLED) { | 594 state == GoogleServiceAuthError::ACCOUNT_DISABLED) { |
| 428 error_msg = GetProfileCreationErrorMessageSignin(); | 595 error_msg = GetProfileCreateErrorMessageSignin(); |
| 429 } else { | 596 } else { |
| 430 error_msg = GetProfileCreationErrorMessageRemote(); | 597 error_msg = GetProfileCreateErrorMessageRemote(); |
| 431 } | 598 } |
| 432 ShowProfileCreationError(profile, error_msg); | 599 ShowProfileCreationError(profile, error_msg); |
| 433 } | 600 } |
| 434 | 601 |
| 435 void CreateProfileHandler::ShowProfileCreationWarning( | 602 void SigninCreateProfileHandler::ShowProfileCreationWarning( |
| 436 const base::string16& warning) { | 603 const base::string16& warning) { |
| 437 DCHECK_EQ(SUPERVISED_PROFILE_CREATION, profile_creation_type_); | 604 DCHECK_EQ(SUPERVISED_PROFILE_CREATION, profile_creation_type_); |
| 438 web_ui()->CallJavascriptFunction("BrowserOptions.showCreateProfileWarning", | 605 web_ui()->CallJavascriptFunction("signin.ProfileApi.onCreateProfileWarning", |
| 439 base::StringValue(warning)); | 606 base::StringValue(warning)); |
| 440 } | 607 } |
| 441 | 608 |
| 442 void CreateProfileHandler::RecordSupervisedProfileCreationMetrics( | 609 void SigninCreateProfileHandler::RecordSupervisedProfileCreationMetrics( |
| 443 GoogleServiceAuthError::State error_state) { | 610 GoogleServiceAuthError::State error_state) { |
| 444 if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION) { | 611 if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION) { |
| 445 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileCreateError", | 612 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileCreateError", |
| 446 error_state, | 613 error_state, GoogleServiceAuthError::NUM_STATES); |
| 447 GoogleServiceAuthError::NUM_STATES); | |
| 448 UMA_HISTOGRAM_MEDIUM_TIMES( | 614 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 449 "Profile.SupervisedProfileTotalCreateTime", | 615 "Profile.SupervisedProfileTotalCreateTime", |
| 450 base::TimeTicks::Now() - profile_creation_start_time_); | 616 base::TimeTicks::Now() - profile_creation_start_time_); |
| 451 } else { | 617 } else { |
| 452 DCHECK_EQ(SUPERVISED_PROFILE_IMPORT, profile_creation_type_); | 618 DCHECK_EQ(SUPERVISED_PROFILE_IMPORT, profile_creation_type_); |
| 453 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileImportError", | 619 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileImportError", |
| 454 error_state, | 620 error_state, GoogleServiceAuthError::NUM_STATES); |
| 455 GoogleServiceAuthError::NUM_STATES); | |
| 456 UMA_HISTOGRAM_MEDIUM_TIMES( | 621 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 457 "Profile.SupervisedProfileTotalImportTime", | 622 "Profile.SupervisedProfileTotalImportTime", |
| 458 base::TimeTicks::Now() - profile_creation_start_time_); | 623 base::TimeTicks::Now() - profile_creation_start_time_); |
| 459 } | 624 } |
| 460 } | 625 } |
| 461 | 626 |
| 462 bool CreateProfileHandler::IsValidExistingSupervisedUserId( | |
| 463 const std::string& existing_supervised_user_id) const { | |
| 464 if (existing_supervised_user_id.empty()) | |
| 465 return true; | |
| 466 | |
| 467 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 468 const base::DictionaryValue* dict = | |
| 469 SupervisedUserSyncServiceFactory::GetForProfile(profile)-> | |
| 470 GetSupervisedUsers(); | |
| 471 if (!dict->HasKey(existing_supervised_user_id)) | |
| 472 return false; | |
| 473 | |
| 474 // Check if this supervised user already exists on this machine. | |
| 475 const ProfileInfoCache& cache = | |
| 476 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 477 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | |
| 478 if (existing_supervised_user_id == | |
| 479 cache.GetSupervisedUserIdOfProfileAtIndex(i)) | |
| 480 return false; | |
| 481 } | |
| 482 return true; | |
| 483 } | |
| 484 #endif | 627 #endif |
| 485 | |
| 486 } // namespace options | |
| OLD | NEW |