OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <set> | 5 #include <set> |
6 | 6 |
7 #include "chrome/browser/profiles/profile_manager.h" | 7 #include "chrome/browser/profiles/profile_manager.h" |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 using content::BrowserThread; | 50 using content::BrowserThread; |
51 | 51 |
52 namespace { | 52 namespace { |
53 | 53 |
54 // Profiles that should be deleted on shutdown. | 54 // Profiles that should be deleted on shutdown. |
55 std::vector<FilePath>& ProfilesToDelete() { | 55 std::vector<FilePath>& ProfilesToDelete() { |
56 CR_DEFINE_STATIC_LOCAL(std::vector<FilePath>, profiles_to_delete, ()); | 56 CR_DEFINE_STATIC_LOCAL(std::vector<FilePath>, profiles_to_delete, ()); |
57 return profiles_to_delete; | 57 return profiles_to_delete; |
58 } | 58 } |
59 | 59 |
| 60 // Checks if any user prefs for |profile| have default values. |
| 61 bool HasAnyDefaultUserPrefs(Profile* profile) { |
| 62 const PrefService::Preference* avatar_index = |
| 63 profile->GetPrefs()->FindPreference(prefs::kProfileAvatarIndex); |
| 64 DCHECK(avatar_index); |
| 65 const PrefService::Preference* profile_name = |
| 66 profile->GetPrefs()->FindPreference(prefs::kProfileName); |
| 67 DCHECK(profile_name); |
| 68 return avatar_index->IsDefaultValue() || |
| 69 profile_name->IsDefaultValue(); |
| 70 } |
| 71 |
60 // Simple task to log the size of the current profile. | 72 // Simple task to log the size of the current profile. |
61 class ProfileSizeTask : public Task { | 73 class ProfileSizeTask : public Task { |
62 public: | 74 public: |
63 explicit ProfileSizeTask(Profile* profile); | 75 explicit ProfileSizeTask(Profile* profile); |
64 virtual ~ProfileSizeTask() {} | 76 virtual ~ProfileSizeTask() {} |
65 | 77 |
66 virtual void Run(); | 78 virtual void Run(); |
67 private: | 79 private: |
68 FilePath path_; | 80 FilePath path_; |
69 int extension_count_; | 81 int extension_count_; |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 DCHECK(local_state); | 474 DCHECK(local_state); |
463 // Only keep track of profiles that we are managing; tests may create others. | 475 // Only keep track of profiles that we are managing; tests may create others. |
464 if (profiles_info_.find(last_active->GetPath()) != profiles_info_.end()) { | 476 if (profiles_info_.find(last_active->GetPath()) != profiles_info_.end()) { |
465 local_state->SetString(prefs::kProfileLastUsed, | 477 local_state->SetString(prefs::kProfileLastUsed, |
466 last_active->GetPath().BaseName().MaybeAsASCII()); | 478 last_active->GetPath().BaseName().MaybeAsASCII()); |
467 } | 479 } |
468 } | 480 } |
469 | 481 |
470 void ProfileManager::DoFinalInit(Profile* profile, bool go_off_the_record) { | 482 void ProfileManager::DoFinalInit(Profile* profile, bool go_off_the_record) { |
471 DoFinalInitForServices(profile, go_off_the_record); | 483 DoFinalInitForServices(profile, go_off_the_record); |
| 484 InitProfileUserPrefs(profile); |
472 AddProfileToCache(profile); | 485 AddProfileToCache(profile); |
473 DoFinalInitLogging(profile); | 486 DoFinalInitLogging(profile); |
474 } | 487 } |
475 | 488 |
476 void ProfileManager::DoFinalInitForServices(Profile* profile, | 489 void ProfileManager::DoFinalInitForServices(Profile* profile, |
477 bool go_off_the_record) { | 490 bool go_off_the_record) { |
478 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 491 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
479 profile->InitExtensions(!go_off_the_record); | 492 profile->InitExtensions(!go_off_the_record); |
480 if (!command_line.HasSwitch(switches::kDisableWebResources)) | 493 if (!command_line.HasSwitch(switches::kDisableWebResources)) |
481 profile->InitPromoResources(); | 494 profile->InitPromoResources(); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 ProfileInfoCache& cache = GetProfileInfoCache(); | 626 ProfileInfoCache& cache = GetProfileInfoCache(); |
614 if (profile->GetPath().DirName() != cache.GetUserDataDir()) | 627 if (profile->GetPath().DirName() != cache.GetUserDataDir()) |
615 return; | 628 return; |
616 | 629 |
617 if (cache.GetIndexOfProfileWithPath(profile->GetPath()) != std::string::npos) | 630 if (cache.GetIndexOfProfileWithPath(profile->GetPath()) != std::string::npos) |
618 return; | 631 return; |
619 | 632 |
620 string16 username = UTF8ToUTF16(profile->GetPrefs()->GetString( | 633 string16 username = UTF8ToUTF16(profile->GetPrefs()->GetString( |
621 prefs::kGoogleServicesUsername)); | 634 prefs::kGoogleServicesUsername)); |
622 | 635 |
623 if (profile->GetPath() == GetDefaultProfileDir(cache.GetUserDataDir())) { | 636 // Profile name and avatar are set by InitProfileUserPrefs and stored in the |
624 cache.AddProfileToCache( | 637 // profile. Use those values to setup the cache entry. |
625 profile->GetPath(), | 638 string16 profile_name = UTF8ToUTF16(profile->GetPrefs()->GetString( |
626 l10n_util::GetStringUTF16(IDS_DEFAULT_PROFILE_NAME), username, 0); | 639 prefs::kProfileName)); |
627 } else { | 640 |
628 size_t icon_index = cache.ChooseAvatarIconIndexForNewProfile(); | 641 size_t icon_index = profile->GetPrefs()->GetInteger( |
629 cache.AddProfileToCache(profile->GetPath(), | 642 prefs::kProfileAvatarIndex); |
630 cache.ChooseNameForNewProfile(icon_index), | 643 |
631 username, | 644 cache.AddProfileToCache(profile->GetPath(), |
632 icon_index); | 645 profile_name, |
| 646 username, |
| 647 icon_index); |
| 648 } |
| 649 |
| 650 void ProfileManager::InitProfileUserPrefs(Profile* profile) { |
| 651 ProfileInfoCache& cache = GetProfileInfoCache(); |
| 652 |
| 653 if (profile->GetPath().DirName() != cache.GetUserDataDir()) |
| 654 return; |
| 655 |
| 656 // Initialize the user preferences (name and avatar) only if the profile |
| 657 // doesn't have default preferenc values for them. |
| 658 if (HasAnyDefaultUserPrefs(profile)) { |
| 659 size_t profile_cache_index = |
| 660 cache.GetIndexOfProfileWithPath(profile->GetPath()); |
| 661 // If the cache has an entry for this profile, use the cache data |
| 662 if (profile_cache_index != std::string::npos) { |
| 663 profile->GetPrefs()->SetInteger(prefs::kProfileAvatarIndex, |
| 664 cache.GetAvatarIconIndexOfProfileAtIndex(profile_cache_index)); |
| 665 profile->GetPrefs()->SetString(prefs::kProfileName, |
| 666 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_cache_index))); |
| 667 } else if (profile->GetPath() == |
| 668 GetDefaultProfileDir(cache.GetUserDataDir())) { |
| 669 profile->GetPrefs()->SetInteger(prefs::kProfileAvatarIndex, 0); |
| 670 profile->GetPrefs()->SetString(prefs::kProfileName, |
| 671 l10n_util::GetStringUTF8(IDS_DEFAULT_PROFILE_NAME)); |
| 672 } else { |
| 673 size_t icon_index = cache.ChooseAvatarIconIndexForNewProfile(); |
| 674 profile->GetPrefs()->SetInteger(prefs::kProfileAvatarIndex, icon_index); |
| 675 profile->GetPrefs()->SetString( |
| 676 prefs::kProfileName, |
| 677 UTF16ToUTF8(cache.ChooseNameForNewProfile(icon_index))); |
| 678 } |
633 } | 679 } |
634 } | 680 } |
635 | 681 |
636 bool ProfileManager::ShouldGoOffTheRecord() { | 682 bool ProfileManager::ShouldGoOffTheRecord() { |
637 bool go_off_the_record = false; | 683 bool go_off_the_record = false; |
638 #if defined(OS_CHROMEOS) | 684 #if defined(OS_CHROMEOS) |
639 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 685 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
640 if (!logged_in_ && | 686 if (!logged_in_ && |
641 (!command_line.HasSwitch(switches::kTestType) || | 687 (!command_line.HasSwitch(switches::kTestType) || |
642 command_line.HasSwitch(switches::kLoginProfile))) { | 688 command_line.HasSwitch(switches::kLoginProfile))) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 RegisterProfile(profile, true); | 760 RegisterProfile(profile, true); |
715 if (add_to_cache) | 761 if (add_to_cache) |
716 AddProfileToCache(profile); | 762 AddProfileToCache(profile); |
717 } | 763 } |
718 | 764 |
719 #if defined(OS_WIN) | 765 #if defined(OS_WIN) |
720 void ProfileManager::RemoveProfileShortcutManagerForTesting() { | 766 void ProfileManager::RemoveProfileShortcutManagerForTesting() { |
721 profile_info_cache_->RemoveObserver(profile_shortcut_manager_.get()); | 767 profile_info_cache_->RemoveObserver(profile_shortcut_manager_.get()); |
722 } | 768 } |
723 #endif | 769 #endif |
OLD | NEW |