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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 | 673 |
674 std::vector<Profile*> to_return; | 674 std::vector<Profile*> to_return; |
675 if (local_state->HasPrefPath(prefs::kProfilesLastActive) && | 675 if (local_state->HasPrefPath(prefs::kProfilesLastActive) && |
676 local_state->GetList(prefs::kProfilesLastActive)) { | 676 local_state->GetList(prefs::kProfilesLastActive)) { |
677 // Make a copy because the list might change in the calls to GetProfile. | 677 // Make a copy because the list might change in the calls to GetProfile. |
678 std::unique_ptr<base::ListValue> profile_list( | 678 std::unique_ptr<base::ListValue> profile_list( |
679 local_state->GetList(prefs::kProfilesLastActive)->DeepCopy()); | 679 local_state->GetList(prefs::kProfilesLastActive)->DeepCopy()); |
680 base::ListValue::const_iterator it; | 680 base::ListValue::const_iterator it; |
681 for (it = profile_list->begin(); it != profile_list->end(); ++it) { | 681 for (it = profile_list->begin(); it != profile_list->end(); ++it) { |
682 std::string profile_path; | 682 std::string profile_path; |
683 if (!(*it)->GetAsString(&profile_path) || | 683 if (!it->GetAsString(&profile_path) || profile_path.empty() || |
684 profile_path.empty() || | |
685 profile_path == | 684 profile_path == |
686 base::FilePath(chrome::kSystemProfileDir).AsUTF8Unsafe()) { | 685 base::FilePath(chrome::kSystemProfileDir).AsUTF8Unsafe()) { |
687 LOG(WARNING) << "Invalid entry in " << prefs::kProfilesLastActive; | 686 LOG(WARNING) << "Invalid entry in " << prefs::kProfilesLastActive; |
688 continue; | 687 continue; |
689 } | 688 } |
690 Profile* profile = GetProfile(user_data_dir.AppendASCII(profile_path)); | 689 Profile* profile = GetProfile(user_data_dir.AppendASCII(profile_path)); |
691 if (profile) | 690 if (profile) |
692 to_return.push_back(profile); | 691 to_return.push_back(profile); |
693 } | 692 } |
694 } | 693 } |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
896 } | 895 } |
897 } | 896 } |
898 | 897 |
899 void ProfileManager::CleanUpDeletedProfiles() { | 898 void ProfileManager::CleanUpDeletedProfiles() { |
900 PrefService* local_state = g_browser_process->local_state(); | 899 PrefService* local_state = g_browser_process->local_state(); |
901 DCHECK(local_state); | 900 DCHECK(local_state); |
902 const base::ListValue* deleted_profiles = | 901 const base::ListValue* deleted_profiles = |
903 local_state->GetList(prefs::kProfilesDeleted); | 902 local_state->GetList(prefs::kProfilesDeleted); |
904 DCHECK(deleted_profiles); | 903 DCHECK(deleted_profiles); |
905 | 904 |
906 for (const std::unique_ptr<base::Value>& value : *deleted_profiles) { | 905 for (const base::Value& value : *deleted_profiles) { |
907 base::FilePath profile_path; | 906 base::FilePath profile_path; |
908 bool is_valid_profile_path = | 907 bool is_valid_profile_path = |
909 base::GetValueAsFilePath(*value, &profile_path) && | 908 base::GetValueAsFilePath(value, &profile_path) && |
910 profile_path.DirName() == user_data_dir(); | 909 profile_path.DirName() == user_data_dir(); |
911 // Although it should never happen, make sure this is a valid path in the | 910 // Although it should never happen, make sure this is a valid path in the |
912 // user_data_dir, so we don't accidentially delete something else. | 911 // user_data_dir, so we don't accidentially delete something else. |
913 if (is_valid_profile_path) { | 912 if (is_valid_profile_path) { |
914 if (base::PathExists(profile_path)) { | 913 if (base::PathExists(profile_path)) { |
915 LOG(WARNING) << "Files of a deleted profile still exist after restart. " | 914 LOG(WARNING) << "Files of a deleted profile still exist after restart. " |
916 "Cleaning up now."; | 915 "Cleaning up now."; |
917 BrowserThread::PostTaskAndReply( | 916 BrowserThread::PostTaskAndReply( |
918 BrowserThread::FILE, FROM_HERE, | 917 BrowserThread::FILE, FROM_HERE, |
919 base::Bind(&NukeProfileFromDisk, profile_path), | 918 base::Bind(&NukeProfileFromDisk, profile_path), |
920 base::Bind(&ProfileCleanedUp, value.get())); | 919 base::Bind(&ProfileCleanedUp, &value)); |
921 } else { | 920 } else { |
922 // Everything is fine, the profile was removed on shutdown. | 921 // Everything is fine, the profile was removed on shutdown. |
923 BrowserThread::PostTask( | 922 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
924 BrowserThread::UI, FROM_HERE, | 923 base::Bind(&ProfileCleanedUp, &value)); |
925 base::Bind(&ProfileCleanedUp, value.get())); | |
926 } | 924 } |
927 } else { | 925 } else { |
928 LOG(ERROR) << "Found invalid profile path in deleted_profiles: " | 926 LOG(ERROR) << "Found invalid profile path in deleted_profiles: " |
929 << profile_path.AsUTF8Unsafe(); | 927 << profile_path.AsUTF8Unsafe(); |
930 NOTREACHED(); | 928 NOTREACHED(); |
931 } | 929 } |
932 } | 930 } |
933 } | 931 } |
934 | 932 |
935 void ProfileManager::InitProfileUserPrefs(Profile* profile) { | 933 void ProfileManager::InitProfileUserPrefs(Profile* profile) { |
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1796 | 1794 |
1797 const base::FilePath new_active_profile_dir = | 1795 const base::FilePath new_active_profile_dir = |
1798 found_entry ? found_entry->GetPath() : GenerateNextProfileDirectoryPath(); | 1796 found_entry ? found_entry->GetPath() : GenerateNextProfileDirectoryPath(); |
1799 FinishDeletingProfile(profile_dir, new_active_profile_dir); | 1797 FinishDeletingProfile(profile_dir, new_active_profile_dir); |
1800 } | 1798 } |
1801 #endif // !defined(OS_ANDROID) | 1799 #endif // !defined(OS_ANDROID) |
1802 | 1800 |
1803 ProfileManagerWithoutInit::ProfileManagerWithoutInit( | 1801 ProfileManagerWithoutInit::ProfileManagerWithoutInit( |
1804 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { | 1802 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { |
1805 } | 1803 } |
OLD | NEW |