Skip to content

Commit

Permalink
Add gaia_id to ProfileInfoCache.
Browse files Browse the repository at this point in the history
Renaming sync_state to username.

BUG=None

Review URL: https://codereview.chromium.org/1117453002

Cr-Commit-Position: refs/heads/master@{#329244}
  • Loading branch information
rogerta authored and Commit bot committed May 11, 2015
1 parent 3d1921c commit e226596
Show file tree
Hide file tree
Showing 37 changed files with 222 additions and 140 deletions.
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/profiles/profile_list_chromeos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void ProfileListChromeOS::RebuildMenu() {

AvatarMenu::Item* item = new AvatarMenu::Item(i, i, icon);
item->name = (*it)->GetDisplayName();
item->sync_state = profile_info_->GetUserNameOfProfileAtIndex(i);
item->username = profile_info_->GetUserNameOfProfileAtIndex(i);
item->profile_path = profile_info_->GetPathOfProfileAtIndex(i);
DCHECK(!profile_info_->ProfileIsLegacySupervisedAtIndex(i));
item->legacy_supervised = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ TEST_F(ProfileListChromeOSTest, DontShowSupervisedUsers) {
// Add a managed user profile.
ProfileInfoCache* cache = manager()->profile_info_cache();
manager()->profile_info_cache()->AddProfileToCache(
cache->GetUserDataDir().AppendASCII("p2"), supervised_name,
cache->GetUserDataDir().AppendASCII("p2"), supervised_name, std::string(),
base::string16(), 0, "TEST_ID");

GetFakeChromeUserManager()->AddUser(base::UTF16ToASCII(supervised_name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class ScreenlockPrivateApiTest : public ExtensionApiTest,
g_browser_process->profile_manager()->GetProfileInfoCache();
size_t index = info_cache.GetIndexOfProfileWithPath(profile()->GetPath());
ASSERT_NE(std::string::npos, index);
info_cache.SetUserNameOfProfileAtIndex(index, base::UTF8ToUTF16(kTestUser));
info_cache.SetAuthInfoOfProfileAtIndex(index, kTestGaiaId,
base::UTF8ToUTF16(kTestUser));
ExtensionApiTest::SetUpOnMainThread();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ void MessageCenterSettingsController::OnProfileNameChanged(
const base::string16& old_profile_name) {
RebuildNotifierGroups(true);
}
void MessageCenterSettingsController::OnProfileUserNameChanged(
void MessageCenterSettingsController::OnProfileAuthInfoChanged(
const base::FilePath& profile_path) {
RebuildNotifierGroups(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class MessageCenterSettingsController
const base::string16& profile_name) override;
void OnProfileNameChanged(const base::FilePath& profile_path,
const base::string16& old_profile_name) override;
void OnProfileUserNameChanged(const base::FilePath& profile_path) override;
void OnProfileAuthInfoChanged(const base::FilePath& profile_path) override;

void OnFaviconLoaded(const GURL& url,
const favicon_base::FaviconImageResult& favicon_result);
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/profiles/avatar_menu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void AvatarMenu::OnProfileNameChanged(const base::FilePath& profile_path,
Update();
}

void AvatarMenu::OnProfileUserNameChanged(const base::FilePath& profile_path) {
void AvatarMenu::OnProfileAuthInfoChanged(const base::FilePath& profile_path) {
Update();
}

Expand Down
7 changes: 4 additions & 3 deletions chrome/browser/profiles/avatar_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ class AvatarMenu :
// The name of this profile.
base::string16 name;

// A string representing the sync state of the profile.
base::string16 sync_state;
// A string representing the username of the profile, if signed in. Empty
// when not signed in.
base::string16 username;

// Whether or not the current profile is signed in. If true, |sync_state| is
// expected to be the email of the signed in user.
Expand Down Expand Up @@ -157,7 +158,7 @@ class AvatarMenu :
const base::string16& profile_name) override;
void OnProfileNameChanged(const base::FilePath& profile_path,
const base::string16& old_profile_name) override;
void OnProfileUserNameChanged(const base::FilePath& profile_path) override;
void OnProfileAuthInfoChanged(const base::FilePath& profile_path) override;
void OnProfileAvatarChanged(const base::FilePath& profile_path) override;
void OnProfileHighResAvatarLoaded(
const base::FilePath& profile_path) override;
Expand Down
36 changes: 31 additions & 5 deletions chrome/browser/profiles/profile_info_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const char kNameKey[] = "name";
const char kShortcutNameKey[] = "shortcut_name";
const char kGAIANameKey[] = "gaia_name";
const char kGAIAGivenNameKey[] = "gaia_given_name";
const char kGAIAIdKey[] = "gaia_id";
const char kUserNameKey[] = "user_name";
const char kIsUsingDefaultNameKey[] = "is_using_default_name";
const char kIsUsingDefaultAvatarKey[] = "is_using_default_avatar";
Expand Down Expand Up @@ -197,7 +198,8 @@ ProfileInfoCache::~ProfileInfoCache() {
void ProfileInfoCache::AddProfileToCache(
const base::FilePath& profile_path,
const base::string16& name,
const base::string16& username,
const std::string& gaia_id,
const base::string16& user_name,
size_t icon_index,
const std::string& supervised_user_id) {
std::string key = CacheKeyFromProfilePath(profile_path);
Expand All @@ -206,7 +208,8 @@ void ProfileInfoCache::AddProfileToCache(

scoped_ptr<base::DictionaryValue> info(new base::DictionaryValue);
info->SetString(kNameKey, name);
info->SetString(kUserNameKey, username);
info->SetString(kGAIAIdKey, gaia_id);
info->SetString(kUserNameKey, user_name);
info->SetString(kAvatarIconKey,
profiles::GetDefaultAvatarIconUrl(icon_index));
// Default value for whether background apps are running is false.
Expand Down Expand Up @@ -369,6 +372,13 @@ base::string16 ProfileInfoCache::GetGAIAGivenNameOfProfileAtIndex(
return name;
}

std::string ProfileInfoCache::GetGAIAIdOfProfileAtIndex(
size_t index) const {
std::string gaia_id;
GetInfoForProfileAtIndex(index)->GetString(kGAIAIdKey, &gaia_id);
return gaia_id;
}

const gfx::Image* ProfileInfoCache::GetGAIAPictureOfProfileAtIndex(
size_t index) const {
base::FilePath path = GetPathOfProfileAtIndex(index);
Expand Down Expand Up @@ -447,6 +457,15 @@ bool ProfileInfoCache::ProfileIsUsingDefaultNameAtIndex(size_t index) const {
return value;
}

bool ProfileInfoCache::ProfileIsAuthenticatedAtIndex(size_t index) const {
// The profile is authenticated if the gaia_id of the info is not empty.
// If it is empty, also check if the user name is not empty. This latter
// check is needed in case the profile has not been loaded yet and the
// gaia_id property has not yet been written.
return !GetGAIAIdOfProfileAtIndex(index).empty() ||
!GetUserNameOfProfileAtIndex(index).empty();
}

bool ProfileInfoCache::ProfileIsUsingDefaultAvatarAtIndex(size_t index) const {
bool value = false;
GetInfoForProfileAtIndex(index)->GetBoolean(kIsUsingDefaultAvatarKey, &value);
Expand Down Expand Up @@ -521,22 +540,29 @@ void ProfileInfoCache::SetShortcutNameOfProfileAtIndex(
SetInfoForProfileAtIndex(index, info.release());
}

void ProfileInfoCache::SetUserNameOfProfileAtIndex(
void ProfileInfoCache::SetAuthInfoOfProfileAtIndex(
size_t index,
const std::string& gaia_id,
const base::string16& user_name) {
if (user_name == GetUserNameOfProfileAtIndex(index))
// If both gaia_id and username are unchanged, abort early.
if (gaia_id == GetGAIAIdOfProfileAtIndex(index) &&
user_name == GetUserNameOfProfileAtIndex(index)) {
return;
}

scoped_ptr<base::DictionaryValue> info(
GetInfoForProfileAtIndex(index)->DeepCopy());

info->SetString(kGAIAIdKey, gaia_id);
info->SetString(kUserNameKey, user_name);

// This takes ownership of |info|.
SetInfoForProfileAtIndex(index, info.release());

base::FilePath profile_path = GetPathOfProfileAtIndex(index);
FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
observer_list_,
OnProfileUserNameChanged(profile_path));
OnProfileAuthInfoChanged(profile_path));
}

void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index,
Expand Down
8 changes: 6 additions & 2 deletions chrome/browser/profiles/profile_info_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class ProfileInfoCache : public ProfileInfoInterface,
// be shown in the menu.
void AddProfileToCache(const base::FilePath& profile_path,
const base::string16& name,
const base::string16& username,
const std::string& gaia_id,
const base::string16& user_name,
size_t icon_index,
const std::string& supervised_user_id);
void DeleteProfileFromCache(const base::FilePath& profile_path);
Expand All @@ -71,6 +72,7 @@ class ProfileInfoCache : public ProfileInfoInterface,
bool GetBackgroundStatusOfProfileAtIndex(size_t index) const override;
base::string16 GetGAIANameOfProfileAtIndex(size_t index) const override;
base::string16 GetGAIAGivenNameOfProfileAtIndex(size_t index) const override;
std::string GetGAIAIdOfProfileAtIndex(size_t index) const override;
// Returns the GAIA picture for the given profile. This may return NULL
// if the profile does not have a GAIA picture or if the picture must be
// loaded from disk.
Expand All @@ -84,6 +86,7 @@ class ProfileInfoCache : public ProfileInfoInterface,
std::string GetSupervisedUserIdOfProfileAtIndex(size_t index) const override;
bool ProfileIsEphemeralAtIndex(size_t index) const override;
bool ProfileIsUsingDefaultNameAtIndex(size_t index) const override;
bool ProfileIsAuthenticatedAtIndex(size_t index) const override;
bool ProfileIsUsingDefaultAvatarAtIndex(size_t index) const override;
bool ProfileIsAuthErrorAtIndex(size_t index) const;

Expand All @@ -94,7 +97,8 @@ class ProfileInfoCache : public ProfileInfoInterface,
void SetNameOfProfileAtIndex(size_t index, const base::string16& name);
void SetShortcutNameOfProfileAtIndex(size_t index,
const base::string16& name);
void SetUserNameOfProfileAtIndex(size_t index,
void SetAuthInfoOfProfileAtIndex(size_t index,
const std::string& gaia_id,
const base::string16& user_name);
void SetAvatarIconOfProfileAtIndex(size_t index, size_t icon_index);
void SetIsOmittedProfileAtIndex(size_t index, bool is_omitted);
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/profiles/profile_info_cache_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ProfileInfoCacheObserver {
const base::string16& profile_name) {}
virtual void OnProfileNameChanged(const base::FilePath& profile_path,
const base::string16& old_profile_name) {}
virtual void OnProfileUserNameChanged(const base::FilePath& profile_path) {}
virtual void OnProfileAuthInfoChanged(const base::FilePath& profile_path) {}
virtual void OnProfileAvatarChanged(const base::FilePath& profile_path) {}
virtual void OnProfileHighResAvatarLoaded(
const base::FilePath& profile_path) {}
Expand Down
Loading

0 comments on commit e226596

Please sign in to comment.