Chromium Code Reviews| 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/profile_statistics.h" | 46 #include "chrome/browser/profiles/profile_statistics.h" |
| 46 #include "chrome/browser/profiles/profiles_state.h" | 47 #include "chrome/browser/profiles/profiles_state.h" |
| 47 #include "chrome/browser/sessions/session_service_factory.h" | 48 #include "chrome/browser/sessions/session_service_factory.h" |
| 48 #include "chrome/browser/signin/account_fetcher_service_factory.h" | 49 #include "chrome/browser/signin/account_fetcher_service_factory.h" |
| 49 #include "chrome/browser/signin/account_reconcilor_factory.h" | 50 #include "chrome/browser/signin/account_reconcilor_factory.h" |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 | 395 |
| 395 // If the profile is already loaded (e.g., chrome.exe launched twice), just | 396 // If the profile is already loaded (e.g., chrome.exe launched twice), just |
| 396 // return it. | 397 // return it. |
| 397 Profile* profile = GetProfileByPath(profile_dir); | 398 Profile* profile = GetProfileByPath(profile_dir); |
| 398 if (profile) | 399 if (profile) |
| 399 return profile; | 400 return profile; |
| 400 return CreateAndInitializeProfile(profile_dir); | 401 return CreateAndInitializeProfile(profile_dir); |
| 401 } | 402 } |
| 402 | 403 |
| 403 size_t ProfileManager::GetNumberOfProfiles() { | 404 size_t ProfileManager::GetNumberOfProfiles() { |
| 404 return GetProfileInfoCache().GetNumberOfProfiles(); | 405 return GetProfileAttributesStorage().GetNumberOfProfiles(); |
| 405 } | 406 } |
| 406 | 407 |
| 407 void ProfileManager::CreateProfileAsync( | 408 void ProfileManager::CreateProfileAsync( |
| 408 const base::FilePath& profile_path, | 409 const base::FilePath& profile_path, |
| 409 const CreateCallback& callback, | 410 const CreateCallback& callback, |
| 410 const base::string16& name, | 411 const base::string16& name, |
| 411 const std::string& icon_url, | 412 const std::string& icon_url, |
| 412 const std::string& supervised_user_id) { | 413 const std::string& supervised_user_id) { |
| 413 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 414 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 414 TRACE_EVENT1("browser,startup", | 415 TRACE_EVENT1("browser,startup", |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 425 | 426 |
| 426 // Create the profile if needed and collect its ProfileInfo. | 427 // Create the profile if needed and collect its ProfileInfo. |
| 427 ProfilesInfoMap::iterator iter = profiles_info_.find(profile_path); | 428 ProfilesInfoMap::iterator iter = profiles_info_.find(profile_path); |
| 428 ProfileInfo* info = NULL; | 429 ProfileInfo* info = NULL; |
| 429 | 430 |
| 430 if (iter != profiles_info_.end()) { | 431 if (iter != profiles_info_.end()) { |
| 431 info = iter->second.get(); | 432 info = iter->second.get(); |
| 432 } else { | 433 } else { |
| 433 // Initiate asynchronous creation process. | 434 // Initiate asynchronous creation process. |
| 434 info = RegisterProfile(CreateProfileAsyncHelper(profile_path, this), false); | 435 info = RegisterProfile(CreateProfileAsyncHelper(profile_path, this), false); |
| 435 ProfileInfoCache& cache = GetProfileInfoCache(); | |
| 436 // Get the icon index from the user's icon url | |
| 437 size_t icon_index; | 436 size_t icon_index; |
| 438 DCHECK(base::IsStringASCII(icon_url)); | 437 DCHECK(base::IsStringASCII(icon_url)); |
| 439 if (profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index)) { | 438 if (profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index)) { |
| 440 // add profile to cache with user selected name and avatar | 439 // add profile to cache with user selected name and avatar |
| 441 cache.AddProfileToCache(profile_path, name, std::string(), | 440 GetProfileAttributesStorage().AddProfile(profile_path, name, |
| 442 base::string16(), icon_index, supervised_user_id); | 441 std::string(), base::string16(), icon_index, supervised_user_id); |
| 443 } | 442 } |
| 444 | 443 |
| 445 if (!supervised_user_id.empty()) { | 444 if (!supervised_user_id.empty()) { |
| 446 content::RecordAction( | 445 content::RecordAction( |
| 447 UserMetricsAction("ManagedMode_LocallyManagedUserCreated")); | 446 UserMetricsAction("ManagedMode_LocallyManagedUserCreated")); |
| 448 } | 447 } |
| 449 | 448 |
| 450 ProfileMetrics::UpdateReportedProfilesStatistics(this); | 449 ProfileMetrics::UpdateReportedProfilesStatistics(this); |
| 451 } | 450 } |
| 452 | 451 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 679 // Cancel all in-progress downloads before deleting the profile to prevent a | 678 // Cancel all in-progress downloads before deleting the profile to prevent a |
| 680 // "Do you want to exit Google Chrome and cancel the downloads?" prompt | 679 // "Do you want to exit Google Chrome and cancel the downloads?" prompt |
| 681 // (crbug.com/336725). | 680 // (crbug.com/336725). |
| 682 Profile* profile = GetProfileByPath(profile_dir); | 681 Profile* profile = GetProfileByPath(profile_dir); |
| 683 if (profile) { | 682 if (profile) { |
| 684 DownloadService* service = | 683 DownloadService* service = |
| 685 DownloadServiceFactory::GetForBrowserContext(profile); | 684 DownloadServiceFactory::GetForBrowserContext(profile); |
| 686 service->CancelDownloads(); | 685 service->CancelDownloads(); |
| 687 } | 686 } |
| 688 | 687 |
| 689 ProfileInfoCache& cache = GetProfileInfoCache(); | 688 ProfileAttributesStorage& storage = GetProfileAttributesStorage(); |
| 690 | |
| 691 // If we're deleting the last (non-legacy-supervised) profile, then create a | 689 // If we're deleting the last (non-legacy-supervised) profile, then create a |
| 692 // new profile in its place. | 690 // new profile in its place. |
| 693 base::FilePath last_non_supervised_profile_path; | 691 base::FilePath last_non_supervised_profile_path; |
| 694 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 692 std::vector<ProfileAttributesEntry*> entries = |
| 695 base::FilePath cur_path = cache.GetPathOfProfileAtIndex(i); | 693 storage.GetAllProfilesAttributes(); |
| 694 for (ProfileAttributesEntry* entry : entries) { | |
|
Mike Lerman
2016/03/18 17:10:44
why assign storage.GetAllProfilesAttribures() to a
lwchkg
2016/03/19 18:48:46
Did think of this, because in other places the cod
Mike Lerman
2016/03/30 01:18:10
And really, I'm sure the compiler optimizes this a
lwchkg
2016/03/31 19:32:26
Stupid typo. Should be "Didn't think of this" (i.e
| |
| 695 base::FilePath cur_path = entry->GetPath(); | |
| 696 // Make sure that this profile is not pending deletion, and is not | 696 // Make sure that this profile is not pending deletion, and is not |
| 697 // legacy-supervised. | 697 // legacy-supervised. |
| 698 if (cur_path != profile_dir && | 698 if (cur_path != profile_dir && |
| 699 !cache.ProfileIsLegacySupervisedAtIndex(i) && | 699 !entry->IsLegacySupervised() && |
| 700 !IsProfileMarkedForDeletion(cur_path)) { | 700 !IsProfileMarkedForDeletion(cur_path)) { |
| 701 last_non_supervised_profile_path = cur_path; | 701 last_non_supervised_profile_path = cur_path; |
| 702 break; | 702 break; |
| 703 } | 703 } |
| 704 } | 704 } |
| 705 | 705 |
| 706 if (last_non_supervised_profile_path.empty()) { | 706 if (last_non_supervised_profile_path.empty()) { |
| 707 std::string new_avatar_url; | 707 std::string new_avatar_url; |
| 708 base::string16 new_profile_name; | 708 base::string16 new_profile_name; |
| 709 | 709 |
| 710 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 710 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 711 int avatar_index = profiles::GetPlaceholderAvatarIndex(); | 711 int avatar_index = profiles::GetPlaceholderAvatarIndex(); |
| 712 new_avatar_url = profiles::GetDefaultAvatarIconUrl(avatar_index); | 712 new_avatar_url = profiles::GetDefaultAvatarIconUrl(avatar_index); |
| 713 new_profile_name = cache.ChooseNameForNewProfile(avatar_index); | 713 new_profile_name = storage.ChooseNameForNewProfile(avatar_index); |
| 714 #endif | 714 #endif |
| 715 | 715 |
| 716 base::FilePath new_path(GenerateNextProfileDirectoryPath()); | 716 base::FilePath new_path(GenerateNextProfileDirectoryPath()); |
| 717 CreateProfileAsync(new_path, | 717 CreateProfileAsync(new_path, |
| 718 base::Bind(&ProfileManager::OnNewActiveProfileLoaded, | 718 base::Bind(&ProfileManager::OnNewActiveProfileLoaded, |
| 719 base::Unretained(this), | 719 base::Unretained(this), |
| 720 profile_dir, | 720 profile_dir, |
| 721 new_path, | 721 new_path, |
| 722 callback), | 722 callback), |
| 723 new_profile_name, | 723 new_profile_name, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 757 void ProfileManager::AutoloadProfiles() { | 757 void ProfileManager::AutoloadProfiles() { |
| 758 // If running in the background is disabled for the browser, do not autoload | 758 // If running in the background is disabled for the browser, do not autoload |
| 759 // any profiles. | 759 // any profiles. |
| 760 PrefService* local_state = g_browser_process->local_state(); | 760 PrefService* local_state = g_browser_process->local_state(); |
| 761 DCHECK(local_state); | 761 DCHECK(local_state); |
| 762 if (!local_state->HasPrefPath(prefs::kBackgroundModeEnabled) || | 762 if (!local_state->HasPrefPath(prefs::kBackgroundModeEnabled) || |
| 763 !local_state->GetBoolean(prefs::kBackgroundModeEnabled)) { | 763 !local_state->GetBoolean(prefs::kBackgroundModeEnabled)) { |
| 764 return; | 764 return; |
| 765 } | 765 } |
| 766 | 766 |
| 767 ProfileInfoCache& cache = GetProfileInfoCache(); | 767 std::vector<ProfileAttributesEntry*> entries = |
| 768 size_t number_of_profiles = cache.GetNumberOfProfiles(); | 768 GetProfileAttributesStorage().GetAllProfilesAttributes(); |
| 769 for (size_t p = 0; p < number_of_profiles; ++p) { | 769 for (ProfileAttributesEntry* entry : entries) { |
| 770 if (cache.GetBackgroundStatusOfProfileAtIndex(p)) { | 770 if (entry->GetBackgroundStatus()) { |
| 771 // If status is true, that profile is running background apps. By calling | 771 // If status is true, that profile is running background apps. By calling |
| 772 // GetProfile, we automatically cause the profile to be loaded which will | 772 // GetProfile, we automatically cause the profile to be loaded which will |
| 773 // register it with the BackgroundModeManager. | 773 // register it with the BackgroundModeManager. |
| 774 GetProfile(cache.GetPathOfProfileAtIndex(p)); | 774 GetProfile(entry->GetPath()); |
| 775 } | 775 } |
| 776 } | 776 } |
| 777 } | 777 } |
| 778 | 778 |
| 779 void ProfileManager::CleanUpEphemeralProfiles() { | 779 void ProfileManager::CleanUpEphemeralProfiles() { |
| 780 const std::string last_used_profile = GetLastUsedProfileName(); | 780 const std::string last_used_profile = GetLastUsedProfileName(); |
| 781 | 781 |
| 782 bool last_active_profile_deleted = false; | 782 bool last_active_profile_deleted = false; |
| 783 base::FilePath new_profile_path; | 783 base::FilePath new_profile_path; |
| 784 std::vector<base::FilePath> profiles_to_delete; | 784 std::vector<base::FilePath> profiles_to_delete; |
| 785 ProfileInfoCache& profile_cache = GetProfileInfoCache(); | 785 ProfileAttributesStorage& storage = GetProfileAttributesStorage(); |
| 786 size_t profiles_count = profile_cache.GetNumberOfProfiles(); | 786 std::vector<ProfileAttributesEntry*> entries = |
| 787 for (size_t i = 0; i < profiles_count; ++i) { | 787 storage.GetAllProfilesAttributes(); |
| 788 base::FilePath profile_path = profile_cache.GetPathOfProfileAtIndex(i); | 788 for (ProfileAttributesEntry* entry : entries) { |
| 789 if (profile_cache.ProfileIsEphemeralAtIndex(i)) { | 789 base::FilePath profile_path = entry->GetPath(); |
| 790 if (entry->IsEphemeral()) { | |
| 790 profiles_to_delete.push_back(profile_path); | 791 profiles_to_delete.push_back(profile_path); |
| 791 if (profile_path.BaseName().MaybeAsASCII() == last_used_profile) | 792 if (profile_path.BaseName().MaybeAsASCII() == last_used_profile) |
| 792 last_active_profile_deleted = true; | 793 last_active_profile_deleted = true; |
| 793 } else if (new_profile_path.empty()) { | 794 } else if (new_profile_path.empty()) { |
| 794 new_profile_path = profile_path; | 795 new_profile_path = profile_path; |
| 795 } | 796 } |
| 796 } | 797 } |
| 797 | 798 |
| 798 // If the last active profile was ephemeral, set a new one. | 799 // If the last active profile was ephemeral, set a new one. |
| 799 if (last_active_profile_deleted) { | 800 if (last_active_profile_deleted) { |
| 800 if (new_profile_path.empty()) | 801 if (new_profile_path.empty()) |
| 801 new_profile_path = GenerateNextProfileDirectoryPath(); | 802 new_profile_path = GenerateNextProfileDirectoryPath(); |
| 802 | 803 |
| 803 profiles::SetLastUsedProfile(new_profile_path.BaseName().MaybeAsASCII()); | 804 profiles::SetLastUsedProfile(new_profile_path.BaseName().MaybeAsASCII()); |
| 804 } | 805 } |
| 805 | 806 |
| 806 // This uses a separate loop, because deleting the profile from the | 807 // This uses a separate loop, because deleting the profile from the |
| 807 // ProfileInfoCache will modify indices. | 808 // ProfileInfoCache will modify indices. |
| 808 for (const base::FilePath& profile_path : profiles_to_delete) { | 809 for (const base::FilePath& profile_path : profiles_to_delete) { |
| 809 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 810 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 810 base::Bind(&NukeProfileFromDisk, profile_path)); | 811 base::Bind(&NukeProfileFromDisk, profile_path)); |
| 811 | 812 |
| 812 profile_cache.DeleteProfileFromCache(profile_path); | 813 storage.RemoveProfile(profile_path); |
| 813 } | 814 } |
| 814 } | 815 } |
| 815 | 816 |
| 816 void ProfileManager::InitProfileUserPrefs(Profile* profile) { | 817 void ProfileManager::InitProfileUserPrefs(Profile* profile) { |
| 817 TRACE_EVENT0("browser", "ProfileManager::InitProfileUserPrefs"); | 818 TRACE_EVENT0("browser", "ProfileManager::InitProfileUserPrefs"); |
| 818 ProfileInfoCache& cache = GetProfileInfoCache(); | 819 ProfileAttributesStorage& storage = GetProfileAttributesStorage(); |
| 819 | 820 |
| 820 if (profile->GetPath().DirName() != cache.GetUserDataDir()) | 821 if (profile->GetPath().DirName() != user_data_dir()) |
|
lwchkg
2016/03/14 15:49:10
I want to change this code (and a few similar code
Mike Lerman
2016/03/18 17:10:44
Maybe this helps with testing?
It seems safe to le
lwchkg
2016/03/19 18:48:46
Not sure, but very possible. I guess it *helped* t
Mike Lerman
2016/03/30 01:18:10
We can add a UserCount and then a Googler can go a
lwchkg
2016/03/31 19:32:26
Sorry... what is a UserCount?
Mike Lerman
2016/04/04 15:45:31
It's a way to gather statistics from the Chrome us
| |
| 821 return; | 822 return; |
| 822 | 823 |
| 823 size_t avatar_index; | 824 size_t avatar_index; |
| 824 std::string profile_name; | 825 std::string profile_name; |
| 825 std::string supervised_user_id; | 826 std::string supervised_user_id; |
| 826 if (profile->IsGuestSession()) { | 827 if (profile->IsGuestSession()) { |
| 827 profile_name = l10n_util::GetStringUTF8(IDS_PROFILES_GUEST_PROFILE_NAME); | 828 profile_name = l10n_util::GetStringUTF8(IDS_PROFILES_GUEST_PROFILE_NAME); |
| 828 avatar_index = 0; | 829 avatar_index = 0; |
| 829 } else { | 830 } else { |
| 830 size_t profile_cache_index = | 831 ProfileAttributesEntry* entry; |
| 831 cache.GetIndexOfProfileWithPath(profile->GetPath()); | 832 bool has_entry = storage.GetProfileAttributesWithPath(profile->GetPath(), |
| 832 // If the cache has an entry for this profile, use the cache data. | 833 &entry); |
| 833 if (profile_cache_index != std::string::npos) { | 834 // If the profile attributes storage has an entry for this profile, use the |
| 834 avatar_index = | 835 // data in the profile attributes storage. |
| 835 cache.GetAvatarIconIndexOfProfileAtIndex(profile_cache_index); | 836 if (has_entry) { |
| 836 profile_name = | 837 avatar_index = entry->GetAvatarIconIndex(); |
| 837 base::UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_cache_index)); | 838 profile_name = base::UTF16ToUTF8(entry->GetName()); |
| 838 supervised_user_id = | 839 supervised_user_id = entry->GetSupervisedUserId(); |
| 839 cache.GetSupervisedUserIdOfProfileAtIndex(profile_cache_index); | |
| 840 } else if (profile->GetPath() == | 840 } else if (profile->GetPath() == |
| 841 profiles::GetDefaultProfileDir(cache.GetUserDataDir())) { | 841 profiles::GetDefaultProfileDir(user_data_dir())) { |
| 842 avatar_index = profiles::GetPlaceholderAvatarIndex(); | 842 avatar_index = profiles::GetPlaceholderAvatarIndex(); |
| 843 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 843 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 844 profile_name = | 844 profile_name = |
| 845 base::UTF16ToUTF8(cache.ChooseNameForNewProfile(avatar_index)); | 845 base::UTF16ToUTF8(storage.ChooseNameForNewProfile(avatar_index)); |
| 846 #else | 846 #else |
| 847 profile_name = l10n_util::GetStringUTF8(IDS_DEFAULT_PROFILE_NAME); | 847 profile_name = l10n_util::GetStringUTF8(IDS_DEFAULT_PROFILE_NAME); |
| 848 #endif | 848 #endif |
| 849 } else { | 849 } else { |
| 850 avatar_index = cache.ChooseAvatarIconIndexForNewProfile(); | 850 avatar_index = storage.ChooseAvatarIconIndexForNewProfile(); |
| 851 profile_name = | 851 profile_name = |
| 852 base::UTF16ToUTF8(cache.ChooseNameForNewProfile(avatar_index)); | 852 base::UTF16ToUTF8(storage.ChooseNameForNewProfile(avatar_index)); |
| 853 } | 853 } |
| 854 } | 854 } |
| 855 | 855 |
| 856 if (!profile->GetPrefs()->HasPrefPath(prefs::kProfileAvatarIndex)) | 856 if (!profile->GetPrefs()->HasPrefPath(prefs::kProfileAvatarIndex)) |
| 857 profile->GetPrefs()->SetInteger(prefs::kProfileAvatarIndex, avatar_index); | 857 profile->GetPrefs()->SetInteger(prefs::kProfileAvatarIndex, avatar_index); |
| 858 | 858 |
| 859 if (!profile->GetPrefs()->HasPrefPath(prefs::kProfileName)) | 859 if (!profile->GetPrefs()->HasPrefPath(prefs::kProfileName)) |
| 860 profile->GetPrefs()->SetString(prefs::kProfileName, profile_name); | 860 profile->GetPrefs()->SetString(prefs::kProfileName, profile_name); |
| 861 | 861 |
| 862 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 862 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 863 bool force_supervised_user_id = | 863 bool force_supervised_user_id = |
| 864 #if defined(OS_CHROMEOS) | 864 #if defined(OS_CHROMEOS) |
| 865 g_browser_process->platform_part() | 865 g_browser_process->platform_part() |
| 866 ->profile_helper() | 866 ->profile_helper() |
| 867 ->GetSigninProfileDir() != profile->GetPath() && | 867 ->GetSigninProfileDir() != profile->GetPath() && |
| 868 #endif | 868 #endif |
| 869 command_line->HasSwitch(switches::kSupervisedUserId); | 869 command_line->HasSwitch(switches::kSupervisedUserId); |
| 870 if (force_supervised_user_id) { | 870 if (force_supervised_user_id) { |
| 871 supervised_user_id = | 871 supervised_user_id = |
| 872 command_line->GetSwitchValueASCII(switches::kSupervisedUserId); | 872 command_line->GetSwitchValueASCII(switches::kSupervisedUserId); |
| 873 } | 873 } |
| 874 if (force_supervised_user_id || | 874 if (force_supervised_user_id || |
| 875 !profile->GetPrefs()->HasPrefPath(prefs::kSupervisedUserId)) { | 875 !profile->GetPrefs()->HasPrefPath(prefs::kSupervisedUserId)) { |
| 876 profile->GetPrefs()->SetString(prefs::kSupervisedUserId, | 876 profile->GetPrefs()->SetString(prefs::kSupervisedUserId, |
| 877 supervised_user_id); | 877 supervised_user_id); |
| 878 } | 878 } |
| 879 } | 879 } |
| 880 | 880 |
| 881 void ProfileManager::RegisterTestingProfile(Profile* profile, | 881 void ProfileManager::RegisterTestingProfile(Profile* profile, |
| 882 bool add_to_cache, | 882 bool add_to_storage, |
| 883 bool start_deferred_task_runners) { | 883 bool start_deferred_task_runners) { |
| 884 RegisterProfile(profile, true); | 884 RegisterProfile(profile, true); |
| 885 if (add_to_cache) { | 885 if (add_to_storage) { |
| 886 InitProfileUserPrefs(profile); | 886 InitProfileUserPrefs(profile); |
| 887 AddProfileToCache(profile); | 887 AddProfileToStorage(profile); |
| 888 } | 888 } |
| 889 if (start_deferred_task_runners) { | 889 if (start_deferred_task_runners) { |
| 890 StartupTaskRunnerServiceFactory::GetForProfile(profile)-> | 890 StartupTaskRunnerServiceFactory::GetForProfile(profile)-> |
| 891 StartDeferredTaskRunners(); | 891 StartDeferredTaskRunners(); |
| 892 } | 892 } |
| 893 } | 893 } |
| 894 | 894 |
| 895 void ProfileManager::Observe( | 895 void ProfileManager::Observe( |
| 896 int type, | 896 int type, |
| 897 const content::NotificationSource& source, | 897 const content::NotificationSource& source, |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1049 RunCallbacks(callbacks, profile, | 1049 RunCallbacks(callbacks, profile, |
| 1050 profile ? Profile::CREATE_STATUS_INITIALIZED : | 1050 profile ? Profile::CREATE_STATUS_INITIALIZED : |
| 1051 Profile::CREATE_STATUS_LOCAL_FAIL); | 1051 Profile::CREATE_STATUS_LOCAL_FAIL); |
| 1052 } | 1052 } |
| 1053 | 1053 |
| 1054 void ProfileManager::DoFinalInit(Profile* profile, bool go_off_the_record) { | 1054 void ProfileManager::DoFinalInit(Profile* profile, bool go_off_the_record) { |
| 1055 TRACE_EVENT0("browser", "ProfileManager::DoFinalInit"); | 1055 TRACE_EVENT0("browser", "ProfileManager::DoFinalInit"); |
| 1056 TRACK_SCOPED_REGION("Startup", "ProfileManager::DoFinalInit"); | 1056 TRACK_SCOPED_REGION("Startup", "ProfileManager::DoFinalInit"); |
| 1057 | 1057 |
| 1058 DoFinalInitForServices(profile, go_off_the_record); | 1058 DoFinalInitForServices(profile, go_off_the_record); |
| 1059 AddProfileToCache(profile); | 1059 AddProfileToStorage(profile); |
| 1060 DoFinalInitLogging(profile); | 1060 DoFinalInitLogging(profile); |
| 1061 | 1061 |
| 1062 ProfileMetrics::LogNumberOfProfiles(this); | 1062 ProfileMetrics::LogNumberOfProfiles(this); |
| 1063 content::NotificationService::current()->Notify( | 1063 content::NotificationService::current()->Notify( |
| 1064 chrome::NOTIFICATION_PROFILE_ADDED, | 1064 chrome::NOTIFICATION_PROFILE_ADDED, |
| 1065 content::Source<Profile>(profile), | 1065 content::Source<Profile>(profile), |
| 1066 content::NotificationService::NoDetails()); | 1066 content::NotificationService::NoDetails()); |
| 1067 | 1067 |
| 1068 // Record statistics to ProfileInfoCache if statistics were not recorded | 1068 // Record statistics to ProfileAttributesStorage if statistics were not |
| 1069 // during shutdown, i.e. the last shutdown was a system shutdown or a crash. | 1069 // recorded during shutdown, i.e. the last shutdown was a system shutdown or a |
| 1070 if (!profile->IsGuestSession() && !profile->IsSystemProfile() && | 1070 // crash. |
| 1071 if (!profile->IsGuestSession() && !profile->IsSystemProfile() && | |
| 1071 !profile->IsNewProfile() && !go_off_the_record && | 1072 !profile->IsNewProfile() && !go_off_the_record && |
| 1072 profile->GetLastSessionExitType() != Profile::EXIT_NORMAL) { | 1073 profile->GetLastSessionExitType() != Profile::EXIT_NORMAL) { |
| 1073 profiles::GatherProfileStatistics( | 1074 profiles::GatherProfileStatistics( |
| 1074 profile, profiles::ProfileStatisticsCallback(), nullptr); | 1075 profile, profiles::ProfileStatisticsCallback(), nullptr); |
| 1075 } | 1076 } |
| 1076 } | 1077 } |
| 1077 | 1078 |
| 1078 void ProfileManager::DoFinalInitForServices(Profile* profile, | 1079 void ProfileManager::DoFinalInitForServices(Profile* profile, |
| 1079 bool go_off_the_record) { | 1080 bool go_off_the_record) { |
| 1080 TRACE_EVENT0("browser", "ProfileManager::DoFinalInitForServices"); | 1081 TRACE_EVENT0("browser", "ProfileManager::DoFinalInitForServices"); |
| 1081 TRACK_SCOPED_REGION("Startup", "ProfileManager::DoFinalInitForServices"); | 1082 TRACK_SCOPED_REGION("Startup", "ProfileManager::DoFinalInitForServices"); |
| 1082 | 1083 |
| 1083 #if defined(ENABLE_EXTENSIONS) | 1084 #if defined(ENABLE_EXTENSIONS) |
| 1084 ProfileInfoCache& cache = GetProfileInfoCache(); | |
| 1085 | |
| 1086 // Ensure that the HostContentSettingsMap has been created before the | 1085 // Ensure that the HostContentSettingsMap has been created before the |
| 1087 // ExtensionSystem is initialized otherwise the ExtensionSystem will be | 1086 // ExtensionSystem is initialized otherwise the ExtensionSystem will be |
| 1088 // registered twice | 1087 // registered twice |
| 1089 HostContentSettingsMap* content_settings_map = | 1088 HostContentSettingsMap* content_settings_map = |
| 1090 HostContentSettingsMapFactory::GetForProfile(profile); | 1089 HostContentSettingsMapFactory::GetForProfile(profile); |
| 1091 | 1090 |
| 1092 extensions::ExtensionSystem::Get(profile)->InitForRegularProfile( | 1091 extensions::ExtensionSystem::Get(profile)->InitForRegularProfile( |
| 1093 !go_off_the_record); | 1092 !go_off_the_record); |
| 1094 // During tests, when |profile| is an instance of TestingProfile, | 1093 // During tests, when |profile| is an instance of TestingProfile, |
| 1095 // ExtensionSystem might not create an ExtensionService. | 1094 // ExtensionSystem might not create an ExtensionService. |
| 1096 // This block is duplicated in the HostContentSettingsMapFactory | 1095 // This block is duplicated in the HostContentSettingsMapFactory |
| 1097 // ::BuildServiceInstanceFor method, it should be called once when both the | 1096 // ::BuildServiceInstanceFor method, it should be called once when both the |
| 1098 // HostContentSettingsMap and the extension_service are set up. | 1097 // HostContentSettingsMap and the extension_service are set up. |
| 1099 if (extensions::ExtensionSystem::Get(profile)->extension_service()) { | 1098 if (extensions::ExtensionSystem::Get(profile)->extension_service()) { |
| 1100 extensions::ExtensionSystem::Get(profile)->extension_service()-> | 1099 extensions::ExtensionSystem::Get(profile)->extension_service()-> |
| 1101 RegisterContentSettings(content_settings_map); | 1100 RegisterContentSettings(content_settings_map); |
| 1102 } | 1101 } |
| 1103 // Set the block extensions bit on the ExtensionService. There likely are no | 1102 // Set the block extensions bit on the ExtensionService. There likely are no |
| 1104 // blockable extensions to block. | 1103 // blockable extensions to block. |
| 1105 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 1104 ProfileAttributesEntry* entry; |
| 1106 if (profile_index != std::string::npos && | 1105 bool has_entry = GetProfileAttributesStorage(). |
| 1107 cache.ProfileIsSigninRequiredAtIndex(profile_index)) { | 1106 GetProfileAttributesWithPath(profile->GetPath(), &entry); |
| 1107 if (has_entry && entry->IsSigninRequired()) { | |
| 1108 extensions::ExtensionSystem::Get(profile) | 1108 extensions::ExtensionSystem::Get(profile) |
| 1109 ->extension_service() | 1109 ->extension_service() |
| 1110 ->BlockAllExtensions(); | 1110 ->BlockAllExtensions(); |
| 1111 } | 1111 } |
| 1112 | 1112 |
| 1113 #endif | 1113 #endif |
| 1114 #if defined(ENABLE_SUPERVISED_USERS) | 1114 #if defined(ENABLE_SUPERVISED_USERS) |
| 1115 // Initialization needs to happen after extension system initialization (for | 1115 // Initialization needs to happen after extension system initialization (for |
| 1116 // extension::ManagementPolicy) and InitProfileUserPrefs (for setting the | 1116 // extension::ManagementPolicy) and InitProfileUserPrefs (for setting the |
| 1117 // initializing the supervised flag if necessary). | 1117 // initializing the supervised flag if necessary). |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1274 | 1274 |
| 1275 #if !defined(OS_ANDROID) | 1275 #if !defined(OS_ANDROID) |
| 1276 void ProfileManager::FinishDeletingProfile( | 1276 void ProfileManager::FinishDeletingProfile( |
| 1277 const base::FilePath& profile_dir, | 1277 const base::FilePath& profile_dir, |
| 1278 const base::FilePath& new_active_profile_dir) { | 1278 const base::FilePath& new_active_profile_dir) { |
| 1279 // Update the last used profile pref before closing browser windows. This | 1279 // Update the last used profile pref before closing browser windows. This |
| 1280 // way the correct last used profile is set for any notification observers. | 1280 // way the correct last used profile is set for any notification observers. |
| 1281 profiles::SetLastUsedProfile( | 1281 profiles::SetLastUsedProfile( |
| 1282 new_active_profile_dir.BaseName().MaybeAsASCII()); | 1282 new_active_profile_dir.BaseName().MaybeAsASCII()); |
| 1283 | 1283 |
| 1284 ProfileInfoCache& cache = GetProfileInfoCache(); | 1284 ProfileAttributesStorage& storage = GetProfileAttributesStorage(); |
| 1285 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we | 1285 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we |
| 1286 // start deleting the profile instance we need to close background apps too. | 1286 // start deleting the profile instance we need to close background apps too. |
| 1287 Profile* profile = GetProfileByPath(profile_dir); | 1287 Profile* profile = GetProfileByPath(profile_dir); |
| 1288 | 1288 |
| 1289 if (profile) { | 1289 if (profile) { |
| 1290 // TODO: Migrate additional code in this block to observe this notification | 1290 // TODO: Migrate additional code in this block to observe this notification |
| 1291 // instead of being implemented here. | 1291 // instead of being implemented here. |
| 1292 content::NotificationService::current()->Notify( | 1292 content::NotificationService::current()->Notify( |
| 1293 chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, | 1293 chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, |
| 1294 content::Source<Profile>(profile), | 1294 content::Source<Profile>(profile), |
| 1295 content::NotificationService::NoDetails()); | 1295 content::NotificationService::NoDetails()); |
| 1296 | 1296 |
| 1297 // By this point, all in-progress downloads for the profile being deleted | 1297 // By this point, all in-progress downloads for the profile being deleted |
| 1298 // must have been canceled (crbug.com/336725). | 1298 // must have been canceled (crbug.com/336725). |
| 1299 DCHECK(DownloadServiceFactory::GetForBrowserContext(profile)-> | 1299 DCHECK(DownloadServiceFactory::GetForBrowserContext(profile)-> |
| 1300 NonMaliciousDownloadCount() == 0); | 1300 NonMaliciousDownloadCount() == 0); |
| 1301 BrowserList::CloseAllBrowsersWithProfile(profile); | 1301 BrowserList::CloseAllBrowsersWithProfile(profile); |
| 1302 | 1302 |
| 1303 // Disable sync for doomed profile. | 1303 // Disable sync for doomed profile. |
| 1304 if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( | 1304 if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( |
| 1305 profile)) { | 1305 profile)) { |
| 1306 ProfileSyncService* sync_service = | 1306 ProfileSyncService* sync_service = |
| 1307 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); | 1307 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); |
| 1308 if (sync_service->IsSyncRequested()) { | 1308 if (sync_service->IsSyncRequested()) { |
| 1309 // Record sync stopped by profile destruction if it was on before. | 1309 // Record sync stopped by profile destruction if it was on before. |
| 1310 UMA_HISTOGRAM_ENUMERATION("Sync.StopSource", | 1310 UMA_HISTOGRAM_ENUMERATION("Sync.StopSource", |
| 1311 syncer::PROFILE_DESTRUCTION, | 1311 syncer::PROFILE_DESTRUCTION, |
| 1312 syncer::STOP_SOURCE_LIMIT); | 1312 syncer::STOP_SOURCE_LIMIT); |
| 1313 } | 1313 } |
| 1314 // Ensure data is cleared even if sync was already off. | 1314 // Ensure data is cleared even if sync was already off. |
| 1315 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 1315 ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| 1316 profile)->RequestStop(ProfileSyncService::CLEAR_DATA); | 1316 profile)->RequestStop(ProfileSyncService::CLEAR_DATA); |
| 1317 } | 1317 } |
| 1318 | 1318 |
| 1319 ProfileMetrics::LogProfileDelete(cache.ProfileIsAuthenticatedAtIndex( | 1319 ProfileAttributesEntry* entry; |
| 1320 cache.GetIndexOfProfileWithPath(profile_dir))); | 1320 bool has_entry = storage.GetProfileAttributesWithPath(profile_dir, &entry); |
| 1321 DCHECK(has_entry); | |
| 1322 ProfileMetrics::LogProfileDelete(entry->IsAuthenticated()); | |
| 1321 // Some platforms store passwords in keychains. They should be removed. | 1323 // Some platforms store passwords in keychains. They should be removed. |
| 1322 scoped_refptr<password_manager::PasswordStore> password_store = | 1324 scoped_refptr<password_manager::PasswordStore> password_store = |
| 1323 PasswordStoreFactory::GetForProfile( | 1325 PasswordStoreFactory::GetForProfile( |
| 1324 profile, ServiceAccessType::EXPLICIT_ACCESS).get(); | 1326 profile, ServiceAccessType::EXPLICIT_ACCESS).get(); |
| 1325 if (password_store.get()) { | 1327 if (password_store.get()) { |
| 1326 password_store->RemoveLoginsCreatedBetween( | 1328 password_store->RemoveLoginsCreatedBetween( |
| 1327 base::Time(), base::Time::Max(), base::Closure()); | 1329 base::Time(), base::Time::Max(), base::Closure()); |
| 1328 } | 1330 } |
| 1329 | 1331 |
| 1330 // The Profile Data doesn't get wiped until Chrome closes. Since we promised | 1332 // The Profile Data doesn't get wiped until Chrome closes. Since we promised |
| 1331 // that the user's data would be removed, do so immediately. | 1333 // that the user's data would be removed, do so immediately. |
| 1332 profiles::RemoveBrowsingDataForProfile(profile_dir); | 1334 profiles::RemoveBrowsingDataForProfile(profile_dir); |
| 1333 } else { | 1335 } else { |
| 1334 // It is safe to delete a not yet loaded Profile from disk. | 1336 // It is safe to delete a not yet loaded Profile from disk. |
| 1335 BrowserThread::PostTask( | 1337 BrowserThread::PostTask( |
| 1336 BrowserThread::FILE, FROM_HERE, | 1338 BrowserThread::FILE, FROM_HERE, |
| 1337 base::Bind(&NukeProfileFromDisk, profile_dir)); | 1339 base::Bind(&NukeProfileFromDisk, profile_dir)); |
| 1338 } | 1340 } |
| 1339 | 1341 |
| 1340 // Queue even a profile that was nuked so it will be MarkedForDeletion and so | 1342 // Queue even a profile that was nuked so it will be MarkedForDeletion and so |
| 1341 // CreateProfileAsync can't create it. | 1343 // CreateProfileAsync can't create it. |
| 1342 QueueProfileDirectoryForDeletion(profile_dir); | 1344 QueueProfileDirectoryForDeletion(profile_dir); |
| 1343 cache.DeleteProfileFromCache(profile_dir); | 1345 storage.RemoveProfile(profile_dir); |
| 1344 ProfileMetrics::UpdateReportedProfilesStatistics(this); | 1346 ProfileMetrics::UpdateReportedProfilesStatistics(this); |
| 1345 } | 1347 } |
| 1346 #endif // !defined(OS_ANDROID) | 1348 #endif // !defined(OS_ANDROID) |
| 1347 | 1349 |
| 1348 ProfileManager::ProfileInfo* ProfileManager::RegisterProfile( | 1350 ProfileManager::ProfileInfo* ProfileManager::RegisterProfile( |
| 1349 Profile* profile, | 1351 Profile* profile, |
| 1350 bool created) { | 1352 bool created) { |
| 1351 TRACE_EVENT0("browser", "ProfileManager::RegisterProfile"); | 1353 TRACE_EVENT0("browser", "ProfileManager::RegisterProfile"); |
| 1352 ProfileInfo* info = new ProfileInfo(profile, created); | 1354 ProfileInfo* info = new ProfileInfo(profile, created); |
| 1353 profiles_info_.insert( | 1355 profiles_info_.insert( |
| 1354 std::make_pair(profile->GetPath(), linked_ptr<ProfileInfo>(info))); | 1356 std::make_pair(profile->GetPath(), linked_ptr<ProfileInfo>(info))); |
| 1355 return info; | 1357 return info; |
| 1356 } | 1358 } |
| 1357 | 1359 |
| 1358 ProfileManager::ProfileInfo* ProfileManager::GetProfileInfoByPath( | 1360 ProfileManager::ProfileInfo* ProfileManager::GetProfileInfoByPath( |
| 1359 const base::FilePath& path) const { | 1361 const base::FilePath& path) const { |
| 1360 ProfilesInfoMap::const_iterator iter = profiles_info_.find(path); | 1362 ProfilesInfoMap::const_iterator iter = profiles_info_.find(path); |
| 1361 return (iter == profiles_info_.end()) ? NULL : iter->second.get(); | 1363 return (iter == profiles_info_.end()) ? NULL : iter->second.get(); |
| 1362 } | 1364 } |
| 1363 | 1365 |
| 1364 void ProfileManager::AddProfileToCache(Profile* profile) { | 1366 void ProfileManager::AddProfileToStorage(Profile* profile) { |
| 1365 TRACE_EVENT0("browser", "ProfileManager::AddProfileToCache"); | 1367 TRACE_EVENT0("browser", "ProfileManager::AddProfileToCache"); |
| 1366 if (profile->IsGuestSession() || profile->IsSystemProfile()) | 1368 if (profile->IsGuestSession() || profile->IsSystemProfile()) |
| 1367 return; | 1369 return; |
| 1368 ProfileInfoCache& cache = GetProfileInfoCache(); | 1370 if (profile->GetPath().DirName() != user_data_dir()) |
| 1369 if (profile->GetPath().DirName() != cache.GetUserDataDir()) | |
| 1370 return; | 1371 return; |
| 1371 | 1372 |
| 1372 SigninManagerBase* signin_manager = | 1373 SigninManagerBase* signin_manager = |
| 1373 SigninManagerFactory::GetForProfile(profile); | 1374 SigninManagerFactory::GetForProfile(profile); |
| 1374 AccountTrackerService* account_tracker = | 1375 AccountTrackerService* account_tracker = |
| 1375 AccountTrackerServiceFactory::GetForProfile(profile); | 1376 AccountTrackerServiceFactory::GetForProfile(profile); |
| 1376 AccountInfo account_info = account_tracker->GetAccountInfo( | 1377 AccountInfo account_info = account_tracker->GetAccountInfo( |
| 1377 signin_manager->GetAuthenticatedAccountId()); | 1378 signin_manager->GetAuthenticatedAccountId()); |
| 1378 base::string16 username = base::UTF8ToUTF16(account_info.email); | 1379 base::string16 username = base::UTF8ToUTF16(account_info.email); |
| 1379 | 1380 |
| 1380 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 1381 ProfileAttributesStorage& storage = GetProfileAttributesStorage(); |
| 1381 if (profile_index != std::string::npos) { | 1382 { |
|
Mike Lerman
2016/03/18 17:10:44
you left a set of parens here
lwchkg
2016/03/19 18:48:46
Actually I deliberately added the braces for scopi
Mike Lerman
2016/03/30 01:18:10
Sure, leave a comment for that please.
lwchkg
2016/03/31 19:32:26
Acknowledged.
| |
| 1382 // The ProfileInfoCache's info must match the Signin Manager. | 1383 ProfileAttributesEntry* entry; |
| 1383 cache.SetAuthInfoOfProfileAtIndex(profile_index, account_info.gaia, | 1384 bool has_entry = storage.GetProfileAttributesWithPath(profile->GetPath(), |
| 1384 username); | 1385 &entry); |
| 1385 return; | 1386 if (has_entry) { |
| 1387 // The ProfileAttributesStorage's info must match the Signin Manager. | |
| 1388 entry->SetAuthInfo(account_info.gaia, username); | |
| 1389 return; | |
| 1390 } | |
| 1386 } | 1391 } |
| 1387 | 1392 |
| 1388 // Profile name and avatar are set by InitProfileUserPrefs and stored in the | 1393 // Profile name and avatar are set by InitProfileUserPrefs and stored in the |
| 1389 // profile. Use those values to setup the cache entry. | 1394 // profile. Use those values to setup the entry in profile attributes storage. |
| 1390 base::string16 profile_name = | 1395 base::string16 profile_name = |
| 1391 base::UTF8ToUTF16(profile->GetPrefs()->GetString(prefs::kProfileName)); | 1396 base::UTF8ToUTF16(profile->GetPrefs()->GetString(prefs::kProfileName)); |
| 1392 | 1397 |
| 1393 size_t icon_index = profile->GetPrefs()->GetInteger( | 1398 size_t icon_index = |
| 1394 prefs::kProfileAvatarIndex); | 1399 profile->GetPrefs()->GetInteger(prefs::kProfileAvatarIndex); |
| 1395 | 1400 |
| 1396 std::string supervised_user_id = | 1401 std::string supervised_user_id = |
| 1397 profile->GetPrefs()->GetString(prefs::kSupervisedUserId); | 1402 profile->GetPrefs()->GetString(prefs::kSupervisedUserId); |
| 1398 | 1403 |
| 1399 cache.AddProfileToCache(profile->GetPath(), | 1404 storage.AddProfile(profile->GetPath(), profile_name, account_info.gaia, |
| 1400 profile_name, | 1405 username, icon_index, supervised_user_id); |
| 1401 account_info.gaia, | |
| 1402 username, | |
| 1403 icon_index, | |
| 1404 supervised_user_id); | |
| 1405 | 1406 |
| 1406 if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) { | 1407 if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) { |
| 1407 cache.SetProfileIsEphemeralAtIndex( | 1408 ProfileAttributesEntry* entry; |
| 1408 cache.GetIndexOfProfileWithPath(profile->GetPath()), true); | 1409 bool has_entry = storage.GetProfileAttributesWithPath(profile->GetPath(), |
| 1410 &entry); | |
| 1411 DCHECK(has_entry); | |
| 1412 entry->SetIsEphemeral(true); | |
| 1409 } | 1413 } |
| 1410 } | 1414 } |
| 1411 | 1415 |
| 1412 void ProfileManager::SetNonPersonalProfilePrefs(Profile* profile) { | 1416 void ProfileManager::SetNonPersonalProfilePrefs(Profile* profile) { |
| 1413 PrefService* prefs = profile->GetPrefs(); | 1417 PrefService* prefs = profile->GetPrefs(); |
| 1414 prefs->SetBoolean(prefs::kSigninAllowed, false); | 1418 prefs->SetBoolean(prefs::kSigninAllowed, false); |
| 1415 prefs->SetBoolean(bookmarks::prefs::kEditBookmarksEnabled, false); | 1419 prefs->SetBoolean(bookmarks::prefs::kEditBookmarksEnabled, false); |
| 1416 prefs->SetBoolean(bookmarks::prefs::kShowBookmarkBar, false); | 1420 prefs->SetBoolean(bookmarks::prefs::kShowBookmarkBar, false); |
| 1417 prefs->ClearPref(DefaultSearchManager::kDefaultSearchProviderDataPrefName); | 1421 prefs->ClearPref(DefaultSearchManager::kDefaultSearchProviderDataPrefName); |
| 1418 } | 1422 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1450 DCHECK(local_state); | 1454 DCHECK(local_state); |
| 1451 // Only keep track of profiles that we are managing; tests may create others. | 1455 // Only keep track of profiles that we are managing; tests may create others. |
| 1452 // Also never consider the SystemProfile as "active". | 1456 // Also never consider the SystemProfile as "active". |
| 1453 if (profiles_info_.find(last_active->GetPath()) != profiles_info_.end() && | 1457 if (profiles_info_.find(last_active->GetPath()) != profiles_info_.end() && |
| 1454 !last_active->IsSystemProfile()) { | 1458 !last_active->IsSystemProfile()) { |
| 1455 std::string profile_path_base = | 1459 std::string profile_path_base = |
| 1456 last_active->GetPath().BaseName().MaybeAsASCII(); | 1460 last_active->GetPath().BaseName().MaybeAsASCII(); |
| 1457 if (profile_path_base != GetLastUsedProfileName()) | 1461 if (profile_path_base != GetLastUsedProfileName()) |
| 1458 profiles::SetLastUsedProfile(profile_path_base); | 1462 profiles::SetLastUsedProfile(profile_path_base); |
| 1459 | 1463 |
| 1460 ProfileInfoCache& cache = GetProfileInfoCache(); | 1464 ProfileAttributesEntry* entry; |
| 1461 size_t profile_index = | 1465 if (GetProfileAttributesStorage(). |
| 1462 cache.GetIndexOfProfileWithPath(last_active->GetPath()); | 1466 GetProfileAttributesWithPath(last_active->GetPath(), &entry)) { |
| 1463 if (profile_index != std::string::npos) { | |
| 1464 #if !defined(OS_CHROMEOS) | 1467 #if !defined(OS_CHROMEOS) |
| 1465 // Incognito Profiles don't have ProfileKeyedServices. | 1468 // Incognito Profiles don't have ProfileKeyedServices. |
| 1466 if (!last_active->IsOffTheRecord()) { | 1469 if (!last_active->IsOffTheRecord()) { |
| 1467 CrossDevicePromoFactory::GetForProfile(last_active) | 1470 CrossDevicePromoFactory::GetForProfile(last_active)-> |
| 1468 ->MaybeBrowsingSessionStarted( | 1471 MaybeBrowsingSessionStarted(entry->GetActiveTime()); |
| 1469 cache.GetProfileActiveTimeAtIndex(profile_index)); | |
| 1470 } | 1472 } |
| 1471 #endif | 1473 #endif |
| 1472 cache.SetProfileActiveTimeAtIndex(profile_index); | 1474 entry->SetActiveTimeToNow(); |
| 1473 } | 1475 } |
| 1474 } | 1476 } |
| 1475 } | 1477 } |
| 1476 | 1478 |
| 1477 ProfileManager::BrowserListObserver::BrowserListObserver( | 1479 ProfileManager::BrowserListObserver::BrowserListObserver( |
| 1478 ProfileManager* manager) | 1480 ProfileManager* manager) |
| 1479 : profile_manager_(manager) { | 1481 : profile_manager_(manager) { |
| 1480 BrowserList::AddObserver(this); | 1482 BrowserList::AddObserver(this); |
| 1481 } | 1483 } |
| 1482 | 1484 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1498 } | 1500 } |
| 1499 | 1501 |
| 1500 base::FilePath path = profile->GetPath(); | 1502 base::FilePath path = profile->GetPath(); |
| 1501 if (IsProfileMarkedForDeletion(path)) { | 1503 if (IsProfileMarkedForDeletion(path)) { |
| 1502 // Do nothing if the profile is already being deleted. | 1504 // Do nothing if the profile is already being deleted. |
| 1503 } else if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) { | 1505 } else if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) { |
| 1504 // Delete if the profile is an ephemeral profile. | 1506 // Delete if the profile is an ephemeral profile. |
| 1505 g_browser_process->profile_manager()->ScheduleProfileForDeletion( | 1507 g_browser_process->profile_manager()->ScheduleProfileForDeletion( |
| 1506 path, ProfileManager::CreateCallback()); | 1508 path, ProfileManager::CreateCallback()); |
| 1507 } else if (!profile->IsSystemProfile()) { | 1509 } else if (!profile->IsSystemProfile()) { |
| 1508 // Gather statistics and store into ProfileInfoCache. For incognito profile | 1510 // Gather statistics and store into ProfileAttributesStorage. For incognito |
| 1509 // we gather the statistics of its parent profile instead, because a window | 1511 // profile we gather the statistics of its parent profile instead, because a |
| 1510 // of the parent profile was open. | 1512 // window of the parent profile was open. |
| 1511 profiles::GatherProfileStatistics( | 1513 profiles::GatherProfileStatistics( |
| 1512 original_profile, profiles::ProfileStatisticsCallback(), nullptr); | 1514 original_profile, profiles::ProfileStatisticsCallback(), nullptr); |
| 1513 } | 1515 } |
| 1514 } | 1516 } |
| 1515 | 1517 |
| 1516 void ProfileManager::BrowserListObserver::OnBrowserSetLastActive( | 1518 void ProfileManager::BrowserListObserver::OnBrowserSetLastActive( |
| 1517 Browser* browser) { | 1519 Browser* browser) { |
| 1518 // If all browsers are being closed (e.g. the user is in the process of | 1520 // If all browsers are being closed (e.g. the user is in the process of |
| 1519 // shutting down), this event will be fired after each browser is | 1521 // shutting down), this event will be fired after each browser is |
| 1520 // closed. This does not represent a user intention to change the active | 1522 // closed. This does not represent a user intention to change the active |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1555 | 1557 |
| 1556 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); | 1558 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); |
| 1557 if (!original_callback.is_null()) | 1559 if (!original_callback.is_null()) |
| 1558 original_callback.Run(loaded_profile, status); | 1560 original_callback.Run(loaded_profile, status); |
| 1559 } | 1561 } |
| 1560 #endif // !defined(OS_ANDROID) | 1562 #endif // !defined(OS_ANDROID) |
| 1561 | 1563 |
| 1562 ProfileManagerWithoutInit::ProfileManagerWithoutInit( | 1564 ProfileManagerWithoutInit::ProfileManagerWithoutInit( |
| 1563 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { | 1565 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { |
| 1564 } | 1566 } |
| OLD | NEW |