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" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 profile_creation_start_time_ = base::TimeTicks::Now(); | 86 profile_creation_start_time_ = base::TimeTicks::Now(); |
87 | 87 |
88 base::string16 name; | 88 base::string16 name; |
89 base::string16 icon; | 89 base::string16 icon; |
90 bool create_shortcut = false; | 90 bool create_shortcut = false; |
91 if (args->GetString(0, &name) && args->GetString(1, &icon)) { | 91 if (args->GetString(0, &name) && args->GetString(1, &icon)) { |
92 base::TrimWhitespace(name, base::TRIM_ALL, &name); | 92 base::TrimWhitespace(name, base::TRIM_ALL, &name); |
93 CHECK(!name.empty()); | 93 CHECK(!name.empty()); |
94 args->GetBoolean(2, &create_shortcut); | 94 args->GetBoolean(2, &create_shortcut); |
95 } | 95 } |
96 std::string supervised_user_id; | 96 user_manager::UserID supervised_user_id = user_manager::UserID(std::string(),
std::string()); |
97 #if defined(ENABLE_SUPERVISED_USERS) | 97 #if defined(ENABLE_SUPERVISED_USERS) |
98 if (!ProcessSupervisedCreateProfileArgs(args, &supervised_user_id)) | 98 if (!ProcessSupervisedCreateProfileArgs(args, &supervised_user_id)) |
99 return; | 99 return; |
100 #endif | 100 #endif |
101 | 101 |
102 ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_DIALOG); | 102 ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_DIALOG); |
103 | 103 |
104 profile_path_being_created_ = ProfileManager::CreateMultiProfileAsync( | 104 profile_path_being_created_ = ProfileManager::CreateMultiProfileAsync( |
105 name, icon, | 105 name, icon, |
106 base::Bind(&CreateProfileHandler::OnProfileCreated, | 106 base::Bind(&CreateProfileHandler::OnProfileCreated, |
107 weak_ptr_factory_.GetWeakPtr(), | 107 weak_ptr_factory_.GetWeakPtr(), |
108 create_shortcut, | 108 create_shortcut, |
109 helper::GetDesktopType(web_ui()), | 109 helper::GetDesktopType(web_ui()), |
110 supervised_user_id), | 110 supervised_user_id), |
111 supervised_user_id); | 111 supervised_user_id); |
112 } | 112 } |
113 | 113 |
114 void CreateProfileHandler::OnProfileCreated( | 114 void CreateProfileHandler::OnProfileCreated( |
115 bool create_shortcut, | 115 bool create_shortcut, |
116 chrome::HostDesktopType desktop_type, | 116 chrome::HostDesktopType desktop_type, |
117 const std::string& supervised_user_id, | 117 const user_manager::UserID& supervised_user_id, |
118 Profile* profile, | 118 Profile* profile, |
119 Profile::CreateStatus status) { | 119 Profile::CreateStatus status) { |
120 if (status != Profile::CREATE_STATUS_CREATED) | 120 if (status != Profile::CREATE_STATUS_CREATED) |
121 RecordProfileCreationMetrics(status); | 121 RecordProfileCreationMetrics(status); |
122 | 122 |
123 switch (status) { | 123 switch (status) { |
124 case Profile::CREATE_STATUS_LOCAL_FAIL: { | 124 case Profile::CREATE_STATUS_LOCAL_FAIL: { |
125 ShowProfileCreationError(profile, GetProfileCreationErrorMessageLocal()); | 125 ShowProfileCreationError(profile, GetProfileCreationErrorMessageLocal()); |
126 break; | 126 break; |
127 } | 127 } |
(...skipping 15 matching lines...) Expand all Loading... |
143 case Profile::MAX_CREATE_STATUS: { | 143 case Profile::MAX_CREATE_STATUS: { |
144 NOTREACHED(); | 144 NOTREACHED(); |
145 break; | 145 break; |
146 } | 146 } |
147 } | 147 } |
148 } | 148 } |
149 | 149 |
150 void CreateProfileHandler::HandleProfileCreationSuccess( | 150 void CreateProfileHandler::HandleProfileCreationSuccess( |
151 bool create_shortcut, | 151 bool create_shortcut, |
152 chrome::HostDesktopType desktop_type, | 152 chrome::HostDesktopType desktop_type, |
153 const std::string& supervised_user_id, | 153 const user_manager::UserID& supervised_user_id, |
154 Profile* profile) { | 154 Profile* profile) { |
155 switch (profile_creation_type_) { | 155 switch (profile_creation_type_) { |
156 case NON_SUPERVISED_PROFILE_CREATION: { | 156 case NON_SUPERVISED_PROFILE_CREATION: { |
157 DCHECK(supervised_user_id.empty()); | 157 DCHECK(supervised_user_id.empty()); |
158 CreateShortcutAndShowSuccess(create_shortcut, desktop_type, profile); | 158 CreateShortcutAndShowSuccess(create_shortcut, desktop_type, profile); |
159 break; | 159 break; |
160 } | 160 } |
161 #if defined(ENABLE_SUPERVISED_USERS) | 161 #if defined(ENABLE_SUPERVISED_USERS) |
162 case SUPERVISED_PROFILE_CREATION: | 162 case SUPERVISED_PROFILE_CREATION: |
163 case SUPERVISED_PROFILE_IMPORT: | 163 case SUPERVISED_PROFILE_IMPORT: |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 } | 295 } |
296 break; | 296 break; |
297 } | 297 } |
298 | 298 |
299 NOTREACHED(); | 299 NOTREACHED(); |
300 return std::string(); | 300 return std::string(); |
301 } | 301 } |
302 | 302 |
303 #if defined(ENABLE_SUPERVISED_USERS) | 303 #if defined(ENABLE_SUPERVISED_USERS) |
304 bool CreateProfileHandler::ProcessSupervisedCreateProfileArgs( | 304 bool CreateProfileHandler::ProcessSupervisedCreateProfileArgs( |
305 const base::ListValue* args, std::string* supervised_user_id) { | 305 const base::ListValue* args, user_manager::UserID* supervised_user_id) { |
306 bool supervised_user = false; | 306 bool supervised_user = false; |
307 if (args->GetSize() >= 5) { | 307 if (args->GetSize() >= 5) { |
308 bool success = args->GetBoolean(3, &supervised_user); | 308 bool success = args->GetBoolean(3, &supervised_user); |
309 DCHECK(success); | 309 DCHECK(success); |
310 | 310 |
311 success = args->GetString(4, supervised_user_id); | 311 std::string supervised_user_email; |
| 312 success = args->GetString(4, &supervised_user_email); |
312 DCHECK(success); | 313 DCHECK(success); |
| 314 *(supervised_user_id) = user_manager::UserID::FromUserEmail(supervised_use
r_email); |
313 } | 315 } |
314 | 316 |
315 if (supervised_user) { | 317 if (supervised_user) { |
316 if (!IsValidExistingSupervisedUserId(*supervised_user_id)) | 318 if (!IsValidExistingSupervisedUserId(*supervised_user_id)) |
317 return false; | 319 return false; |
318 | 320 |
319 profile_creation_type_ = SUPERVISED_PROFILE_IMPORT; | 321 profile_creation_type_ = SUPERVISED_PROFILE_IMPORT; |
320 if (supervised_user_id->empty()) { | 322 if (supervised_user_id->empty()) { |
321 profile_creation_type_ = SUPERVISED_PROFILE_CREATION; | 323 profile_creation_type_ = SUPERVISED_PROFILE_CREATION; |
322 *supervised_user_id = | 324 *supervised_user_id = |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 | 373 |
372 // Cancelling registration means the callback passed into | 374 // Cancelling registration means the callback passed into |
373 // RegisterAndInitSync() won't be called, so the cleanup must be done here. | 375 // RegisterAndInitSync() won't be called, so the cleanup must be done here. |
374 profile_path_being_created_.clear(); | 376 profile_path_being_created_.clear(); |
375 helper::DeleteProfileAtPath(new_profile->GetPath(), web_ui()); | 377 helper::DeleteProfileAtPath(new_profile->GetPath(), web_ui()); |
376 } | 378 } |
377 | 379 |
378 void CreateProfileHandler::RegisterSupervisedUser( | 380 void CreateProfileHandler::RegisterSupervisedUser( |
379 bool create_shortcut, | 381 bool create_shortcut, |
380 chrome::HostDesktopType desktop_type, | 382 chrome::HostDesktopType desktop_type, |
381 const std::string& supervised_user_id, | 383 const user_manager::UserID& supervised_user_id, |
382 Profile* new_profile) { | 384 Profile* new_profile) { |
383 DCHECK_EQ(profile_path_being_created_.value(), | 385 DCHECK_EQ(profile_path_being_created_.value(), |
384 new_profile->GetPath().value()); | 386 new_profile->GetPath().value()); |
385 | 387 |
386 SupervisedUserService* supervised_user_service = | 388 SupervisedUserService* supervised_user_service = |
387 SupervisedUserServiceFactory::GetForProfile(new_profile); | 389 SupervisedUserServiceFactory::GetForProfile(new_profile); |
388 | 390 |
389 // Register the supervised user using the profile of the custodian. | 391 // Register the supervised user using the profile of the custodian. |
390 supervised_user_registration_utility_ = | 392 supervised_user_registration_utility_ = |
391 SupervisedUserRegistrationUtility::Create(Profile::FromWebUI(web_ui())); | 393 SupervisedUserRegistrationUtility::Create(Profile::FromWebUI(web_ui())); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileImportError", | 447 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileImportError", |
446 error_state, | 448 error_state, |
447 GoogleServiceAuthError::NUM_STATES); | 449 GoogleServiceAuthError::NUM_STATES); |
448 UMA_HISTOGRAM_MEDIUM_TIMES( | 450 UMA_HISTOGRAM_MEDIUM_TIMES( |
449 "Profile.SupervisedProfileTotalImportTime", | 451 "Profile.SupervisedProfileTotalImportTime", |
450 base::TimeTicks::Now() - profile_creation_start_time_); | 452 base::TimeTicks::Now() - profile_creation_start_time_); |
451 } | 453 } |
452 } | 454 } |
453 | 455 |
454 bool CreateProfileHandler::IsValidExistingSupervisedUserId( | 456 bool CreateProfileHandler::IsValidExistingSupervisedUserId( |
455 const std::string& existing_supervised_user_id) const { | 457 const user_manager::UserID& existing_supervised_user_id) const { |
456 if (existing_supervised_user_id.empty()) | 458 if (existing_supervised_user_id.empty()) |
457 return true; | 459 return true; |
458 | 460 |
459 Profile* profile = Profile::FromWebUI(web_ui()); | 461 Profile* profile = Profile::FromWebUI(web_ui()); |
460 const base::DictionaryValue* dict = | 462 const base::DictionaryValue* dict = |
461 SupervisedUserSyncServiceFactory::GetForProfile(profile)-> | 463 SupervisedUserSyncServiceFactory::GetForProfile(profile)-> |
462 GetSupervisedUsers(); | 464 GetSupervisedUsers(); |
463 if (!dict->HasKey(existing_supervised_user_id)) | 465 if (!dict->HasKey(existing_supervised_user_id.GetUserEmail())) |
464 return false; | 466 return false; |
465 | 467 |
466 // Check if this supervised user already exists on this machine. | 468 // Check if this supervised user already exists on this machine. |
467 const ProfileInfoCache& cache = | 469 const ProfileInfoCache& cache = |
468 g_browser_process->profile_manager()->GetProfileInfoCache(); | 470 g_browser_process->profile_manager()->GetProfileInfoCache(); |
469 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 471 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
470 if (existing_supervised_user_id == | 472 if (existing_supervised_user_id == |
471 cache.GetSupervisedUserIdOfProfileAtIndex(i)) | 473 cache.GetSupervisedUserIdOfProfileAtIndex(i)) |
472 return false; | 474 return false; |
473 } | 475 } |
474 return true; | 476 return true; |
475 } | 477 } |
476 #endif | 478 #endif |
477 | 479 |
478 } // namespace options | 480 } // namespace options |
OLD | NEW |