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

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

Issue 8771024: Making profile avatars and names sync. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: updating to rlp's changes and fixing things so unit tests run and pass 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
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
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
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 string16 profile_name = UTF8ToUTF16(profile->GetPrefs()->GetString(
sail 2011/12/02 19:07:10 can you add a comment to explain why you're doing
jwd 2011/12/02 21:10:16 Done.
624 cache.AddProfileToCache( 637 prefs::kProfileName));
625 profile->GetPath(), 638
626 l10n_util::GetStringUTF16(IDS_DEFAULT_PROFILE_NAME), username, 0); 639 size_t icon_index = profile->GetPrefs()->GetInteger(
627 } else { 640 prefs::kProfileAvatarIndex);
628 size_t icon_index = cache.ChooseAvatarIconIndexForNewProfile(); 641
629 cache.AddProfileToCache(profile->GetPath(), 642 cache.AddProfileToCache(profile->GetPath(),
630 cache.ChooseNameForNewProfile(icon_index), 643 profile_name,
631 username, 644 username,
632 icon_index); 645 icon_index);
646 }
647
648 void ProfileManager::InitProfileUserPrefs(Profile* profile) {
649 ProfileInfoCache& cache = GetProfileInfoCache();
650
651 if (profile->GetPath().DirName() != cache.GetUserDataDir())
652 return;
653
654 if (HasAnyDefaultUserPrefs(profile)) {
sail 2011/12/02 19:07:10 can you add a comment to explain why you're doing
jwd 2011/12/02 21:10:16 Done.
655 size_t profile_cache_index =
656 cache.GetIndexOfProfileWithPath(profile->GetPath());
657 if (profile_cache_index != std::string::npos) {
658 profile->GetPrefs()->SetInteger(prefs::kProfileAvatarIndex,
659 cache.GetAvatarIconIndexOfProfileAtIndex(profile_cache_index));
660 profile->GetPrefs()->SetString(prefs::kProfileName,
661 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_cache_index)));
662 } else if (profile->GetPath() ==
663 GetDefaultProfileDir(cache.GetUserDataDir())) {
664 profile->GetPrefs()->SetInteger(prefs::kProfileAvatarIndex, 0);
665 profile->GetPrefs()->SetString(prefs::kProfileName,
666 l10n_util::GetStringUTF8(IDS_DEFAULT_PROFILE_NAME));
667 } else {
668 size_t icon_index = cache.ChooseAvatarIconIndexForNewProfile();
669 profile->GetPrefs()->SetInteger(prefs::kProfileAvatarIndex, icon_index);
670 profile->GetPrefs()->SetString(
671 prefs::kProfileName,
672 UTF16ToUTF8(cache.ChooseNameForNewProfile(icon_index)));
673 }
633 } 674 }
634 } 675 }
635 676
636 bool ProfileManager::ShouldGoOffTheRecord() { 677 bool ProfileManager::ShouldGoOffTheRecord() {
637 bool go_off_the_record = false; 678 bool go_off_the_record = false;
638 #if defined(OS_CHROMEOS) 679 #if defined(OS_CHROMEOS)
639 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 680 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
640 if (!logged_in_ && 681 if (!logged_in_ &&
641 (!command_line.HasSwitch(switches::kTestType) || 682 (!command_line.HasSwitch(switches::kTestType) ||
642 command_line.HasSwitch(switches::kLoginProfile))) { 683 command_line.HasSwitch(switches::kLoginProfile))) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 RegisterProfile(profile, true); 755 RegisterProfile(profile, true);
715 if (add_to_cache) 756 if (add_to_cache)
716 AddProfileToCache(profile); 757 AddProfileToCache(profile);
717 } 758 }
718 759
719 #if defined(OS_WIN) 760 #if defined(OS_WIN)
720 void ProfileManager::RemoveProfileShortcutManagerForTesting() { 761 void ProfileManager::RemoveProfileShortcutManagerForTesting() {
721 profile_info_cache_->RemoveObserver(profile_shortcut_manager_.get()); 762 profile_info_cache_->RemoveObserver(profile_shortcut_manager_.get());
722 } 763 }
723 #endif 764 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698