Chromium Code Reviews| 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/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/value_conversions.h" | 11 #include "base/value_conversions.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
| 15 #include "chrome/browser/profiles/profile_metrics.h" | 15 #include "chrome/browser/profiles/profile_metrics.h" |
| 16 #include "chrome/browser/profiles/profiles_state.h" | 16 #include "chrome/browser/profiles/profiles_state.h" |
| 17 #include "chrome/browser/sync/profile_sync_service.h" | |
| 18 #include "chrome/browser/sync/profile_sync_service_factory.h" | |
| 19 #include "chrome/browser/ui/webui/options/options_handlers_helper.h" | |
| 20 #include "chrome/common/pref_names.h" | |
| 21 #include "content/public/browser/web_ui.h" | |
| 22 #include "grit/generated_resources.h" | |
| 23 #include "ui/base/l10n/l10n_util.h" | |
| 24 | |
| 25 #if defined(ENABLE_MANAGED_USERS) | |
| 17 #include "chrome/browser/supervised_user/supervised_user_registration_utility.h" | 26 #include "chrome/browser/supervised_user/supervised_user_registration_utility.h" |
| 18 #include "chrome/browser/supervised_user/supervised_user_service.h" | 27 #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 19 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | 28 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
| 20 #include "chrome/browser/supervised_user/supervised_user_sync_service.h" | 29 #include "chrome/browser/supervised_user/supervised_user_sync_service.h" |
| 21 #include "chrome/browser/supervised_user/supervised_user_sync_service_factory.h" | 30 #include "chrome/browser/supervised_user/supervised_user_sync_service_factory.h" |
| 22 #include "chrome/browser/sync/profile_sync_service.h" | 31 #endif |
| 23 #include "chrome/browser/sync/profile_sync_service_factory.h" | |
| 24 #include "chrome/browser/ui/webui/options/options_handlers_helper.h" | |
| 25 #include "chrome/common/pref_names.h" | |
| 26 #include "grit/generated_resources.h" | |
| 27 #include "ui/base/l10n/l10n_util.h" | |
| 28 | 32 |
| 29 namespace options { | 33 namespace options { |
| 30 | 34 |
| 31 CreateProfileHandler::CreateProfileHandler() | 35 CreateProfileHandler::CreateProfileHandler() |
| 32 : profile_creation_type_(NO_CREATION_IN_PROGRESS), | 36 : profile_creation_type_(NO_CREATION_IN_PROGRESS), |
| 33 weak_ptr_factory_(this) { | 37 weak_ptr_factory_(this) { |
| 34 } | 38 } |
| 35 | 39 |
| 36 CreateProfileHandler::~CreateProfileHandler() { | 40 CreateProfileHandler::~CreateProfileHandler() { |
| 37 CancelProfileRegistration(false); | 41 CancelProfileRegistration(false); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 if (args->GetString(0, &name) && args->GetString(1, &icon)) { | 86 if (args->GetString(0, &name) && args->GetString(1, &icon)) { |
| 83 if (args->GetBoolean(2, &create_shortcut)) { | 87 if (args->GetBoolean(2, &create_shortcut)) { |
| 84 bool success = args->GetBoolean(3, &supervised_user); | 88 bool success = args->GetBoolean(3, &supervised_user); |
| 85 DCHECK(success); | 89 DCHECK(success); |
| 86 success = args->GetString(4, &supervised_user_id); | 90 success = args->GetString(4, &supervised_user_id); |
| 87 DCHECK(success); | 91 DCHECK(success); |
| 88 } | 92 } |
| 89 } | 93 } |
| 90 | 94 |
| 91 if (supervised_user) { | 95 if (supervised_user) { |
| 96 #if defined(ENABLE_MANAGED_USERS) | |
|
James Hawkins
2014/06/27 21:09:57
OK, you're not gonna like this. (At least) the we
mckev
2014/06/27 21:14:10
Haha, no worries at all. I'd be happy to assist i
| |
| 92 if (!IsValidExistingSupervisedUserId(supervised_user_id)) | 97 if (!IsValidExistingSupervisedUserId(supervised_user_id)) |
| 93 return; | 98 return; |
| 94 | 99 |
| 95 profile_creation_type_ = SUPERVISED_PROFILE_IMPORT; | 100 profile_creation_type_ = SUPERVISED_PROFILE_IMPORT; |
| 96 if (supervised_user_id.empty()) { | 101 if (supervised_user_id.empty()) { |
| 97 profile_creation_type_ = SUPERVISED_PROFILE_CREATION; | 102 profile_creation_type_ = SUPERVISED_PROFILE_CREATION; |
| 98 supervised_user_id = | 103 supervised_user_id = |
| 99 SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId(); | 104 SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId(); |
| 100 | 105 |
| 101 // If sync is not yet fully initialized, the creation may take extra time, | 106 // 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 | 107 // so show a message. Import doesn't wait for an acknowledgement, so it |
| 103 // won't have the same potential delay. | 108 // won't have the same potential delay. |
| 104 ProfileSyncService* sync_service = | 109 ProfileSyncService* sync_service = |
| 105 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 110 ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| 106 current_profile); | 111 current_profile); |
| 107 ProfileSyncService::SyncStatusSummary status = | 112 ProfileSyncService::SyncStatusSummary status = |
| 108 sync_service->QuerySyncStatusSummary(); | 113 sync_service->QuerySyncStatusSummary(); |
| 109 if (status == ProfileSyncService::DATATYPES_NOT_INITIALIZED) { | 114 if (status == ProfileSyncService::DATATYPES_NOT_INITIALIZED) { |
| 110 ShowProfileCreationWarning(l10n_util::GetStringUTF16( | 115 ShowProfileCreationWarning(l10n_util::GetStringUTF16( |
| 111 IDS_PROFILES_CREATE_SUPERVISED_JUST_SIGNED_IN)); | 116 IDS_PROFILES_CREATE_SUPERVISED_JUST_SIGNED_IN)); |
| 112 } | 117 } |
| 113 } | 118 } |
| 119 #else | |
| 120 DCHECK(false) << "Supervised users aren't enabled."; | |
| 121 #endif | |
| 114 } | 122 } |
| 115 | 123 |
| 116 ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_DIALOG); | 124 ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_DIALOG); |
| 117 | 125 |
| 118 profile_path_being_created_ = ProfileManager::CreateMultiProfileAsync( | 126 profile_path_being_created_ = ProfileManager::CreateMultiProfileAsync( |
| 119 name, icon, | 127 name, icon, |
| 120 base::Bind(&CreateProfileHandler::OnProfileCreated, | 128 base::Bind(&CreateProfileHandler::OnProfileCreated, |
| 121 weak_ptr_factory_.GetWeakPtr(), | 129 weak_ptr_factory_.GetWeakPtr(), |
| 122 create_shortcut, | 130 create_shortcut, |
| 123 helper::GetDesktopType(web_ui()), | 131 helper::GetDesktopType(web_ui()), |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 NOTREACHED(); | 190 NOTREACHED(); |
| 183 break; | 191 break; |
| 184 } | 192 } |
| 185 } | 193 } |
| 186 | 194 |
| 187 void CreateProfileHandler::RegisterSupervisedUser( | 195 void CreateProfileHandler::RegisterSupervisedUser( |
| 188 bool create_shortcut, | 196 bool create_shortcut, |
| 189 chrome::HostDesktopType desktop_type, | 197 chrome::HostDesktopType desktop_type, |
| 190 const std::string& supervised_user_id, | 198 const std::string& supervised_user_id, |
| 191 Profile* new_profile) { | 199 Profile* new_profile) { |
| 200 #if defined(ENABLE_MANAGED_USERS) | |
|
Bernhard Bauer
2014/06/30 16:04:19
We might also want to move this whole method (and
| |
| 192 DCHECK_EQ(profile_path_being_created_.value(), | 201 DCHECK_EQ(profile_path_being_created_.value(), |
| 193 new_profile->GetPath().value()); | 202 new_profile->GetPath().value()); |
| 194 | 203 |
| 195 SupervisedUserService* supervised_user_service = | 204 SupervisedUserService* supervised_user_service = |
| 196 SupervisedUserServiceFactory::GetForProfile(new_profile); | 205 SupervisedUserServiceFactory::GetForProfile(new_profile); |
| 197 | 206 |
| 198 // Register the supervised user using the profile of the custodian. | 207 // Register the supervised user using the profile of the custodian. |
| 199 supervised_user_registration_utility_ = | 208 supervised_user_registration_utility_ = |
| 200 SupervisedUserRegistrationUtility::Create(Profile::FromWebUI(web_ui())); | 209 SupervisedUserRegistrationUtility::Create(Profile::FromWebUI(web_ui())); |
| 201 supervised_user_service->RegisterAndInitSync( | 210 supervised_user_service->RegisterAndInitSync( |
| 202 supervised_user_registration_utility_.get(), | 211 supervised_user_registration_utility_.get(), |
| 203 Profile::FromWebUI(web_ui()), | 212 Profile::FromWebUI(web_ui()), |
| 204 supervised_user_id, | 213 supervised_user_id, |
| 205 base::Bind(&CreateProfileHandler::OnSupervisedUserRegistered, | 214 base::Bind(&CreateProfileHandler::OnSupervisedUserRegistered, |
| 206 weak_ptr_factory_.GetWeakPtr(), | 215 weak_ptr_factory_.GetWeakPtr(), |
| 207 create_shortcut, | 216 create_shortcut, |
| 208 desktop_type, | 217 desktop_type, |
| 209 new_profile)); | 218 new_profile)); |
| 219 #else | |
| 220 DCHECK(false) << "Supervised users aren't enabled."; | |
| 221 #endif | |
| 210 } | 222 } |
| 211 | 223 |
| 212 void CreateProfileHandler::OnSupervisedUserRegistered( | 224 void CreateProfileHandler::OnSupervisedUserRegistered( |
| 213 bool create_shortcut, | 225 bool create_shortcut, |
| 214 chrome::HostDesktopType desktop_type, | 226 chrome::HostDesktopType desktop_type, |
| 215 Profile* profile, | 227 Profile* profile, |
| 216 const GoogleServiceAuthError& error) { | 228 const GoogleServiceAuthError& error) { |
| 217 GoogleServiceAuthError::State state = error.state(); | 229 GoogleServiceAuthError::State state = error.state(); |
| 218 RecordSupervisedProfileCreationMetrics(state); | 230 RecordSupervisedProfileCreationMetrics(state); |
| 219 if (state == GoogleServiceAuthError::NONE) { | 231 if (state == GoogleServiceAuthError::NONE) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 if (!new_profile->IsSupervised()) | 325 if (!new_profile->IsSupervised()) |
| 314 return; | 326 return; |
| 315 | 327 |
| 316 if (user_initiated) { | 328 if (user_initiated) { |
| 317 UMA_HISTOGRAM_MEDIUM_TIMES( | 329 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 318 "Profile.CreateTimeCanceledNoTimeout", | 330 "Profile.CreateTimeCanceledNoTimeout", |
| 319 base::TimeTicks::Now() - profile_creation_start_time_); | 331 base::TimeTicks::Now() - profile_creation_start_time_); |
| 320 RecordProfileCreationMetrics(Profile::CREATE_STATUS_CANCELED); | 332 RecordProfileCreationMetrics(Profile::CREATE_STATUS_CANCELED); |
| 321 } | 333 } |
| 322 | 334 |
| 335 #if defined(ENABLE_MANAGED_USERS) | |
| 323 DCHECK(supervised_user_registration_utility_.get()); | 336 DCHECK(supervised_user_registration_utility_.get()); |
| 324 supervised_user_registration_utility_.reset(); | 337 supervised_user_registration_utility_.reset(); |
| 338 #endif | |
| 325 | 339 |
| 326 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); | 340 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); |
| 327 profile_creation_type_ = NO_CREATION_IN_PROGRESS; | 341 profile_creation_type_ = NO_CREATION_IN_PROGRESS; |
| 328 | 342 |
| 329 // Cancelling registration means the callback passed into | 343 // Cancelling registration means the callback passed into |
| 330 // RegisterAndInitSync() won't be called, so the cleanup must be done here. | 344 // RegisterAndInitSync() won't be called, so the cleanup must be done here. |
| 331 profile_path_being_created_.clear(); | 345 profile_path_being_created_.clear(); |
| 332 helper::DeleteProfileAtPath(new_profile->GetPath(), web_ui()); | 346 helper::DeleteProfileAtPath(new_profile->GetPath(), web_ui()); |
| 333 } | 347 } |
| 334 | 348 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 401 "BrowserOptions.showManagedUserImportError" : | 415 "BrowserOptions.showManagedUserImportError" : |
| 402 "BrowserOptions.showCreateProfileError"; | 416 "BrowserOptions.showCreateProfileError"; |
| 403 } | 417 } |
| 404 | 418 |
| 405 NOTREACHED(); | 419 NOTREACHED(); |
| 406 return std::string(); | 420 return std::string(); |
| 407 } | 421 } |
| 408 | 422 |
| 409 bool CreateProfileHandler::IsValidExistingSupervisedUserId( | 423 bool CreateProfileHandler::IsValidExistingSupervisedUserId( |
| 410 const std::string& existing_supervised_user_id) const { | 424 const std::string& existing_supervised_user_id) const { |
| 425 #if defined(ENABLE_MANAGED_USERS) | |
| 411 if (existing_supervised_user_id.empty()) | 426 if (existing_supervised_user_id.empty()) |
| 412 return true; | 427 return true; |
| 413 | 428 |
| 414 Profile* profile = Profile::FromWebUI(web_ui()); | 429 Profile* profile = Profile::FromWebUI(web_ui()); |
| 415 const base::DictionaryValue* dict = | 430 const base::DictionaryValue* dict = |
| 416 SupervisedUserSyncServiceFactory::GetForProfile(profile)-> | 431 SupervisedUserSyncServiceFactory::GetForProfile(profile)-> |
| 417 GetSupervisedUsers(); | 432 GetSupervisedUsers(); |
| 418 if (!dict->HasKey(existing_supervised_user_id)) | 433 if (!dict->HasKey(existing_supervised_user_id)) |
| 419 return false; | 434 return false; |
| 420 | 435 |
| 421 // Check if this supervised user already exists on this machine. | 436 // Check if this supervised user already exists on this machine. |
| 422 const ProfileInfoCache& cache = | 437 const ProfileInfoCache& cache = |
| 423 g_browser_process->profile_manager()->GetProfileInfoCache(); | 438 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 424 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 439 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
| 425 if (existing_supervised_user_id == | 440 if (existing_supervised_user_id == |
| 426 cache.GetSupervisedUserIdOfProfileAtIndex(i)) | 441 cache.GetSupervisedUserIdOfProfileAtIndex(i)) |
| 427 return false; | 442 return false; |
| 428 } | 443 } |
| 429 return true; | 444 return true; |
| 445 #else | |
| 446 DCHECK(false) << "Supervised users aren't enabled."; | |
| 447 return false; | |
| 448 #endif | |
| 430 } | 449 } |
| 431 | 450 |
| 432 } // namespace options | 451 } // namespace options |
| OLD | NEW |