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