| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 BrowserThread::FILE, FROM_HERE, | 122 BrowserThread::FILE, FROM_HERE, |
| 123 NewRunnableFunction(&DeleteProfileDirectories, profiles_to_delete_)); | 123 NewRunnableFunction(&DeleteProfileDirectories, profiles_to_delete_)); |
| 124 profiles_to_delete_.clear(); | 124 profiles_to_delete_.clear(); |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 | 127 |
| 128 FilePath ProfileManager::GetDefaultProfileDir( | 128 FilePath ProfileManager::GetDefaultProfileDir( |
| 129 const FilePath& user_data_dir) { | 129 const FilePath& user_data_dir) { |
| 130 FilePath default_profile_dir(user_data_dir); | 130 FilePath default_profile_dir(user_data_dir); |
| 131 default_profile_dir = | 131 default_profile_dir = |
| 132 default_profile_dir.AppendASCII(chrome::kNotSignedInProfile); | 132 default_profile_dir.AppendASCII(chrome::kInitialProfile); |
| 133 return default_profile_dir; | 133 return default_profile_dir; |
| 134 } | 134 } |
| 135 | 135 |
| 136 FilePath ProfileManager::GetProfilePrefsPath( | 136 FilePath ProfileManager::GetProfilePrefsPath( |
| 137 const FilePath &profile_dir) { | 137 const FilePath &profile_dir) { |
| 138 FilePath default_prefs_path(profile_dir); | 138 FilePath default_prefs_path(profile_dir); |
| 139 default_prefs_path = default_prefs_path.Append(chrome::kPreferencesFilename); | 139 default_prefs_path = default_prefs_path.Append(chrome::kPreferencesFilename); |
| 140 return default_prefs_path; | 140 return default_prefs_path; |
| 141 } | 141 } |
| 142 | 142 |
| 143 FilePath ProfileManager::GetCurrentProfileDir() { | 143 FilePath ProfileManager::GetInitialProfileDir() { |
| 144 FilePath relative_profile_dir; | 144 FilePath relative_profile_dir; |
| 145 #if defined(OS_CHROMEOS) | 145 #if defined(OS_CHROMEOS) |
| 146 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 146 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 147 if (logged_in_) { | 147 if (logged_in_) { |
| 148 FilePath profile_dir; | 148 FilePath profile_dir; |
| 149 // If the user has logged in, pick up the new profile. | 149 // If the user has logged in, pick up the new profile. |
| 150 if (command_line.HasSwitch(switches::kLoginProfile)) { | 150 if (command_line.HasSwitch(switches::kLoginProfile)) { |
| 151 profile_dir = command_line.GetSwitchValuePath(switches::kLoginProfile); | 151 profile_dir = command_line.GetSwitchValuePath(switches::kLoginProfile); |
| 152 } else { | 152 } else { |
| 153 // We should never be logged in with no profile dir. | 153 // We should never be logged in with no profile dir. |
| 154 NOTREACHED(); | 154 NOTREACHED(); |
| 155 return FilePath(""); | 155 return FilePath(""); |
| 156 } | 156 } |
| 157 relative_profile_dir = relative_profile_dir.Append(profile_dir); | 157 relative_profile_dir = relative_profile_dir.Append(profile_dir); |
| 158 return relative_profile_dir; | 158 return relative_profile_dir; |
| 159 } | 159 } |
| 160 #endif | 160 #endif |
| 161 // TODO(mirandac): should not automatically be default profile. | 161 // TODO(mirandac): should not automatically be default profile. |
| 162 relative_profile_dir = | 162 relative_profile_dir = |
| 163 relative_profile_dir.AppendASCII(chrome::kNotSignedInProfile); | 163 relative_profile_dir.AppendASCII(chrome::kInitialProfile); |
| 164 return relative_profile_dir; | 164 return relative_profile_dir; |
| 165 } | 165 } |
| 166 | 166 |
| 167 Profile* ProfileManager::GetLastUsedProfile(const FilePath& user_data_dir) { | 167 Profile* ProfileManager::GetLastUsedProfile(const FilePath& user_data_dir) { |
| 168 FilePath last_used_profile_dir(user_data_dir); | 168 FilePath last_used_profile_dir(user_data_dir); |
| 169 std::string last_profile_used; | 169 std::string last_profile_used; |
| 170 PrefService* local_state = g_browser_process->local_state(); | 170 PrefService* local_state = g_browser_process->local_state(); |
| 171 DCHECK(local_state); | 171 DCHECK(local_state); |
| 172 | 172 |
| 173 if (local_state->HasPrefPath(prefs::kProfileLastUsed)) | 173 if (local_state->HasPrefPath(prefs::kProfileLastUsed)) |
| 174 last_profile_used = local_state->GetString(prefs::kProfileLastUsed); | 174 last_profile_used = local_state->GetString(prefs::kProfileLastUsed); |
| 175 last_used_profile_dir = last_profile_used.empty() ? | 175 last_used_profile_dir = last_profile_used.empty() ? |
| 176 last_used_profile_dir.AppendASCII(chrome::kNotSignedInProfile) : | 176 last_used_profile_dir.AppendASCII(chrome::kInitialProfile) : |
| 177 last_used_profile_dir.AppendASCII(last_profile_used); | 177 last_used_profile_dir.AppendASCII(last_profile_used); |
| 178 return GetProfile(last_used_profile_dir); | 178 return GetProfile(last_used_profile_dir); |
| 179 } | 179 } |
| 180 | 180 |
| 181 void ProfileManager::RegisterProfileName(Profile* profile) { | 181 void ProfileManager::RegisterProfileName(Profile* profile) { |
| 182 std::string profile_name = profile->GetProfileName(); | 182 std::string profile_name = profile->GetProfileName(); |
| 183 std::string dir_base = profile->GetPath().BaseName().MaybeAsASCII(); | 183 std::string dir_base = profile->GetPath().BaseName().MaybeAsASCII(); |
| 184 DictionaryPrefUpdate update(g_browser_process->local_state(), | 184 DictionaryPrefUpdate update(g_browser_process->local_state(), |
| 185 prefs::kProfileDirectoryMap); | 185 prefs::kProfileDirectoryMap); |
| 186 DictionaryValue* path_map = update.Get(); | 186 DictionaryValue* path_map = update.Get(); |
| 187 // We don't check for duplicates because we should be able to overwrite | 187 // We don't check for duplicates because we should be able to overwrite |
| 188 // path->name mappings here, if the user syncs a local account to a | 188 // path->name mappings here, if the user syncs a local account to a |
| 189 // different Google account. | 189 // different Google account. |
| 190 path_map->SetString(dir_base, profile_name); | 190 path_map->SetString(dir_base, profile_name); |
| 191 } | 191 } |
| 192 | 192 |
| 193 Profile* ProfileManager::GetDefaultProfile(const FilePath& user_data_dir) { | 193 Profile* ProfileManager::GetDefaultProfile(const FilePath& user_data_dir) { |
| 194 FilePath default_profile_dir(user_data_dir); | 194 FilePath default_profile_dir(user_data_dir); |
| 195 default_profile_dir = default_profile_dir.Append(GetCurrentProfileDir()); | 195 default_profile_dir = default_profile_dir.Append(GetInitialProfileDir()); |
| 196 #if defined(OS_CHROMEOS) | 196 #if defined(OS_CHROMEOS) |
| 197 if (!logged_in_) { | 197 if (!logged_in_) { |
| 198 Profile* profile; | 198 Profile* profile; |
| 199 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 199 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 200 | 200 |
| 201 // For cros, return the OTR profile so we never accidentally keep | 201 // For cros, return the OTR profile so we never accidentally keep |
| 202 // user data in an unencrypted profile. But doing this makes | 202 // user data in an unencrypted profile. But doing this makes |
| 203 // many of the browser and ui tests fail. We do return the OTR profile | 203 // many of the browser and ui tests fail. We do return the OTR profile |
| 204 // if the login-profile switch is passed so that we can test this. | 204 // if the login-profile switch is passed so that we can test this. |
| 205 // TODO(davemoore) Fix the tests so they allow OTR profiles. | 205 // TODO(davemoore) Fix the tests so they allow OTR profiles. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 // static | 286 // static |
| 287 void ProfileManager::CreateDefaultProfileAsync( | 287 void ProfileManager::CreateDefaultProfileAsync( |
| 288 ProfileManagerObserver* observer) { | 288 ProfileManagerObserver* observer) { |
| 289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 290 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 290 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 291 | 291 |
| 292 FilePath default_profile_dir; | 292 FilePath default_profile_dir; |
| 293 PathService::Get(chrome::DIR_USER_DATA, &default_profile_dir); | 293 PathService::Get(chrome::DIR_USER_DATA, &default_profile_dir); |
| 294 // TODO(mirandac): current directory will not always be default in the future | 294 // TODO(mirandac): current directory will not always be default in the future |
| 295 default_profile_dir = default_profile_dir.Append( | 295 default_profile_dir = default_profile_dir.Append( |
| 296 profile_manager->GetCurrentProfileDir()); | 296 profile_manager->GetInitialProfileDir()); |
| 297 | 297 |
| 298 profile_manager->CreateProfileAsync(default_profile_dir, | 298 profile_manager->CreateProfileAsync(default_profile_dir, |
| 299 observer); | 299 observer); |
| 300 } | 300 } |
| 301 | 301 |
| 302 bool ProfileManager::AddProfile(Profile* profile) { | 302 bool ProfileManager::AddProfile(Profile* profile) { |
| 303 DCHECK(profile); | 303 DCHECK(profile); |
| 304 | 304 |
| 305 // Make sure that we're not loading a profile with the same ID as a profile | 305 // Make sure that we're not loading a profile with the same ID as a profile |
| 306 // that's already loaded. | 306 // that's already loaded. |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 cache.DeleteProfileFromCache(profile_dir); | 560 cache.DeleteProfileFromCache(profile_dir); |
| 561 } | 561 } |
| 562 | 562 |
| 563 // static | 563 // static |
| 564 bool ProfileManager::IsMultipleProfilesEnabled() { | 564 bool ProfileManager::IsMultipleProfilesEnabled() { |
| 565 #if defined(TOOLKIT_VIEWS) && !defined(OS_CHROMEOS) | 565 #if defined(TOOLKIT_VIEWS) && !defined(OS_CHROMEOS) |
| 566 return true; | 566 return true; |
| 567 #endif | 567 #endif |
| 568 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles); | 568 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles); |
| 569 } | 569 } |
| OLD | NEW |