Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(491)

Side by Side Diff: chrome/browser/profiles/profile_manager.cc

Issue 8801034: Revert 112856 - Making profile avatars and names sync. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
72 // Simple task to log the size of the current profile. 60 // Simple task to log the size of the current profile.
73 class ProfileSizeTask : public Task { 61 class ProfileSizeTask : public Task {
74 public: 62 public:
75 explicit ProfileSizeTask(Profile* profile); 63 explicit ProfileSizeTask(Profile* profile);
76 virtual ~ProfileSizeTask() {} 64 virtual ~ProfileSizeTask() {}
77 65
78 virtual void Run(); 66 virtual void Run();
79 private: 67 private:
80 FilePath path_; 68 FilePath path_;
81 int extension_count_; 69 int extension_count_;
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 DCHECK(local_state); 462 DCHECK(local_state);
475 // Only keep track of profiles that we are managing; tests may create others. 463 // Only keep track of profiles that we are managing; tests may create others.
476 if (profiles_info_.find(last_active->GetPath()) != profiles_info_.end()) { 464 if (profiles_info_.find(last_active->GetPath()) != profiles_info_.end()) {
477 local_state->SetString(prefs::kProfileLastUsed, 465 local_state->SetString(prefs::kProfileLastUsed,
478 last_active->GetPath().BaseName().MaybeAsASCII()); 466 last_active->GetPath().BaseName().MaybeAsASCII());
479 } 467 }
480 } 468 }
481 469
482 void ProfileManager::DoFinalInit(Profile* profile, bool go_off_the_record) { 470 void ProfileManager::DoFinalInit(Profile* profile, bool go_off_the_record) {
483 DoFinalInitForServices(profile, go_off_the_record); 471 DoFinalInitForServices(profile, go_off_the_record);
484 InitProfileUserPrefs(profile);
485 AddProfileToCache(profile); 472 AddProfileToCache(profile);
486 DoFinalInitLogging(profile); 473 DoFinalInitLogging(profile);
487 } 474 }
488 475
489 void ProfileManager::DoFinalInitForServices(Profile* profile, 476 void ProfileManager::DoFinalInitForServices(Profile* profile,
490 bool go_off_the_record) { 477 bool go_off_the_record) {
491 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 478 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
492 profile->InitExtensions(!go_off_the_record); 479 profile->InitExtensions(!go_off_the_record);
493 if (!command_line.HasSwitch(switches::kDisableWebResources)) 480 if (!command_line.HasSwitch(switches::kDisableWebResources))
494 profile->InitPromoResources(); 481 profile->InitPromoResources();
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 ProfileInfoCache& cache = GetProfileInfoCache(); 613 ProfileInfoCache& cache = GetProfileInfoCache();
627 if (profile->GetPath().DirName() != cache.GetUserDataDir()) 614 if (profile->GetPath().DirName() != cache.GetUserDataDir())
628 return; 615 return;
629 616
630 if (cache.GetIndexOfProfileWithPath(profile->GetPath()) != std::string::npos) 617 if (cache.GetIndexOfProfileWithPath(profile->GetPath()) != std::string::npos)
631 return; 618 return;
632 619
633 string16 username = UTF8ToUTF16(profile->GetPrefs()->GetString( 620 string16 username = UTF8ToUTF16(profile->GetPrefs()->GetString(
634 prefs::kGoogleServicesUsername)); 621 prefs::kGoogleServicesUsername));
635 622
636 // Profile name and avatar are set by InitProfileUserPrefs and stored in the 623 if (profile->GetPath() == GetDefaultProfileDir(cache.GetUserDataDir())) {
637 // profile. Use those values to setup the cache entry. 624 cache.AddProfileToCache(
638 string16 profile_name = UTF8ToUTF16(profile->GetPrefs()->GetString( 625 profile->GetPath(),
639 prefs::kProfileName)); 626 l10n_util::GetStringUTF16(IDS_DEFAULT_PROFILE_NAME), username, 0);
640 627 } else {
641 size_t icon_index = profile->GetPrefs()->GetInteger( 628 size_t icon_index = cache.ChooseAvatarIconIndexForNewProfile();
642 prefs::kProfileAvatarIndex); 629 cache.AddProfileToCache(profile->GetPath(),
643 630 cache.ChooseNameForNewProfile(icon_index),
644 cache.AddProfileToCache(profile->GetPath(), 631 username,
645 profile_name, 632 icon_index);
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 }
679 } 633 }
680 } 634 }
681 635
682 bool ProfileManager::ShouldGoOffTheRecord() { 636 bool ProfileManager::ShouldGoOffTheRecord() {
683 bool go_off_the_record = false; 637 bool go_off_the_record = false;
684 #if defined(OS_CHROMEOS) 638 #if defined(OS_CHROMEOS)
685 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 639 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
686 if (!logged_in_ && 640 if (!logged_in_ &&
687 (!command_line.HasSwitch(switches::kTestType) || 641 (!command_line.HasSwitch(switches::kTestType) ||
688 command_line.HasSwitch(switches::kLoginProfile))) { 642 command_line.HasSwitch(switches::kLoginProfile))) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 RegisterProfile(profile, true); 719 RegisterProfile(profile, true);
766 if (add_to_cache) 720 if (add_to_cache)
767 AddProfileToCache(profile); 721 AddProfileToCache(profile);
768 } 722 }
769 723
770 #if defined(OS_WIN) 724 #if defined(OS_WIN)
771 void ProfileManager::RemoveProfileShortcutManagerForTesting() { 725 void ProfileManager::RemoveProfileShortcutManagerForTesting() {
772 profile_info_cache_->RemoveObserver(profile_shortcut_manager_.get()); 726 profile_info_cache_->RemoveObserver(profile_shortcut_manager_.get());
773 } 727 }
774 #endif 728 #endif
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_manager.h ('k') | chrome/browser/profiles/profile_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698