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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 177 |
178 size = ComputeFilesSize(path, FILE_PATH_LITERAL("Policy")); | 178 size = ComputeFilesSize(path, FILE_PATH_LITERAL("Policy")); |
179 size_MB = static_cast<int>(size / kBytesInOneMB); | 179 size_MB = static_cast<int>(size / kBytesInOneMB); |
180 UMA_HISTOGRAM_COUNTS_10000("Profile.PolicySize", size_MB); | 180 UMA_HISTOGRAM_COUNTS_10000("Profile.PolicySize", size_MB); |
181 | 181 |
182 // Count number of enabled apps in this profile, if we know. | 182 // Count number of enabled apps in this profile, if we know. |
183 if (enabled_app_count != -1) | 183 if (enabled_app_count != -1) |
184 UMA_HISTOGRAM_COUNTS_10000("Profile.AppCount", enabled_app_count); | 184 UMA_HISTOGRAM_COUNTS_10000("Profile.AppCount", enabled_app_count); |
185 } | 185 } |
186 | 186 |
| 187 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
187 void QueueProfileDirectoryForDeletion(const base::FilePath& path) { | 188 void QueueProfileDirectoryForDeletion(const base::FilePath& path) { |
188 ProfilesToDelete().push_back(path); | 189 ProfilesToDelete().push_back(path); |
189 } | 190 } |
| 191 #endif |
190 | 192 |
191 bool IsProfileMarkedForDeletion(const base::FilePath& profile_path) { | 193 bool IsProfileMarkedForDeletion(const base::FilePath& profile_path) { |
192 return std::find(ProfilesToDelete().begin(), ProfilesToDelete().end(), | 194 return std::find(ProfilesToDelete().begin(), ProfilesToDelete().end(), |
193 profile_path) != ProfilesToDelete().end(); | 195 profile_path) != ProfilesToDelete().end(); |
194 } | 196 } |
195 | 197 |
196 // Physically remove deleted profile directories from disk. | 198 // Physically remove deleted profile directories from disk. |
197 void NukeProfileFromDisk(const base::FilePath& profile_path) { | 199 void NukeProfileFromDisk(const base::FilePath& profile_path) { |
198 // Delete both the profile directory and its corresponding cache. | 200 // Delete both the profile directory and its corresponding cache. |
199 base::FilePath cache_path; | 201 base::FilePath cache_path; |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 profile_info_cache_.reset(new ProfileInfoCache( | 649 profile_info_cache_.reset(new ProfileInfoCache( |
648 g_browser_process->local_state(), user_data_dir_)); | 650 g_browser_process->local_state(), user_data_dir_)); |
649 } | 651 } |
650 return *profile_info_cache_.get(); | 652 return *profile_info_cache_.get(); |
651 } | 653 } |
652 | 654 |
653 ProfileShortcutManager* ProfileManager::profile_shortcut_manager() { | 655 ProfileShortcutManager* ProfileManager::profile_shortcut_manager() { |
654 return profile_shortcut_manager_.get(); | 656 return profile_shortcut_manager_.get(); |
655 } | 657 } |
656 | 658 |
| 659 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
657 void ProfileManager::ScheduleProfileForDeletion( | 660 void ProfileManager::ScheduleProfileForDeletion( |
658 const base::FilePath& profile_dir, | 661 const base::FilePath& profile_dir, |
659 const CreateCallback& callback) { | 662 const CreateCallback& callback) { |
660 DCHECK(profiles::IsMultipleProfilesEnabled()); | 663 DCHECK(profiles::IsMultipleProfilesEnabled()); |
661 | 664 |
662 // Cancel all in-progress downloads before deleting the profile to prevent a | 665 // Cancel all in-progress downloads before deleting the profile to prevent a |
663 // "Do you want to exit Google Chrome and cancel the downloads?" prompt | 666 // "Do you want to exit Google Chrome and cancel the downloads?" prompt |
664 // (crbug.com/336725). | 667 // (crbug.com/336725). |
665 Profile* profile = GetProfileByPath(profile_dir); | 668 Profile* profile = GetProfileByPath(profile_dir); |
666 if (profile) { | 669 if (profile) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 callback), | 733 callback), |
731 base::string16(), | 734 base::string16(), |
732 base::string16(), | 735 base::string16(), |
733 std::string()); | 736 std::string()); |
734 return; | 737 return; |
735 } | 738 } |
736 #endif // defined(OS_MACOSX) | 739 #endif // defined(OS_MACOSX) |
737 | 740 |
738 FinishDeletingProfile(profile_dir, last_non_supervised_profile_path); | 741 FinishDeletingProfile(profile_dir, last_non_supervised_profile_path); |
739 } | 742 } |
| 743 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) |
740 | 744 |
741 void ProfileManager::AutoloadProfiles() { | 745 void ProfileManager::AutoloadProfiles() { |
742 // If running in the background is disabled for the browser, do not autoload | 746 // If running in the background is disabled for the browser, do not autoload |
743 // any profiles. | 747 // any profiles. |
744 PrefService* local_state = g_browser_process->local_state(); | 748 PrefService* local_state = g_browser_process->local_state(); |
745 DCHECK(local_state); | 749 DCHECK(local_state); |
746 if (!local_state->HasPrefPath(prefs::kBackgroundModeEnabled) || | 750 if (!local_state->HasPrefPath(prefs::kBackgroundModeEnabled) || |
747 !local_state->GetBoolean(prefs::kBackgroundModeEnabled)) { | 751 !local_state->GetBoolean(prefs::kBackgroundModeEnabled)) { |
748 return; | 752 return; |
749 } | 753 } |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1215 CHECK(!GetProfileByPathInternal(profile_dir)); | 1219 CHECK(!GetProfileByPathInternal(profile_dir)); |
1216 Profile* profile = CreateProfileHelper(profile_dir); | 1220 Profile* profile = CreateProfileHelper(profile_dir); |
1217 DCHECK(profile); | 1221 DCHECK(profile); |
1218 if (profile) { | 1222 if (profile) { |
1219 bool result = AddProfile(profile); | 1223 bool result = AddProfile(profile); |
1220 DCHECK(result); | 1224 DCHECK(result); |
1221 } | 1225 } |
1222 return profile; | 1226 return profile; |
1223 } | 1227 } |
1224 | 1228 |
| 1229 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
1225 void ProfileManager::FinishDeletingProfile( | 1230 void ProfileManager::FinishDeletingProfile( |
1226 const base::FilePath& profile_dir, | 1231 const base::FilePath& profile_dir, |
1227 const base::FilePath& new_active_profile_dir) { | 1232 const base::FilePath& new_active_profile_dir) { |
1228 // Update the last used profile pref before closing browser windows. This | 1233 // Update the last used profile pref before closing browser windows. This |
1229 // way the correct last used profile is set for any notification observers. | 1234 // way the correct last used profile is set for any notification observers. |
1230 profiles::SetLastUsedProfile( | 1235 profiles::SetLastUsedProfile( |
1231 new_active_profile_dir.BaseName().MaybeAsASCII()); | 1236 new_active_profile_dir.BaseName().MaybeAsASCII()); |
1232 | 1237 |
1233 ProfileInfoCache& cache = GetProfileInfoCache(); | 1238 ProfileInfoCache& cache = GetProfileInfoCache(); |
1234 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we | 1239 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1276 BrowserThread::FILE, FROM_HERE, | 1281 BrowserThread::FILE, FROM_HERE, |
1277 base::Bind(&NukeProfileFromDisk, profile_dir)); | 1282 base::Bind(&NukeProfileFromDisk, profile_dir)); |
1278 } | 1283 } |
1279 | 1284 |
1280 // Queue even a profile that was nuked so it will be MarkedForDeletion and so | 1285 // Queue even a profile that was nuked so it will be MarkedForDeletion and so |
1281 // CreateProfileAsync can't create it. | 1286 // CreateProfileAsync can't create it. |
1282 QueueProfileDirectoryForDeletion(profile_dir); | 1287 QueueProfileDirectoryForDeletion(profile_dir); |
1283 cache.DeleteProfileFromCache(profile_dir); | 1288 cache.DeleteProfileFromCache(profile_dir); |
1284 ProfileMetrics::UpdateReportedProfilesStatistics(this); | 1289 ProfileMetrics::UpdateReportedProfilesStatistics(this); |
1285 } | 1290 } |
| 1291 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) |
1286 | 1292 |
1287 ProfileManager::ProfileInfo* ProfileManager::RegisterProfile( | 1293 ProfileManager::ProfileInfo* ProfileManager::RegisterProfile( |
1288 Profile* profile, | 1294 Profile* profile, |
1289 bool created) { | 1295 bool created) { |
1290 TRACE_EVENT0("browser", "ProfileManager::RegisterProfile"); | 1296 TRACE_EVENT0("browser", "ProfileManager::RegisterProfile"); |
1291 ProfileInfo* info = new ProfileInfo(profile, created); | 1297 ProfileInfo* info = new ProfileInfo(profile, created); |
1292 profiles_info_.insert( | 1298 profiles_info_.insert( |
1293 std::make_pair(profile->GetPath(), linked_ptr<ProfileInfo>(info))); | 1299 std::make_pair(profile->GetPath(), linked_ptr<ProfileInfo>(info))); |
1294 return info; | 1300 return info; |
1295 } | 1301 } |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1456 | 1462 |
1457 Profile* last_active = browser->profile(); | 1463 Profile* last_active = browser->profile(); |
1458 | 1464 |
1459 // Don't remember ephemeral profiles as last because they are not going to | 1465 // Don't remember ephemeral profiles as last because they are not going to |
1460 // persist after restart. | 1466 // persist after restart. |
1461 if (last_active->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) | 1467 if (last_active->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) |
1462 return; | 1468 return; |
1463 | 1469 |
1464 profile_manager_->UpdateLastUser(last_active); | 1470 profile_manager_->UpdateLastUser(last_active); |
1465 } | 1471 } |
1466 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) | |
1467 | 1472 |
1468 void ProfileManager::OnNewActiveProfileLoaded( | 1473 void ProfileManager::OnNewActiveProfileLoaded( |
1469 const base::FilePath& profile_to_delete_path, | 1474 const base::FilePath& profile_to_delete_path, |
1470 const base::FilePath& new_active_profile_path, | 1475 const base::FilePath& new_active_profile_path, |
1471 const CreateCallback& original_callback, | 1476 const CreateCallback& original_callback, |
1472 Profile* loaded_profile, | 1477 Profile* loaded_profile, |
1473 Profile::CreateStatus status) { | 1478 Profile::CreateStatus status) { |
1474 DCHECK(status != Profile::CREATE_STATUS_LOCAL_FAIL && | 1479 DCHECK(status != Profile::CREATE_STATUS_LOCAL_FAIL && |
1475 status != Profile::CREATE_STATUS_REMOTE_FAIL); | 1480 status != Profile::CREATE_STATUS_REMOTE_FAIL); |
1476 | 1481 |
1477 // Only run the code if the profile initialization has finished completely. | 1482 // Only run the code if the profile initialization has finished completely. |
1478 if (status != Profile::CREATE_STATUS_INITIALIZED) | 1483 if (status != Profile::CREATE_STATUS_INITIALIZED) |
1479 return; | 1484 return; |
1480 | 1485 |
1481 if (IsProfileMarkedForDeletion(new_active_profile_path)) { | 1486 if (IsProfileMarkedForDeletion(new_active_profile_path)) { |
1482 // If the profile we tried to load as the next active profile has been | 1487 // If the profile we tried to load as the next active profile has been |
1483 // deleted, then retry deleting this profile to redo the logic to load | 1488 // deleted, then retry deleting this profile to redo the logic to load |
1484 // the next available profile. | 1489 // the next available profile. |
1485 ScheduleProfileForDeletion(profile_to_delete_path, original_callback); | 1490 ScheduleProfileForDeletion(profile_to_delete_path, original_callback); |
1486 return; | 1491 return; |
1487 } | 1492 } |
1488 | 1493 |
1489 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); | 1494 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); |
1490 if (!original_callback.is_null()) | 1495 if (!original_callback.is_null()) |
1491 original_callback.Run(loaded_profile, status); | 1496 original_callback.Run(loaded_profile, status); |
1492 } | 1497 } |
| 1498 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) |
1493 | 1499 |
1494 ProfileManagerWithoutInit::ProfileManagerWithoutInit( | 1500 ProfileManagerWithoutInit::ProfileManagerWithoutInit( |
1495 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { | 1501 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { |
1496 } | 1502 } |
OLD | NEW |