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