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