OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/profiles/profile_manager.h" | 5 #include "chrome/browser/profiles/profile_manager.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 | 386 |
387 size_t ProfileManager::GetNumberOfProfiles() { | 387 size_t ProfileManager::GetNumberOfProfiles() { |
388 return GetProfileInfoCache().GetNumberOfProfiles(); | 388 return GetProfileInfoCache().GetNumberOfProfiles(); |
389 } | 389 } |
390 | 390 |
391 void ProfileManager::CreateProfileAsync( | 391 void ProfileManager::CreateProfileAsync( |
392 const base::FilePath& profile_path, | 392 const base::FilePath& profile_path, |
393 const CreateCallback& callback, | 393 const CreateCallback& callback, |
394 const base::string16& name, | 394 const base::string16& name, |
395 const base::string16& icon_url, | 395 const base::string16& icon_url, |
396 const std::string& supervised_user_id) { | 396 const user_manager::UserID& supervised_user_id) { |
397 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 397 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
398 TRACE_EVENT1("browser,startup", | 398 TRACE_EVENT1("browser,startup", |
399 "ProfileManager::CreateProfileAsync", | 399 "ProfileManager::CreateProfileAsync", |
400 "profile_path", | 400 "profile_path", |
401 profile_path.AsUTF8Unsafe()); | 401 profile_path.AsUTF8Unsafe()); |
402 | 402 |
403 // Make sure that this profile is not pending deletion. | 403 // Make sure that this profile is not pending deletion. |
404 if (IsProfileMarkedForDeletion(profile_path)) { | 404 if (IsProfileMarkedForDeletion(profile_path)) { |
405 if (!callback.is_null()) | 405 if (!callback.is_null()) |
406 callback.Run(NULL, Profile::CREATE_STATUS_LOCAL_FAIL); | 406 callback.Run(NULL, Profile::CREATE_STATUS_LOCAL_FAIL); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
567 ProfileInfo* profile_info = GetProfileInfoByPath(path); | 567 ProfileInfo* profile_info = GetProfileInfoByPath(path); |
568 return (profile_info && profile_info->created) ? profile_info->profile.get() | 568 return (profile_info && profile_info->created) ? profile_info->profile.get() |
569 : nullptr; | 569 : nullptr; |
570 } | 570 } |
571 | 571 |
572 // static | 572 // static |
573 base::FilePath ProfileManager::CreateMultiProfileAsync( | 573 base::FilePath ProfileManager::CreateMultiProfileAsync( |
574 const base::string16& name, | 574 const base::string16& name, |
575 const base::string16& icon_url, | 575 const base::string16& icon_url, |
576 const CreateCallback& callback, | 576 const CreateCallback& callback, |
577 const std::string& supervised_user_id) { | 577 const user_manager::UserID& supervised_user_id) { |
578 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 578 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
579 | 579 |
580 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 580 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
581 | 581 |
582 base::FilePath new_path = profile_manager->GenerateNextProfileDirectoryPath(); | 582 base::FilePath new_path = profile_manager->GenerateNextProfileDirectoryPath(); |
583 | 583 |
584 profile_manager->CreateProfileAsync(new_path, | 584 profile_manager->CreateProfileAsync(new_path, |
585 callback, | 585 callback, |
586 name, | 586 name, |
587 icon_url, | 587 icon_url, |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
688 | 688 |
689 new_path = GenerateNextProfileDirectoryPath(); | 689 new_path = GenerateNextProfileDirectoryPath(); |
690 CreateProfileAsync(new_path, | 690 CreateProfileAsync(new_path, |
691 base::Bind(&ProfileManager::OnNewActiveProfileLoaded, | 691 base::Bind(&ProfileManager::OnNewActiveProfileLoaded, |
692 base::Unretained(this), | 692 base::Unretained(this), |
693 profile_dir, | 693 profile_dir, |
694 new_path, | 694 new_path, |
695 callback), | 695 callback), |
696 new_profile_name, | 696 new_profile_name, |
697 new_avatar_url, | 697 new_avatar_url, |
698 std::string()); | 698 user_manager::UserID(std::string(), std::string())); |
Denis Kuznetsov (DE-MUC)
2015/06/10 16:50:45
EmptyUserID
| |
699 | 699 |
700 ProfileMetrics::LogProfileAddNewUser( | 700 ProfileMetrics::LogProfileAddNewUser( |
701 ProfileMetrics::ADD_NEW_USER_LAST_DELETED); | 701 ProfileMetrics::ADD_NEW_USER_LAST_DELETED); |
702 return; | 702 return; |
703 } | 703 } |
704 | 704 |
705 #if defined(OS_MACOSX) | 705 #if defined(OS_MACOSX) |
706 // On the Mac, the browser process is not killed when all browser windows are | 706 // On the Mac, the browser process is not killed when all browser windows are |
707 // closed, so just in case we are deleting the active profile, and no other | 707 // closed, so just in case we are deleting the active profile, and no other |
708 // profile has been loaded, we must pre-load a next one. | 708 // profile has been loaded, we must pre-load a next one. |
709 const base::FilePath last_used_profile = | 709 const base::FilePath last_used_profile = |
710 GetLastUsedProfileDir(user_data_dir_); | 710 GetLastUsedProfileDir(user_data_dir_); |
711 if (last_used_profile == profile_dir || | 711 if (last_used_profile == profile_dir || |
712 last_used_profile == GetGuestProfilePath()) { | 712 last_used_profile == GetGuestProfilePath()) { |
713 CreateProfileAsync(last_non_supervised_profile_path, | 713 CreateProfileAsync(last_non_supervised_profile_path, |
714 base::Bind(&ProfileManager::OnNewActiveProfileLoaded, | 714 base::Bind(&ProfileManager::OnNewActiveProfileLoaded, |
715 base::Unretained(this), | 715 base::Unretained(this), |
716 profile_dir, | 716 profile_dir, |
717 last_non_supervised_profile_path, | 717 last_non_supervised_profile_path, |
718 callback), | 718 callback), |
719 base::string16(), | 719 base::string16(), |
720 base::string16(), | 720 base::string16(), |
721 std::string()); | 721 user_manager::UserID(std::string(), std::string())); |
Denis Kuznetsov (DE-MUC)
2015/06/10 16:50:44
EmtpyUserID
| |
722 return; | 722 return; |
723 } | 723 } |
724 #endif // defined(OS_MACOSX) | 724 #endif // defined(OS_MACOSX) |
725 | 725 |
726 FinishDeletingProfile(profile_dir, last_non_supervised_profile_path); | 726 FinishDeletingProfile(profile_dir, last_non_supervised_profile_path); |
727 } | 727 } |
728 | 728 |
729 void ProfileManager::AutoloadProfiles() { | 729 void ProfileManager::AutoloadProfiles() { |
730 // If running in the background is disabled for the browser, do not autoload | 730 // If running in the background is disabled for the browser, do not autoload |
731 // any profiles. | 731 // any profiles. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
789 | 789 |
790 void ProfileManager::InitProfileUserPrefs(Profile* profile) { | 790 void ProfileManager::InitProfileUserPrefs(Profile* profile) { |
791 TRACE_EVENT0("browser", "ProfileManager::InitProfileUserPrefs"); | 791 TRACE_EVENT0("browser", "ProfileManager::InitProfileUserPrefs"); |
792 ProfileInfoCache& cache = GetProfileInfoCache(); | 792 ProfileInfoCache& cache = GetProfileInfoCache(); |
793 | 793 |
794 if (profile->GetPath().DirName() != cache.GetUserDataDir()) | 794 if (profile->GetPath().DirName() != cache.GetUserDataDir()) |
795 return; | 795 return; |
796 | 796 |
797 size_t avatar_index; | 797 size_t avatar_index; |
798 std::string profile_name; | 798 std::string profile_name; |
799 std::string supervised_user_id; | 799 user_manager::UserID supervised_user_id = user_manager::UserID(std::string(), std::string()); |
Denis Kuznetsov (DE-MUC)
2015/06/10 16:50:45
EmptyUserID
| |
800 if (profile->IsGuestSession()) { | 800 if (profile->IsGuestSession()) { |
801 profile_name = l10n_util::GetStringUTF8(IDS_PROFILES_GUEST_PROFILE_NAME); | 801 profile_name = l10n_util::GetStringUTF8(IDS_PROFILES_GUEST_PROFILE_NAME); |
802 avatar_index = 0; | 802 avatar_index = 0; |
803 } else { | 803 } else { |
804 size_t profile_cache_index = | 804 size_t profile_cache_index = |
805 cache.GetIndexOfProfileWithPath(profile->GetPath()); | 805 cache.GetIndexOfProfileWithPath(profile->GetPath()); |
806 // If the cache has an entry for this profile, use the cache data. | 806 // If the cache has an entry for this profile, use the cache data. |
807 if (profile_cache_index != std::string::npos) { | 807 if (profile_cache_index != std::string::npos) { |
808 avatar_index = | 808 avatar_index = |
809 cache.GetAvatarIconIndexOfProfileAtIndex(profile_cache_index); | 809 cache.GetAvatarIconIndexOfProfileAtIndex(profile_cache_index); |
(...skipping 24 matching lines...) Expand all Loading... | |
834 | 834 |
835 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 835 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
836 bool force_supervised_user_id = | 836 bool force_supervised_user_id = |
837 #if defined(OS_CHROMEOS) | 837 #if defined(OS_CHROMEOS) |
838 g_browser_process->platform_part() | 838 g_browser_process->platform_part() |
839 ->profile_helper() | 839 ->profile_helper() |
840 ->GetSigninProfileDir() != profile->GetPath() && | 840 ->GetSigninProfileDir() != profile->GetPath() && |
841 #endif | 841 #endif |
842 command_line->HasSwitch(switches::kSupervisedUserId); | 842 command_line->HasSwitch(switches::kSupervisedUserId); |
843 if (force_supervised_user_id) { | 843 if (force_supervised_user_id) { |
844 supervised_user_id = | 844 supervised_user_id = user_manager::UserID::FromUserEmail( |
845 command_line->GetSwitchValueASCII(switches::kSupervisedUserId); | 845 command_line->GetSwitchValueASCII(switches::kSupervisedUserId)); |
846 } | 846 } |
847 if (force_supervised_user_id || | 847 if (force_supervised_user_id || |
848 !profile->GetPrefs()->HasPrefPath(prefs::kSupervisedUserId)) { | 848 !profile->GetPrefs()->HasPrefPath(prefs::kSupervisedUserId)) { |
849 profile->GetPrefs()->SetString(prefs::kSupervisedUserId, | 849 profile->GetPrefs()->SetString(prefs::kSupervisedUserId, |
850 supervised_user_id); | 850 supervised_user_id.GetUserEmail()); |
851 } | 851 } |
852 } | 852 } |
853 | 853 |
854 void ProfileManager::RegisterTestingProfile(Profile* profile, | 854 void ProfileManager::RegisterTestingProfile(Profile* profile, |
855 bool add_to_cache, | 855 bool add_to_cache, |
856 bool start_deferred_task_runners) { | 856 bool start_deferred_task_runners) { |
857 RegisterProfile(profile, true); | 857 RegisterProfile(profile, true); |
858 if (add_to_cache) { | 858 if (add_to_cache) { |
859 InitProfileUserPrefs(profile); | 859 InitProfileUserPrefs(profile); |
860 AddProfileToCache(profile); | 860 AddProfileToCache(profile); |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1303 } | 1303 } |
1304 | 1304 |
1305 // Profile name and avatar are set by InitProfileUserPrefs and stored in the | 1305 // Profile name and avatar are set by InitProfileUserPrefs and stored in the |
1306 // profile. Use those values to setup the cache entry. | 1306 // profile. Use those values to setup the cache entry. |
1307 base::string16 profile_name = | 1307 base::string16 profile_name = |
1308 base::UTF8ToUTF16(profile->GetPrefs()->GetString(prefs::kProfileName)); | 1308 base::UTF8ToUTF16(profile->GetPrefs()->GetString(prefs::kProfileName)); |
1309 | 1309 |
1310 size_t icon_index = profile->GetPrefs()->GetInteger( | 1310 size_t icon_index = profile->GetPrefs()->GetInteger( |
1311 prefs::kProfileAvatarIndex); | 1311 prefs::kProfileAvatarIndex); |
1312 | 1312 |
1313 std::string supervised_user_id = | 1313 const user_manager::UserID& supervised_user_id = |
1314 profile->GetPrefs()->GetString(prefs::kSupervisedUserId); | 1314 user_manager::UserID::FromUserEmail(profile->GetPrefs()->GetString(prefs:: kSupervisedUserId)); |
1315 | 1315 |
1316 cache.AddProfileToCache(profile->GetPath(), | 1316 cache.AddProfileToCache(profile->GetPath(), |
1317 profile_name, | 1317 profile_name, |
1318 account_info.gaia, | 1318 account_info.gaia, |
1319 username, | 1319 username, |
1320 icon_index, | 1320 icon_index, |
1321 supervised_user_id); | 1321 supervised_user_id); |
1322 | 1322 |
1323 if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) { | 1323 if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) { |
1324 cache.SetProfileIsEphemeralAtIndex( | 1324 cache.SetProfileIsEphemeralAtIndex( |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1467 } | 1467 } |
1468 | 1468 |
1469 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); | 1469 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); |
1470 if (!original_callback.is_null()) | 1470 if (!original_callback.is_null()) |
1471 original_callback.Run(loaded_profile, status); | 1471 original_callback.Run(loaded_profile, status); |
1472 } | 1472 } |
1473 | 1473 |
1474 ProfileManagerWithoutInit::ProfileManagerWithoutInit( | 1474 ProfileManagerWithoutInit::ProfileManagerWithoutInit( |
1475 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { | 1475 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { |
1476 } | 1476 } |
OLD | NEW |