| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 156 |
| 157 // Count number of extensions in this profile, if we know. | 157 // Count number of extensions in this profile, if we know. |
| 158 if (extension_count != -1) | 158 if (extension_count != -1) |
| 159 UMA_HISTOGRAM_COUNTS_10000("Profile.AppCount", extension_count); | 159 UMA_HISTOGRAM_COUNTS_10000("Profile.AppCount", extension_count); |
| 160 } | 160 } |
| 161 | 161 |
| 162 void QueueProfileDirectoryForDeletion(const base::FilePath& path) { | 162 void QueueProfileDirectoryForDeletion(const base::FilePath& path) { |
| 163 ProfilesToDelete().push_back(path); | 163 ProfilesToDelete().push_back(path); |
| 164 } | 164 } |
| 165 | 165 |
| 166 // Called upon completion of profile creation. This function takes care of | |
| 167 // launching a new browser window and signing the user in to their Google | |
| 168 // account. | |
| 169 void OnOpenWindowForNewProfile( | |
| 170 chrome::HostDesktopType desktop_type, | |
| 171 const ProfileManager::CreateCallback& callback, | |
| 172 Profile* profile, | |
| 173 Profile::CreateStatus status) { | |
| 174 // Invoke the callback before we open a window for this new profile, so the | |
| 175 // callback has a chance to update the profile state first (to do things like | |
| 176 // sign in the profile). | |
| 177 if (!callback.is_null()) | |
| 178 callback.Run(profile, status); | |
| 179 | |
| 180 if (status == Profile::CREATE_STATUS_INITIALIZED) { | |
| 181 | |
| 182 ProfileManager::FindOrCreateNewWindowForProfile( | |
| 183 profile, | |
| 184 chrome::startup::IS_PROCESS_STARTUP, | |
| 185 chrome::startup::IS_FIRST_RUN, | |
| 186 desktop_type, | |
| 187 false); | |
| 188 } | |
| 189 } | |
| 190 | |
| 191 #if defined(OS_CHROMEOS) | 166 #if defined(OS_CHROMEOS) |
| 192 void CheckCryptohomeIsMounted(chromeos::DBusMethodCallStatus call_status, | 167 void CheckCryptohomeIsMounted(chromeos::DBusMethodCallStatus call_status, |
| 193 bool is_mounted) { | 168 bool is_mounted) { |
| 194 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) { | 169 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) { |
| 195 LOG(ERROR) << "IsMounted call failed."; | 170 LOG(ERROR) << "IsMounted call failed."; |
| 196 return; | 171 return; |
| 197 } | 172 } |
| 198 if (!is_mounted) | 173 if (!is_mounted) |
| 199 LOG(ERROR) << "Cryptohome is not mounted."; | 174 LOG(ERROR) << "Cryptohome is not mounted."; |
| 200 } | 175 } |
| (...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 base::FilePath new_path = user_data_dir_; | 861 base::FilePath new_path = user_data_dir_; |
| 887 #if defined(OS_WIN) | 862 #if defined(OS_WIN) |
| 888 new_path = new_path.Append(ASCIIToUTF16(profile_name)); | 863 new_path = new_path.Append(ASCIIToUTF16(profile_name)); |
| 889 #else | 864 #else |
| 890 new_path = new_path.Append(profile_name); | 865 new_path = new_path.Append(profile_name); |
| 891 #endif | 866 #endif |
| 892 local_state->SetInteger(prefs::kProfilesNumCreated, ++next_directory); | 867 local_state->SetInteger(prefs::kProfilesNumCreated, ++next_directory); |
| 893 return new_path; | 868 return new_path; |
| 894 } | 869 } |
| 895 | 870 |
| 896 // TODO(robertshield): ProfileManager should not be opening windows and should | |
| 897 // not have to care about HostDesktopType. See http://crbug.com/153864 | |
| 898 // static | 871 // static |
| 899 void ProfileManager::CreateMultiProfileAsync( | 872 void ProfileManager::CreateMultiProfileAsync( |
| 900 const string16& name, | 873 const string16& name, |
| 901 const string16& icon_url, | 874 const string16& icon_url, |
| 902 const CreateCallback& callback, | 875 const CreateCallback& callback, |
| 903 chrome::HostDesktopType desktop_type, | |
| 904 bool is_managed) { | 876 bool is_managed) { |
| 905 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 877 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 906 | 878 |
| 907 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 879 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 908 | 880 |
| 909 base::FilePath new_path = profile_manager->GenerateNextProfileDirectoryPath(); | 881 base::FilePath new_path = profile_manager->GenerateNextProfileDirectoryPath(); |
| 910 | 882 |
| 911 profile_manager->CreateProfileAsync(new_path, | 883 profile_manager->CreateProfileAsync(new_path, |
| 912 base::Bind(&OnOpenWindowForNewProfile, | 884 callback, |
| 913 desktop_type, | |
| 914 callback), | |
| 915 name, | 885 name, |
| 916 icon_url, | 886 icon_url, |
| 917 is_managed); | 887 is_managed); |
| 918 } | 888 } |
| 919 | 889 |
| 920 // static | 890 // static |
| 921 void ProfileManager::RegisterPrefs(PrefRegistrySimple* registry) { | 891 void ProfileManager::RegisterPrefs(PrefRegistrySimple* registry) { |
| 922 registry->RegisterStringPref(prefs::kProfileLastUsed, std::string()); | 892 registry->RegisterStringPref(prefs::kProfileLastUsed, std::string()); |
| 923 registry->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); | 893 registry->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); |
| 924 registry->RegisterListPref(prefs::kProfilesLastActive); | 894 registry->RegisterListPref(prefs::kProfilesLastActive); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1024 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 994 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 1025 if (!logged_in_ && | 995 if (!logged_in_ && |
| 1026 (!command_line.HasSwitch(switches::kTestType) || | 996 (!command_line.HasSwitch(switches::kTestType) || |
| 1027 command_line.HasSwitch(chromeos::switches::kLoginProfile))) { | 997 command_line.HasSwitch(chromeos::switches::kLoginProfile))) { |
| 1028 go_off_the_record = true; | 998 go_off_the_record = true; |
| 1029 } | 999 } |
| 1030 #endif | 1000 #endif |
| 1031 return go_off_the_record; | 1001 return go_off_the_record; |
| 1032 } | 1002 } |
| 1033 | 1003 |
| 1034 // TODO(robertshield): ProfileManager should not be opening windows and should | |
| 1035 // not have to care about HostDesktopType. See http://crbug.com/153864 | |
| 1036 void ProfileManager::ScheduleProfileForDeletion( | 1004 void ProfileManager::ScheduleProfileForDeletion( |
| 1037 const base::FilePath& profile_dir, | 1005 const base::FilePath& profile_dir, |
| 1038 chrome::HostDesktopType desktop_type) { | 1006 const CreateCallback& callback) { |
| 1039 DCHECK(IsMultipleProfilesEnabled()); | 1007 DCHECK(IsMultipleProfilesEnabled()); |
| 1040 | 1008 |
| 1041 PrefService* local_state = g_browser_process->local_state(); | 1009 PrefService* local_state = g_browser_process->local_state(); |
| 1042 ProfileInfoCache& cache = GetProfileInfoCache(); | 1010 ProfileInfoCache& cache = GetProfileInfoCache(); |
| 1043 if (profile_dir.BaseName().MaybeAsASCII() == | 1011 if (profile_dir.BaseName().MaybeAsASCII() == |
| 1044 local_state->GetString(prefs::kProfileLastUsed)) { | 1012 local_state->GetString(prefs::kProfileLastUsed)) { |
| 1045 // Update the last used profile pref before closing browser windows. This | 1013 // Update the last used profile pref before closing browser windows. This |
| 1046 // way the correct last used profile is set for any notification observers. | 1014 // way the correct last used profile is set for any notification observers. |
| 1047 std::string last_non_managed_profile; | 1015 std::string last_non_managed_profile; |
| 1048 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 1016 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
| 1049 base::FilePath cur_path = cache.GetPathOfProfileAtIndex(i); | 1017 base::FilePath cur_path = cache.GetPathOfProfileAtIndex(i); |
| 1050 if (cur_path != profile_dir && !cache.ProfileIsManagedAtIndex(i)) { | 1018 if (cur_path != profile_dir && !cache.ProfileIsManagedAtIndex(i)) { |
| 1051 last_non_managed_profile = cur_path.BaseName().MaybeAsASCII(); | 1019 last_non_managed_profile = cur_path.BaseName().MaybeAsASCII(); |
| 1052 break; | 1020 break; |
| 1053 } | 1021 } |
| 1054 } | 1022 } |
| 1055 // If we're deleting the last (non-managed) profile, then create a new | 1023 // If we're deleting the last (non-managed) profile, then create a new |
| 1056 // profile in its place. | 1024 // profile in its place. |
| 1057 if (last_non_managed_profile.empty()) { | 1025 if (last_non_managed_profile.empty()) { |
| 1058 base::FilePath new_path = GenerateNextProfileDirectoryPath(); | 1026 base::FilePath new_path = GenerateNextProfileDirectoryPath(); |
| 1059 // Make sure the last used profile path is pointing at it. This way the | 1027 // Make sure the last used profile path is pointing at it. This way the |
| 1060 // correct last used profile is set for any notification observers. | 1028 // correct last used profile is set for any notification observers. |
| 1061 local_state->SetString(prefs::kProfileLastUsed, | 1029 local_state->SetString(prefs::kProfileLastUsed, |
| 1062 new_path.BaseName().MaybeAsASCII()); | 1030 new_path.BaseName().MaybeAsASCII()); |
| 1063 // TODO(robertshield): This desktop type needs to come from the invoker, | |
| 1064 // currently that involves plumbing this through web UI. | |
| 1065 chrome::HostDesktopType desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE; | |
| 1066 CreateProfileAsync(new_path, | 1031 CreateProfileAsync(new_path, |
| 1067 base::Bind(&OnOpenWindowForNewProfile, | 1032 callback, |
| 1068 desktop_type, | |
| 1069 CreateCallback()), | |
| 1070 string16(), | 1033 string16(), |
| 1071 string16(), | 1034 string16(), |
| 1072 false); | 1035 false); |
| 1073 } else { | 1036 } else { |
| 1074 local_state->SetString(prefs::kProfileLastUsed, last_non_managed_profile); | 1037 local_state->SetString(prefs::kProfileLastUsed, last_non_managed_profile); |
| 1075 } | 1038 } |
| 1076 } | 1039 } |
| 1077 | 1040 |
| 1078 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we | 1041 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we |
| 1079 // start deleting the profile instance we need to close background apps too. | 1042 // start deleting the profile instance we need to close background apps too. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1155 ProfileManager::ProfileInfo::ProfileInfo( | 1118 ProfileManager::ProfileInfo::ProfileInfo( |
| 1156 Profile* profile, | 1119 Profile* profile, |
| 1157 bool created) | 1120 bool created) |
| 1158 : profile(profile), | 1121 : profile(profile), |
| 1159 created(created) { | 1122 created(created) { |
| 1160 } | 1123 } |
| 1161 | 1124 |
| 1162 ProfileManager::ProfileInfo::~ProfileInfo() { | 1125 ProfileManager::ProfileInfo::~ProfileInfo() { |
| 1163 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); | 1126 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); |
| 1164 } | 1127 } |
| OLD | NEW |