| 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 <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 30 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 31 #include "chrome/browser/download/download_service.h" | 31 #include "chrome/browser/download/download_service.h" |
| 32 #include "chrome/browser/download/download_service_factory.h" | 32 #include "chrome/browser/download/download_service_factory.h" |
| 33 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" | 33 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" |
| 34 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 34 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
| 35 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" | 35 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" |
| 36 #include "chrome/browser/password_manager/password_manager_setting_migrator_serv
ice_factory.h" | 36 #include "chrome/browser/password_manager/password_manager_setting_migrator_serv
ice_factory.h" |
| 37 #include "chrome/browser/password_manager/password_store_factory.h" | 37 #include "chrome/browser/password_manager/password_store_factory.h" |
| 38 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 38 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 39 #include "chrome/browser/profiles/bookmark_model_loaded_observer.h" | 39 #include "chrome/browser/profiles/bookmark_model_loaded_observer.h" |
| 40 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 40 #include "chrome/browser/profiles/profile_attributes_storage.h" | 41 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 41 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 42 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 42 #include "chrome/browser/profiles/profile_destroyer.h" | 43 #include "chrome/browser/profiles/profile_destroyer.h" |
| 43 #include "chrome/browser/profiles/profile_info_cache.h" | 44 #include "chrome/browser/profiles/profile_info_cache.h" |
| 44 #include "chrome/browser/profiles/profile_metrics.h" | 45 #include "chrome/browser/profiles/profile_metrics.h" |
| 45 #include "chrome/browser/profiles/profiles_state.h" | 46 #include "chrome/browser/profiles/profiles_state.h" |
| 46 #include "chrome/browser/sessions/session_service_factory.h" | 47 #include "chrome/browser/sessions/session_service_factory.h" |
| 47 #include "chrome/browser/signin/account_fetcher_service_factory.h" | 48 #include "chrome/browser/signin/account_fetcher_service_factory.h" |
| 48 #include "chrome/browser/signin/account_reconcilor_factory.h" | 49 #include "chrome/browser/signin/account_reconcilor_factory.h" |
| 49 #include "chrome/browser/signin/account_tracker_service_factory.h" | 50 #include "chrome/browser/signin/account_tracker_service_factory.h" |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 | 424 |
| 424 // If the profile is already loaded (e.g., chrome.exe launched twice), just | 425 // If the profile is already loaded (e.g., chrome.exe launched twice), just |
| 425 // return it. | 426 // return it. |
| 426 Profile* profile = GetProfileByPath(profile_dir); | 427 Profile* profile = GetProfileByPath(profile_dir); |
| 427 if (profile) | 428 if (profile) |
| 428 return profile; | 429 return profile; |
| 429 return CreateAndInitializeProfile(profile_dir); | 430 return CreateAndInitializeProfile(profile_dir); |
| 430 } | 431 } |
| 431 | 432 |
| 432 size_t ProfileManager::GetNumberOfProfiles() { | 433 size_t ProfileManager::GetNumberOfProfiles() { |
| 433 return GetProfileInfoCache().GetNumberOfProfiles(); | 434 return GetProfileAttributesStorage().GetNumberOfProfiles(); |
| 434 } | 435 } |
| 435 | 436 |
| 436 bool ProfileManager::LoadProfile(const std::string& profile_name, | 437 bool ProfileManager::LoadProfile(const std::string& profile_name, |
| 437 bool incognito, | 438 bool incognito, |
| 438 const ProfileLoadedCallback& callback) { | 439 const ProfileLoadedCallback& callback) { |
| 439 const base::FilePath profile_path = user_data_dir().AppendASCII(profile_name); | 440 const base::FilePath profile_path = user_data_dir().AppendASCII(profile_name); |
| 440 | 441 |
| 441 ProfileAttributesEntry* entry = nullptr; | 442 ProfileAttributesEntry* entry = nullptr; |
| 442 if (!GetProfileAttributesStorage().GetProfileAttributesWithPath(profile_path, | 443 if (!GetProfileAttributesStorage().GetProfileAttributesWithPath(profile_path, |
| 443 &entry)) { | 444 &entry)) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 473 | 474 |
| 474 // Create the profile if needed and collect its ProfileInfo. | 475 // Create the profile if needed and collect its ProfileInfo. |
| 475 ProfilesInfoMap::iterator iter = profiles_info_.find(profile_path); | 476 ProfilesInfoMap::iterator iter = profiles_info_.find(profile_path); |
| 476 ProfileInfo* info = NULL; | 477 ProfileInfo* info = NULL; |
| 477 | 478 |
| 478 if (iter != profiles_info_.end()) { | 479 if (iter != profiles_info_.end()) { |
| 479 info = iter->second.get(); | 480 info = iter->second.get(); |
| 480 } else { | 481 } else { |
| 481 // Initiate asynchronous creation process. | 482 // Initiate asynchronous creation process. |
| 482 info = RegisterProfile(CreateProfileAsyncHelper(profile_path, this), false); | 483 info = RegisterProfile(CreateProfileAsyncHelper(profile_path, this), false); |
| 483 ProfileInfoCache& cache = GetProfileInfoCache(); | |
| 484 // Get the icon index from the user's icon url | |
| 485 size_t icon_index; | 484 size_t icon_index; |
| 486 DCHECK(base::IsStringASCII(icon_url)); | 485 DCHECK(base::IsStringASCII(icon_url)); |
| 487 if (profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index)) { | 486 if (profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index)) { |
| 488 // add profile to cache with user selected name and avatar | 487 // add profile to cache with user selected name and avatar |
| 489 cache.AddProfileToCache(profile_path, name, std::string(), | 488 GetProfileAttributesStorage().AddProfile(profile_path, name, |
| 490 base::string16(), icon_index, supervised_user_id); | 489 std::string(), base::string16(), icon_index, supervised_user_id); |
| 491 } | 490 } |
| 492 | 491 |
| 493 if (!supervised_user_id.empty()) { | 492 if (!supervised_user_id.empty()) { |
| 494 content::RecordAction( | 493 content::RecordAction( |
| 495 UserMetricsAction("ManagedMode_LocallyManagedUserCreated")); | 494 UserMetricsAction("ManagedMode_LocallyManagedUserCreated")); |
| 496 } | 495 } |
| 497 | 496 |
| 498 ProfileMetrics::UpdateReportedProfilesStatistics(this); | 497 ProfileMetrics::UpdateReportedProfilesStatistics(this); |
| 499 } | 498 } |
| 500 | 499 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 // Cancel all in-progress downloads before deleting the profile to prevent a | 726 // Cancel all in-progress downloads before deleting the profile to prevent a |
| 728 // "Do you want to exit Google Chrome and cancel the downloads?" prompt | 727 // "Do you want to exit Google Chrome and cancel the downloads?" prompt |
| 729 // (crbug.com/336725). | 728 // (crbug.com/336725). |
| 730 Profile* profile = GetProfileByPath(profile_dir); | 729 Profile* profile = GetProfileByPath(profile_dir); |
| 731 if (profile) { | 730 if (profile) { |
| 732 DownloadService* service = | 731 DownloadService* service = |
| 733 DownloadServiceFactory::GetForBrowserContext(profile); | 732 DownloadServiceFactory::GetForBrowserContext(profile); |
| 734 service->CancelDownloads(); | 733 service->CancelDownloads(); |
| 735 } | 734 } |
| 736 | 735 |
| 737 ProfileInfoCache& cache = GetProfileInfoCache(); | 736 ProfileAttributesStorage& storage = GetProfileAttributesStorage(); |
| 738 | |
| 739 // If we're deleting the last (non-legacy-supervised) profile, then create a | 737 // If we're deleting the last (non-legacy-supervised) profile, then create a |
| 740 // new profile in its place. | 738 // new profile in its place. |
| 741 base::FilePath last_non_supervised_profile_path; | 739 base::FilePath last_non_supervised_profile_path; |
| 742 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 740 std::vector<ProfileAttributesEntry*> entries = |
| 743 base::FilePath cur_path = cache.GetPathOfProfileAtIndex(i); | 741 storage.GetAllProfilesAttributes(); |
| 742 for (ProfileAttributesEntry* entry : entries) { |
| 743 base::FilePath cur_path = entry->GetPath(); |
| 744 // Make sure that this profile is not pending deletion, and is not | 744 // Make sure that this profile is not pending deletion, and is not |
| 745 // legacy-supervised. | 745 // legacy-supervised. |
| 746 if (cur_path != profile_dir && | 746 if (cur_path != profile_dir && |
| 747 !cache.ProfileIsLegacySupervisedAtIndex(i) && | 747 !entry->IsLegacySupervised() && |
| 748 !IsProfileMarkedForDeletion(cur_path)) { | 748 !IsProfileMarkedForDeletion(cur_path)) { |
| 749 last_non_supervised_profile_path = cur_path; | 749 last_non_supervised_profile_path = cur_path; |
| 750 break; | 750 break; |
| 751 } | 751 } |
| 752 } | 752 } |
| 753 | 753 |
| 754 if (last_non_supervised_profile_path.empty()) { | 754 if (last_non_supervised_profile_path.empty()) { |
| 755 std::string new_avatar_url; | 755 std::string new_avatar_url; |
| 756 base::string16 new_profile_name; | 756 base::string16 new_profile_name; |
| 757 | 757 |
| 758 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 758 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 759 int avatar_index = profiles::GetPlaceholderAvatarIndex(); | 759 int avatar_index = profiles::GetPlaceholderAvatarIndex(); |
| 760 new_avatar_url = profiles::GetDefaultAvatarIconUrl(avatar_index); | 760 new_avatar_url = profiles::GetDefaultAvatarIconUrl(avatar_index); |
| 761 new_profile_name = cache.ChooseNameForNewProfile(avatar_index); | 761 new_profile_name = storage.ChooseNameForNewProfile(avatar_index); |
| 762 #endif | 762 #endif |
| 763 | 763 |
| 764 base::FilePath new_path(GenerateNextProfileDirectoryPath()); | 764 base::FilePath new_path(GenerateNextProfileDirectoryPath()); |
| 765 CreateProfileAsync(new_path, | 765 CreateProfileAsync(new_path, |
| 766 base::Bind(&ProfileManager::OnNewActiveProfileLoaded, | 766 base::Bind(&ProfileManager::OnNewActiveProfileLoaded, |
| 767 base::Unretained(this), | 767 base::Unretained(this), |
| 768 profile_dir, | 768 profile_dir, |
| 769 new_path, | 769 new_path, |
| 770 callback), | 770 callback), |
| 771 new_profile_name, | 771 new_profile_name, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 void ProfileManager::AutoloadProfiles() { | 805 void ProfileManager::AutoloadProfiles() { |
| 806 // If running in the background is disabled for the browser, do not autoload | 806 // If running in the background is disabled for the browser, do not autoload |
| 807 // any profiles. | 807 // any profiles. |
| 808 PrefService* local_state = g_browser_process->local_state(); | 808 PrefService* local_state = g_browser_process->local_state(); |
| 809 DCHECK(local_state); | 809 DCHECK(local_state); |
| 810 if (!local_state->HasPrefPath(prefs::kBackgroundModeEnabled) || | 810 if (!local_state->HasPrefPath(prefs::kBackgroundModeEnabled) || |
| 811 !local_state->GetBoolean(prefs::kBackgroundModeEnabled)) { | 811 !local_state->GetBoolean(prefs::kBackgroundModeEnabled)) { |
| 812 return; | 812 return; |
| 813 } | 813 } |
| 814 | 814 |
| 815 ProfileInfoCache& cache = GetProfileInfoCache(); | 815 std::vector<ProfileAttributesEntry*> entries = |
| 816 size_t number_of_profiles = cache.GetNumberOfProfiles(); | 816 GetProfileAttributesStorage().GetAllProfilesAttributes(); |
| 817 for (size_t p = 0; p < number_of_profiles; ++p) { | 817 for (ProfileAttributesEntry* entry : entries) { |
| 818 if (cache.GetBackgroundStatusOfProfileAtIndex(p)) { | 818 if (entry->GetBackgroundStatus()) { |
| 819 // If status is true, that profile is running background apps. By calling | 819 // If status is true, that profile is running background apps. By calling |
| 820 // GetProfile, we automatically cause the profile to be loaded which will | 820 // GetProfile, we automatically cause the profile to be loaded which will |
| 821 // register it with the BackgroundModeManager. | 821 // register it with the BackgroundModeManager. |
| 822 GetProfile(cache.GetPathOfProfileAtIndex(p)); | 822 GetProfile(entry->GetPath()); |
| 823 } | 823 } |
| 824 } | 824 } |
| 825 } | 825 } |
| 826 | 826 |
| 827 void ProfileManager::CleanUpEphemeralProfiles() { | 827 void ProfileManager::CleanUpEphemeralProfiles() { |
| 828 const std::string last_used_profile = GetLastUsedProfileName(); | 828 const std::string last_used_profile = GetLastUsedProfileName(); |
| 829 | 829 |
| 830 bool last_active_profile_deleted = false; | 830 bool last_active_profile_deleted = false; |
| 831 base::FilePath new_profile_path; | 831 base::FilePath new_profile_path; |
| 832 std::vector<base::FilePath> profiles_to_delete; | 832 std::vector<base::FilePath> profiles_to_delete; |
| 833 ProfileInfoCache& profile_cache = GetProfileInfoCache(); | 833 ProfileAttributesStorage& storage = GetProfileAttributesStorage(); |
| 834 size_t profiles_count = profile_cache.GetNumberOfProfiles(); | 834 std::vector<ProfileAttributesEntry*> entries = |
| 835 for (size_t i = 0; i < profiles_count; ++i) { | 835 storage.GetAllProfilesAttributes(); |
| 836 base::FilePath profile_path = profile_cache.GetPathOfProfileAtIndex(i); | 836 for (ProfileAttributesEntry* entry : entries) { |
| 837 if (profile_cache.ProfileIsEphemeralAtIndex(i)) { | 837 base::FilePath profile_path = entry->GetPath(); |
| 838 if (entry->IsEphemeral()) { |
| 838 profiles_to_delete.push_back(profile_path); | 839 profiles_to_delete.push_back(profile_path); |
| 839 if (profile_path.BaseName().MaybeAsASCII() == last_used_profile) | 840 if (profile_path.BaseName().MaybeAsASCII() == last_used_profile) |
| 840 last_active_profile_deleted = true; | 841 last_active_profile_deleted = true; |
| 841 } else if (new_profile_path.empty()) { | 842 } else if (new_profile_path.empty()) { |
| 842 new_profile_path = profile_path; | 843 new_profile_path = profile_path; |
| 843 } | 844 } |
| 844 } | 845 } |
| 845 | 846 |
| 846 // If the last active profile was ephemeral, set a new one. | 847 // If the last active profile was ephemeral, set a new one. |
| 847 if (last_active_profile_deleted) { | 848 if (last_active_profile_deleted) { |
| 848 if (new_profile_path.empty()) | 849 if (new_profile_path.empty()) |
| 849 new_profile_path = GenerateNextProfileDirectoryPath(); | 850 new_profile_path = GenerateNextProfileDirectoryPath(); |
| 850 | 851 |
| 851 profiles::SetLastUsedProfile(new_profile_path.BaseName().MaybeAsASCII()); | 852 profiles::SetLastUsedProfile(new_profile_path.BaseName().MaybeAsASCII()); |
| 852 } | 853 } |
| 853 | 854 |
| 854 // This uses a separate loop, because deleting the profile from the | 855 // This uses a separate loop, because deleting the profile from the |
| 855 // ProfileInfoCache will modify indices. | 856 // ProfileInfoCache will modify indices. |
| 856 for (const base::FilePath& profile_path : profiles_to_delete) { | 857 for (const base::FilePath& profile_path : profiles_to_delete) { |
| 857 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 858 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 858 base::Bind(&NukeProfileFromDisk, profile_path)); | 859 base::Bind(&NukeProfileFromDisk, profile_path)); |
| 859 | 860 |
| 860 profile_cache.DeleteProfileFromCache(profile_path); | 861 storage.RemoveProfile(profile_path); |
| 861 } | 862 } |
| 862 } | 863 } |
| 863 | 864 |
| 864 void ProfileManager::InitProfileUserPrefs(Profile* profile) { | 865 void ProfileManager::InitProfileUserPrefs(Profile* profile) { |
| 865 TRACE_EVENT0("browser", "ProfileManager::InitProfileUserPrefs"); | 866 TRACE_EVENT0("browser", "ProfileManager::InitProfileUserPrefs"); |
| 866 ProfileInfoCache& cache = GetProfileInfoCache(); | 867 ProfileAttributesStorage& storage = GetProfileAttributesStorage(); |
| 867 | 868 |
| 868 if (profile->GetPath().DirName() != cache.GetUserDataDir()) | 869 if (profile->GetPath().DirName() != user_data_dir()) |
| 869 return; | 870 return; |
| 870 | 871 |
| 871 size_t avatar_index; | 872 size_t avatar_index; |
| 872 std::string profile_name; | 873 std::string profile_name; |
| 873 std::string supervised_user_id; | 874 std::string supervised_user_id; |
| 874 if (profile->IsGuestSession()) { | 875 if (profile->IsGuestSession()) { |
| 875 profile_name = l10n_util::GetStringUTF8(IDS_PROFILES_GUEST_PROFILE_NAME); | 876 profile_name = l10n_util::GetStringUTF8(IDS_PROFILES_GUEST_PROFILE_NAME); |
| 876 avatar_index = 0; | 877 avatar_index = 0; |
| 877 } else { | 878 } else { |
| 878 size_t profile_cache_index = | 879 ProfileAttributesEntry* entry; |
| 879 cache.GetIndexOfProfileWithPath(profile->GetPath()); | 880 bool has_entry = storage.GetProfileAttributesWithPath(profile->GetPath(), |
| 880 // If the cache has an entry for this profile, use the cache data. | 881 &entry); |
| 881 if (profile_cache_index != std::string::npos) { | 882 // If the profile attributes storage has an entry for this profile, use the |
| 882 avatar_index = | 883 // data in the profile attributes storage. |
| 883 cache.GetAvatarIconIndexOfProfileAtIndex(profile_cache_index); | 884 if (has_entry) { |
| 884 profile_name = | 885 avatar_index = entry->GetAvatarIconIndex(); |
| 885 base::UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_cache_index)); | 886 profile_name = base::UTF16ToUTF8(entry->GetName()); |
| 886 supervised_user_id = | 887 supervised_user_id = entry->GetSupervisedUserId(); |
| 887 cache.GetSupervisedUserIdOfProfileAtIndex(profile_cache_index); | |
| 888 } else if (profile->GetPath() == | 888 } else if (profile->GetPath() == |
| 889 profiles::GetDefaultProfileDir(cache.GetUserDataDir())) { | 889 profiles::GetDefaultProfileDir(user_data_dir())) { |
| 890 avatar_index = profiles::GetPlaceholderAvatarIndex(); | 890 avatar_index = profiles::GetPlaceholderAvatarIndex(); |
| 891 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 891 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 892 profile_name = | 892 profile_name = |
| 893 base::UTF16ToUTF8(cache.ChooseNameForNewProfile(avatar_index)); | 893 base::UTF16ToUTF8(storage.ChooseNameForNewProfile(avatar_index)); |
| 894 #else | 894 #else |
| 895 profile_name = l10n_util::GetStringUTF8(IDS_DEFAULT_PROFILE_NAME); | 895 profile_name = l10n_util::GetStringUTF8(IDS_DEFAULT_PROFILE_NAME); |
| 896 #endif | 896 #endif |
| 897 } else { | 897 } else { |
| 898 avatar_index = cache.ChooseAvatarIconIndexForNewProfile(); | 898 avatar_index = storage.ChooseAvatarIconIndexForNewProfile(); |
| 899 profile_name = | 899 profile_name = |
| 900 base::UTF16ToUTF8(cache.ChooseNameForNewProfile(avatar_index)); | 900 base::UTF16ToUTF8(storage.ChooseNameForNewProfile(avatar_index)); |
| 901 } | 901 } |
| 902 } | 902 } |
| 903 | 903 |
| 904 if (!profile->GetPrefs()->HasPrefPath(prefs::kProfileAvatarIndex)) | 904 if (!profile->GetPrefs()->HasPrefPath(prefs::kProfileAvatarIndex)) |
| 905 profile->GetPrefs()->SetInteger(prefs::kProfileAvatarIndex, avatar_index); | 905 profile->GetPrefs()->SetInteger(prefs::kProfileAvatarIndex, avatar_index); |
| 906 | 906 |
| 907 if (!profile->GetPrefs()->HasPrefPath(prefs::kProfileName)) | 907 if (!profile->GetPrefs()->HasPrefPath(prefs::kProfileName)) |
| 908 profile->GetPrefs()->SetString(prefs::kProfileName, profile_name); | 908 profile->GetPrefs()->SetString(prefs::kProfileName, profile_name); |
| 909 | 909 |
| 910 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 910 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 911 bool force_supervised_user_id = | 911 bool force_supervised_user_id = |
| 912 #if defined(OS_CHROMEOS) | 912 #if defined(OS_CHROMEOS) |
| 913 g_browser_process->platform_part() | 913 g_browser_process->platform_part() |
| 914 ->profile_helper() | 914 ->profile_helper() |
| 915 ->GetSigninProfileDir() != profile->GetPath() && | 915 ->GetSigninProfileDir() != profile->GetPath() && |
| 916 #endif | 916 #endif |
| 917 command_line->HasSwitch(switches::kSupervisedUserId); | 917 command_line->HasSwitch(switches::kSupervisedUserId); |
| 918 if (force_supervised_user_id) { | 918 if (force_supervised_user_id) { |
| 919 supervised_user_id = | 919 supervised_user_id = |
| 920 command_line->GetSwitchValueASCII(switches::kSupervisedUserId); | 920 command_line->GetSwitchValueASCII(switches::kSupervisedUserId); |
| 921 } | 921 } |
| 922 if (force_supervised_user_id || | 922 if (force_supervised_user_id || |
| 923 !profile->GetPrefs()->HasPrefPath(prefs::kSupervisedUserId)) { | 923 !profile->GetPrefs()->HasPrefPath(prefs::kSupervisedUserId)) { |
| 924 profile->GetPrefs()->SetString(prefs::kSupervisedUserId, | 924 profile->GetPrefs()->SetString(prefs::kSupervisedUserId, |
| 925 supervised_user_id); | 925 supervised_user_id); |
| 926 } | 926 } |
| 927 } | 927 } |
| 928 | 928 |
| 929 void ProfileManager::RegisterTestingProfile(Profile* profile, | 929 void ProfileManager::RegisterTestingProfile(Profile* profile, |
| 930 bool add_to_cache, | 930 bool add_to_storage, |
| 931 bool start_deferred_task_runners) { | 931 bool start_deferred_task_runners) { |
| 932 RegisterProfile(profile, true); | 932 RegisterProfile(profile, true); |
| 933 if (add_to_cache) { | 933 if (add_to_storage) { |
| 934 InitProfileUserPrefs(profile); | 934 InitProfileUserPrefs(profile); |
| 935 AddProfileToCache(profile); | 935 AddProfileToStorage(profile); |
| 936 } | 936 } |
| 937 if (start_deferred_task_runners) { | 937 if (start_deferred_task_runners) { |
| 938 StartupTaskRunnerServiceFactory::GetForProfile(profile)-> | 938 StartupTaskRunnerServiceFactory::GetForProfile(profile)-> |
| 939 StartDeferredTaskRunners(); | 939 StartDeferredTaskRunners(); |
| 940 } | 940 } |
| 941 } | 941 } |
| 942 | 942 |
| 943 void ProfileManager::Observe( | 943 void ProfileManager::Observe( |
| 944 int type, | 944 int type, |
| 945 const content::NotificationSource& source, | 945 const content::NotificationSource& source, |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1097 RunCallbacks(callbacks, profile, | 1097 RunCallbacks(callbacks, profile, |
| 1098 profile ? Profile::CREATE_STATUS_INITIALIZED : | 1098 profile ? Profile::CREATE_STATUS_INITIALIZED : |
| 1099 Profile::CREATE_STATUS_LOCAL_FAIL); | 1099 Profile::CREATE_STATUS_LOCAL_FAIL); |
| 1100 } | 1100 } |
| 1101 | 1101 |
| 1102 void ProfileManager::DoFinalInit(Profile* profile, bool go_off_the_record) { | 1102 void ProfileManager::DoFinalInit(Profile* profile, bool go_off_the_record) { |
| 1103 TRACE_EVENT0("browser", "ProfileManager::DoFinalInit"); | 1103 TRACE_EVENT0("browser", "ProfileManager::DoFinalInit"); |
| 1104 TRACK_SCOPED_REGION("Startup", "ProfileManager::DoFinalInit"); | 1104 TRACK_SCOPED_REGION("Startup", "ProfileManager::DoFinalInit"); |
| 1105 | 1105 |
| 1106 DoFinalInitForServices(profile, go_off_the_record); | 1106 DoFinalInitForServices(profile, go_off_the_record); |
| 1107 AddProfileToCache(profile); | 1107 AddProfileToStorage(profile); |
| 1108 DoFinalInitLogging(profile); | 1108 DoFinalInitLogging(profile); |
| 1109 | 1109 |
| 1110 ProfileMetrics::LogNumberOfProfiles(this); | 1110 ProfileMetrics::LogNumberOfProfiles(this); |
| 1111 content::NotificationService::current()->Notify( | 1111 content::NotificationService::current()->Notify( |
| 1112 chrome::NOTIFICATION_PROFILE_ADDED, | 1112 chrome::NOTIFICATION_PROFILE_ADDED, |
| 1113 content::Source<Profile>(profile), | 1113 content::Source<Profile>(profile), |
| 1114 content::NotificationService::NoDetails()); | 1114 content::NotificationService::NoDetails()); |
| 1115 | 1115 |
| 1116 #if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS) | 1116 #if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS) |
| 1117 // Record statistics to ProfileInfoCache if statistics were not recorded | 1117 // Record statistics to ProfileInfoCache if statistics were not recorded |
| 1118 // during shutdown, i.e. the last shutdown was a system shutdown or a crash. | 1118 // during shutdown, i.e. the last shutdown was a system shutdown or a crash. |
| 1119 if (!profile->IsGuestSession() && !profile->IsSystemProfile() && | 1119 if (!profile->IsGuestSession() && !profile->IsSystemProfile() && |
| 1120 !profile->IsNewProfile() && !go_off_the_record && | 1120 !profile->IsNewProfile() && !go_off_the_record && |
| 1121 profile->GetLastSessionExitType() != Profile::EXIT_NORMAL) { | 1121 profile->GetLastSessionExitType() != Profile::EXIT_NORMAL) { |
| 1122 ProfileStatisticsFactory::GetForProfile(profile)->GatherStatistics( | 1122 ProfileStatisticsFactory::GetForProfile(profile)->GatherStatistics( |
| 1123 profiles::ProfileStatisticsCallback()); | 1123 profiles::ProfileStatisticsCallback()); |
| 1124 } | 1124 } |
| 1125 #endif | 1125 #endif |
| 1126 } | 1126 } |
| 1127 | 1127 |
| 1128 void ProfileManager::DoFinalInitForServices(Profile* profile, | 1128 void ProfileManager::DoFinalInitForServices(Profile* profile, |
| 1129 bool go_off_the_record) { | 1129 bool go_off_the_record) { |
| 1130 TRACE_EVENT0("browser", "ProfileManager::DoFinalInitForServices"); | 1130 TRACE_EVENT0("browser", "ProfileManager::DoFinalInitForServices"); |
| 1131 TRACK_SCOPED_REGION("Startup", "ProfileManager::DoFinalInitForServices"); | 1131 TRACK_SCOPED_REGION("Startup", "ProfileManager::DoFinalInitForServices"); |
| 1132 | 1132 |
| 1133 #if defined(ENABLE_EXTENSIONS) | 1133 #if defined(ENABLE_EXTENSIONS) |
| 1134 ProfileInfoCache& cache = GetProfileInfoCache(); | |
| 1135 | |
| 1136 // Ensure that the HostContentSettingsMap has been created before the | 1134 // Ensure that the HostContentSettingsMap has been created before the |
| 1137 // ExtensionSystem is initialized otherwise the ExtensionSystem will be | 1135 // ExtensionSystem is initialized otherwise the ExtensionSystem will be |
| 1138 // registered twice | 1136 // registered twice |
| 1139 HostContentSettingsMap* content_settings_map = | 1137 HostContentSettingsMap* content_settings_map = |
| 1140 HostContentSettingsMapFactory::GetForProfile(profile); | 1138 HostContentSettingsMapFactory::GetForProfile(profile); |
| 1141 | 1139 |
| 1142 extensions::ExtensionSystem::Get(profile)->InitForRegularProfile( | 1140 extensions::ExtensionSystem::Get(profile)->InitForRegularProfile( |
| 1143 !go_off_the_record); | 1141 !go_off_the_record); |
| 1144 // During tests, when |profile| is an instance of TestingProfile, | 1142 // During tests, when |profile| is an instance of TestingProfile, |
| 1145 // ExtensionSystem might not create an ExtensionService. | 1143 // ExtensionSystem might not create an ExtensionService. |
| 1146 // This block is duplicated in the HostContentSettingsMapFactory | 1144 // This block is duplicated in the HostContentSettingsMapFactory |
| 1147 // ::BuildServiceInstanceFor method, it should be called once when both the | 1145 // ::BuildServiceInstanceFor method, it should be called once when both the |
| 1148 // HostContentSettingsMap and the extension_service are set up. | 1146 // HostContentSettingsMap and the extension_service are set up. |
| 1149 if (extensions::ExtensionSystem::Get(profile)->extension_service()) { | 1147 if (extensions::ExtensionSystem::Get(profile)->extension_service()) { |
| 1150 extensions::ExtensionSystem::Get(profile)->extension_service()-> | 1148 extensions::ExtensionSystem::Get(profile)->extension_service()-> |
| 1151 RegisterContentSettings(content_settings_map); | 1149 RegisterContentSettings(content_settings_map); |
| 1152 } | 1150 } |
| 1153 // Set the block extensions bit on the ExtensionService. There likely are no | 1151 // Set the block extensions bit on the ExtensionService. There likely are no |
| 1154 // blockable extensions to block. | 1152 // blockable extensions to block. |
| 1155 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 1153 ProfileAttributesEntry* entry; |
| 1156 if (profile_index != std::string::npos && | 1154 bool has_entry = GetProfileAttributesStorage(). |
| 1157 cache.ProfileIsSigninRequiredAtIndex(profile_index)) { | 1155 GetProfileAttributesWithPath(profile->GetPath(), &entry); |
| 1156 if (has_entry && entry->IsSigninRequired()) { |
| 1158 extensions::ExtensionSystem::Get(profile) | 1157 extensions::ExtensionSystem::Get(profile) |
| 1159 ->extension_service() | 1158 ->extension_service() |
| 1160 ->BlockAllExtensions(); | 1159 ->BlockAllExtensions(); |
| 1161 } | 1160 } |
| 1162 | 1161 |
| 1163 #endif | 1162 #endif |
| 1164 #if defined(ENABLE_SUPERVISED_USERS) | 1163 #if defined(ENABLE_SUPERVISED_USERS) |
| 1165 // Initialization needs to happen after extension system initialization (for | 1164 // Initialization needs to happen after extension system initialization (for |
| 1166 // extension::ManagementPolicy) and InitProfileUserPrefs (for setting the | 1165 // extension::ManagementPolicy) and InitProfileUserPrefs (for setting the |
| 1167 // initializing the supervised flag if necessary). | 1166 // initializing the supervised flag if necessary). |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1324 | 1323 |
| 1325 #if !defined(OS_ANDROID) | 1324 #if !defined(OS_ANDROID) |
| 1326 void ProfileManager::FinishDeletingProfile( | 1325 void ProfileManager::FinishDeletingProfile( |
| 1327 const base::FilePath& profile_dir, | 1326 const base::FilePath& profile_dir, |
| 1328 const base::FilePath& new_active_profile_dir) { | 1327 const base::FilePath& new_active_profile_dir) { |
| 1329 // Update the last used profile pref before closing browser windows. This | 1328 // Update the last used profile pref before closing browser windows. This |
| 1330 // way the correct last used profile is set for any notification observers. | 1329 // way the correct last used profile is set for any notification observers. |
| 1331 profiles::SetLastUsedProfile( | 1330 profiles::SetLastUsedProfile( |
| 1332 new_active_profile_dir.BaseName().MaybeAsASCII()); | 1331 new_active_profile_dir.BaseName().MaybeAsASCII()); |
| 1333 | 1332 |
| 1334 ProfileInfoCache& cache = GetProfileInfoCache(); | 1333 ProfileAttributesStorage& storage = GetProfileAttributesStorage(); |
| 1335 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we | 1334 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we |
| 1336 // start deleting the profile instance we need to close background apps too. | 1335 // start deleting the profile instance we need to close background apps too. |
| 1337 Profile* profile = GetProfileByPath(profile_dir); | 1336 Profile* profile = GetProfileByPath(profile_dir); |
| 1338 | 1337 |
| 1339 if (profile) { | 1338 if (profile) { |
| 1340 // TODO: Migrate additional code in this block to observe this notification | 1339 // TODO: Migrate additional code in this block to observe this notification |
| 1341 // instead of being implemented here. | 1340 // instead of being implemented here. |
| 1342 content::NotificationService::current()->Notify( | 1341 content::NotificationService::current()->Notify( |
| 1343 chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, | 1342 chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, |
| 1344 content::Source<Profile>(profile), | 1343 content::Source<Profile>(profile), |
| 1345 content::NotificationService::NoDetails()); | 1344 content::NotificationService::NoDetails()); |
| 1346 | 1345 |
| 1347 // By this point, all in-progress downloads for the profile being deleted | 1346 // By this point, all in-progress downloads for the profile being deleted |
| 1348 // must have been canceled (crbug.com/336725). | 1347 // must have been canceled (crbug.com/336725). |
| 1349 DCHECK(DownloadServiceFactory::GetForBrowserContext(profile)-> | 1348 DCHECK(DownloadServiceFactory::GetForBrowserContext(profile)-> |
| 1350 NonMaliciousDownloadCount() == 0); | 1349 NonMaliciousDownloadCount() == 0); |
| 1351 BrowserList::CloseAllBrowsersWithProfile(profile); | 1350 BrowserList::CloseAllBrowsersWithProfile(profile); |
| 1352 | 1351 |
| 1353 // Disable sync for doomed profile. | 1352 // Disable sync for doomed profile. |
| 1354 if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( | 1353 if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( |
| 1355 profile)) { | 1354 profile)) { |
| 1356 ProfileSyncService* sync_service = | 1355 ProfileSyncService* sync_service = |
| 1357 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); | 1356 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); |
| 1358 if (sync_service->IsSyncRequested()) { | 1357 if (sync_service->IsSyncRequested()) { |
| 1359 // Record sync stopped by profile destruction if it was on before. | 1358 // Record sync stopped by profile destruction if it was on before. |
| 1360 UMA_HISTOGRAM_ENUMERATION("Sync.StopSource", | 1359 UMA_HISTOGRAM_ENUMERATION("Sync.StopSource", |
| 1361 syncer::PROFILE_DESTRUCTION, | 1360 syncer::PROFILE_DESTRUCTION, |
| 1362 syncer::STOP_SOURCE_LIMIT); | 1361 syncer::STOP_SOURCE_LIMIT); |
| 1363 } | 1362 } |
| 1364 // Ensure data is cleared even if sync was already off. | 1363 // Ensure data is cleared even if sync was already off. |
| 1365 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 1364 ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| 1366 profile)->RequestStop(ProfileSyncService::CLEAR_DATA); | 1365 profile)->RequestStop(ProfileSyncService::CLEAR_DATA); |
| 1367 } | 1366 } |
| 1368 | 1367 |
| 1369 ProfileMetrics::LogProfileDelete(cache.ProfileIsAuthenticatedAtIndex( | 1368 ProfileAttributesEntry* entry; |
| 1370 cache.GetIndexOfProfileWithPath(profile_dir))); | 1369 bool has_entry = storage.GetProfileAttributesWithPath(profile_dir, &entry); |
| 1370 DCHECK(has_entry); |
| 1371 ProfileMetrics::LogProfileDelete(entry->IsAuthenticated()); |
| 1371 // Some platforms store passwords in keychains. They should be removed. | 1372 // Some platforms store passwords in keychains. They should be removed. |
| 1372 scoped_refptr<password_manager::PasswordStore> password_store = | 1373 scoped_refptr<password_manager::PasswordStore> password_store = |
| 1373 PasswordStoreFactory::GetForProfile( | 1374 PasswordStoreFactory::GetForProfile( |
| 1374 profile, ServiceAccessType::EXPLICIT_ACCESS).get(); | 1375 profile, ServiceAccessType::EXPLICIT_ACCESS).get(); |
| 1375 if (password_store.get()) { | 1376 if (password_store.get()) { |
| 1376 password_store->RemoveLoginsCreatedBetween( | 1377 password_store->RemoveLoginsCreatedBetween( |
| 1377 base::Time(), base::Time::Max(), base::Closure()); | 1378 base::Time(), base::Time::Max(), base::Closure()); |
| 1378 } | 1379 } |
| 1379 | 1380 |
| 1380 // The Profile Data doesn't get wiped until Chrome closes. Since we promised | 1381 // The Profile Data doesn't get wiped until Chrome closes. Since we promised |
| 1381 // that the user's data would be removed, do so immediately. | 1382 // that the user's data would be removed, do so immediately. |
| 1382 profiles::RemoveBrowsingDataForProfile(profile_dir); | 1383 profiles::RemoveBrowsingDataForProfile(profile_dir); |
| 1383 } else { | 1384 } else { |
| 1384 // It is safe to delete a not yet loaded Profile from disk. | 1385 // It is safe to delete a not yet loaded Profile from disk. |
| 1385 BrowserThread::PostTask( | 1386 BrowserThread::PostTask( |
| 1386 BrowserThread::FILE, FROM_HERE, | 1387 BrowserThread::FILE, FROM_HERE, |
| 1387 base::Bind(&NukeProfileFromDisk, profile_dir)); | 1388 base::Bind(&NukeProfileFromDisk, profile_dir)); |
| 1388 } | 1389 } |
| 1389 | 1390 |
| 1390 // Queue even a profile that was nuked so it will be MarkedForDeletion and so | 1391 // Queue even a profile that was nuked so it will be MarkedForDeletion and so |
| 1391 // CreateProfileAsync can't create it. | 1392 // CreateProfileAsync can't create it. |
| 1392 QueueProfileDirectoryForDeletion(profile_dir); | 1393 QueueProfileDirectoryForDeletion(profile_dir); |
| 1393 cache.DeleteProfileFromCache(profile_dir); | 1394 storage.RemoveProfile(profile_dir); |
| 1394 ProfileMetrics::UpdateReportedProfilesStatistics(this); | 1395 ProfileMetrics::UpdateReportedProfilesStatistics(this); |
| 1395 } | 1396 } |
| 1396 #endif // !defined(OS_ANDROID) | 1397 #endif // !defined(OS_ANDROID) |
| 1397 | 1398 |
| 1398 ProfileManager::ProfileInfo* ProfileManager::RegisterProfile( | 1399 ProfileManager::ProfileInfo* ProfileManager::RegisterProfile( |
| 1399 Profile* profile, | 1400 Profile* profile, |
| 1400 bool created) { | 1401 bool created) { |
| 1401 TRACE_EVENT0("browser", "ProfileManager::RegisterProfile"); | 1402 TRACE_EVENT0("browser", "ProfileManager::RegisterProfile"); |
| 1402 ProfileInfo* info = new ProfileInfo(profile, created); | 1403 ProfileInfo* info = new ProfileInfo(profile, created); |
| 1403 profiles_info_.insert( | 1404 profiles_info_.insert( |
| 1404 std::make_pair(profile->GetPath(), linked_ptr<ProfileInfo>(info))); | 1405 std::make_pair(profile->GetPath(), linked_ptr<ProfileInfo>(info))); |
| 1405 return info; | 1406 return info; |
| 1406 } | 1407 } |
| 1407 | 1408 |
| 1408 ProfileManager::ProfileInfo* ProfileManager::GetProfileInfoByPath( | 1409 ProfileManager::ProfileInfo* ProfileManager::GetProfileInfoByPath( |
| 1409 const base::FilePath& path) const { | 1410 const base::FilePath& path) const { |
| 1410 ProfilesInfoMap::const_iterator iter = profiles_info_.find(path); | 1411 ProfilesInfoMap::const_iterator iter = profiles_info_.find(path); |
| 1411 return (iter == profiles_info_.end()) ? NULL : iter->second.get(); | 1412 return (iter == profiles_info_.end()) ? NULL : iter->second.get(); |
| 1412 } | 1413 } |
| 1413 | 1414 |
| 1414 void ProfileManager::AddProfileToCache(Profile* profile) { | 1415 void ProfileManager::AddProfileToStorage(Profile* profile) { |
| 1415 TRACE_EVENT0("browser", "ProfileManager::AddProfileToCache"); | 1416 TRACE_EVENT0("browser", "ProfileManager::AddProfileToCache"); |
| 1416 if (profile->IsGuestSession() || profile->IsSystemProfile()) | 1417 if (profile->IsGuestSession() || profile->IsSystemProfile()) |
| 1417 return; | 1418 return; |
| 1418 ProfileInfoCache& cache = GetProfileInfoCache(); | 1419 if (profile->GetPath().DirName() != user_data_dir()) |
| 1419 if (profile->GetPath().DirName() != cache.GetUserDataDir()) | |
| 1420 return; | 1420 return; |
| 1421 | 1421 |
| 1422 SigninManagerBase* signin_manager = | 1422 SigninManagerBase* signin_manager = |
| 1423 SigninManagerFactory::GetForProfile(profile); | 1423 SigninManagerFactory::GetForProfile(profile); |
| 1424 AccountTrackerService* account_tracker = | 1424 AccountTrackerService* account_tracker = |
| 1425 AccountTrackerServiceFactory::GetForProfile(profile); | 1425 AccountTrackerServiceFactory::GetForProfile(profile); |
| 1426 AccountInfo account_info = account_tracker->GetAccountInfo( | 1426 AccountInfo account_info = account_tracker->GetAccountInfo( |
| 1427 signin_manager->GetAuthenticatedAccountId()); | 1427 signin_manager->GetAuthenticatedAccountId()); |
| 1428 base::string16 username = base::UTF8ToUTF16(account_info.email); | 1428 base::string16 username = base::UTF8ToUTF16(account_info.email); |
| 1429 | 1429 |
| 1430 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 1430 ProfileAttributesStorage& storage = GetProfileAttributesStorage(); |
| 1431 if (profile_index != std::string::npos) { | 1431 { |
| 1432 // The ProfileInfoCache's info must match the Signin Manager. | 1432 ProfileAttributesEntry* entry; |
| 1433 cache.SetAuthInfoOfProfileAtIndex(profile_index, account_info.gaia, | 1433 bool has_entry = storage.GetProfileAttributesWithPath(profile->GetPath(), |
| 1434 username); | 1434 &entry); |
| 1435 return; | 1435 if (has_entry) { |
| 1436 // The ProfileAttributesStorage's info must match the Signin Manager. |
| 1437 entry->SetAuthInfo(account_info.gaia, username); |
| 1438 return; |
| 1439 } |
| 1436 } | 1440 } |
| 1437 | 1441 |
| 1438 // Profile name and avatar are set by InitProfileUserPrefs and stored in the | 1442 // Profile name and avatar are set by InitProfileUserPrefs and stored in the |
| 1439 // profile. Use those values to setup the cache entry. | 1443 // profile. Use those values to setup the entry in profile attributes storage. |
| 1440 base::string16 profile_name = | 1444 base::string16 profile_name = |
| 1441 base::UTF8ToUTF16(profile->GetPrefs()->GetString(prefs::kProfileName)); | 1445 base::UTF8ToUTF16(profile->GetPrefs()->GetString(prefs::kProfileName)); |
| 1442 | 1446 |
| 1443 size_t icon_index = profile->GetPrefs()->GetInteger( | 1447 size_t icon_index = |
| 1444 prefs::kProfileAvatarIndex); | 1448 profile->GetPrefs()->GetInteger(prefs::kProfileAvatarIndex); |
| 1445 | 1449 |
| 1446 std::string supervised_user_id = | 1450 std::string supervised_user_id = |
| 1447 profile->GetPrefs()->GetString(prefs::kSupervisedUserId); | 1451 profile->GetPrefs()->GetString(prefs::kSupervisedUserId); |
| 1448 | 1452 |
| 1449 cache.AddProfileToCache(profile->GetPath(), | 1453 storage.AddProfile(profile->GetPath(), profile_name, account_info.gaia, |
| 1450 profile_name, | 1454 username, icon_index, supervised_user_id); |
| 1451 account_info.gaia, | |
| 1452 username, | |
| 1453 icon_index, | |
| 1454 supervised_user_id); | |
| 1455 | 1455 |
| 1456 if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) { | 1456 if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) { |
| 1457 cache.SetProfileIsEphemeralAtIndex( | 1457 ProfileAttributesEntry* entry; |
| 1458 cache.GetIndexOfProfileWithPath(profile->GetPath()), true); | 1458 bool has_entry = storage.GetProfileAttributesWithPath(profile->GetPath(), |
| 1459 &entry); |
| 1460 DCHECK(has_entry); |
| 1461 entry->SetIsEphemeral(true); |
| 1459 } | 1462 } |
| 1460 } | 1463 } |
| 1461 | 1464 |
| 1462 void ProfileManager::SetNonPersonalProfilePrefs(Profile* profile) { | 1465 void ProfileManager::SetNonPersonalProfilePrefs(Profile* profile) { |
| 1463 PrefService* prefs = profile->GetPrefs(); | 1466 PrefService* prefs = profile->GetPrefs(); |
| 1464 prefs->SetBoolean(prefs::kSigninAllowed, false); | 1467 prefs->SetBoolean(prefs::kSigninAllowed, false); |
| 1465 prefs->SetBoolean(bookmarks::prefs::kEditBookmarksEnabled, false); | 1468 prefs->SetBoolean(bookmarks::prefs::kEditBookmarksEnabled, false); |
| 1466 prefs->SetBoolean(bookmarks::prefs::kShowBookmarkBar, false); | 1469 prefs->SetBoolean(bookmarks::prefs::kShowBookmarkBar, false); |
| 1467 prefs->ClearPref(DefaultSearchManager::kDefaultSearchProviderDataPrefName); | 1470 prefs->ClearPref(DefaultSearchManager::kDefaultSearchProviderDataPrefName); |
| 1468 } | 1471 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1500 DCHECK(local_state); | 1503 DCHECK(local_state); |
| 1501 // Only keep track of profiles that we are managing; tests may create others. | 1504 // Only keep track of profiles that we are managing; tests may create others. |
| 1502 // Also never consider the SystemProfile as "active". | 1505 // Also never consider the SystemProfile as "active". |
| 1503 if (profiles_info_.find(last_active->GetPath()) != profiles_info_.end() && | 1506 if (profiles_info_.find(last_active->GetPath()) != profiles_info_.end() && |
| 1504 !last_active->IsSystemProfile()) { | 1507 !last_active->IsSystemProfile()) { |
| 1505 std::string profile_path_base = | 1508 std::string profile_path_base = |
| 1506 last_active->GetPath().BaseName().MaybeAsASCII(); | 1509 last_active->GetPath().BaseName().MaybeAsASCII(); |
| 1507 if (profile_path_base != GetLastUsedProfileName()) | 1510 if (profile_path_base != GetLastUsedProfileName()) |
| 1508 profiles::SetLastUsedProfile(profile_path_base); | 1511 profiles::SetLastUsedProfile(profile_path_base); |
| 1509 | 1512 |
| 1510 ProfileInfoCache& cache = GetProfileInfoCache(); | 1513 ProfileAttributesEntry* entry; |
| 1511 size_t profile_index = | 1514 if (GetProfileAttributesStorage(). |
| 1512 cache.GetIndexOfProfileWithPath(last_active->GetPath()); | 1515 GetProfileAttributesWithPath(last_active->GetPath(), &entry)) { |
| 1513 if (profile_index != std::string::npos) { | |
| 1514 #if !defined(OS_CHROMEOS) | 1516 #if !defined(OS_CHROMEOS) |
| 1515 // Incognito Profiles don't have ProfileKeyedServices. | 1517 // Incognito Profiles don't have ProfileKeyedServices. |
| 1516 if (!last_active->IsOffTheRecord()) { | 1518 if (!last_active->IsOffTheRecord()) { |
| 1517 CrossDevicePromoFactory::GetForProfile(last_active) | 1519 CrossDevicePromoFactory::GetForProfile(last_active)-> |
| 1518 ->MaybeBrowsingSessionStarted( | 1520 MaybeBrowsingSessionStarted(entry->GetActiveTime()); |
| 1519 cache.GetProfileActiveTimeAtIndex(profile_index)); | |
| 1520 } | 1521 } |
| 1521 #endif | 1522 #endif |
| 1522 cache.SetProfileActiveTimeAtIndex(profile_index); | 1523 entry->SetActiveTimeToNow(); |
| 1523 } | 1524 } |
| 1524 } | 1525 } |
| 1525 } | 1526 } |
| 1526 | 1527 |
| 1527 ProfileManager::BrowserListObserver::BrowserListObserver( | 1528 ProfileManager::BrowserListObserver::BrowserListObserver( |
| 1528 ProfileManager* manager) | 1529 ProfileManager* manager) |
| 1529 : profile_manager_(manager) { | 1530 : profile_manager_(manager) { |
| 1530 BrowserList::AddObserver(this); | 1531 BrowserList::AddObserver(this); |
| 1531 } | 1532 } |
| 1532 | 1533 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1609 | 1610 |
| 1610 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); | 1611 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); |
| 1611 if (!original_callback.is_null()) | 1612 if (!original_callback.is_null()) |
| 1612 original_callback.Run(loaded_profile, status); | 1613 original_callback.Run(loaded_profile, status); |
| 1613 } | 1614 } |
| 1614 #endif // !defined(OS_ANDROID) | 1615 #endif // !defined(OS_ANDROID) |
| 1615 | 1616 |
| 1616 ProfileManagerWithoutInit::ProfileManagerWithoutInit( | 1617 ProfileManagerWithoutInit::ProfileManagerWithoutInit( |
| 1617 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { | 1618 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { |
| 1618 } | 1619 } |
| OLD | NEW |