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