| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 ui::HostDesktopType desktop_type, |
| 117 const std::string& supervised_user_id, | 117 const std::string& 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; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 142 case Profile::CREATE_STATUS_REMOTE_FAIL: | 142 case Profile::CREATE_STATUS_REMOTE_FAIL: |
| 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 ui::HostDesktopType desktop_type, |
| 153 const std::string& supervised_user_id, | 153 const std::string& 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: |
| 164 RegisterSupervisedUser(create_shortcut, desktop_type, | 164 RegisterSupervisedUser(create_shortcut, desktop_type, |
| 165 supervised_user_id, profile); | 165 supervised_user_id, profile); |
| 166 break; | 166 break; |
| 167 #endif | 167 #endif |
| 168 case NO_CREATION_IN_PROGRESS: | 168 case NO_CREATION_IN_PROGRESS: |
| 169 NOTREACHED(); | 169 NOTREACHED(); |
| 170 break; | 170 break; |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 | 173 |
| 174 void CreateProfileHandler::CreateShortcutAndShowSuccess( | 174 void CreateProfileHandler::CreateShortcutAndShowSuccess( |
| 175 bool create_shortcut, | 175 bool create_shortcut, |
| 176 chrome::HostDesktopType desktop_type, | 176 ui::HostDesktopType desktop_type, |
| 177 Profile* profile) { | 177 Profile* profile) { |
| 178 if (create_shortcut) { | 178 if (create_shortcut) { |
| 179 ProfileShortcutManager* shortcut_manager = | 179 ProfileShortcutManager* shortcut_manager = |
| 180 g_browser_process->profile_manager()->profile_shortcut_manager(); | 180 g_browser_process->profile_manager()->profile_shortcut_manager(); |
| 181 | 181 |
| 182 if (shortcut_manager) | 182 if (shortcut_manager) |
| 183 shortcut_manager->CreateProfileShortcut(profile->GetPath()); | 183 shortcut_manager->CreateProfileShortcut(profile->GetPath()); |
| 184 } | 184 } |
| 185 | 185 |
| 186 DCHECK_EQ(profile_path_being_created_.value(), profile->GetPath().value()); | 186 DCHECK_EQ(profile_path_being_created_.value(), profile->GetPath().value()); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 profile_creation_type_ = NO_CREATION_IN_PROGRESS; | 370 profile_creation_type_ = NO_CREATION_IN_PROGRESS; |
| 371 | 371 |
| 372 // Cancelling registration means the callback passed into | 372 // Cancelling registration means the callback passed into |
| 373 // RegisterAndInitSync() won't be called, so the cleanup must be done here. | 373 // RegisterAndInitSync() won't be called, so the cleanup must be done here. |
| 374 profile_path_being_created_.clear(); | 374 profile_path_being_created_.clear(); |
| 375 helper::DeleteProfileAtPath(new_profile->GetPath(), web_ui()); | 375 helper::DeleteProfileAtPath(new_profile->GetPath(), web_ui()); |
| 376 } | 376 } |
| 377 | 377 |
| 378 void CreateProfileHandler::RegisterSupervisedUser( | 378 void CreateProfileHandler::RegisterSupervisedUser( |
| 379 bool create_shortcut, | 379 bool create_shortcut, |
| 380 chrome::HostDesktopType desktop_type, | 380 ui::HostDesktopType desktop_type, |
| 381 const std::string& supervised_user_id, | 381 const std::string& supervised_user_id, |
| 382 Profile* new_profile) { | 382 Profile* new_profile) { |
| 383 DCHECK_EQ(profile_path_being_created_.value(), | 383 DCHECK_EQ(profile_path_being_created_.value(), |
| 384 new_profile->GetPath().value()); | 384 new_profile->GetPath().value()); |
| 385 | 385 |
| 386 SupervisedUserService* supervised_user_service = | 386 SupervisedUserService* supervised_user_service = |
| 387 SupervisedUserServiceFactory::GetForProfile(new_profile); | 387 SupervisedUserServiceFactory::GetForProfile(new_profile); |
| 388 | 388 |
| 389 // Register the supervised user using the profile of the custodian. | 389 // Register the supervised user using the profile of the custodian. |
| 390 supervised_user_registration_utility_ = | 390 supervised_user_registration_utility_ = |
| 391 SupervisedUserRegistrationUtility::Create(Profile::FromWebUI(web_ui())); | 391 SupervisedUserRegistrationUtility::Create(Profile::FromWebUI(web_ui())); |
| 392 supervised_user_service->RegisterAndInitSync( | 392 supervised_user_service->RegisterAndInitSync( |
| 393 supervised_user_registration_utility_.get(), | 393 supervised_user_registration_utility_.get(), |
| 394 Profile::FromWebUI(web_ui()), | 394 Profile::FromWebUI(web_ui()), |
| 395 supervised_user_id, | 395 supervised_user_id, |
| 396 base::Bind(&CreateProfileHandler::OnSupervisedUserRegistered, | 396 base::Bind(&CreateProfileHandler::OnSupervisedUserRegistered, |
| 397 weak_ptr_factory_.GetWeakPtr(), | 397 weak_ptr_factory_.GetWeakPtr(), |
| 398 create_shortcut, | 398 create_shortcut, |
| 399 desktop_type, | 399 desktop_type, |
| 400 new_profile)); | 400 new_profile)); |
| 401 } | 401 } |
| 402 | 402 |
| 403 void CreateProfileHandler::OnSupervisedUserRegistered( | 403 void CreateProfileHandler::OnSupervisedUserRegistered( |
| 404 bool create_shortcut, | 404 bool create_shortcut, |
| 405 chrome::HostDesktopType desktop_type, | 405 ui::HostDesktopType desktop_type, |
| 406 Profile* profile, | 406 Profile* profile, |
| 407 const GoogleServiceAuthError& error) { | 407 const GoogleServiceAuthError& error) { |
| 408 GoogleServiceAuthError::State state = error.state(); | 408 GoogleServiceAuthError::State state = error.state(); |
| 409 RecordSupervisedProfileCreationMetrics(state); | 409 RecordSupervisedProfileCreationMetrics(state); |
| 410 if (state == GoogleServiceAuthError::NONE) { | 410 if (state == GoogleServiceAuthError::NONE) { |
| 411 CreateShortcutAndShowSuccess(create_shortcut, desktop_type, profile); | 411 CreateShortcutAndShowSuccess(create_shortcut, desktop_type, profile); |
| 412 return; | 412 return; |
| 413 } | 413 } |
| 414 | 414 |
| 415 base::string16 error_msg; | 415 base::string16 error_msg; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 469 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
| 470 if (existing_supervised_user_id == | 470 if (existing_supervised_user_id == |
| 471 cache.GetSupervisedUserIdOfProfileAtIndex(i)) | 471 cache.GetSupervisedUserIdOfProfileAtIndex(i)) |
| 472 return false; | 472 return false; |
| 473 } | 473 } |
| 474 return true; | 474 return true; |
| 475 } | 475 } |
| 476 #endif | 476 #endif |
| 477 | 477 |
| 478 } // namespace options | 478 } // namespace options |
| OLD | NEW |