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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 } | 103 } |
104 std::string supervised_user_id; | 104 std::string supervised_user_id; |
105 #if defined(ENABLE_SUPERVISED_USERS) | 105 #if defined(ENABLE_SUPERVISED_USERS) |
106 if (!ProcessSupervisedCreateProfileArgs(args, &supervised_user_id)) | 106 if (!ProcessSupervisedCreateProfileArgs(args, &supervised_user_id)) |
107 return; | 107 return; |
108 #endif | 108 #endif |
109 | 109 |
110 ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_DIALOG); | 110 ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_DIALOG); |
111 | 111 |
112 profile_path_being_created_ = ProfileManager::CreateMultiProfileAsync( | 112 profile_path_being_created_ = ProfileManager::CreateMultiProfileAsync( |
113 name, icon_url, | 113 name, icon_url, base::Bind(&CreateProfileHandler::OnProfileCreated, |
114 base::Bind(&CreateProfileHandler::OnProfileCreated, | 114 weak_ptr_factory_.GetWeakPtr(), |
115 weak_ptr_factory_.GetWeakPtr(), | 115 create_shortcut, supervised_user_id), |
116 create_shortcut, | |
117 helper::GetDesktopType(web_ui()), | |
118 supervised_user_id), | |
119 supervised_user_id); | 116 supervised_user_id); |
120 } | 117 } |
121 | 118 |
122 void CreateProfileHandler::OnProfileCreated( | 119 void CreateProfileHandler::OnProfileCreated( |
123 bool create_shortcut, | 120 bool create_shortcut, |
124 chrome::HostDesktopType desktop_type, | |
125 const std::string& supervised_user_id, | 121 const std::string& supervised_user_id, |
126 Profile* profile, | 122 Profile* profile, |
127 Profile::CreateStatus status) { | 123 Profile::CreateStatus status) { |
128 if (status != Profile::CREATE_STATUS_CREATED) | 124 if (status != Profile::CREATE_STATUS_CREATED) |
129 RecordProfileCreationMetrics(status); | 125 RecordProfileCreationMetrics(status); |
130 | 126 |
131 switch (status) { | 127 switch (status) { |
132 case Profile::CREATE_STATUS_LOCAL_FAIL: { | 128 case Profile::CREATE_STATUS_LOCAL_FAIL: { |
133 ShowProfileCreationError(profile, GetProfileCreationErrorMessageLocal()); | 129 ShowProfileCreationError(profile, GetProfileCreationErrorMessageLocal()); |
134 break; | 130 break; |
135 } | 131 } |
136 case Profile::CREATE_STATUS_CREATED: { | 132 case Profile::CREATE_STATUS_CREATED: { |
137 // Do nothing for an intermediate status. | 133 // Do nothing for an intermediate status. |
138 break; | 134 break; |
139 } | 135 } |
140 case Profile::CREATE_STATUS_INITIALIZED: { | 136 case Profile::CREATE_STATUS_INITIALIZED: { |
141 HandleProfileCreationSuccess(create_shortcut, desktop_type, | 137 HandleProfileCreationSuccess(create_shortcut, supervised_user_id, |
142 supervised_user_id, profile); | 138 profile); |
143 break; | 139 break; |
144 } | 140 } |
145 // User-initiated cancellation is handled in CancelProfileRegistration and | 141 // User-initiated cancellation is handled in CancelProfileRegistration and |
146 // does not call this callback. | 142 // does not call this callback. |
147 case Profile::CREATE_STATUS_CANCELED: | 143 case Profile::CREATE_STATUS_CANCELED: |
148 // Supervised user registration errors are handled in | 144 // Supervised user registration errors are handled in |
149 // OnSupervisedUserRegistered(). | 145 // OnSupervisedUserRegistered(). |
150 case Profile::CREATE_STATUS_REMOTE_FAIL: | 146 case Profile::CREATE_STATUS_REMOTE_FAIL: |
151 case Profile::MAX_CREATE_STATUS: { | 147 case Profile::MAX_CREATE_STATUS: { |
152 NOTREACHED(); | 148 NOTREACHED(); |
153 break; | 149 break; |
154 } | 150 } |
155 } | 151 } |
156 } | 152 } |
157 | 153 |
158 void CreateProfileHandler::HandleProfileCreationSuccess( | 154 void CreateProfileHandler::HandleProfileCreationSuccess( |
159 bool create_shortcut, | 155 bool create_shortcut, |
160 chrome::HostDesktopType desktop_type, | |
161 const std::string& supervised_user_id, | 156 const std::string& supervised_user_id, |
162 Profile* profile) { | 157 Profile* profile) { |
163 switch (profile_creation_type_) { | 158 switch (profile_creation_type_) { |
164 case NON_SUPERVISED_PROFILE_CREATION: { | 159 case NON_SUPERVISED_PROFILE_CREATION: { |
165 DCHECK(supervised_user_id.empty()); | 160 DCHECK(supervised_user_id.empty()); |
166 CreateShortcutAndShowSuccess(create_shortcut, desktop_type, profile); | 161 CreateShortcutAndShowSuccess(create_shortcut, profile); |
167 break; | 162 break; |
168 } | 163 } |
169 #if defined(ENABLE_SUPERVISED_USERS) | 164 #if defined(ENABLE_SUPERVISED_USERS) |
170 case SUPERVISED_PROFILE_CREATION: | 165 case SUPERVISED_PROFILE_CREATION: |
171 case SUPERVISED_PROFILE_IMPORT: | 166 case SUPERVISED_PROFILE_IMPORT: |
172 RegisterSupervisedUser(create_shortcut, desktop_type, | 167 RegisterSupervisedUser(create_shortcut, supervised_user_id, profile); |
173 supervised_user_id, profile); | |
174 break; | 168 break; |
175 #endif | 169 #endif |
176 case NO_CREATION_IN_PROGRESS: | 170 case NO_CREATION_IN_PROGRESS: |
177 NOTREACHED(); | 171 NOTREACHED(); |
178 break; | 172 break; |
179 } | 173 } |
180 } | 174 } |
181 | 175 |
182 void CreateProfileHandler::CreateShortcutAndShowSuccess( | 176 void CreateProfileHandler::CreateShortcutAndShowSuccess(bool create_shortcut, |
183 bool create_shortcut, | 177 Profile* profile) { |
184 chrome::HostDesktopType desktop_type, | |
185 Profile* profile) { | |
186 if (create_shortcut) { | 178 if (create_shortcut) { |
187 ProfileShortcutManager* shortcut_manager = | 179 ProfileShortcutManager* shortcut_manager = |
188 g_browser_process->profile_manager()->profile_shortcut_manager(); | 180 g_browser_process->profile_manager()->profile_shortcut_manager(); |
189 | 181 |
190 if (shortcut_manager) | 182 if (shortcut_manager) |
191 shortcut_manager->CreateProfileShortcut(profile->GetPath()); | 183 shortcut_manager->CreateProfileShortcut(profile->GetPath()); |
192 } | 184 } |
193 | 185 |
194 DCHECK_EQ(profile_path_being_created_.value(), profile->GetPath().value()); | 186 DCHECK_EQ(profile_path_being_created_.value(), profile->GetPath().value()); |
195 profile_path_being_created_.clear(); | 187 profile_path_being_created_.clear(); |
(...skipping 18 matching lines...) Expand all Loading... |
214 // the new window now. | 206 // the new window now. |
215 bool should_open_new_window = true; | 207 bool should_open_new_window = true; |
216 #if defined(ENABLE_SUPERVISED_USERS) | 208 #if defined(ENABLE_SUPERVISED_USERS) |
217 if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION) | 209 if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION) |
218 should_open_new_window = false; | 210 should_open_new_window = false; |
219 #endif | 211 #endif |
220 | 212 |
221 if (should_open_new_window) { | 213 if (should_open_new_window) { |
222 // Opening the new window must be the last action, after all callbacks | 214 // Opening the new window must be the last action, after all callbacks |
223 // have been run, to give them a chance to initialize the profile. | 215 // have been run, to give them a chance to initialize the profile. |
224 helper::OpenNewWindowForProfile(desktop_type, | 216 helper::OpenNewWindowForProfile(profile, |
225 profile, | |
226 Profile::CREATE_STATUS_INITIALIZED); | 217 Profile::CREATE_STATUS_INITIALIZED); |
227 } | 218 } |
228 profile_creation_type_ = NO_CREATION_IN_PROGRESS; | 219 profile_creation_type_ = NO_CREATION_IN_PROGRESS; |
229 } | 220 } |
230 | 221 |
231 void CreateProfileHandler::ShowProfileCreationError( | 222 void CreateProfileHandler::ShowProfileCreationError( |
232 Profile* profile, | 223 Profile* profile, |
233 const base::string16& error) { | 224 const base::string16& error) { |
234 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); | 225 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); |
235 profile_creation_type_ = NO_CREATION_IN_PROGRESS; | 226 profile_creation_type_ = NO_CREATION_IN_PROGRESS; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 profile_creation_type_ = NO_CREATION_IN_PROGRESS; | 369 profile_creation_type_ = NO_CREATION_IN_PROGRESS; |
379 | 370 |
380 // Cancelling registration means the callback passed into | 371 // Cancelling registration means the callback passed into |
381 // RegisterAndInitSync() won't be called, so the cleanup must be done here. | 372 // RegisterAndInitSync() won't be called, so the cleanup must be done here. |
382 profile_path_being_created_.clear(); | 373 profile_path_being_created_.clear(); |
383 helper::DeleteProfileAtPath(new_profile->GetPath(), web_ui()); | 374 helper::DeleteProfileAtPath(new_profile->GetPath(), web_ui()); |
384 } | 375 } |
385 | 376 |
386 void CreateProfileHandler::RegisterSupervisedUser( | 377 void CreateProfileHandler::RegisterSupervisedUser( |
387 bool create_shortcut, | 378 bool create_shortcut, |
388 chrome::HostDesktopType desktop_type, | |
389 const std::string& supervised_user_id, | 379 const std::string& supervised_user_id, |
390 Profile* new_profile) { | 380 Profile* new_profile) { |
391 DCHECK_EQ(profile_path_being_created_.value(), | 381 DCHECK_EQ(profile_path_being_created_.value(), |
392 new_profile->GetPath().value()); | 382 new_profile->GetPath().value()); |
393 | 383 |
394 SupervisedUserService* supervised_user_service = | 384 SupervisedUserService* supervised_user_service = |
395 SupervisedUserServiceFactory::GetForProfile(new_profile); | 385 SupervisedUserServiceFactory::GetForProfile(new_profile); |
396 | 386 |
397 // Register the supervised user using the profile of the custodian. | 387 // Register the supervised user using the profile of the custodian. |
398 supervised_user_registration_utility_ = | 388 supervised_user_registration_utility_ = |
399 SupervisedUserRegistrationUtility::Create(Profile::FromWebUI(web_ui())); | 389 SupervisedUserRegistrationUtility::Create(Profile::FromWebUI(web_ui())); |
400 supervised_user_service->RegisterAndInitSync( | 390 supervised_user_service->RegisterAndInitSync( |
401 supervised_user_registration_utility_.get(), | 391 supervised_user_registration_utility_.get(), |
402 Profile::FromWebUI(web_ui()), | 392 Profile::FromWebUI(web_ui()), |
403 supervised_user_id, | 393 supervised_user_id, |
404 base::Bind(&CreateProfileHandler::OnSupervisedUserRegistered, | 394 base::Bind(&CreateProfileHandler::OnSupervisedUserRegistered, |
405 weak_ptr_factory_.GetWeakPtr(), | 395 weak_ptr_factory_.GetWeakPtr(), |
406 create_shortcut, | 396 create_shortcut, |
407 desktop_type, | |
408 new_profile)); | 397 new_profile)); |
409 } | 398 } |
410 | 399 |
411 void CreateProfileHandler::OnSupervisedUserRegistered( | 400 void CreateProfileHandler::OnSupervisedUserRegistered( |
412 bool create_shortcut, | 401 bool create_shortcut, |
413 chrome::HostDesktopType desktop_type, | |
414 Profile* profile, | 402 Profile* profile, |
415 const GoogleServiceAuthError& error) { | 403 const GoogleServiceAuthError& error) { |
416 GoogleServiceAuthError::State state = error.state(); | 404 GoogleServiceAuthError::State state = error.state(); |
417 RecordSupervisedProfileCreationMetrics(state); | 405 RecordSupervisedProfileCreationMetrics(state); |
418 if (state == GoogleServiceAuthError::NONE) { | 406 if (state == GoogleServiceAuthError::NONE) { |
419 CreateShortcutAndShowSuccess(create_shortcut, desktop_type, profile); | 407 CreateShortcutAndShowSuccess(create_shortcut, profile); |
420 return; | 408 return; |
421 } | 409 } |
422 | 410 |
423 base::string16 error_msg; | 411 base::string16 error_msg; |
424 if (state == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || | 412 if (state == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || |
425 state == GoogleServiceAuthError::USER_NOT_SIGNED_UP || | 413 state == GoogleServiceAuthError::USER_NOT_SIGNED_UP || |
426 state == GoogleServiceAuthError::ACCOUNT_DELETED || | 414 state == GoogleServiceAuthError::ACCOUNT_DELETED || |
427 state == GoogleServiceAuthError::ACCOUNT_DISABLED) { | 415 state == GoogleServiceAuthError::ACCOUNT_DISABLED) { |
428 error_msg = GetProfileCreationErrorMessageSignin(); | 416 error_msg = GetProfileCreationErrorMessageSignin(); |
429 } else { | 417 } else { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 465 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
478 if (existing_supervised_user_id == | 466 if (existing_supervised_user_id == |
479 cache.GetSupervisedUserIdOfProfileAtIndex(i)) | 467 cache.GetSupervisedUserIdOfProfileAtIndex(i)) |
480 return false; | 468 return false; |
481 } | 469 } |
482 return true; | 470 return true; |
483 } | 471 } |
484 #endif | 472 #endif |
485 | 473 |
486 } // namespace options | 474 } // namespace options |
OLD | NEW |