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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 ProfileInfoCache& cache = GetProfileInfoCache(); | 621 ProfileInfoCache& cache = GetProfileInfoCache(); |
609 if (profile->GetPath().DirName() != cache.GetUserDataDir()) | 622 if (profile->GetPath().DirName() != cache.GetUserDataDir()) |
610 return; | 623 return; |
611 | 624 |
612 if (cache.GetIndexOfProfileWithPath(profile->GetPath()) != std::string::npos) | 625 if (cache.GetIndexOfProfileWithPath(profile->GetPath()) != std::string::npos) |
613 return; | 626 return; |
614 | 627 |
615 string16 username = UTF8ToUTF16(profile->GetPrefs()->GetString( | 628 string16 username = UTF8ToUTF16(profile->GetPrefs()->GetString( |
616 prefs::kGoogleServicesUsername)); | 629 prefs::kGoogleServicesUsername)); |
617 | 630 |
618 if (profile->GetPath() == GetDefaultProfileDir(cache.GetUserDataDir())) { | 631 string16 profile_name = UTF8ToUTF16(profile->GetPrefs()->GetString( |
619 cache.AddProfileToCache( | 632 prefs::kProfileName)); |
620 profile->GetPath(), | 633 |
621 l10n_util::GetStringUTF16(IDS_DEFAULT_PROFILE_NAME), username, 0); | 634 size_t icon_index = profile->GetPrefs()->GetInteger( |
622 } else { | 635 prefs::kProfileAvatarIndex); |
623 size_t icon_index = cache.ChooseAvatarIconIndexForNewProfile(); | 636 |
624 cache.AddProfileToCache(profile->GetPath(), | 637 cache.AddProfileToCache(profile->GetPath(), |
625 cache.ChooseNameForNewProfile(icon_index), | 638 profile_name, |
626 username, | 639 username, |
627 icon_index); | 640 icon_index); |
| 641 } |
| 642 |
| 643 void ProfileManager::InitProfileUserPrefs(Profile* profile) { |
| 644 ProfileInfoCache& cache = GetProfileInfoCache(); |
| 645 |
| 646 if (profile->GetPath().DirName() != cache.GetUserDataDir()) |
| 647 return; |
| 648 |
| 649 if (HasAnyDefaultUserPrefs(profile)) { |
| 650 size_t profile_cache_index = |
| 651 cache.GetIndexOfProfileWithPath(profile->GetPath()); |
| 652 if (profile_cache_index != std::string::npos) { |
| 653 profile->GetPrefs()->SetInteger(prefs::kProfileAvatarIndex, |
| 654 cache.GetAvatarIconIndexOfProfileAtIndex(profile_cache_index)); |
| 655 profile->GetPrefs()->SetString(prefs::kProfileName, |
| 656 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_cache_index))); |
| 657 } else if (profile->GetPath() == |
| 658 GetDefaultProfileDir(cache.GetUserDataDir())) { |
| 659 profile->GetPrefs()->SetInteger(prefs::kProfileAvatarIndex, 0); |
| 660 profile->GetPrefs()->SetString(prefs::kProfileName, |
| 661 l10n_util::GetStringUTF8(IDS_DEFAULT_PROFILE_NAME)); |
| 662 } else { |
| 663 size_t icon_index = cache.ChooseAvatarIconIndexForNewProfile(); |
| 664 profile->GetPrefs()->SetInteger(prefs::kProfileAvatarIndex, icon_index); |
| 665 profile->GetPrefs()->SetString( |
| 666 prefs::kProfileName, |
| 667 UTF16ToUTF8(cache.ChooseNameForNewProfile(icon_index))); |
| 668 } |
628 } | 669 } |
629 } | 670 } |
630 | 671 |
631 bool ProfileManager::ShouldGoOffTheRecord() { | 672 bool ProfileManager::ShouldGoOffTheRecord() { |
632 bool go_off_the_record = false; | 673 bool go_off_the_record = false; |
633 #if defined(OS_CHROMEOS) | 674 #if defined(OS_CHROMEOS) |
634 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 675 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
635 if (!logged_in_ && | 676 if (!logged_in_ && |
636 (!command_line.HasSwitch(switches::kTestType) || | 677 (!command_line.HasSwitch(switches::kTestType) || |
637 command_line.HasSwitch(switches::kLoginProfile))) { | 678 command_line.HasSwitch(switches::kLoginProfile))) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 RegisterProfile(profile, true); | 750 RegisterProfile(profile, true); |
710 if (add_to_cache) | 751 if (add_to_cache) |
711 AddProfileToCache(profile); | 752 AddProfileToCache(profile); |
712 } | 753 } |
713 | 754 |
714 #if defined(OS_WIN) | 755 #if defined(OS_WIN) |
715 void ProfileManager::RemoveProfileShortcutManagerForTesting() { | 756 void ProfileManager::RemoveProfileShortcutManagerForTesting() { |
716 profile_info_cache_->RemoveObserver(profile_shortcut_manager_.get()); | 757 profile_info_cache_->RemoveObserver(profile_shortcut_manager_.get()); |
717 } | 758 } |
718 #endif | 759 #endif |
OLD | NEW |