Chromium Code Reviews| 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 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 // Invoke INITIALIZED or FAIL for all profiles. | 678 // Invoke INITIALIZED or FAIL for all profiles. |
| 679 RunCallbacks(callbacks, profile, | 679 RunCallbacks(callbacks, profile, |
| 680 profile ? Profile::CREATE_STATUS_INITIALIZED : | 680 profile ? Profile::CREATE_STATUS_INITIALIZED : |
| 681 Profile::CREATE_STATUS_FAIL); | 681 Profile::CREATE_STATUS_FAIL); |
| 682 } | 682 } |
| 683 | 683 |
| 684 FilePath ProfileManager::GenerateNextProfileDirectoryPath() { | 684 FilePath ProfileManager::GenerateNextProfileDirectoryPath() { |
| 685 PrefService* local_state = g_browser_process->local_state(); | 685 PrefService* local_state = g_browser_process->local_state(); |
| 686 DCHECK(local_state); | 686 DCHECK(local_state); |
| 687 | 687 |
| 688 DCHECK(!local_state->GetBoolean(prefs::kInManagedMode)); | |
| 689 | |
| 688 // Create the next profile in the next available directory slot. | 690 // Create the next profile in the next available directory slot. |
| 689 int next_directory = local_state->GetInteger(prefs::kProfilesNumCreated); | 691 int next_directory = local_state->GetInteger(prefs::kProfilesNumCreated); |
| 690 std::string profile_name = chrome::kMultiProfileDirPrefix; | 692 std::string profile_name = chrome::kMultiProfileDirPrefix; |
| 691 profile_name.append(base::IntToString(next_directory)); | 693 profile_name.append(base::IntToString(next_directory)); |
| 692 FilePath new_path = user_data_dir_; | 694 FilePath new_path = user_data_dir_; |
| 693 #if defined(OS_WIN) | 695 #if defined(OS_WIN) |
| 694 new_path = new_path.Append(ASCIIToUTF16(profile_name)); | 696 new_path = new_path.Append(ASCIIToUTF16(profile_name)); |
| 695 #else | 697 #else |
| 696 new_path = new_path.Append(profile_name); | 698 new_path = new_path.Append(profile_name); |
| 697 #endif | 699 #endif |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 709 | 711 |
| 710 profile_manager->CreateProfileAsync(new_path, | 712 profile_manager->CreateProfileAsync(new_path, |
| 711 base::Bind(&OnOpenWindowForNewProfile)); | 713 base::Bind(&OnOpenWindowForNewProfile)); |
| 712 } | 714 } |
| 713 | 715 |
| 714 // static | 716 // static |
| 715 void ProfileManager::RegisterPrefs(PrefService* prefs) { | 717 void ProfileManager::RegisterPrefs(PrefService* prefs) { |
| 716 prefs->RegisterStringPref(prefs::kProfileLastUsed, ""); | 718 prefs->RegisterStringPref(prefs::kProfileLastUsed, ""); |
| 717 prefs->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); | 719 prefs->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); |
| 718 prefs->RegisterListPref(prefs::kProfilesLastActive); | 720 prefs->RegisterListPref(prefs::kProfilesLastActive); |
| 721 prefs->RegisterBooleanPref(prefs::kInManagedMode, false); | |
|
Robert Sesek
2012/03/05 18:33:49
Is this pref not already registered?
Bernhard Bauer
2012/03/05 22:08:54
I forgot that in the previous CL :-(
| |
| 719 } | 722 } |
| 720 | 723 |
| 721 size_t ProfileManager::GetNumberOfProfiles() { | 724 size_t ProfileManager::GetNumberOfProfiles() { |
| 722 return GetProfileInfoCache().GetNumberOfProfiles(); | 725 return GetProfileInfoCache().GetNumberOfProfiles(); |
| 723 } | 726 } |
| 724 | 727 |
| 725 bool ProfileManager::CompareProfilePathAndName( | 728 bool ProfileManager::CompareProfilePathAndName( |
| 726 const ProfileManager::ProfilePathAndName& pair1, | 729 const ProfileManager::ProfilePathAndName& pair1, |
| 727 const ProfileManager::ProfilePathAndName& pair2) { | 730 const ProfileManager::ProfilePathAndName& pair2) { |
| 728 int name_compare = pair1.second.compare(pair2.second); | 731 int name_compare = pair1.second.compare(pair2.second); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 836 if (!logged_in_ && | 839 if (!logged_in_ && |
| 837 (!command_line.HasSwitch(switches::kTestType) || | 840 (!command_line.HasSwitch(switches::kTestType) || |
| 838 command_line.HasSwitch(switches::kLoginProfile))) { | 841 command_line.HasSwitch(switches::kLoginProfile))) { |
| 839 go_off_the_record = true; | 842 go_off_the_record = true; |
| 840 } | 843 } |
| 841 #endif | 844 #endif |
| 842 return go_off_the_record; | 845 return go_off_the_record; |
| 843 } | 846 } |
| 844 | 847 |
| 845 void ProfileManager::ScheduleProfileForDeletion(const FilePath& profile_dir) { | 848 void ProfileManager::ScheduleProfileForDeletion(const FilePath& profile_dir) { |
| 849 PrefService* local_state = g_browser_process->local_state(); | |
| 850 DCHECK(!local_state->GetBoolean(prefs::kInManagedMode)); | |
| 851 | |
| 846 // If we're deleting the last profile, then create a new profile in its | 852 // If we're deleting the last profile, then create a new profile in its |
| 847 // place. | 853 // place. |
| 848 ProfileInfoCache& cache = GetProfileInfoCache(); | 854 ProfileInfoCache& cache = GetProfileInfoCache(); |
| 849 if (cache.GetNumberOfProfiles() == 1) { | 855 if (cache.GetNumberOfProfiles() == 1) { |
| 850 FilePath new_path = GenerateNextProfileDirectoryPath(); | 856 FilePath new_path = GenerateNextProfileDirectoryPath(); |
| 851 | 857 |
| 852 CreateProfileAsync(new_path, base::Bind(&OnOpenWindowForNewProfile)); | 858 CreateProfileAsync(new_path, base::Bind(&OnOpenWindowForNewProfile)); |
| 853 } | 859 } |
| 854 | 860 |
| 855 // Update the last used profile pref before closing browser windows. This way | 861 // Update the last used profile pref before closing browser windows. This way |
| 856 // the correct last used profile is set for any notification observers. | 862 // the correct last used profile is set for any notification observers. |
| 857 PrefService* local_state = g_browser_process->local_state(); | |
| 858 std::string last_profile = local_state->GetString(prefs::kProfileLastUsed); | 863 std::string last_profile = local_state->GetString(prefs::kProfileLastUsed); |
| 859 if (profile_dir.BaseName().MaybeAsASCII() == last_profile) { | 864 if (profile_dir.BaseName().MaybeAsASCII() == last_profile) { |
| 860 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 865 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
| 861 FilePath cur_path = cache.GetPathOfProfileAtIndex(i); | 866 FilePath cur_path = cache.GetPathOfProfileAtIndex(i); |
| 862 if (cur_path != profile_dir) { | 867 if (cur_path != profile_dir) { |
| 863 local_state->SetString( | 868 local_state->SetString( |
| 864 prefs::kProfileLastUsed, cur_path.BaseName().MaybeAsASCII()); | 869 prefs::kProfileLastUsed, cur_path.BaseName().MaybeAsASCII()); |
| 865 break; | 870 break; |
| 866 } | 871 } |
| 867 } | 872 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 912 ProfileMetrics::STARTUP_PROFILE_EVENT); | 917 ProfileMetrics::STARTUP_PROFILE_EVENT); |
| 913 } | 918 } |
| 914 | 919 |
| 915 ProfileManagerWithoutInit::ProfileManagerWithoutInit( | 920 ProfileManagerWithoutInit::ProfileManagerWithoutInit( |
| 916 const FilePath& user_data_dir) : ProfileManager(user_data_dir) { | 921 const FilePath& user_data_dir) : ProfileManager(user_data_dir) { |
| 917 } | 922 } |
| 918 | 923 |
| 919 void ProfileManager::RegisterTestingProfile(Profile* profile, | 924 void ProfileManager::RegisterTestingProfile(Profile* profile, |
| 920 bool add_to_cache) { | 925 bool add_to_cache) { |
| 921 RegisterProfile(profile, true); | 926 RegisterProfile(profile, true); |
| 922 if (add_to_cache){ | 927 if (add_to_cache) { |
| 923 InitProfileUserPrefs(profile); | 928 InitProfileUserPrefs(profile); |
| 924 AddProfileToCache(profile); | 929 AddProfileToCache(profile); |
| 925 } | 930 } |
| 926 } | 931 } |
| 927 | 932 |
| 928 void ProfileManager::RunCallbacks(const std::vector<CreateCallback>& callbacks, | 933 void ProfileManager::RunCallbacks(const std::vector<CreateCallback>& callbacks, |
| 929 Profile* profile, | 934 Profile* profile, |
| 930 Profile::CreateStatus status) { | 935 Profile::CreateStatus status) { |
| 931 for (size_t i = 0; i < callbacks.size(); ++i) | 936 for (size_t i = 0; i < callbacks.size(); ++i) |
| 932 callbacks[i].Run(profile, status); | 937 callbacks[i].Run(profile, status); |
| 933 } | 938 } |
| OLD | NEW |