| 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 <set> | 5 #include <set> |
| 6 | 6 |
| 7 #include "chrome/browser/profiles/profile_manager.h" | 7 #include "chrome/browser/profiles/profile_manager.h" |
| 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 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 // Invoke INITIALIZED or FAIL for all profiles. | 671 // Invoke INITIALIZED or FAIL for all profiles. |
| 672 RunCallbacks(callbacks, profile, | 672 RunCallbacks(callbacks, profile, |
| 673 profile ? Profile::CREATE_STATUS_INITIALIZED : | 673 profile ? Profile::CREATE_STATUS_INITIALIZED : |
| 674 Profile::CREATE_STATUS_FAIL); | 674 Profile::CREATE_STATUS_FAIL); |
| 675 } | 675 } |
| 676 | 676 |
| 677 FilePath ProfileManager::GenerateNextProfileDirectoryPath() { | 677 FilePath ProfileManager::GenerateNextProfileDirectoryPath() { |
| 678 PrefService* local_state = g_browser_process->local_state(); | 678 PrefService* local_state = g_browser_process->local_state(); |
| 679 DCHECK(local_state); | 679 DCHECK(local_state); |
| 680 | 680 |
| 681 DCHECK(!local_state->GetBoolean(prefs::kInManagedMode)); |
| 682 |
| 681 // Create the next profile in the next available directory slot. | 683 // Create the next profile in the next available directory slot. |
| 682 int next_directory = local_state->GetInteger(prefs::kProfilesNumCreated); | 684 int next_directory = local_state->GetInteger(prefs::kProfilesNumCreated); |
| 683 std::string profile_name = chrome::kMultiProfileDirPrefix; | 685 std::string profile_name = chrome::kMultiProfileDirPrefix; |
| 684 profile_name.append(base::IntToString(next_directory)); | 686 profile_name.append(base::IntToString(next_directory)); |
| 685 FilePath new_path = user_data_dir_; | 687 FilePath new_path = user_data_dir_; |
| 686 #if defined(OS_WIN) | 688 #if defined(OS_WIN) |
| 687 new_path = new_path.Append(ASCIIToUTF16(profile_name)); | 689 new_path = new_path.Append(ASCIIToUTF16(profile_name)); |
| 688 #else | 690 #else |
| 689 new_path = new_path.Append(profile_name); | 691 new_path = new_path.Append(profile_name); |
| 690 #endif | 692 #endif |
| (...skipping 11 matching lines...) Expand all Loading... |
| 702 | 704 |
| 703 profile_manager->CreateProfileAsync(new_path, | 705 profile_manager->CreateProfileAsync(new_path, |
| 704 base::Bind(&OnOpenWindowForNewProfile)); | 706 base::Bind(&OnOpenWindowForNewProfile)); |
| 705 } | 707 } |
| 706 | 708 |
| 707 // static | 709 // static |
| 708 void ProfileManager::RegisterPrefs(PrefService* prefs) { | 710 void ProfileManager::RegisterPrefs(PrefService* prefs) { |
| 709 prefs->RegisterStringPref(prefs::kProfileLastUsed, ""); | 711 prefs->RegisterStringPref(prefs::kProfileLastUsed, ""); |
| 710 prefs->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); | 712 prefs->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); |
| 711 prefs->RegisterListPref(prefs::kProfilesLastActive); | 713 prefs->RegisterListPref(prefs::kProfilesLastActive); |
| 714 prefs->RegisterBooleanPref(prefs::kInManagedMode, false); |
| 712 } | 715 } |
| 713 | 716 |
| 714 size_t ProfileManager::GetNumberOfProfiles() { | 717 size_t ProfileManager::GetNumberOfProfiles() { |
| 715 return GetProfileInfoCache().GetNumberOfProfiles(); | 718 return GetProfileInfoCache().GetNumberOfProfiles(); |
| 716 } | 719 } |
| 717 | 720 |
| 718 bool ProfileManager::CompareProfilePathAndName( | 721 bool ProfileManager::CompareProfilePathAndName( |
| 719 const ProfileManager::ProfilePathAndName& pair1, | 722 const ProfileManager::ProfilePathAndName& pair1, |
| 720 const ProfileManager::ProfilePathAndName& pair2) { | 723 const ProfileManager::ProfilePathAndName& pair2) { |
| 721 int name_compare = pair1.second.compare(pair2.second); | 724 int name_compare = pair1.second.compare(pair2.second); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 if (!logged_in_ && | 832 if (!logged_in_ && |
| 830 (!command_line.HasSwitch(switches::kTestType) || | 833 (!command_line.HasSwitch(switches::kTestType) || |
| 831 command_line.HasSwitch(switches::kLoginProfile))) { | 834 command_line.HasSwitch(switches::kLoginProfile))) { |
| 832 go_off_the_record = true; | 835 go_off_the_record = true; |
| 833 } | 836 } |
| 834 #endif | 837 #endif |
| 835 return go_off_the_record; | 838 return go_off_the_record; |
| 836 } | 839 } |
| 837 | 840 |
| 838 void ProfileManager::ScheduleProfileForDeletion(const FilePath& profile_dir) { | 841 void ProfileManager::ScheduleProfileForDeletion(const FilePath& profile_dir) { |
| 842 PrefService* local_state = g_browser_process->local_state(); |
| 843 DCHECK(!local_state->GetBoolean(prefs::kInManagedMode)); |
| 844 |
| 839 // If we're deleting the last profile, then create a new profile in its | 845 // If we're deleting the last profile, then create a new profile in its |
| 840 // place. | 846 // place. |
| 841 ProfileInfoCache& cache = GetProfileInfoCache(); | 847 ProfileInfoCache& cache = GetProfileInfoCache(); |
| 842 if (cache.GetNumberOfProfiles() == 1) { | 848 if (cache.GetNumberOfProfiles() == 1) { |
| 843 FilePath new_path = GenerateNextProfileDirectoryPath(); | 849 FilePath new_path = GenerateNextProfileDirectoryPath(); |
| 844 | 850 |
| 845 CreateProfileAsync(new_path, base::Bind(&OnOpenWindowForNewProfile)); | 851 CreateProfileAsync(new_path, base::Bind(&OnOpenWindowForNewProfile)); |
| 846 } | 852 } |
| 847 | 853 |
| 848 // Update the last used profile pref before closing browser windows. This way | 854 // Update the last used profile pref before closing browser windows. This way |
| 849 // the correct last used profile is set for any notification observers. | 855 // the correct last used profile is set for any notification observers. |
| 850 PrefService* local_state = g_browser_process->local_state(); | |
| 851 std::string last_profile = local_state->GetString(prefs::kProfileLastUsed); | 856 std::string last_profile = local_state->GetString(prefs::kProfileLastUsed); |
| 852 if (profile_dir.BaseName().MaybeAsASCII() == last_profile) { | 857 if (profile_dir.BaseName().MaybeAsASCII() == last_profile) { |
| 853 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 858 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
| 854 FilePath cur_path = cache.GetPathOfProfileAtIndex(i); | 859 FilePath cur_path = cache.GetPathOfProfileAtIndex(i); |
| 855 if (cur_path != profile_dir) { | 860 if (cur_path != profile_dir) { |
| 856 local_state->SetString( | 861 local_state->SetString( |
| 857 prefs::kProfileLastUsed, cur_path.BaseName().MaybeAsASCII()); | 862 prefs::kProfileLastUsed, cur_path.BaseName().MaybeAsASCII()); |
| 858 break; | 863 break; |
| 859 } | 864 } |
| 860 } | 865 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 ProfileMetrics::STARTUP_PROFILE_EVENT); | 910 ProfileMetrics::STARTUP_PROFILE_EVENT); |
| 906 } | 911 } |
| 907 | 912 |
| 908 ProfileManagerWithoutInit::ProfileManagerWithoutInit( | 913 ProfileManagerWithoutInit::ProfileManagerWithoutInit( |
| 909 const FilePath& user_data_dir) : ProfileManager(user_data_dir) { | 914 const FilePath& user_data_dir) : ProfileManager(user_data_dir) { |
| 910 } | 915 } |
| 911 | 916 |
| 912 void ProfileManager::RegisterTestingProfile(Profile* profile, | 917 void ProfileManager::RegisterTestingProfile(Profile* profile, |
| 913 bool add_to_cache) { | 918 bool add_to_cache) { |
| 914 RegisterProfile(profile, true); | 919 RegisterProfile(profile, true); |
| 915 if (add_to_cache){ | 920 if (add_to_cache) { |
| 916 InitProfileUserPrefs(profile); | 921 InitProfileUserPrefs(profile); |
| 917 AddProfileToCache(profile); | 922 AddProfileToCache(profile); |
| 918 } | 923 } |
| 919 } | 924 } |
| 920 | 925 |
| 921 void ProfileManager::RunCallbacks(const std::vector<CreateCallback>& callbacks, | 926 void ProfileManager::RunCallbacks(const std::vector<CreateCallback>& callbacks, |
| 922 Profile* profile, | 927 Profile* profile, |
| 923 Profile::CreateStatus status) { | 928 Profile::CreateStatus status) { |
| 924 for (size_t i = 0; i < callbacks.size(); ++i) | 929 for (size_t i = 0; i < callbacks.size(); ++i) |
| 925 callbacks[i].Run(profile, status); | 930 callbacks[i].Run(profile, status); |
| 926 } | 931 } |
| OLD | NEW |