| 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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 // Cancel all in-progress downloads before deleting the profile to prevent a | 734 // Cancel all in-progress downloads before deleting the profile to prevent a |
| 736 // "Do you want to exit Google Chrome and cancel the downloads?" prompt | 735 // "Do you want to exit Google Chrome and cancel the downloads?" prompt |
| 737 // (crbug.com/336725). | 736 // (crbug.com/336725). |
| 738 Profile* profile = GetProfileByPath(profile_dir); | 737 Profile* profile = GetProfileByPath(profile_dir); |
| 739 if (profile) { | 738 if (profile) { |
| 740 DownloadService* service = | 739 DownloadService* service = |
| 741 DownloadServiceFactory::GetForBrowserContext(profile); | 740 DownloadServiceFactory::GetForBrowserContext(profile); |
| 742 service->CancelDownloads(); | 741 service->CancelDownloads(); |
| 743 } | 742 } |
| 744 | 743 |
| 745 ProfileInfoCache& cache = GetProfileInfoCache(); | 744 ProfileAttributesStorage& storage = GetProfileAttributesStorage(); |
| 746 | |
| 747 // If we're deleting the last (non-legacy-supervised) profile, then create a | 745 // If we're deleting the last (non-legacy-supervised) profile, then create a |
| 748 // new profile in its place. | 746 // new profile in its place. |
| 749 base::FilePath last_non_supervised_profile_path; | 747 base::FilePath last_non_supervised_profile_path; |
| 750 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 748 std::vector<ProfileAttributesEntry*> entries = |
| 751 base::FilePath cur_path = cache.GetPathOfProfileAtIndex(i); | 749 storage.GetAllProfilesAttributes(); |
| 750 for (ProfileAttributesEntry* entry : entries) { |
| 751 base::FilePath cur_path = entry->GetPath(); |
| 752 // Make sure that this profile is not pending deletion, and is not | 752 // Make sure that this profile is not pending deletion, and is not |
| 753 // legacy-supervised. | 753 // legacy-supervised. |
| 754 if (cur_path != profile_dir && | 754 if (cur_path != profile_dir && |
| 755 !cache.ProfileIsLegacySupervisedAtIndex(i) && | 755 !entry->IsLegacySupervised() && |
| 756 !IsProfileMarkedForDeletion(cur_path)) { | 756 !IsProfileMarkedForDeletion(cur_path)) { |
| 757 last_non_supervised_profile_path = cur_path; | 757 last_non_supervised_profile_path = cur_path; |
| 758 break; | 758 break; |
| 759 } | 759 } |
| 760 } | 760 } |
| 761 | 761 |
| 762 if (last_non_supervised_profile_path.empty()) { | 762 if (last_non_supervised_profile_path.empty()) { |
| 763 std::string new_avatar_url; | 763 std::string new_avatar_url; |
| 764 base::string16 new_profile_name; | 764 base::string16 new_profile_name; |
| 765 | 765 |
| 766 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 766 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 767 int avatar_index = profiles::GetPlaceholderAvatarIndex(); | 767 int avatar_index = profiles::GetPlaceholderAvatarIndex(); |
| 768 new_avatar_url = profiles::GetDefaultAvatarIconUrl(avatar_index); | 768 new_avatar_url = profiles::GetDefaultAvatarIconUrl(avatar_index); |
| 769 new_profile_name = cache.ChooseNameForNewProfile(avatar_index); | 769 new_profile_name = storage.ChooseNameForNewProfile(avatar_index); |
| 770 #endif | 770 #endif |
| 771 | 771 |
| 772 base::FilePath new_path(GenerateNextProfileDirectoryPath()); | 772 base::FilePath new_path(GenerateNextProfileDirectoryPath()); |
| 773 CreateProfileAsync(new_path, | 773 CreateProfileAsync(new_path, |
| 774 base::Bind(&ProfileManager::OnNewActiveProfileLoaded, | 774 base::Bind(&ProfileManager::OnNewActiveProfileLoaded, |
| 775 base::Unretained(this), | 775 base::Unretained(this), |
| 776 profile_dir, | 776 profile_dir, |
| 777 new_path, | 777 new_path, |
| 778 callback), | 778 callback), |
| 779 new_profile_name, | 779 new_profile_name, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 void ProfileManager::AutoloadProfiles() { | 813 void ProfileManager::AutoloadProfiles() { |
| 814 // If running in the background is disabled for the browser, do not autoload | 814 // If running in the background is disabled for the browser, do not autoload |
| 815 // any profiles. | 815 // any profiles. |
| 816 PrefService* local_state = g_browser_process->local_state(); | 816 PrefService* local_state = g_browser_process->local_state(); |
| 817 DCHECK(local_state); | 817 DCHECK(local_state); |
| 818 if (!local_state->HasPrefPath(prefs::kBackgroundModeEnabled) || | 818 if (!local_state->HasPrefPath(prefs::kBackgroundModeEnabled) || |
| 819 !local_state->GetBoolean(prefs::kBackgroundModeEnabled)) { | 819 !local_state->GetBoolean(prefs::kBackgroundModeEnabled)) { |
| 820 return; | 820 return; |
| 821 } | 821 } |
| 822 | 822 |
| 823 ProfileInfoCache& cache = GetProfileInfoCache(); | 823 std::vector<ProfileAttributesEntry*> entries = |
| 824 size_t number_of_profiles = cache.GetNumberOfProfiles(); | 824 GetProfileAttributesStorage().GetAllProfilesAttributes(); |
| 825 for (size_t p = 0; p < number_of_profiles; ++p) { | 825 for (ProfileAttributesEntry* entry : entries) { |
| 826 if (cache.GetBackgroundStatusOfProfileAtIndex(p)) { | 826 if (entry->GetBackgroundStatus()) { |
| 827 // If status is true, that profile is running background apps. By calling | 827 // If status is true, that profile is running background apps. By calling |
| 828 // GetProfile, we automatically cause the profile to be loaded which will | 828 // GetProfile, we automatically cause the profile to be loaded which will |
| 829 // register it with the BackgroundModeManager. | 829 // register it with the BackgroundModeManager. |
| 830 GetProfile(cache.GetPathOfProfileAtIndex(p)); | 830 GetProfile(entry->GetPath()); |
| 831 } | 831 } |
| 832 } | 832 } |
| 833 } | 833 } |
| 834 | 834 |
| 835 void ProfileManager::CleanUpEphemeralProfiles() { | 835 void ProfileManager::CleanUpEphemeralProfiles() { |
| 836 const std::string last_used_profile = GetLastUsedProfileName(); | 836 const std::string last_used_profile = GetLastUsedProfileName(); |
| 837 | 837 |
| 838 bool last_active_profile_deleted = false; | 838 bool last_active_profile_deleted = false; |
| 839 base::FilePath new_profile_path; | 839 base::FilePath new_profile_path; |
| 840 std::vector<base::FilePath> profiles_to_delete; | 840 std::vector<base::FilePath> profiles_to_delete; |
| 841 ProfileInfoCache& profile_cache = GetProfileInfoCache(); | 841 ProfileAttributesStorage& storage = GetProfileAttributesStorage(); |
| 842 size_t profiles_count = profile_cache.GetNumberOfProfiles(); | 842 std::vector<ProfileAttributesEntry*> entries = |
| 843 for (size_t i = 0; i < profiles_count; ++i) { | 843 storage.GetAllProfilesAttributes(); |
| 844 base::FilePath profile_path = profile_cache.GetPathOfProfileAtIndex(i); | 844 for (ProfileAttributesEntry* entry : entries) { |
| 845 if (profile_cache.ProfileIsEphemeralAtIndex(i)) { | 845 base::FilePath profile_path = entry->GetPath(); |
| 846 if (entry->IsEphemeral()) { |
| 846 profiles_to_delete.push_back(profile_path); | 847 profiles_to_delete.push_back(profile_path); |
| 847 if (profile_path.BaseName().MaybeAsASCII() == last_used_profile) | 848 if (profile_path.BaseName().MaybeAsASCII() == last_used_profile) |
| 848 last_active_profile_deleted = true; | 849 last_active_profile_deleted = true; |
| 849 } else if (new_profile_path.empty()) { | 850 } else if (new_profile_path.empty()) { |
| 850 new_profile_path = profile_path; | 851 new_profile_path = profile_path; |
| 851 } | 852 } |
| 852 } | 853 } |
| 853 | 854 |
| 854 // If the last active profile was ephemeral, set a new one. | 855 // If the last active profile was ephemeral, set a new one. |
| 855 if (last_active_profile_deleted) { | 856 if (last_active_profile_deleted) { |
| 856 if (new_profile_path.empty()) | 857 if (new_profile_path.empty()) |
| 857 new_profile_path = GenerateNextProfileDirectoryPath(); | 858 new_profile_path = GenerateNextProfileDirectoryPath(); |
| 858 | 859 |
| 859 profiles::SetLastUsedProfile(new_profile_path.BaseName().MaybeAsASCII()); | 860 profiles::SetLastUsedProfile(new_profile_path.BaseName().MaybeAsASCII()); |
| 860 } | 861 } |
| 861 | 862 |
| 862 // This uses a separate loop, because deleting the profile from the | 863 // This uses a separate loop, because deleting the profile from the |
| 863 // ProfileInfoCache will modify indices. | 864 // ProfileInfoCache will modify indices. |
| 864 for (const base::FilePath& profile_path : profiles_to_delete) { | 865 for (const base::FilePath& profile_path : profiles_to_delete) { |
| 865 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 866 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 866 base::Bind(&NukeProfileFromDisk, profile_path)); | 867 base::Bind(&NukeProfileFromDisk, profile_path)); |
| 867 | 868 |
| 868 profile_cache.DeleteProfileFromCache(profile_path); | 869 storage.RemoveProfile(profile_path); |
| 869 } | 870 } |
| 870 } | 871 } |
| 871 | 872 |
| 872 void ProfileManager::InitProfileUserPrefs(Profile* profile) { | 873 void ProfileManager::InitProfileUserPrefs(Profile* profile) { |
| 873 TRACE_EVENT0("browser", "ProfileManager::InitProfileUserPrefs"); | 874 TRACE_EVENT0("browser", "ProfileManager::InitProfileUserPrefs"); |
| 874 ProfileInfoCache& cache = GetProfileInfoCache(); | 875 ProfileAttributesStorage& storage = GetProfileAttributesStorage(); |
| 875 | 876 |
| 876 if (profile->GetPath().DirName() != cache.GetUserDataDir()) | 877 if (profile->GetPath().DirName() != user_data_dir()) { |
| 878 UMA_HISTOGRAM_BOOLEAN("Profile.InitProfileUserPrefs.OutsideUserDir", true); |
| 877 return; | 879 return; |
| 880 } |
| 878 | 881 |
| 879 size_t avatar_index; | 882 size_t avatar_index; |
| 880 std::string profile_name; | 883 std::string profile_name; |
| 881 std::string supervised_user_id; | 884 std::string supervised_user_id; |
| 882 if (profile->IsGuestSession()) { | 885 if (profile->IsGuestSession()) { |
| 883 profile_name = l10n_util::GetStringUTF8(IDS_PROFILES_GUEST_PROFILE_NAME); | 886 profile_name = l10n_util::GetStringUTF8(IDS_PROFILES_GUEST_PROFILE_NAME); |
| 884 avatar_index = 0; | 887 avatar_index = 0; |
| 885 } else { | 888 } else { |
| 886 size_t profile_cache_index = | 889 ProfileAttributesEntry* entry; |
| 887 cache.GetIndexOfProfileWithPath(profile->GetPath()); | 890 bool has_entry = storage.GetProfileAttributesWithPath(profile->GetPath(), |
| 888 // If the cache has an entry for this profile, use the cache data. | 891 &entry); |
| 889 if (profile_cache_index != std::string::npos) { | 892 // If the profile attributes storage has an entry for this profile, use the |
| 890 avatar_index = | 893 // data in the profile attributes storage. |
| 891 cache.GetAvatarIconIndexOfProfileAtIndex(profile_cache_index); | 894 if (has_entry) { |
| 892 profile_name = | 895 avatar_index = entry->GetAvatarIconIndex(); |
| 893 base::UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_cache_index)); | 896 profile_name = base::UTF16ToUTF8(entry->GetName()); |
| 894 supervised_user_id = | 897 supervised_user_id = entry->GetSupervisedUserId(); |
| 895 cache.GetSupervisedUserIdOfProfileAtIndex(profile_cache_index); | |
| 896 } else if (profile->GetPath() == | 898 } else if (profile->GetPath() == |
| 897 profiles::GetDefaultProfileDir(cache.GetUserDataDir())) { | 899 profiles::GetDefaultProfileDir(user_data_dir())) { |
| 898 avatar_index = profiles::GetPlaceholderAvatarIndex(); | 900 avatar_index = profiles::GetPlaceholderAvatarIndex(); |
| 899 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 901 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 900 profile_name = | 902 profile_name = |
| 901 base::UTF16ToUTF8(cache.ChooseNameForNewProfile(avatar_index)); | 903 base::UTF16ToUTF8(storage.ChooseNameForNewProfile(avatar_index)); |
| 902 #else | 904 #else |
| 903 profile_name = l10n_util::GetStringUTF8(IDS_DEFAULT_PROFILE_NAME); | 905 profile_name = l10n_util::GetStringUTF8(IDS_DEFAULT_PROFILE_NAME); |
| 904 #endif | 906 #endif |
| 905 } else { | 907 } else { |
| 906 avatar_index = cache.ChooseAvatarIconIndexForNewProfile(); | 908 avatar_index = storage.ChooseAvatarIconIndexForNewProfile(); |
| 907 profile_name = | 909 profile_name = |
| 908 base::UTF16ToUTF8(cache.ChooseNameForNewProfile(avatar_index)); | 910 base::UTF16ToUTF8(storage.ChooseNameForNewProfile(avatar_index)); |
| 909 } | 911 } |
| 910 } | 912 } |
| 911 | 913 |
| 912 if (!profile->GetPrefs()->HasPrefPath(prefs::kProfileAvatarIndex)) | 914 if (!profile->GetPrefs()->HasPrefPath(prefs::kProfileAvatarIndex)) |
| 913 profile->GetPrefs()->SetInteger(prefs::kProfileAvatarIndex, avatar_index); | 915 profile->GetPrefs()->SetInteger(prefs::kProfileAvatarIndex, avatar_index); |
| 914 | 916 |
| 915 if (!profile->GetPrefs()->HasPrefPath(prefs::kProfileName)) | 917 if (!profile->GetPrefs()->HasPrefPath(prefs::kProfileName)) |
| 916 profile->GetPrefs()->SetString(prefs::kProfileName, profile_name); | 918 profile->GetPrefs()->SetString(prefs::kProfileName, profile_name); |
| 917 | 919 |
| 918 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 920 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 919 bool force_supervised_user_id = | 921 bool force_supervised_user_id = |
| 920 #if defined(OS_CHROMEOS) | 922 #if defined(OS_CHROMEOS) |
| 921 g_browser_process->platform_part() | 923 g_browser_process->platform_part() |
| 922 ->profile_helper() | 924 ->profile_helper() |
| 923 ->GetSigninProfileDir() != profile->GetPath() && | 925 ->GetSigninProfileDir() != profile->GetPath() && |
| 924 #endif | 926 #endif |
| 925 command_line->HasSwitch(switches::kSupervisedUserId); | 927 command_line->HasSwitch(switches::kSupervisedUserId); |
| 926 if (force_supervised_user_id) { | 928 if (force_supervised_user_id) { |
| 927 supervised_user_id = | 929 supervised_user_id = |
| 928 command_line->GetSwitchValueASCII(switches::kSupervisedUserId); | 930 command_line->GetSwitchValueASCII(switches::kSupervisedUserId); |
| 929 } | 931 } |
| 930 if (force_supervised_user_id || | 932 if (force_supervised_user_id || |
| 931 !profile->GetPrefs()->HasPrefPath(prefs::kSupervisedUserId)) { | 933 !profile->GetPrefs()->HasPrefPath(prefs::kSupervisedUserId)) { |
| 932 profile->GetPrefs()->SetString(prefs::kSupervisedUserId, | 934 profile->GetPrefs()->SetString(prefs::kSupervisedUserId, |
| 933 supervised_user_id); | 935 supervised_user_id); |
| 934 } | 936 } |
| 935 } | 937 } |
| 936 | 938 |
| 937 void ProfileManager::RegisterTestingProfile(Profile* profile, | 939 void ProfileManager::RegisterTestingProfile(Profile* profile, |
| 938 bool add_to_cache, | 940 bool add_to_storage, |
| 939 bool start_deferred_task_runners) { | 941 bool start_deferred_task_runners) { |
| 940 RegisterProfile(profile, true); | 942 RegisterProfile(profile, true); |
| 941 if (add_to_cache) { | 943 if (add_to_storage) { |
| 942 InitProfileUserPrefs(profile); | 944 InitProfileUserPrefs(profile); |
| 943 AddProfileToCache(profile); | 945 AddProfileToStorage(profile); |
| 944 } | 946 } |
| 945 if (start_deferred_task_runners) { | 947 if (start_deferred_task_runners) { |
| 946 StartupTaskRunnerServiceFactory::GetForProfile(profile)-> | 948 StartupTaskRunnerServiceFactory::GetForProfile(profile)-> |
| 947 StartDeferredTaskRunners(); | 949 StartDeferredTaskRunners(); |
| 948 } | 950 } |
| 949 } | 951 } |
| 950 | 952 |
| 951 void ProfileManager::Observe( | 953 void ProfileManager::Observe( |
| 952 int type, | 954 int type, |
| 953 const content::NotificationSource& source, | 955 const content::NotificationSource& source, |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1105 RunCallbacks(callbacks, profile, | 1107 RunCallbacks(callbacks, profile, |
| 1106 profile ? Profile::CREATE_STATUS_INITIALIZED : | 1108 profile ? Profile::CREATE_STATUS_INITIALIZED : |
| 1107 Profile::CREATE_STATUS_LOCAL_FAIL); | 1109 Profile::CREATE_STATUS_LOCAL_FAIL); |
| 1108 } | 1110 } |
| 1109 | 1111 |
| 1110 void ProfileManager::DoFinalInit(Profile* profile, bool go_off_the_record) { | 1112 void ProfileManager::DoFinalInit(Profile* profile, bool go_off_the_record) { |
| 1111 TRACE_EVENT0("browser", "ProfileManager::DoFinalInit"); | 1113 TRACE_EVENT0("browser", "ProfileManager::DoFinalInit"); |
| 1112 TRACK_SCOPED_REGION("Startup", "ProfileManager::DoFinalInit"); | 1114 TRACK_SCOPED_REGION("Startup", "ProfileManager::DoFinalInit"); |
| 1113 | 1115 |
| 1114 DoFinalInitForServices(profile, go_off_the_record); | 1116 DoFinalInitForServices(profile, go_off_the_record); |
| 1115 AddProfileToCache(profile); | 1117 AddProfileToStorage(profile); |
| 1116 DoFinalInitLogging(profile); | 1118 DoFinalInitLogging(profile); |
| 1117 | 1119 |
| 1118 ProfileMetrics::LogNumberOfProfiles(this); | 1120 ProfileMetrics::LogNumberOfProfiles(this); |
| 1119 content::NotificationService::current()->Notify( | 1121 content::NotificationService::current()->Notify( |
| 1120 chrome::NOTIFICATION_PROFILE_ADDED, | 1122 chrome::NOTIFICATION_PROFILE_ADDED, |
| 1121 content::Source<Profile>(profile), | 1123 content::Source<Profile>(profile), |
| 1122 content::NotificationService::NoDetails()); | 1124 content::NotificationService::NoDetails()); |
| 1123 | 1125 |
| 1124 #if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS) | 1126 #if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS) |
| 1125 // Record statistics to ProfileInfoCache if statistics were not recorded | 1127 // Record statistics to ProfileInfoCache if statistics were not recorded |
| 1126 // during shutdown, i.e. the last shutdown was a system shutdown or a crash. | 1128 // during shutdown, i.e. the last shutdown was a system shutdown or a crash. |
| 1127 if (!profile->IsGuestSession() && !profile->IsSystemProfile() && | 1129 if (!profile->IsGuestSession() && !profile->IsSystemProfile() && |
| 1128 !profile->IsNewProfile() && !go_off_the_record && | 1130 !profile->IsNewProfile() && !go_off_the_record && |
| 1129 profile->GetLastSessionExitType() != Profile::EXIT_NORMAL) { | 1131 profile->GetLastSessionExitType() != Profile::EXIT_NORMAL) { |
| 1130 ProfileStatisticsFactory::GetForProfile(profile)->GatherStatistics( | 1132 ProfileStatisticsFactory::GetForProfile(profile)->GatherStatistics( |
| 1131 profiles::ProfileStatisticsCallback()); | 1133 profiles::ProfileStatisticsCallback()); |
| 1132 } | 1134 } |
| 1133 #endif | 1135 #endif |
| 1134 } | 1136 } |
| 1135 | 1137 |
| 1136 void ProfileManager::DoFinalInitForServices(Profile* profile, | 1138 void ProfileManager::DoFinalInitForServices(Profile* profile, |
| 1137 bool go_off_the_record) { | 1139 bool go_off_the_record) { |
| 1138 TRACE_EVENT0("browser", "ProfileManager::DoFinalInitForServices"); | 1140 TRACE_EVENT0("browser", "ProfileManager::DoFinalInitForServices"); |
| 1139 TRACK_SCOPED_REGION("Startup", "ProfileManager::DoFinalInitForServices"); | 1141 TRACK_SCOPED_REGION("Startup", "ProfileManager::DoFinalInitForServices"); |
| 1140 | 1142 |
| 1141 #if defined(ENABLE_EXTENSIONS) | 1143 #if defined(ENABLE_EXTENSIONS) |
| 1142 ProfileInfoCache& cache = GetProfileInfoCache(); | |
| 1143 | |
| 1144 // Ensure that the HostContentSettingsMap has been created before the | 1144 // Ensure that the HostContentSettingsMap has been created before the |
| 1145 // ExtensionSystem is initialized otherwise the ExtensionSystem will be | 1145 // ExtensionSystem is initialized otherwise the ExtensionSystem will be |
| 1146 // registered twice | 1146 // registered twice |
| 1147 HostContentSettingsMap* content_settings_map = | 1147 HostContentSettingsMap* content_settings_map = |
| 1148 HostContentSettingsMapFactory::GetForProfile(profile); | 1148 HostContentSettingsMapFactory::GetForProfile(profile); |
| 1149 | 1149 |
| 1150 extensions::ExtensionSystem::Get(profile)->InitForRegularProfile( | 1150 extensions::ExtensionSystem::Get(profile)->InitForRegularProfile( |
| 1151 !go_off_the_record); | 1151 !go_off_the_record); |
| 1152 // During tests, when |profile| is an instance of TestingProfile, | 1152 // During tests, when |profile| is an instance of TestingProfile, |
| 1153 // ExtensionSystem might not create an ExtensionService. | 1153 // ExtensionSystem might not create an ExtensionService. |
| 1154 // This block is duplicated in the HostContentSettingsMapFactory | 1154 // This block is duplicated in the HostContentSettingsMapFactory |
| 1155 // ::BuildServiceInstanceFor method, it should be called once when both the | 1155 // ::BuildServiceInstanceFor method, it should be called once when both the |
| 1156 // HostContentSettingsMap and the extension_service are set up. | 1156 // HostContentSettingsMap and the extension_service are set up. |
| 1157 if (extensions::ExtensionSystem::Get(profile)->extension_service()) { | 1157 if (extensions::ExtensionSystem::Get(profile)->extension_service()) { |
| 1158 extensions::ExtensionSystem::Get(profile)->extension_service()-> | 1158 extensions::ExtensionSystem::Get(profile)->extension_service()-> |
| 1159 RegisterContentSettings(content_settings_map); | 1159 RegisterContentSettings(content_settings_map); |
| 1160 } | 1160 } |
| 1161 // Set the block extensions bit on the ExtensionService. There likely are no | 1161 // Set the block extensions bit on the ExtensionService. There likely are no |
| 1162 // blockable extensions to block. | 1162 // blockable extensions to block. |
| 1163 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 1163 ProfileAttributesEntry* entry; |
| 1164 if (profile_index != std::string::npos && | 1164 bool has_entry = GetProfileAttributesStorage(). |
| 1165 cache.ProfileIsSigninRequiredAtIndex(profile_index)) { | 1165 GetProfileAttributesWithPath(profile->GetPath(), &entry); |
| 1166 if (has_entry && entry->IsSigninRequired()) { |
| 1166 extensions::ExtensionSystem::Get(profile) | 1167 extensions::ExtensionSystem::Get(profile) |
| 1167 ->extension_service() | 1168 ->extension_service() |
| 1168 ->BlockAllExtensions(); | 1169 ->BlockAllExtensions(); |
| 1169 } | 1170 } |
| 1170 | 1171 |
| 1171 #endif | 1172 #endif |
| 1172 #if defined(ENABLE_SUPERVISED_USERS) | 1173 #if defined(ENABLE_SUPERVISED_USERS) |
| 1173 // Initialization needs to happen after extension system initialization (for | 1174 // Initialization needs to happen after extension system initialization (for |
| 1174 // extension::ManagementPolicy) and InitProfileUserPrefs (for setting the | 1175 // extension::ManagementPolicy) and InitProfileUserPrefs (for setting the |
| 1175 // initializing the supervised flag if necessary). | 1176 // initializing the supervised flag if necessary). |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1332 | 1333 |
| 1333 #if !defined(OS_ANDROID) | 1334 #if !defined(OS_ANDROID) |
| 1334 void ProfileManager::FinishDeletingProfile( | 1335 void ProfileManager::FinishDeletingProfile( |
| 1335 const base::FilePath& profile_dir, | 1336 const base::FilePath& profile_dir, |
| 1336 const base::FilePath& new_active_profile_dir) { | 1337 const base::FilePath& new_active_profile_dir) { |
| 1337 // Update the last used profile pref before closing browser windows. This | 1338 // Update the last used profile pref before closing browser windows. This |
| 1338 // way the correct last used profile is set for any notification observers. | 1339 // way the correct last used profile is set for any notification observers. |
| 1339 profiles::SetLastUsedProfile( | 1340 profiles::SetLastUsedProfile( |
| 1340 new_active_profile_dir.BaseName().MaybeAsASCII()); | 1341 new_active_profile_dir.BaseName().MaybeAsASCII()); |
| 1341 | 1342 |
| 1342 ProfileInfoCache& cache = GetProfileInfoCache(); | 1343 ProfileAttributesStorage& storage = GetProfileAttributesStorage(); |
| 1343 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we | 1344 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we |
| 1344 // start deleting the profile instance we need to close background apps too. | 1345 // start deleting the profile instance we need to close background apps too. |
| 1345 Profile* profile = GetProfileByPath(profile_dir); | 1346 Profile* profile = GetProfileByPath(profile_dir); |
| 1346 | 1347 |
| 1347 if (profile) { | 1348 if (profile) { |
| 1348 // TODO: Migrate additional code in this block to observe this notification | 1349 // TODO: Migrate additional code in this block to observe this notification |
| 1349 // instead of being implemented here. | 1350 // instead of being implemented here. |
| 1350 content::NotificationService::current()->Notify( | 1351 content::NotificationService::current()->Notify( |
| 1351 chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, | 1352 chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, |
| 1352 content::Source<Profile>(profile), | 1353 content::Source<Profile>(profile), |
| 1353 content::NotificationService::NoDetails()); | 1354 content::NotificationService::NoDetails()); |
| 1354 | 1355 |
| 1355 // By this point, all in-progress downloads for the profile being deleted | 1356 // By this point, all in-progress downloads for the profile being deleted |
| 1356 // must have been canceled (crbug.com/336725). | 1357 // must have been canceled (crbug.com/336725). |
| 1357 DCHECK(DownloadServiceFactory::GetForBrowserContext(profile)-> | 1358 DCHECK(DownloadServiceFactory::GetForBrowserContext(profile)-> |
| 1358 NonMaliciousDownloadCount() == 0); | 1359 NonMaliciousDownloadCount() == 0); |
| 1359 BrowserList::CloseAllBrowsersWithProfile(profile); | 1360 BrowserList::CloseAllBrowsersWithProfile(profile); |
| 1360 | 1361 |
| 1361 // Disable sync for doomed profile. | 1362 // Disable sync for doomed profile. |
| 1362 if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( | 1363 if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( |
| 1363 profile)) { | 1364 profile)) { |
| 1364 ProfileSyncService* sync_service = | 1365 ProfileSyncService* sync_service = |
| 1365 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); | 1366 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); |
| 1366 if (sync_service->IsSyncRequested()) { | 1367 if (sync_service->IsSyncRequested()) { |
| 1367 // Record sync stopped by profile destruction if it was on before. | 1368 // Record sync stopped by profile destruction if it was on before. |
| 1368 UMA_HISTOGRAM_ENUMERATION("Sync.StopSource", | 1369 UMA_HISTOGRAM_ENUMERATION("Sync.StopSource", |
| 1369 syncer::PROFILE_DESTRUCTION, | 1370 syncer::PROFILE_DESTRUCTION, |
| 1370 syncer::STOP_SOURCE_LIMIT); | 1371 syncer::STOP_SOURCE_LIMIT); |
| 1371 } | 1372 } |
| 1372 // Ensure data is cleared even if sync was already off. | 1373 // Ensure data is cleared even if sync was already off. |
| 1373 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 1374 ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| 1374 profile)->RequestStop(ProfileSyncService::CLEAR_DATA); | 1375 profile)->RequestStop(ProfileSyncService::CLEAR_DATA); |
| 1375 } | 1376 } |
| 1376 | 1377 |
| 1377 ProfileMetrics::LogProfileDelete(cache.ProfileIsAuthenticatedAtIndex( | 1378 ProfileAttributesEntry* entry; |
| 1378 cache.GetIndexOfProfileWithPath(profile_dir))); | 1379 bool has_entry = storage.GetProfileAttributesWithPath(profile_dir, &entry); |
| 1380 DCHECK(has_entry); |
| 1381 ProfileMetrics::LogProfileDelete(entry->IsAuthenticated()); |
| 1379 // Some platforms store passwords in keychains. They should be removed. | 1382 // Some platforms store passwords in keychains. They should be removed. |
| 1380 scoped_refptr<password_manager::PasswordStore> password_store = | 1383 scoped_refptr<password_manager::PasswordStore> password_store = |
| 1381 PasswordStoreFactory::GetForProfile( | 1384 PasswordStoreFactory::GetForProfile( |
| 1382 profile, ServiceAccessType::EXPLICIT_ACCESS).get(); | 1385 profile, ServiceAccessType::EXPLICIT_ACCESS).get(); |
| 1383 if (password_store.get()) { | 1386 if (password_store.get()) { |
| 1384 password_store->RemoveLoginsCreatedBetween( | 1387 password_store->RemoveLoginsCreatedBetween( |
| 1385 base::Time(), base::Time::Max(), base::Closure()); | 1388 base::Time(), base::Time::Max(), base::Closure()); |
| 1386 } | 1389 } |
| 1387 | 1390 |
| 1388 // The Profile Data doesn't get wiped until Chrome closes. Since we promised | 1391 // The Profile Data doesn't get wiped until Chrome closes. Since we promised |
| 1389 // that the user's data would be removed, do so immediately. | 1392 // that the user's data would be removed, do so immediately. |
| 1390 profiles::RemoveBrowsingDataForProfile(profile_dir); | 1393 profiles::RemoveBrowsingDataForProfile(profile_dir); |
| 1391 } else { | 1394 } else { |
| 1392 // It is safe to delete a not yet loaded Profile from disk. | 1395 // It is safe to delete a not yet loaded Profile from disk. |
| 1393 BrowserThread::PostTask( | 1396 BrowserThread::PostTask( |
| 1394 BrowserThread::FILE, FROM_HERE, | 1397 BrowserThread::FILE, FROM_HERE, |
| 1395 base::Bind(&NukeProfileFromDisk, profile_dir)); | 1398 base::Bind(&NukeProfileFromDisk, profile_dir)); |
| 1396 } | 1399 } |
| 1397 | 1400 |
| 1398 // Queue even a profile that was nuked so it will be MarkedForDeletion and so | 1401 // Queue even a profile that was nuked so it will be MarkedForDeletion and so |
| 1399 // CreateProfileAsync can't create it. | 1402 // CreateProfileAsync can't create it. |
| 1400 QueueProfileDirectoryForDeletion(profile_dir); | 1403 QueueProfileDirectoryForDeletion(profile_dir); |
| 1401 cache.DeleteProfileFromCache(profile_dir); | 1404 storage.RemoveProfile(profile_dir); |
| 1402 ProfileMetrics::UpdateReportedProfilesStatistics(this); | 1405 ProfileMetrics::UpdateReportedProfilesStatistics(this); |
| 1403 } | 1406 } |
| 1404 #endif // !defined(OS_ANDROID) | 1407 #endif // !defined(OS_ANDROID) |
| 1405 | 1408 |
| 1406 ProfileManager::ProfileInfo* ProfileManager::RegisterProfile( | 1409 ProfileManager::ProfileInfo* ProfileManager::RegisterProfile( |
| 1407 Profile* profile, | 1410 Profile* profile, |
| 1408 bool created) { | 1411 bool created) { |
| 1409 TRACE_EVENT0("browser", "ProfileManager::RegisterProfile"); | 1412 TRACE_EVENT0("browser", "ProfileManager::RegisterProfile"); |
| 1410 ProfileInfo* info = new ProfileInfo(profile, created); | 1413 ProfileInfo* info = new ProfileInfo(profile, created); |
| 1411 profiles_info_.insert( | 1414 profiles_info_.insert( |
| 1412 std::make_pair(profile->GetPath(), linked_ptr<ProfileInfo>(info))); | 1415 std::make_pair(profile->GetPath(), linked_ptr<ProfileInfo>(info))); |
| 1413 return info; | 1416 return info; |
| 1414 } | 1417 } |
| 1415 | 1418 |
| 1416 ProfileManager::ProfileInfo* ProfileManager::GetProfileInfoByPath( | 1419 ProfileManager::ProfileInfo* ProfileManager::GetProfileInfoByPath( |
| 1417 const base::FilePath& path) const { | 1420 const base::FilePath& path) const { |
| 1418 ProfilesInfoMap::const_iterator iter = profiles_info_.find(path); | 1421 ProfilesInfoMap::const_iterator iter = profiles_info_.find(path); |
| 1419 return (iter == profiles_info_.end()) ? NULL : iter->second.get(); | 1422 return (iter == profiles_info_.end()) ? NULL : iter->second.get(); |
| 1420 } | 1423 } |
| 1421 | 1424 |
| 1422 void ProfileManager::AddProfileToCache(Profile* profile) { | 1425 void ProfileManager::AddProfileToStorage(Profile* profile) { |
| 1423 TRACE_EVENT0("browser", "ProfileManager::AddProfileToCache"); | 1426 TRACE_EVENT0("browser", "ProfileManager::AddProfileToCache"); |
| 1424 if (profile->IsGuestSession() || profile->IsSystemProfile()) | 1427 if (profile->IsGuestSession() || profile->IsSystemProfile()) |
| 1425 return; | 1428 return; |
| 1426 ProfileInfoCache& cache = GetProfileInfoCache(); | 1429 if (profile->GetPath().DirName() != user_data_dir()) { |
| 1427 if (profile->GetPath().DirName() != cache.GetUserDataDir()) | 1430 UMA_HISTOGRAM_BOOLEAN("Profile.GetProfileInfoPath.OutsideUserDir", true); |
| 1428 return; | 1431 return; |
| 1432 } |
| 1433 |
| 1429 | 1434 |
| 1430 SigninManagerBase* signin_manager = | 1435 SigninManagerBase* signin_manager = |
| 1431 SigninManagerFactory::GetForProfile(profile); | 1436 SigninManagerFactory::GetForProfile(profile); |
| 1432 AccountTrackerService* account_tracker = | 1437 AccountTrackerService* account_tracker = |
| 1433 AccountTrackerServiceFactory::GetForProfile(profile); | 1438 AccountTrackerServiceFactory::GetForProfile(profile); |
| 1434 AccountInfo account_info = account_tracker->GetAccountInfo( | 1439 AccountInfo account_info = account_tracker->GetAccountInfo( |
| 1435 signin_manager->GetAuthenticatedAccountId()); | 1440 signin_manager->GetAuthenticatedAccountId()); |
| 1436 base::string16 username = base::UTF8ToUTF16(account_info.email); | 1441 base::string16 username = base::UTF8ToUTF16(account_info.email); |
| 1437 | 1442 |
| 1438 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 1443 ProfileAttributesStorage& storage = GetProfileAttributesStorage(); |
| 1439 if (profile_index != std::string::npos) { | 1444 // |entry| and |has_entry| below are put inside a pair of brackets for |
| 1440 // The ProfileInfoCache's info must match the Signin Manager. | 1445 // scoping, to avoid potential clashes of variable names. |
| 1441 cache.SetAuthInfoOfProfileAtIndex(profile_index, account_info.gaia, | 1446 { |
| 1442 username); | 1447 ProfileAttributesEntry* entry; |
| 1443 return; | 1448 bool has_entry = storage.GetProfileAttributesWithPath(profile->GetPath(), |
| 1449 &entry); |
| 1450 if (has_entry) { |
| 1451 // The ProfileAttributesStorage's info must match the Signin Manager. |
| 1452 entry->SetAuthInfo(account_info.gaia, username); |
| 1453 return; |
| 1454 } |
| 1444 } | 1455 } |
| 1445 | 1456 |
| 1446 // Profile name and avatar are set by InitProfileUserPrefs and stored in the | 1457 // Profile name and avatar are set by InitProfileUserPrefs and stored in the |
| 1447 // profile. Use those values to setup the cache entry. | 1458 // profile. Use those values to setup the entry in profile attributes storage. |
| 1448 base::string16 profile_name = | 1459 base::string16 profile_name = |
| 1449 base::UTF8ToUTF16(profile->GetPrefs()->GetString(prefs::kProfileName)); | 1460 base::UTF8ToUTF16(profile->GetPrefs()->GetString(prefs::kProfileName)); |
| 1450 | 1461 |
| 1451 size_t icon_index = profile->GetPrefs()->GetInteger( | 1462 size_t icon_index = |
| 1452 prefs::kProfileAvatarIndex); | 1463 profile->GetPrefs()->GetInteger(prefs::kProfileAvatarIndex); |
| 1453 | 1464 |
| 1454 std::string supervised_user_id = | 1465 std::string supervised_user_id = |
| 1455 profile->GetPrefs()->GetString(prefs::kSupervisedUserId); | 1466 profile->GetPrefs()->GetString(prefs::kSupervisedUserId); |
| 1456 | 1467 |
| 1457 cache.AddProfileToCache(profile->GetPath(), | 1468 storage.AddProfile(profile->GetPath(), profile_name, account_info.gaia, |
| 1458 profile_name, | 1469 username, icon_index, supervised_user_id); |
| 1459 account_info.gaia, | |
| 1460 username, | |
| 1461 icon_index, | |
| 1462 supervised_user_id); | |
| 1463 | 1470 |
| 1464 if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) { | 1471 if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) { |
| 1465 cache.SetProfileIsEphemeralAtIndex( | 1472 ProfileAttributesEntry* entry; |
| 1466 cache.GetIndexOfProfileWithPath(profile->GetPath()), true); | 1473 bool has_entry = storage.GetProfileAttributesWithPath(profile->GetPath(), |
| 1474 &entry); |
| 1475 DCHECK(has_entry); |
| 1476 entry->SetIsEphemeral(true); |
| 1467 } | 1477 } |
| 1468 } | 1478 } |
| 1469 | 1479 |
| 1470 void ProfileManager::SetNonPersonalProfilePrefs(Profile* profile) { | 1480 void ProfileManager::SetNonPersonalProfilePrefs(Profile* profile) { |
| 1471 PrefService* prefs = profile->GetPrefs(); | 1481 PrefService* prefs = profile->GetPrefs(); |
| 1472 prefs->SetBoolean(prefs::kSigninAllowed, false); | 1482 prefs->SetBoolean(prefs::kSigninAllowed, false); |
| 1473 prefs->SetBoolean(bookmarks::prefs::kEditBookmarksEnabled, false); | 1483 prefs->SetBoolean(bookmarks::prefs::kEditBookmarksEnabled, false); |
| 1474 prefs->SetBoolean(bookmarks::prefs::kShowBookmarkBar, false); | 1484 prefs->SetBoolean(bookmarks::prefs::kShowBookmarkBar, false); |
| 1475 prefs->ClearPref(DefaultSearchManager::kDefaultSearchProviderDataPrefName); | 1485 prefs->ClearPref(DefaultSearchManager::kDefaultSearchProviderDataPrefName); |
| 1476 } | 1486 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1508 DCHECK(local_state); | 1518 DCHECK(local_state); |
| 1509 // Only keep track of profiles that we are managing; tests may create others. | 1519 // Only keep track of profiles that we are managing; tests may create others. |
| 1510 // Also never consider the SystemProfile as "active". | 1520 // Also never consider the SystemProfile as "active". |
| 1511 if (profiles_info_.find(last_active->GetPath()) != profiles_info_.end() && | 1521 if (profiles_info_.find(last_active->GetPath()) != profiles_info_.end() && |
| 1512 !last_active->IsSystemProfile()) { | 1522 !last_active->IsSystemProfile()) { |
| 1513 std::string profile_path_base = | 1523 std::string profile_path_base = |
| 1514 last_active->GetPath().BaseName().MaybeAsASCII(); | 1524 last_active->GetPath().BaseName().MaybeAsASCII(); |
| 1515 if (profile_path_base != GetLastUsedProfileName()) | 1525 if (profile_path_base != GetLastUsedProfileName()) |
| 1516 profiles::SetLastUsedProfile(profile_path_base); | 1526 profiles::SetLastUsedProfile(profile_path_base); |
| 1517 | 1527 |
| 1518 ProfileInfoCache& cache = GetProfileInfoCache(); | 1528 ProfileAttributesEntry* entry; |
| 1519 size_t profile_index = | 1529 if (GetProfileAttributesStorage(). |
| 1520 cache.GetIndexOfProfileWithPath(last_active->GetPath()); | 1530 GetProfileAttributesWithPath(last_active->GetPath(), &entry)) { |
| 1521 if (profile_index != std::string::npos) { | |
| 1522 #if !defined(OS_CHROMEOS) | 1531 #if !defined(OS_CHROMEOS) |
| 1523 // Incognito Profiles don't have ProfileKeyedServices. | 1532 // Incognito Profiles don't have ProfileKeyedServices. |
| 1524 if (!last_active->IsOffTheRecord()) { | 1533 if (!last_active->IsOffTheRecord()) { |
| 1525 CrossDevicePromoFactory::GetForProfile(last_active) | 1534 CrossDevicePromoFactory::GetForProfile(last_active)-> |
| 1526 ->MaybeBrowsingSessionStarted( | 1535 MaybeBrowsingSessionStarted(entry->GetActiveTime()); |
| 1527 cache.GetProfileActiveTimeAtIndex(profile_index)); | |
| 1528 } | 1536 } |
| 1529 #endif | 1537 #endif |
| 1530 cache.SetProfileActiveTimeAtIndex(profile_index); | 1538 entry->SetActiveTimeToNow(); |
| 1531 } | 1539 } |
| 1532 } | 1540 } |
| 1533 } | 1541 } |
| 1534 | 1542 |
| 1535 ProfileManager::BrowserListObserver::BrowserListObserver( | 1543 ProfileManager::BrowserListObserver::BrowserListObserver( |
| 1536 ProfileManager* manager) | 1544 ProfileManager* manager) |
| 1537 : profile_manager_(manager) { | 1545 : profile_manager_(manager) { |
| 1538 BrowserList::AddObserver(this); | 1546 BrowserList::AddObserver(this); |
| 1539 } | 1547 } |
| 1540 | 1548 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1617 | 1625 |
| 1618 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); | 1626 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); |
| 1619 if (!original_callback.is_null()) | 1627 if (!original_callback.is_null()) |
| 1620 original_callback.Run(loaded_profile, status); | 1628 original_callback.Run(loaded_profile, status); |
| 1621 } | 1629 } |
| 1622 #endif // !defined(OS_ANDROID) | 1630 #endif // !defined(OS_ANDROID) |
| 1623 | 1631 |
| 1624 ProfileManagerWithoutInit::ProfileManagerWithoutInit( | 1632 ProfileManagerWithoutInit::ProfileManagerWithoutInit( |
| 1625 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { | 1633 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { |
| 1626 } | 1634 } |
| OLD | NEW |