| 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 #include "chrome/browser/ui/webui/signin/signin_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> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/task_runner_util.h" | 16 #include "base/task_runner_util.h" |
| 17 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
| 18 #include "base/value_conversions.h" | 18 #include "base/value_conversions.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/profiles/profile_attributes_entry.h" | 21 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 22 #include "chrome/browser/profiles/profile_attributes_storage.h" | 22 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 23 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 23 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 24 #include "chrome/browser/profiles/profile_manager.h" | 24 #include "chrome/browser/profiles/profile_manager.h" |
| 25 #include "chrome/browser/profiles/profile_metrics.h" | 25 #include "chrome/browser/profiles/profile_metrics.h" |
| 26 #include "chrome/browser/profiles/profiles_state.h" | 26 #include "chrome/browser/profiles/profiles_state.h" |
| 27 #include "chrome/browser/signin/signin_error_controller_factory.h" |
| 27 #include "chrome/browser/signin/signin_manager_factory.h" | 28 #include "chrome/browser/signin/signin_manager_factory.h" |
| 28 #include "chrome/browser/sync/profile_sync_service_factory.h" | 29 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 29 #include "chrome/browser/ui/webui/profile_helper.h" | 30 #include "chrome/browser/ui/webui/profile_helper.h" |
| 30 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 31 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 32 #include "chrome/grit/generated_resources.h" | 33 #include "chrome/grit/generated_resources.h" |
| 33 #include "components/browser_sync/browser/profile_sync_service.h" | 34 #include "components/browser_sync/browser/profile_sync_service.h" |
| 34 #include "components/prefs/pref_service.h" | 35 #include "components/prefs/pref_service.h" |
| 36 #include "components/signin/core/browser/signin_error_controller.h" |
| 35 #include "components/strings/grit/components_strings.h" | 37 #include "components/strings/grit/components_strings.h" |
| 36 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
| 37 #include "content/public/browser/web_ui.h" | 39 #include "content/public/browser/web_ui.h" |
| 38 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
| 39 | 41 |
| 40 #if defined(ENABLE_SUPERVISED_USERS) | 42 #if defined(ENABLE_SUPERVISED_USERS) |
| 41 #include "chrome/browser/supervised_user/legacy/supervised_user_registration_uti
lity.h" | 43 #include "chrome/browser/supervised_user/legacy/supervised_user_registration_uti
lity.h" |
| 42 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service.h" | 44 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service.h" |
| 43 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service_fac
tory.h" | 45 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service_fac
tory.h" |
| 44 #include "chrome/browser/supervised_user/supervised_user_service.h" | 46 #include "chrome/browser/supervised_user/supervised_user_service.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 55 CancelProfileRegistration(false); | 57 CancelProfileRegistration(false); |
| 56 #endif | 58 #endif |
| 57 } | 59 } |
| 58 | 60 |
| 59 void SigninCreateProfileHandler::GetLocalizedValues( | 61 void SigninCreateProfileHandler::GetLocalizedValues( |
| 60 base::DictionaryValue* localized_strings) { | 62 base::DictionaryValue* localized_strings) { |
| 61 localized_strings->SetString( | 63 localized_strings->SetString( |
| 62 "manageProfilesSupervisedSignedInLabel", | 64 "manageProfilesSupervisedSignedInLabel", |
| 63 l10n_util::GetStringUTF16( | 65 l10n_util::GetStringUTF16( |
| 64 IDS_PROFILES_CREATE_SUPERVISED_MULTI_SIGNED_IN_LABEL)); | 66 IDS_PROFILES_CREATE_SUPERVISED_MULTI_SIGNED_IN_LABEL)); |
| 65 localized_strings->SetString( | |
| 66 "manageProfilesSupervisedNotSignedIn", | |
| 67 l10n_util::GetStringUTF16( | |
| 68 IDS_PROFILES_CREATE_SUPERVISED_NOT_SIGNED_IN_HTML)); | |
| 69 localized_strings->SetString("createProfileConfirm", | 67 localized_strings->SetString("createProfileConfirm", |
| 70 l10n_util::GetStringUTF16(IDS_SAVE)); | 68 l10n_util::GetStringUTF16(IDS_SAVE)); |
| 71 localized_strings->SetString("learnMore", | 69 localized_strings->SetString("learnMore", |
| 72 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); | 70 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); |
| 73 localized_strings->SetString( | 71 localized_strings->SetString( |
| 74 "createProfileTitle", | 72 "createProfileTitle", |
| 75 l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_TITLE)); | 73 l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_TITLE)); |
| 76 | |
| 77 localized_strings->SetString( | 74 localized_strings->SetString( |
| 78 "supervisedUserLearnMoreTitle", | 75 "supervisedUserLearnMoreTitle", |
| 79 l10n_util::GetStringUTF16(IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_TITLE)); | 76 l10n_util::GetStringUTF16(IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_TITLE)); |
| 80 localized_strings->SetString( | 77 localized_strings->SetString( |
| 81 "supervisedUserLearnMoreDone", | 78 "supervisedUserLearnMoreDone", |
| 82 l10n_util::GetStringUTF16( | 79 l10n_util::GetStringUTF16( |
| 83 IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_DONE_BUTTON)); | 80 IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_DONE_BUTTON)); |
| 84 localized_strings->SetString( | 81 localized_strings->SetString( |
| 85 "supervisedUserLearnMoreText", | 82 "supervisedUserLearnMoreText", |
| 86 l10n_util::GetStringFUTF16( | 83 l10n_util::GetStringFUTF16( |
| 87 IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_TEXT, | 84 IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_TEXT, |
| 88 base::ASCIIToUTF16( | 85 base::ASCIIToUTF16( |
| 89 chrome::kLegacySupervisedUserManagementDisplayURL))); | 86 chrome::kLegacySupervisedUserManagementDisplayURL))); |
| 87 localized_strings->SetString( |
| 88 "manageProfilesExistingSupervisedUser", |
| 89 l10n_util::GetStringUTF16( |
| 90 IDS_PROFILES_CREATE_LEGACY_SUPERVISED_USER_ERROR_EXISTS_REMOTELY)); |
| 91 localized_strings->SetString( |
| 92 "managedProfilesExistingLocalSupervisedUser", |
| 93 l10n_util::GetStringUTF16( |
| 94 IDS_PROFILES_CREATE_LEGACY_SUPERVISED_USER_ERROR_EXISTS_LOCALLY)); |
| 95 localized_strings->SetString( |
| 96 "custodianAccountNotSelectedError", |
| 97 l10n_util::GetStringUTF16( |
| 98 IDS_PROFILES_CREATE_NO_CUSTODIAN_ACCOUNT_ERROR)); |
| 90 } | 99 } |
| 91 | 100 |
| 92 void SigninCreateProfileHandler::RegisterMessages() { | 101 void SigninCreateProfileHandler::RegisterMessages() { |
| 93 #if defined(ENABLE_SUPERVISED_USERS) | 102 #if defined(ENABLE_SUPERVISED_USERS) |
| 94 // Cancellation is only supported for supervised users. | 103 // Cancellation is only supported for supervised users. |
| 95 web_ui()->RegisterMessageCallback( | 104 web_ui()->RegisterMessageCallback( |
| 96 "cancelCreateProfile", | 105 "cancelCreateProfile", |
| 97 base::Bind(&SigninCreateProfileHandler::HandleCancelProfileCreation, | 106 base::Bind(&SigninCreateProfileHandler::HandleCancelProfileCreation, |
| 98 base::Unretained(this))); | 107 base::Unretained(this))); |
| 99 #endif | 108 #endif |
| (...skipping 21 matching lines...) Expand all Loading... |
| 121 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount() && | 130 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount() && |
| 122 i != placeholder_avatar_index; | 131 i != placeholder_avatar_index; |
| 123 i++) { | 132 i++) { |
| 124 std::string url = profiles::GetDefaultAvatarIconUrl(i); | 133 std::string url = profiles::GetDefaultAvatarIconUrl(i); |
| 125 image_url_list.AppendString(url); | 134 image_url_list.AppendString(url); |
| 126 } | 135 } |
| 127 | 136 |
| 128 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", | 137 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", |
| 129 base::StringValue("profile-icons-received"), | 138 base::StringValue("profile-icons-received"), |
| 130 image_url_list); | 139 image_url_list); |
| 140 |
| 141 SendNewProfileDefaults(); |
| 142 } |
| 143 |
| 144 void SigninCreateProfileHandler::SendNewProfileDefaults() { |
| 145 ProfileInfoCache& cache = |
| 146 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 147 base::DictionaryValue profile_info; |
| 148 profile_info.SetString("name", cache.ChooseNameForNewProfile(0)); |
| 149 |
| 150 web_ui()->CallJavascriptFunction( |
| 151 "cr.webUIListenerCallback", |
| 152 base::StringValue("profile-defaults-received"), |
| 153 profile_info); |
| 131 } | 154 } |
| 132 | 155 |
| 133 void SigninCreateProfileHandler::RequestSignedInProfiles( | 156 void SigninCreateProfileHandler::RequestSignedInProfiles( |
| 134 const base::ListValue* args) { | 157 const base::ListValue* args) { |
| 135 base::ListValue user_info_list; | 158 base::ListValue user_info_list; |
| 136 std::vector<ProfileAttributesEntry*> entries = | 159 std::vector<ProfileAttributesEntry*> entries = |
| 137 g_browser_process->profile_manager()-> | 160 g_browser_process->profile_manager()-> |
| 138 GetProfileAttributesStorage().GetAllProfilesAttributesSortedByName(); | 161 GetProfileAttributesStorage().GetAllProfilesAttributesSortedByName(); |
| 139 for (ProfileAttributesEntry* entry : entries) { | 162 for (ProfileAttributesEntry* entry : entries) { |
| 140 base::string16 username = entry->GetUserName(); | 163 base::string16 username = entry->GetUserName(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 base::TrimWhitespace(name, base::TRIM_ALL, &name); | 198 base::TrimWhitespace(name, base::TRIM_ALL, &name); |
| 176 CHECK(!name.empty()); | 199 CHECK(!name.empty()); |
| 177 #ifndef NDEBUG | 200 #ifndef NDEBUG |
| 178 size_t icon_index; | 201 size_t icon_index; |
| 179 DCHECK(profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index)); | 202 DCHECK(profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index)); |
| 180 #endif | 203 #endif |
| 181 args->GetBoolean(2, &create_shortcut); | 204 args->GetBoolean(2, &create_shortcut); |
| 182 } | 205 } |
| 183 #if defined(ENABLE_SUPERVISED_USERS) | 206 #if defined(ENABLE_SUPERVISED_USERS) |
| 184 std::string supervised_user_id; | 207 std::string supervised_user_id; |
| 185 base::FilePath supervisor_profile_path; | 208 base::FilePath custodian_profile_path; |
| 186 if (GetSupervisedCreateProfileArgs(args, &supervised_user_id, | 209 if (GetSupervisedCreateProfileArgs(args, &supervised_user_id, |
| 187 &supervisor_profile_path)) { | 210 &custodian_profile_path)) { |
| 188 // Load supervisor profile. | 211 // Load custodian profile. |
| 189 g_browser_process->profile_manager()->CreateProfileAsync( | 212 g_browser_process->profile_manager()->CreateProfileAsync( |
| 190 supervisor_profile_path, | 213 custodian_profile_path, |
| 191 base::Bind(&SigninCreateProfileHandler::LoadSupervisorProfileCallback, | 214 base::Bind(&SigninCreateProfileHandler::LoadCustodianProfileCallback, |
| 192 weak_ptr_factory_.GetWeakPtr(), name, icon_url, | 215 weak_ptr_factory_.GetWeakPtr(), name, icon_url, |
| 193 create_shortcut, supervised_user_id), | 216 create_shortcut, supervised_user_id), |
| 194 base::string16(), std::string(), std::string()); | 217 base::string16(), std::string(), std::string()); |
| 195 } else { | 218 } else { |
| 196 DoCreateProfile(name, icon_url, create_shortcut, std::string(), nullptr); | 219 DoCreateProfile(name, icon_url, create_shortcut, std::string(), nullptr); |
| 197 } | 220 } |
| 198 #else | 221 #else |
| 199 DoCreateProfile(name, icon_url, create_shortcut, std::string(), nullptr); | 222 DoCreateProfile(name, icon_url, create_shortcut, std::string(), nullptr); |
| 200 #endif | 223 #endif |
| 201 } | 224 } |
| 202 | 225 |
| 203 void SigninCreateProfileHandler::DoCreateProfile( | 226 void SigninCreateProfileHandler::DoCreateProfile( |
| 204 const base::string16& name, | 227 const base::string16& name, |
| 205 const std::string& icon_url, | 228 const std::string& icon_url, |
| 206 bool create_shortcut, | 229 bool create_shortcut, |
| 207 const std::string& supervised_user_id, | 230 const std::string& supervised_user_id, |
| 208 Profile* supervisor_profile) { | 231 Profile* custodian_profile) { |
| 209 ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_DIALOG); | 232 ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_DIALOG); |
| 210 | 233 |
| 211 profile_path_being_created_ = ProfileManager::CreateMultiProfileAsync( | 234 profile_path_being_created_ = ProfileManager::CreateMultiProfileAsync( |
| 212 name, icon_url, | 235 name, icon_url, |
| 213 base::Bind(&SigninCreateProfileHandler::OnProfileCreated, | 236 base::Bind(&SigninCreateProfileHandler::OnProfileCreated, |
| 214 weak_ptr_factory_.GetWeakPtr(), create_shortcut, | 237 weak_ptr_factory_.GetWeakPtr(), create_shortcut, |
| 215 supervised_user_id, supervisor_profile), | 238 supervised_user_id, custodian_profile), |
| 216 supervised_user_id); | 239 supervised_user_id); |
| 217 } | 240 } |
| 218 | 241 |
| 219 void SigninCreateProfileHandler::OnProfileCreated( | 242 void SigninCreateProfileHandler::OnProfileCreated( |
| 220 bool create_shortcut, | 243 bool create_shortcut, |
| 221 const std::string& supervised_user_id, | 244 const std::string& supervised_user_id, |
| 222 Profile* supervisor_profile, | 245 Profile* custodian_profile, |
| 223 Profile* profile, | 246 Profile* profile, |
| 224 Profile::CreateStatus status) { | 247 Profile::CreateStatus status) { |
| 225 if (status != Profile::CREATE_STATUS_CREATED) | 248 if (status != Profile::CREATE_STATUS_CREATED) |
| 226 RecordProfileCreationMetrics(status); | 249 RecordProfileCreationMetrics(status); |
| 227 | 250 |
| 228 switch (status) { | 251 switch (status) { |
| 229 case Profile::CREATE_STATUS_LOCAL_FAIL: { | 252 case Profile::CREATE_STATUS_LOCAL_FAIL: { |
| 230 ShowProfileCreationError(profile, GetProfileCreationErrorMessageLocal()); | 253 ShowProfileCreationError(profile, GetProfileCreationErrorMessageLocal()); |
| 231 break; | 254 break; |
| 232 } | 255 } |
| 233 case Profile::CREATE_STATUS_CREATED: { | 256 case Profile::CREATE_STATUS_CREATED: { |
| 234 // Do nothing for an intermediate status. | 257 // Do nothing for an intermediate status. |
| 235 break; | 258 break; |
| 236 } | 259 } |
| 237 case Profile::CREATE_STATUS_INITIALIZED: { | 260 case Profile::CREATE_STATUS_INITIALIZED: { |
| 238 HandleProfileCreationSuccess(create_shortcut, supervised_user_id, | 261 HandleProfileCreationSuccess(create_shortcut, supervised_user_id, |
| 239 supervisor_profile, profile); | 262 custodian_profile, profile); |
| 240 break; | 263 break; |
| 241 } | 264 } |
| 242 // User-initiated cancellation is handled in CancelProfileRegistration and | 265 // User-initiated cancellation is handled in CancelProfileRegistration and |
| 243 // does not call this callback. | 266 // does not call this callback. |
| 244 case Profile::CREATE_STATUS_CANCELED: | 267 case Profile::CREATE_STATUS_CANCELED: |
| 245 // Supervised user registration errors are handled in | 268 // Supervised user registration errors are handled in |
| 246 // OnSupervisedUserRegistered(). | 269 // OnSupervisedUserRegistered(). |
| 247 case Profile::CREATE_STATUS_REMOTE_FAIL: | 270 case Profile::CREATE_STATUS_REMOTE_FAIL: |
| 248 case Profile::MAX_CREATE_STATUS: { | 271 case Profile::MAX_CREATE_STATUS: { |
| 249 NOTREACHED(); | 272 NOTREACHED(); |
| 250 break; | 273 break; |
| 251 } | 274 } |
| 252 } | 275 } |
| 253 } | 276 } |
| 254 | 277 |
| 255 void SigninCreateProfileHandler::HandleProfileCreationSuccess( | 278 void SigninCreateProfileHandler::HandleProfileCreationSuccess( |
| 256 bool create_shortcut, | 279 bool create_shortcut, |
| 257 const std::string& supervised_user_id, | 280 const std::string& supervised_user_id, |
| 258 Profile* supervisor_profile, | 281 Profile* custodian_profile, |
| 259 Profile* profile) { | 282 Profile* profile) { |
| 260 switch (profile_creation_type_) { | 283 switch (profile_creation_type_) { |
| 261 case NON_SUPERVISED_PROFILE_CREATION: { | 284 case NON_SUPERVISED_PROFILE_CREATION: { |
| 262 DCHECK(supervised_user_id.empty()); | 285 DCHECK(supervised_user_id.empty()); |
| 263 CreateShortcutAndShowSuccess(create_shortcut, profile); | 286 CreateShortcutAndShowSuccess(create_shortcut, profile); |
| 264 break; | 287 break; |
| 265 } | 288 } |
| 266 #if defined(ENABLE_SUPERVISED_USERS) | 289 #if defined(ENABLE_SUPERVISED_USERS) |
| 267 case SUPERVISED_PROFILE_CREATION: | 290 case SUPERVISED_PROFILE_CREATION: |
| 268 case SUPERVISED_PROFILE_IMPORT: | 291 case SUPERVISED_PROFILE_IMPORT: |
| 269 RegisterSupervisedUser(create_shortcut, supervised_user_id, | 292 RegisterSupervisedUser(create_shortcut, supervised_user_id, |
| 270 supervisor_profile, profile); | 293 custodian_profile, profile); |
| 271 break; | 294 break; |
| 272 #endif | 295 #endif |
| 273 case NO_CREATION_IN_PROGRESS: | 296 case NO_CREATION_IN_PROGRESS: |
| 274 NOTREACHED(); | 297 NOTREACHED(); |
| 275 break; | 298 break; |
| 276 } | 299 } |
| 277 } | 300 } |
| 278 | 301 |
| 279 void SigninCreateProfileHandler::CreateShortcutAndShowSuccess( | 302 void SigninCreateProfileHandler::CreateShortcutAndShowSuccess( |
| 280 bool create_shortcut, | 303 bool create_shortcut, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 webui::OpenNewWindowForProfile( | 343 webui::OpenNewWindowForProfile( |
| 321 profile, Profile::CREATE_STATUS_INITIALIZED); | 344 profile, Profile::CREATE_STATUS_INITIALIZED); |
| 322 } | 345 } |
| 323 profile_creation_type_ = NO_CREATION_IN_PROGRESS; | 346 profile_creation_type_ = NO_CREATION_IN_PROGRESS; |
| 324 } | 347 } |
| 325 | 348 |
| 326 void SigninCreateProfileHandler::ShowProfileCreationError( | 349 void SigninCreateProfileHandler::ShowProfileCreationError( |
| 327 Profile* profile, | 350 Profile* profile, |
| 328 const base::string16& error) { | 351 const base::string16& error) { |
| 329 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); | 352 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); |
| 330 profile_creation_type_ = NO_CREATION_IN_PROGRESS; | |
| 331 profile_path_being_created_.clear(); | |
| 332 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", | 353 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", |
| 333 GetWebUIListenerName(PROFILE_CREATION_ERROR), | 354 GetWebUIListenerName(PROFILE_CREATION_ERROR), |
| 334 base::StringValue(error)); | 355 base::StringValue(error)); |
| 335 // The ProfileManager calls us back with a NULL profile in some cases. | 356 // The ProfileManager calls us back with a NULL profile in some cases. |
| 336 if (profile) | 357 if (profile) |
| 337 webui::DeleteProfileAtPath(profile->GetPath(), web_ui()); | 358 webui::DeleteProfileAtPath(profile->GetPath(), web_ui()); |
| 359 profile_creation_type_ = NO_CREATION_IN_PROGRESS; |
| 360 profile_path_being_created_.clear(); |
| 338 } | 361 } |
| 339 | 362 |
| 340 void SigninCreateProfileHandler::RecordProfileCreationMetrics( | 363 void SigninCreateProfileHandler::RecordProfileCreationMetrics( |
| 341 Profile::CreateStatus status) { | 364 Profile::CreateStatus status) { |
| 342 UMA_HISTOGRAM_ENUMERATION("Profile.CreateResult", status, | 365 UMA_HISTOGRAM_ENUMERATION("Profile.CreateResult", status, |
| 343 Profile::MAX_CREATE_STATUS); | 366 Profile::MAX_CREATE_STATUS); |
| 344 UMA_HISTOGRAM_MEDIUM_TIMES( | 367 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 345 "Profile.CreateTimeNoTimeout", | 368 "Profile.CreateTimeNoTimeout", |
| 346 base::TimeTicks::Now() - profile_creation_start_time_); | 369 base::TimeTicks::Now() - profile_creation_start_time_); |
| 347 } | 370 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 } | 422 } |
| 400 | 423 |
| 401 NOTREACHED(); | 424 NOTREACHED(); |
| 402 return base::StringValue(std::string()); | 425 return base::StringValue(std::string()); |
| 403 } | 426 } |
| 404 | 427 |
| 405 #if defined(ENABLE_SUPERVISED_USERS) | 428 #if defined(ENABLE_SUPERVISED_USERS) |
| 406 bool SigninCreateProfileHandler::GetSupervisedCreateProfileArgs( | 429 bool SigninCreateProfileHandler::GetSupervisedCreateProfileArgs( |
| 407 const base::ListValue* args, | 430 const base::ListValue* args, |
| 408 std::string* supervised_user_id, | 431 std::string* supervised_user_id, |
| 409 base::FilePath* supervisor_profile_path) { | 432 base::FilePath* custodian_profile_path) { |
| 410 bool supervised_user = false; | 433 bool supervised_user = false; |
| 411 bool success = args->GetBoolean(3, &supervised_user); | 434 bool success = args->GetBoolean(3, &supervised_user); |
| 412 DCHECK(success); | 435 DCHECK(success); |
| 413 | 436 |
| 414 if (!supervised_user) | 437 if (!supervised_user) |
| 415 return false; | 438 return false; |
| 416 | 439 |
| 417 success = args->GetString(4, supervised_user_id); | 440 success = args->GetString(4, supervised_user_id); |
| 418 DCHECK(success); | 441 DCHECK(success); |
| 419 const base::Value* path_value; | 442 const base::Value* path_value; |
| 420 success = args->Get(5, &path_value); | 443 success = args->Get(5, &path_value); |
| 421 DCHECK(success); | 444 DCHECK(success); |
| 422 success = base::GetValueAsFilePath(*path_value, supervisor_profile_path); | 445 success = base::GetValueAsFilePath(*path_value, custodian_profile_path); |
| 423 DCHECK(success); | 446 DCHECK(success); |
| 424 | 447 |
| 425 return !supervisor_profile_path->empty(); | 448 return !custodian_profile_path->empty(); |
| 426 } | 449 } |
| 427 | 450 |
| 428 void SigninCreateProfileHandler::LoadSupervisorProfileCallback( | 451 void SigninCreateProfileHandler::LoadCustodianProfileCallback( |
| 429 const base::string16& name, | 452 const base::string16& name, |
| 430 const std::string& icon_url, | 453 const std::string& icon_url, |
| 431 bool create_shortcut, | 454 bool create_shortcut, |
| 432 const std::string& supervised_user_id, | 455 const std::string& supervised_user_id, |
| 433 Profile* supervisor_profile, | 456 Profile* custodian_profile, |
| 434 Profile::CreateStatus status) { | 457 Profile::CreateStatus status) { |
| 435 // This method gets called once before with Profile::CREATE_STATUS_CREATED. | 458 // This method gets called once before with Profile::CREATE_STATUS_CREATED. |
| 436 switch (status) { | 459 switch (status) { |
| 437 case Profile::CREATE_STATUS_LOCAL_FAIL: { | 460 case Profile::CREATE_STATUS_LOCAL_FAIL: { |
| 438 // TODO(mahmadi): see if a better error message is required here. | 461 // TODO(mahmadi): see if a better error message is required here. |
| 439 ShowProfileCreationError(nullptr, GetProfileCreationErrorMessageLocal()); | 462 ShowProfileCreationError(nullptr, GetProfileCreationErrorMessageLocal()); |
| 440 break; | 463 break; |
| 441 } | 464 } |
| 442 case Profile::CREATE_STATUS_CREATED: { | 465 case Profile::CREATE_STATUS_CREATED: { |
| 443 // Ignore the intermediate status. | 466 // Ignore the intermediate status. |
| 444 break; | 467 break; |
| 445 } | 468 } |
| 446 case Profile::CREATE_STATUS_INITIALIZED: { | 469 case Profile::CREATE_STATUS_INITIALIZED: { |
| 447 // We are only interested in Profile::CREATE_STATUS_INITIALIZED when | 470 // We are only interested in Profile::CREATE_STATUS_INITIALIZED when |
| 448 // everything is ready. | 471 // everything is ready. |
| 449 // TODO(mahmadi): display proper error message to the user. | 472 if (!IsAccountConnected(custodian_profile) || |
| 450 PrefService* prefs = supervisor_profile->GetPrefs(); | 473 HasAuthError(custodian_profile)) { |
| 474 ShowProfileCreationError(nullptr, l10n_util::GetStringUTF16( |
| 475 IDS_PROFILES_CREATE_CUSTODIAN_ACCOUNT_DETAILS_OUT_OF_DATE_ERROR)); |
| 476 return; |
| 477 } |
| 478 |
| 479 PrefService* prefs = custodian_profile->GetPrefs(); |
| 451 if (!prefs->GetBoolean(prefs::kSupervisedUserCreationAllowed)) | 480 if (!prefs->GetBoolean(prefs::kSupervisedUserCreationAllowed)) |
| 452 return; | 481 return; |
| 453 | 482 |
| 454 if (!supervised_user_id.empty()) { | 483 if (!supervised_user_id.empty()) { |
| 455 profile_creation_type_ = SUPERVISED_PROFILE_IMPORT; | 484 profile_creation_type_ = SUPERVISED_PROFILE_IMPORT; |
| 456 | 485 |
| 457 SupervisedUserSyncService* supervised_user_sync_service = | 486 SupervisedUserSyncService* supervised_user_sync_service = |
| 458 SupervisedUserSyncServiceFactory::GetForProfile(supervisor_profile); | 487 SupervisedUserSyncServiceFactory::GetForProfile(custodian_profile); |
| 459 if (supervised_user_sync_service) { | 488 if (supervised_user_sync_service) { |
| 460 supervised_user_sync_service->GetSupervisedUsersAsync(base::Bind( | 489 supervised_user_sync_service->GetSupervisedUsersAsync(base::Bind( |
| 461 &SigninCreateProfileHandler::DoCreateProfileIfPossible, | 490 &SigninCreateProfileHandler::DoCreateProfileIfPossible, |
| 462 weak_ptr_factory_.GetWeakPtr(), name, icon_url, create_shortcut, | 491 weak_ptr_factory_.GetWeakPtr(), name, icon_url, create_shortcut, |
| 463 supervised_user_id, supervisor_profile)); | 492 supervised_user_id, custodian_profile)); |
| 464 } | 493 } |
| 465 } else { | 494 } else { |
| 466 profile_creation_type_ = SUPERVISED_PROFILE_CREATION; | 495 profile_creation_type_ = SUPERVISED_PROFILE_CREATION; |
| 467 std::string new_supervised_user_id = | 496 std::string new_supervised_user_id = |
| 468 SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId(); | 497 SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId(); |
| 469 | 498 |
| 470 // If sync is not yet fully initialized, the creation may take extra | 499 // If sync is not yet fully initialized, the creation may take extra |
| 471 // time, so show a message. Import doesn't wait for an acknowledgment, | 500 // time, so show a message. Import doesn't wait for an acknowledgment, |
| 472 // so it won't have the same potential delay. | 501 // so it won't have the same potential delay. |
| 473 ProfileSyncService* sync_service = | 502 ProfileSyncService* sync_service = |
| 474 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 503 ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| 475 supervisor_profile); | 504 custodian_profile); |
| 476 ProfileSyncService::SyncStatusSummary status = | 505 ProfileSyncService::SyncStatusSummary status = |
| 477 sync_service->QuerySyncStatusSummary(); | 506 sync_service->QuerySyncStatusSummary(); |
| 478 if (status == ProfileSyncService::DATATYPES_NOT_INITIALIZED) { | 507 if (status == ProfileSyncService::DATATYPES_NOT_INITIALIZED) { |
| 479 ShowProfileCreationWarning(l10n_util::GetStringUTF16( | 508 ShowProfileCreationWarning(l10n_util::GetStringUTF16( |
| 480 IDS_PROFILES_CREATE_SUPERVISED_JUST_SIGNED_IN)); | 509 IDS_PROFILES_CREATE_SUPERVISED_JUST_SIGNED_IN)); |
| 481 } | 510 } |
| 482 | 511 |
| 483 DoCreateProfile(name, icon_url, create_shortcut, new_supervised_user_id, | 512 DoCreateProfile(name, icon_url, create_shortcut, new_supervised_user_id, |
| 484 supervisor_profile); | 513 custodian_profile); |
| 485 } | 514 } |
| 486 break; | 515 break; |
| 487 } | 516 } |
| 488 case Profile::CREATE_STATUS_CANCELED: | 517 case Profile::CREATE_STATUS_CANCELED: |
| 489 case Profile::CREATE_STATUS_REMOTE_FAIL: | 518 case Profile::CREATE_STATUS_REMOTE_FAIL: |
| 490 case Profile::MAX_CREATE_STATUS: { | 519 case Profile::MAX_CREATE_STATUS: { |
| 491 NOTREACHED(); | 520 NOTREACHED(); |
| 492 break; | 521 break; |
| 493 } | 522 } |
| 494 } | 523 } |
| 495 } | 524 } |
| 496 | 525 |
| 526 bool SigninCreateProfileHandler::IsAccountConnected(Profile* profile) |
| 527 const { |
| 528 SigninManagerBase* signin_manager = |
| 529 SigninManagerFactory::GetForProfile(profile); |
| 530 return signin_manager && signin_manager->IsAuthenticated(); |
| 531 } |
| 532 |
| 533 bool SigninCreateProfileHandler::HasAuthError(Profile* profile) |
| 534 const { |
| 535 SigninErrorController* error_controller = |
| 536 SigninErrorControllerFactory::GetForProfile(profile); |
| 537 if (!error_controller) |
| 538 return true; |
| 539 |
| 540 GoogleServiceAuthError::State state = error_controller->auth_error().state(); |
| 541 return state != GoogleServiceAuthError::NONE; |
| 542 } |
| 543 |
| 497 void SigninCreateProfileHandler::DoCreateProfileIfPossible( | 544 void SigninCreateProfileHandler::DoCreateProfileIfPossible( |
| 498 const base::string16& name, | 545 const base::string16& name, |
| 499 const std::string& icon_url, | 546 const std::string& icon_url, |
| 500 bool create_shortcut, | 547 bool create_shortcut, |
| 501 const std::string& supervised_user_id, | 548 const std::string& supervised_user_id, |
| 502 Profile* supervisor_profile, | 549 Profile* custodian_profile, |
| 503 const base::DictionaryValue* dict) { | 550 const base::DictionaryValue* dict) { |
| 504 DCHECK(dict); | 551 DCHECK(dict); |
| 505 if (!dict->HasKey(supervised_user_id)) | 552 if (!dict->HasKey(supervised_user_id)) |
| 506 return; | 553 return; |
| 507 | 554 |
| 508 // Check if this supervised user already exists on this machine. | 555 // Check if this supervised user already exists on this machine. |
| 509 std::vector<ProfileAttributesEntry*> entries = | 556 std::vector<ProfileAttributesEntry*> entries = |
| 510 g_browser_process->profile_manager()-> | 557 g_browser_process->profile_manager()-> |
| 511 GetProfileAttributesStorage().GetAllProfilesAttributes(); | 558 GetProfileAttributesStorage().GetAllProfilesAttributes(); |
| 512 for (ProfileAttributesEntry* entry : entries) { | 559 for (ProfileAttributesEntry* entry : entries) { |
| 513 if (supervised_user_id == entry->GetSupervisedUserId()) { | 560 if (supervised_user_id == entry->GetSupervisedUserId()) { |
| 514 // TODO(mahmadi): see whether we need a more specific error message here. | 561 // TODO(mahmadi): see whether we need a more specific error message here. |
| 515 ShowProfileCreationError(nullptr, GetProfileCreationErrorMessageLocal()); | 562 ShowProfileCreationError(nullptr, GetProfileCreationErrorMessageLocal()); |
| 516 return; | 563 return; |
| 517 } | 564 } |
| 518 } | 565 } |
| 519 | 566 |
| 520 DoCreateProfile(name, icon_url, create_shortcut, supervised_user_id, | 567 DoCreateProfile(name, icon_url, create_shortcut, supervised_user_id, |
| 521 supervisor_profile); | 568 custodian_profile); |
| 522 } | 569 } |
| 523 | 570 |
| 524 void SigninCreateProfileHandler::HandleCancelProfileCreation( | 571 void SigninCreateProfileHandler::HandleCancelProfileCreation( |
| 525 const base::ListValue* args) { | 572 const base::ListValue* args) { |
| 526 CancelProfileRegistration(true); | 573 CancelProfileRegistration(true); |
| 527 } | 574 } |
| 528 | 575 |
| 529 // Non-supervised user creation cannot be canceled. (Creating a non-supervised | 576 // Non-supervised user creation cannot be canceled. (Creating a non-supervised |
| 530 // profile shouldn't take significant time, and it can easily be deleted | 577 // profile shouldn't take significant time, and it can easily be deleted |
| 531 // afterward.) | 578 // afterward.) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 554 | 601 |
| 555 // Canceling registration means the callback passed into | 602 // Canceling registration means the callback passed into |
| 556 // RegisterAndInitSync() won't be called, so the cleanup must be done here. | 603 // RegisterAndInitSync() won't be called, so the cleanup must be done here. |
| 557 profile_path_being_created_.clear(); | 604 profile_path_being_created_.clear(); |
| 558 webui::DeleteProfileAtPath(new_profile->GetPath(), web_ui()); | 605 webui::DeleteProfileAtPath(new_profile->GetPath(), web_ui()); |
| 559 } | 606 } |
| 560 | 607 |
| 561 void SigninCreateProfileHandler::RegisterSupervisedUser( | 608 void SigninCreateProfileHandler::RegisterSupervisedUser( |
| 562 bool create_shortcut, | 609 bool create_shortcut, |
| 563 const std::string& supervised_user_id, | 610 const std::string& supervised_user_id, |
| 564 Profile* supervisor_profile, | 611 Profile* custodian_profile, |
| 565 Profile* new_profile) { | 612 Profile* new_profile) { |
| 566 DCHECK_EQ(profile_path_being_created_.value(), | 613 DCHECK_EQ(profile_path_being_created_.value(), |
| 567 new_profile->GetPath().value()); | 614 new_profile->GetPath().value()); |
| 568 | 615 |
| 569 SupervisedUserService* supervised_user_service = | 616 SupervisedUserService* supervised_user_service = |
| 570 SupervisedUserServiceFactory::GetForProfile(new_profile); | 617 SupervisedUserServiceFactory::GetForProfile(new_profile); |
| 571 | 618 |
| 572 // Register the supervised user using the profile of the custodian. | 619 // Register the supervised user using the profile of the custodian. |
| 573 supervised_user_registration_utility_ = | 620 supervised_user_registration_utility_ = |
| 574 SupervisedUserRegistrationUtility::Create(supervisor_profile); | 621 SupervisedUserRegistrationUtility::Create(custodian_profile); |
| 575 supervised_user_service->RegisterAndInitSync( | 622 supervised_user_service->RegisterAndInitSync( |
| 576 supervised_user_registration_utility_.get(), supervisor_profile, | 623 supervised_user_registration_utility_.get(), custodian_profile, |
| 577 supervised_user_id, | 624 supervised_user_id, |
| 578 base::Bind(&SigninCreateProfileHandler::OnSupervisedUserRegistered, | 625 base::Bind(&SigninCreateProfileHandler::OnSupervisedUserRegistered, |
| 579 weak_ptr_factory_.GetWeakPtr(), create_shortcut, new_profile)); | 626 weak_ptr_factory_.GetWeakPtr(), create_shortcut, new_profile)); |
| 580 } | 627 } |
| 581 | 628 |
| 582 void SigninCreateProfileHandler::OnSupervisedUserRegistered( | 629 void SigninCreateProfileHandler::OnSupervisedUserRegistered( |
| 583 bool create_shortcut, | 630 bool create_shortcut, |
| 584 Profile* profile, | 631 Profile* profile, |
| 585 const GoogleServiceAuthError& error) { | 632 const GoogleServiceAuthError& error) { |
| 586 GoogleServiceAuthError::State state = error.state(); | 633 GoogleServiceAuthError::State state = error.state(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 DCHECK_EQ(SUPERVISED_PROFILE_IMPORT, profile_creation_type_); | 669 DCHECK_EQ(SUPERVISED_PROFILE_IMPORT, profile_creation_type_); |
| 623 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileImportError", | 670 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileImportError", |
| 624 error_state, GoogleServiceAuthError::NUM_STATES); | 671 error_state, GoogleServiceAuthError::NUM_STATES); |
| 625 UMA_HISTOGRAM_MEDIUM_TIMES( | 672 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 626 "Profile.SupervisedProfileTotalImportTime", | 673 "Profile.SupervisedProfileTotalImportTime", |
| 627 base::TimeTicks::Now() - profile_creation_start_time_); | 674 base::TimeTicks::Now() - profile_creation_start_time_); |
| 628 } | 675 } |
| 629 } | 676 } |
| 630 | 677 |
| 631 #endif | 678 #endif |
| OLD | NEW |