| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/options/create_profile_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 "cancelCreateProfile", | 47 "cancelCreateProfile", |
| 48 base::Bind(&CreateProfileHandler::HandleCancelProfileCreation, | 48 base::Bind(&CreateProfileHandler::HandleCancelProfileCreation, |
| 49 base::Unretained(this))); | 49 base::Unretained(this))); |
| 50 web_ui()->RegisterMessageCallback( | 50 web_ui()->RegisterMessageCallback( |
| 51 "createProfile", | 51 "createProfile", |
| 52 base::Bind(&CreateProfileHandler::CreateProfile, | 52 base::Bind(&CreateProfileHandler::CreateProfile, |
| 53 base::Unretained(this))); | 53 base::Unretained(this))); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void CreateProfileHandler::CreateProfile(const base::ListValue* args) { | 56 void CreateProfileHandler::CreateProfile(const base::ListValue* args) { |
| 57 // This handler could have been called in managed mode, for example because | 57 // This handler could have been called for a supervised user, for example |
| 58 // the user fiddled with the web inspector. Silently return in this case. | 58 // because the user fiddled with the web inspector. Silently return in this |
| 59 // case. |
| 59 Profile* current_profile = Profile::FromWebUI(web_ui()); | 60 Profile* current_profile = Profile::FromWebUI(web_ui()); |
| 60 if (current_profile->IsManaged()) | 61 if (current_profile->IsSupervised()) |
| 61 return; | 62 return; |
| 62 | 63 |
| 63 if (!profiles::IsMultipleProfilesEnabled()) | 64 if (!profiles::IsMultipleProfilesEnabled()) |
| 64 return; | 65 return; |
| 65 | 66 |
| 66 // We can have only one in progress profile creation | 67 // We can have only one in progress profile creation |
| 67 // at any given moment, if new ones are initiated just | 68 // at any given moment, if new ones are initiated just |
| 68 // ignore them until we are done with the old one. | 69 // ignore them until we are done with the old one. |
| 69 if (profile_creation_type_ != NO_CREATION_IN_PROGRESS) | 70 if (profile_creation_type_ != NO_CREATION_IN_PROGRESS) |
| 70 return; | 71 return; |
| 71 | 72 |
| 72 profile_creation_type_ = NON_SUPERVISED_PROFILE_CREATION; | 73 profile_creation_type_ = NON_SUPERVISED_PROFILE_CREATION; |
| 73 | 74 |
| 74 DCHECK(profile_path_being_created_.empty()); | 75 DCHECK(profile_path_being_created_.empty()); |
| 75 profile_creation_start_time_ = base::TimeTicks::Now(); | 76 profile_creation_start_time_ = base::TimeTicks::Now(); |
| 76 | 77 |
| 77 base::string16 name; | 78 base::string16 name; |
| 78 base::string16 icon; | 79 base::string16 icon; |
| 79 std::string managed_user_id; | 80 std::string supervised_user_id; |
| 80 bool create_shortcut = false; | 81 bool create_shortcut = false; |
| 81 bool managed_user = false; | 82 bool supervised_user = false; |
| 82 if (args->GetString(0, &name) && args->GetString(1, &icon)) { | 83 if (args->GetString(0, &name) && args->GetString(1, &icon)) { |
| 83 if (args->GetBoolean(2, &create_shortcut)) { | 84 if (args->GetBoolean(2, &create_shortcut)) { |
| 84 bool success = args->GetBoolean(3, &managed_user); | 85 bool success = args->GetBoolean(3, &supervised_user); |
| 85 DCHECK(success); | 86 DCHECK(success); |
| 86 success = args->GetString(4, &managed_user_id); | 87 success = args->GetString(4, &supervised_user_id); |
| 87 DCHECK(success); | 88 DCHECK(success); |
| 88 } | 89 } |
| 89 } | 90 } |
| 90 | 91 |
| 91 if (managed_user) { | 92 if (supervised_user) { |
| 92 if (!IsValidExistingManagedUserId(managed_user_id)) | 93 if (!IsValidExistingSupervisedUserId(supervised_user_id)) |
| 93 return; | 94 return; |
| 94 | 95 |
| 95 profile_creation_type_ = SUPERVISED_PROFILE_IMPORT; | 96 profile_creation_type_ = SUPERVISED_PROFILE_IMPORT; |
| 96 if (managed_user_id.empty()) { | 97 if (supervised_user_id.empty()) { |
| 97 profile_creation_type_ = SUPERVISED_PROFILE_CREATION; | 98 profile_creation_type_ = SUPERVISED_PROFILE_CREATION; |
| 98 managed_user_id = | 99 supervised_user_id = |
| 99 ManagedUserRegistrationUtility::GenerateNewManagedUserId(); | 100 ManagedUserRegistrationUtility::GenerateNewManagedUserId(); |
| 100 | 101 |
| 101 // If sync is not yet fully initialized, the creation may take extra time, | 102 // If sync is not yet fully initialized, the creation may take extra time, |
| 102 // so show a message. Import doesn't wait for an acknowledgement, so it | 103 // so show a message. Import doesn't wait for an acknowledgement, so it |
| 103 // won't have the same potential delay. | 104 // won't have the same potential delay. |
| 104 ProfileSyncService* sync_service = | 105 ProfileSyncService* sync_service = |
| 105 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 106 ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| 106 current_profile); | 107 current_profile); |
| 107 ProfileSyncService::SyncStatusSummary status = | 108 ProfileSyncService::SyncStatusSummary status = |
| 108 sync_service->QuerySyncStatusSummary(); | 109 sync_service->QuerySyncStatusSummary(); |
| 109 if (status == ProfileSyncService::DATATYPES_NOT_INITIALIZED) { | 110 if (status == ProfileSyncService::DATATYPES_NOT_INITIALIZED) { |
| 110 ShowProfileCreationWarning(l10n_util::GetStringUTF16( | 111 ShowProfileCreationWarning(l10n_util::GetStringUTF16( |
| 111 IDS_PROFILES_CREATE_MANAGED_JUST_SIGNED_IN)); | 112 IDS_PROFILES_CREATE_MANAGED_JUST_SIGNED_IN)); |
| 112 } | 113 } |
| 113 } | 114 } |
| 114 } | 115 } |
| 115 | 116 |
| 116 ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_DIALOG); | 117 ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_DIALOG); |
| 117 | 118 |
| 118 profile_path_being_created_ = ProfileManager::CreateMultiProfileAsync( | 119 profile_path_being_created_ = ProfileManager::CreateMultiProfileAsync( |
| 119 name, icon, | 120 name, icon, |
| 120 base::Bind(&CreateProfileHandler::OnProfileCreated, | 121 base::Bind(&CreateProfileHandler::OnProfileCreated, |
| 121 weak_ptr_factory_.GetWeakPtr(), | 122 weak_ptr_factory_.GetWeakPtr(), |
| 122 create_shortcut, | 123 create_shortcut, |
| 123 helper::GetDesktopType(web_ui()), | 124 helper::GetDesktopType(web_ui()), |
| 124 managed_user_id), | 125 supervised_user_id), |
| 125 managed_user_id); | 126 supervised_user_id); |
| 126 } | 127 } |
| 127 | 128 |
| 128 void CreateProfileHandler::OnProfileCreated( | 129 void CreateProfileHandler::OnProfileCreated( |
| 129 bool create_shortcut, | 130 bool create_shortcut, |
| 130 chrome::HostDesktopType desktop_type, | 131 chrome::HostDesktopType desktop_type, |
| 131 const std::string& managed_user_id, | 132 const std::string& supervised_user_id, |
| 132 Profile* profile, | 133 Profile* profile, |
| 133 Profile::CreateStatus status) { | 134 Profile::CreateStatus status) { |
| 134 if (status != Profile::CREATE_STATUS_CREATED) | 135 if (status != Profile::CREATE_STATUS_CREATED) |
| 135 RecordProfileCreationMetrics(status); | 136 RecordProfileCreationMetrics(status); |
| 136 | 137 |
| 137 switch (status) { | 138 switch (status) { |
| 138 case Profile::CREATE_STATUS_LOCAL_FAIL: { | 139 case Profile::CREATE_STATUS_LOCAL_FAIL: { |
| 139 ShowProfileCreationError(profile, | 140 ShowProfileCreationError(profile, |
| 140 GetProfileCreationErrorMessage(LOCAL_ERROR)); | 141 GetProfileCreationErrorMessage(LOCAL_ERROR)); |
| 141 break; | 142 break; |
| 142 } | 143 } |
| 143 case Profile::CREATE_STATUS_CREATED: { | 144 case Profile::CREATE_STATUS_CREATED: { |
| 144 // Do nothing for an intermediate status. | 145 // Do nothing for an intermediate status. |
| 145 break; | 146 break; |
| 146 } | 147 } |
| 147 case Profile::CREATE_STATUS_INITIALIZED: { | 148 case Profile::CREATE_STATUS_INITIALIZED: { |
| 148 HandleProfileCreationSuccess(create_shortcut, desktop_type, | 149 HandleProfileCreationSuccess(create_shortcut, desktop_type, |
| 149 managed_user_id, profile); | 150 supervised_user_id, profile); |
| 150 break; | 151 break; |
| 151 } | 152 } |
| 152 // User-initiated cancellation is handled in CancelProfileRegistration and | 153 // User-initiated cancellation is handled in CancelProfileRegistration and |
| 153 // does not call this callback. | 154 // does not call this callback. |
| 154 case Profile::CREATE_STATUS_CANCELED: | 155 case Profile::CREATE_STATUS_CANCELED: |
| 155 // Managed user registration errors are handled in | 156 // Supervised user registration errors are handled in |
| 156 // OnManagedUserRegistered(). | 157 // OnSupervisedUserRegistered(). |
| 157 case Profile::CREATE_STATUS_REMOTE_FAIL: | 158 case Profile::CREATE_STATUS_REMOTE_FAIL: |
| 158 case Profile::MAX_CREATE_STATUS: { | 159 case Profile::MAX_CREATE_STATUS: { |
| 159 NOTREACHED(); | 160 NOTREACHED(); |
| 160 break; | 161 break; |
| 161 } | 162 } |
| 162 } | 163 } |
| 163 } | 164 } |
| 164 | 165 |
| 165 void CreateProfileHandler::HandleProfileCreationSuccess( | 166 void CreateProfileHandler::HandleProfileCreationSuccess( |
| 166 bool create_shortcut, | 167 bool create_shortcut, |
| 167 chrome::HostDesktopType desktop_type, | 168 chrome::HostDesktopType desktop_type, |
| 168 const std::string& managed_user_id, | 169 const std::string& supervised_user_id, |
| 169 Profile* profile) { | 170 Profile* profile) { |
| 170 switch (profile_creation_type_) { | 171 switch (profile_creation_type_) { |
| 171 case NON_SUPERVISED_PROFILE_CREATION: { | 172 case NON_SUPERVISED_PROFILE_CREATION: { |
| 172 DCHECK(managed_user_id.empty()); | 173 DCHECK(supervised_user_id.empty()); |
| 173 CreateShortcutAndShowSuccess(create_shortcut, desktop_type, profile); | 174 CreateShortcutAndShowSuccess(create_shortcut, desktop_type, profile); |
| 174 break; | 175 break; |
| 175 } | 176 } |
| 176 case SUPERVISED_PROFILE_CREATION: | 177 case SUPERVISED_PROFILE_CREATION: |
| 177 case SUPERVISED_PROFILE_IMPORT: | 178 case SUPERVISED_PROFILE_IMPORT: |
| 178 RegisterManagedUser(create_shortcut, desktop_type, | 179 RegisterSupervisedUser(create_shortcut, desktop_type, |
| 179 managed_user_id, profile); | 180 supervised_user_id, profile); |
| 180 break; | 181 break; |
| 181 case NO_CREATION_IN_PROGRESS: | 182 case NO_CREATION_IN_PROGRESS: |
| 182 NOTREACHED(); | 183 NOTREACHED(); |
| 183 break; | 184 break; |
| 184 } | 185 } |
| 185 } | 186 } |
| 186 | 187 |
| 187 void CreateProfileHandler::RegisterManagedUser( | 188 void CreateProfileHandler::RegisterSupervisedUser( |
| 188 bool create_shortcut, | 189 bool create_shortcut, |
| 189 chrome::HostDesktopType desktop_type, | 190 chrome::HostDesktopType desktop_type, |
| 190 const std::string& managed_user_id, | 191 const std::string& supervised_user_id, |
| 191 Profile* new_profile) { | 192 Profile* new_profile) { |
| 192 DCHECK_EQ(profile_path_being_created_.value(), | 193 DCHECK_EQ(profile_path_being_created_.value(), |
| 193 new_profile->GetPath().value()); | 194 new_profile->GetPath().value()); |
| 194 | 195 |
| 195 ManagedUserService* managed_user_service = | 196 ManagedUserService* managed_user_service = |
| 196 ManagedUserServiceFactory::GetForProfile(new_profile); | 197 ManagedUserServiceFactory::GetForProfile(new_profile); |
| 197 | 198 |
| 198 // Register the managed user using the profile of the custodian. | 199 // Register the supervised user using the profile of the custodian. |
| 199 managed_user_registration_utility_ = | 200 managed_user_registration_utility_ = |
| 200 ManagedUserRegistrationUtility::Create(Profile::FromWebUI(web_ui())); | 201 ManagedUserRegistrationUtility::Create(Profile::FromWebUI(web_ui())); |
| 201 managed_user_service->RegisterAndInitSync( | 202 managed_user_service->RegisterAndInitSync( |
| 202 managed_user_registration_utility_.get(), | 203 managed_user_registration_utility_.get(), |
| 203 Profile::FromWebUI(web_ui()), | 204 Profile::FromWebUI(web_ui()), |
| 204 managed_user_id, | 205 supervised_user_id, |
| 205 base::Bind(&CreateProfileHandler::OnManagedUserRegistered, | 206 base::Bind(&CreateProfileHandler::OnSupervisedUserRegistered, |
| 206 weak_ptr_factory_.GetWeakPtr(), | 207 weak_ptr_factory_.GetWeakPtr(), |
| 207 create_shortcut, | 208 create_shortcut, |
| 208 desktop_type, | 209 desktop_type, |
| 209 new_profile)); | 210 new_profile)); |
| 210 } | 211 } |
| 211 | 212 |
| 212 void CreateProfileHandler::OnManagedUserRegistered( | 213 void CreateProfileHandler::OnSupervisedUserRegistered( |
| 213 bool create_shortcut, | 214 bool create_shortcut, |
| 214 chrome::HostDesktopType desktop_type, | 215 chrome::HostDesktopType desktop_type, |
| 215 Profile* profile, | 216 Profile* profile, |
| 216 const GoogleServiceAuthError& error) { | 217 const GoogleServiceAuthError& error) { |
| 217 GoogleServiceAuthError::State state = error.state(); | 218 GoogleServiceAuthError::State state = error.state(); |
| 218 RecordSupervisedProfileCreationMetrics(state); | 219 RecordSupervisedProfileCreationMetrics(state); |
| 219 if (state == GoogleServiceAuthError::NONE) { | 220 if (state == GoogleServiceAuthError::NONE) { |
| 220 CreateShortcutAndShowSuccess(create_shortcut, desktop_type, profile); | 221 CreateShortcutAndShowSuccess(create_shortcut, desktop_type, profile); |
| 221 return; | 222 return; |
| 222 } | 223 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 245 shortcut_manager->CreateProfileShortcut(profile->GetPath()); | 246 shortcut_manager->CreateProfileShortcut(profile->GetPath()); |
| 246 } | 247 } |
| 247 | 248 |
| 248 DCHECK_EQ(profile_path_being_created_.value(), profile->GetPath().value()); | 249 DCHECK_EQ(profile_path_being_created_.value(), profile->GetPath().value()); |
| 249 profile_path_being_created_.clear(); | 250 profile_path_being_created_.clear(); |
| 250 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); | 251 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); |
| 251 base::DictionaryValue dict; | 252 base::DictionaryValue dict; |
| 252 dict.SetString("name", | 253 dict.SetString("name", |
| 253 profile->GetPrefs()->GetString(prefs::kProfileName)); | 254 profile->GetPrefs()->GetString(prefs::kProfileName)); |
| 254 dict.Set("filePath", base::CreateFilePathValue(profile->GetPath())); | 255 dict.Set("filePath", base::CreateFilePathValue(profile->GetPath())); |
| 255 bool is_managed = | 256 bool is_supervised = |
| 256 profile_creation_type_ == SUPERVISED_PROFILE_CREATION || | 257 profile_creation_type_ == SUPERVISED_PROFILE_CREATION || |
| 257 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT; | 258 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT; |
| 258 dict.SetBoolean("isManaged", is_managed); | 259 dict.SetBoolean("isManaged", is_supervised); |
| 259 web_ui()->CallJavascriptFunction( | 260 web_ui()->CallJavascriptFunction( |
| 260 GetJavascriptMethodName(PROFILE_CREATION_SUCCESS), dict); | 261 GetJavascriptMethodName(PROFILE_CREATION_SUCCESS), dict); |
| 261 | 262 |
| 262 // If the new profile is a supervised user, instead of opening a new window | 263 // If the new profile is a supervised user, instead of opening a new window |
| 263 // right away, a confirmation overlay will be shown by JS from the creation | 264 // right away, a confirmation overlay will be shown by JS from the creation |
| 264 // dialog. If we are importing an existing supervised profile or creating a | 265 // dialog. If we are importing an existing supervised profile or creating a |
| 265 // new non-supervised user profile we don't show any confirmation, so open | 266 // new non-supervised user profile we don't show any confirmation, so open |
| 266 // the new window now. | 267 // the new window now. |
| 267 if (profile_creation_type_ != SUPERVISED_PROFILE_CREATION) { | 268 if (profile_creation_type_ != SUPERVISED_PROFILE_CREATION) { |
| 268 // Opening the new window must be the last action, after all callbacks | 269 // Opening the new window must be the last action, after all callbacks |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | 301 |
| 301 void CreateProfileHandler::CancelProfileRegistration(bool user_initiated) { | 302 void CreateProfileHandler::CancelProfileRegistration(bool user_initiated) { |
| 302 if (profile_path_being_created_.empty()) | 303 if (profile_path_being_created_.empty()) |
| 303 return; | 304 return; |
| 304 | 305 |
| 305 ProfileManager* manager = g_browser_process->profile_manager(); | 306 ProfileManager* manager = g_browser_process->profile_manager(); |
| 306 Profile* new_profile = manager->GetProfileByPath(profile_path_being_created_); | 307 Profile* new_profile = manager->GetProfileByPath(profile_path_being_created_); |
| 307 if (!new_profile) | 308 if (!new_profile) |
| 308 return; | 309 return; |
| 309 | 310 |
| 310 // Non-managed user creation cannot be canceled. (Creating a non-managed | 311 // Non-supervised user creation cannot be canceled. (Creating a non-supervised |
| 311 // profile shouldn't take significant time, and it can easily be deleted | 312 // profile shouldn't take significant time, and it can easily be deleted |
| 312 // afterward.) | 313 // afterward.) |
| 313 if (!new_profile->IsManaged()) | 314 if (!new_profile->IsSupervised()) |
| 314 return; | 315 return; |
| 315 | 316 |
| 316 if (user_initiated) { | 317 if (user_initiated) { |
| 317 UMA_HISTOGRAM_MEDIUM_TIMES( | 318 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 318 "Profile.CreateTimeCanceledNoTimeout", | 319 "Profile.CreateTimeCanceledNoTimeout", |
| 319 base::TimeTicks::Now() - profile_creation_start_time_); | 320 base::TimeTicks::Now() - profile_creation_start_time_); |
| 320 RecordProfileCreationMetrics(Profile::CREATE_STATUS_CANCELED); | 321 RecordProfileCreationMetrics(Profile::CREATE_STATUS_CANCELED); |
| 321 } | 322 } |
| 322 | 323 |
| 323 DCHECK(managed_user_registration_utility_.get()); | 324 DCHECK(managed_user_registration_utility_.get()); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 case PROFILE_CREATION_ERROR: | 400 case PROFILE_CREATION_ERROR: |
| 400 return profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ? | 401 return profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ? |
| 401 "BrowserOptions.showManagedUserImportError" : | 402 "BrowserOptions.showManagedUserImportError" : |
| 402 "BrowserOptions.showCreateProfileError"; | 403 "BrowserOptions.showCreateProfileError"; |
| 403 } | 404 } |
| 404 | 405 |
| 405 NOTREACHED(); | 406 NOTREACHED(); |
| 406 return std::string(); | 407 return std::string(); |
| 407 } | 408 } |
| 408 | 409 |
| 409 bool CreateProfileHandler::IsValidExistingManagedUserId( | 410 bool CreateProfileHandler::IsValidExistingSupervisedUserId( |
| 410 const std::string& existing_managed_user_id) const { | 411 const std::string& existing_supervised_user_id) const { |
| 411 if (existing_managed_user_id.empty()) | 412 if (existing_supervised_user_id.empty()) |
| 412 return true; | 413 return true; |
| 413 | 414 |
| 414 Profile* profile = Profile::FromWebUI(web_ui()); | 415 Profile* profile = Profile::FromWebUI(web_ui()); |
| 415 const base::DictionaryValue* dict = | 416 const base::DictionaryValue* dict = |
| 416 ManagedUserSyncServiceFactory::GetForProfile(profile)->GetManagedUsers(); | 417 ManagedUserSyncServiceFactory::GetForProfile(profile)->GetManagedUsers(); |
| 417 if (!dict->HasKey(existing_managed_user_id)) | 418 if (!dict->HasKey(existing_supervised_user_id)) |
| 418 return false; | 419 return false; |
| 419 | 420 |
| 420 // Check if this managed user already exists on this machine. | 421 // Check if this supervised user already exists on this machine. |
| 421 const ProfileInfoCache& cache = | 422 const ProfileInfoCache& cache = |
| 422 g_browser_process->profile_manager()->GetProfileInfoCache(); | 423 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 423 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 424 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
| 424 if (existing_managed_user_id == cache.GetManagedUserIdOfProfileAtIndex(i)) | 425 if (existing_supervised_user_id == |
| 426 cache.GetSupervisedUserIdOfProfileAtIndex(i)) |
| 425 return false; | 427 return false; |
| 426 } | 428 } |
| 427 return true; | 429 return true; |
| 428 } | 430 } |
| 429 | 431 |
| 430 } // namespace options | 432 } // namespace options |
| OLD | NEW |