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" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/value_conversions.h" | 12 #include "base/value_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/managed_mode/managed_user_registration_utility.h" | |
16 #include "chrome/browser/managed_mode/managed_user_service.h" | |
17 #include "chrome/browser/managed_mode/managed_user_service_factory.h" | |
18 #include "chrome/browser/managed_mode/managed_user_sync_service.h" | |
19 #include "chrome/browser/managed_mode/managed_user_sync_service_factory.h" | |
20 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
21 #include "chrome/browser/profiles/profile_metrics.h" | 16 #include "chrome/browser/profiles/profile_metrics.h" |
22 #include "chrome/browser/profiles/profiles_state.h" | 17 #include "chrome/browser/profiles/profiles_state.h" |
| 18 #include "chrome/browser/supervised_user/supervised_user_registration_utility.h" |
| 19 #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 20 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
| 21 #include "chrome/browser/supervised_user/supervised_user_sync_service.h" |
| 22 #include "chrome/browser/supervised_user/supervised_user_sync_service_factory.h" |
23 #include "chrome/browser/sync/profile_sync_service.h" | 23 #include "chrome/browser/sync/profile_sync_service.h" |
24 #include "chrome/browser/sync/profile_sync_service_factory.h" | 24 #include "chrome/browser/sync/profile_sync_service_factory.h" |
25 #include "chrome/browser/ui/webui/options/options_handlers_helper.h" | 25 #include "chrome/browser/ui/webui/options/options_handlers_helper.h" |
26 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
27 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
28 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
29 | 29 |
30 namespace options { | 30 namespace options { |
31 | 31 |
32 CreateProfileHandler::CreateProfileHandler() | 32 CreateProfileHandler::CreateProfileHandler() |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 } | 90 } |
91 | 91 |
92 if (supervised_user) { | 92 if (supervised_user) { |
93 if (!IsValidExistingSupervisedUserId(supervised_user_id)) | 93 if (!IsValidExistingSupervisedUserId(supervised_user_id)) |
94 return; | 94 return; |
95 | 95 |
96 profile_creation_type_ = SUPERVISED_PROFILE_IMPORT; | 96 profile_creation_type_ = SUPERVISED_PROFILE_IMPORT; |
97 if (supervised_user_id.empty()) { | 97 if (supervised_user_id.empty()) { |
98 profile_creation_type_ = SUPERVISED_PROFILE_CREATION; | 98 profile_creation_type_ = SUPERVISED_PROFILE_CREATION; |
99 supervised_user_id = | 99 supervised_user_id = |
100 ManagedUserRegistrationUtility::GenerateNewManagedUserId(); | 100 SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId(); |
101 | 101 |
102 // 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, |
103 // 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 |
104 // won't have the same potential delay. | 104 // won't have the same potential delay. |
105 ProfileSyncService* sync_service = | 105 ProfileSyncService* sync_service = |
106 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 106 ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
107 current_profile); | 107 current_profile); |
108 ProfileSyncService::SyncStatusSummary status = | 108 ProfileSyncService::SyncStatusSummary status = |
109 sync_service->QuerySyncStatusSummary(); | 109 sync_service->QuerySyncStatusSummary(); |
110 if (status == ProfileSyncService::DATATYPES_NOT_INITIALIZED) { | 110 if (status == ProfileSyncService::DATATYPES_NOT_INITIALIZED) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } | 186 } |
187 | 187 |
188 void CreateProfileHandler::RegisterSupervisedUser( | 188 void CreateProfileHandler::RegisterSupervisedUser( |
189 bool create_shortcut, | 189 bool create_shortcut, |
190 chrome::HostDesktopType desktop_type, | 190 chrome::HostDesktopType desktop_type, |
191 const std::string& supervised_user_id, | 191 const std::string& supervised_user_id, |
192 Profile* new_profile) { | 192 Profile* new_profile) { |
193 DCHECK_EQ(profile_path_being_created_.value(), | 193 DCHECK_EQ(profile_path_being_created_.value(), |
194 new_profile->GetPath().value()); | 194 new_profile->GetPath().value()); |
195 | 195 |
196 ManagedUserService* managed_user_service = | 196 SupervisedUserService* supervised_user_service = |
197 ManagedUserServiceFactory::GetForProfile(new_profile); | 197 SupervisedUserServiceFactory::GetForProfile(new_profile); |
198 | 198 |
199 // Register the supervised user using the profile of the custodian. | 199 // Register the supervised user using the profile of the custodian. |
200 managed_user_registration_utility_ = | 200 supervised_user_registration_utility_ = |
201 ManagedUserRegistrationUtility::Create(Profile::FromWebUI(web_ui())); | 201 SupervisedUserRegistrationUtility::Create(Profile::FromWebUI(web_ui())); |
202 managed_user_service->RegisterAndInitSync( | 202 supervised_user_service->RegisterAndInitSync( |
203 managed_user_registration_utility_.get(), | 203 supervised_user_registration_utility_.get(), |
204 Profile::FromWebUI(web_ui()), | 204 Profile::FromWebUI(web_ui()), |
205 supervised_user_id, | 205 supervised_user_id, |
206 base::Bind(&CreateProfileHandler::OnSupervisedUserRegistered, | 206 base::Bind(&CreateProfileHandler::OnSupervisedUserRegistered, |
207 weak_ptr_factory_.GetWeakPtr(), | 207 weak_ptr_factory_.GetWeakPtr(), |
208 create_shortcut, | 208 create_shortcut, |
209 desktop_type, | 209 desktop_type, |
210 new_profile)); | 210 new_profile)); |
211 } | 211 } |
212 | 212 |
213 void CreateProfileHandler::OnSupervisedUserRegistered( | 213 void CreateProfileHandler::OnSupervisedUserRegistered( |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 if (!new_profile->IsSupervised()) | 314 if (!new_profile->IsSupervised()) |
315 return; | 315 return; |
316 | 316 |
317 if (user_initiated) { | 317 if (user_initiated) { |
318 UMA_HISTOGRAM_MEDIUM_TIMES( | 318 UMA_HISTOGRAM_MEDIUM_TIMES( |
319 "Profile.CreateTimeCanceledNoTimeout", | 319 "Profile.CreateTimeCanceledNoTimeout", |
320 base::TimeTicks::Now() - profile_creation_start_time_); | 320 base::TimeTicks::Now() - profile_creation_start_time_); |
321 RecordProfileCreationMetrics(Profile::CREATE_STATUS_CANCELED); | 321 RecordProfileCreationMetrics(Profile::CREATE_STATUS_CANCELED); |
322 } | 322 } |
323 | 323 |
324 DCHECK(managed_user_registration_utility_.get()); | 324 DCHECK(supervised_user_registration_utility_.get()); |
325 managed_user_registration_utility_.reset(); | 325 supervised_user_registration_utility_.reset(); |
326 | 326 |
327 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); | 327 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); |
328 profile_creation_type_ = NO_CREATION_IN_PROGRESS; | 328 profile_creation_type_ = NO_CREATION_IN_PROGRESS; |
329 | 329 |
330 // Cancelling registration means the callback passed into | 330 // Cancelling registration means the callback passed into |
331 // RegisterAndInitSync() won't be called, so the cleanup must be done here. | 331 // RegisterAndInitSync() won't be called, so the cleanup must be done here. |
332 profile_path_being_created_.clear(); | 332 profile_path_being_created_.clear(); |
333 helper::DeleteProfileAtPath(new_profile->GetPath(), web_ui()); | 333 helper::DeleteProfileAtPath(new_profile->GetPath(), web_ui()); |
334 } | 334 } |
335 | 335 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 return std::string(); | 407 return std::string(); |
408 } | 408 } |
409 | 409 |
410 bool CreateProfileHandler::IsValidExistingSupervisedUserId( | 410 bool CreateProfileHandler::IsValidExistingSupervisedUserId( |
411 const std::string& existing_supervised_user_id) const { | 411 const std::string& existing_supervised_user_id) const { |
412 if (existing_supervised_user_id.empty()) | 412 if (existing_supervised_user_id.empty()) |
413 return true; | 413 return true; |
414 | 414 |
415 Profile* profile = Profile::FromWebUI(web_ui()); | 415 Profile* profile = Profile::FromWebUI(web_ui()); |
416 const base::DictionaryValue* dict = | 416 const base::DictionaryValue* dict = |
417 ManagedUserSyncServiceFactory::GetForProfile(profile)->GetManagedUsers(); | 417 SupervisedUserSyncServiceFactory::GetForProfile(profile)-> |
| 418 GetSupervisedUsers(); |
418 if (!dict->HasKey(existing_supervised_user_id)) | 419 if (!dict->HasKey(existing_supervised_user_id)) |
419 return false; | 420 return false; |
420 | 421 |
421 // Check if this supervised user already exists on this machine. | 422 // Check if this supervised user already exists on this machine. |
422 const ProfileInfoCache& cache = | 423 const ProfileInfoCache& cache = |
423 g_browser_process->profile_manager()->GetProfileInfoCache(); | 424 g_browser_process->profile_manager()->GetProfileInfoCache(); |
424 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 425 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
425 if (existing_supervised_user_id == | 426 if (existing_supervised_user_id == |
426 cache.GetSupervisedUserIdOfProfileAtIndex(i)) | 427 cache.GetSupervisedUserIdOfProfileAtIndex(i)) |
427 return false; | 428 return false; |
428 } | 429 } |
429 return true; | 430 return true; |
430 } | 431 } |
431 | 432 |
432 } // namespace options | 433 } // namespace options |
OLD | NEW |