OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/profiles/profile_info_cache.h" | 5 #include "chrome/browser/profiles/profile_info_cache.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 // that the user hasn't done this on purpose. | 159 // that the user hasn't done this on purpose. |
160 using_default_name = IsDefaultProfileName(name); | 160 using_default_name = IsDefaultProfileName(name); |
161 info->SetBoolean(kIsUsingDefaultNameKey, using_default_name); | 161 info->SetBoolean(kIsUsingDefaultNameKey, using_default_name); |
162 } | 162 } |
163 | 163 |
164 // For profiles that don't have the "using default avatar" state set yet, | 164 // For profiles that don't have the "using default avatar" state set yet, |
165 // assume it's the same as the "using default name" state. | 165 // assume it's the same as the "using default name" state. |
166 if (!info->HasKey(kIsUsingDefaultAvatarKey)) { | 166 if (!info->HasKey(kIsUsingDefaultAvatarKey)) { |
167 info->SetBoolean(kIsUsingDefaultAvatarKey, using_default_name); | 167 info->SetBoolean(kIsUsingDefaultAvatarKey, using_default_name); |
168 } | 168 } |
| 169 |
| 170 std::string supervised_user_id; |
| 171 if (info->GetString(kSupervisedUserId, &supervised_user_id) && |
| 172 !supervised_user_id.empty()) { |
| 173 prefs_->SetBoolean(prefs::kSupervisedUserExistsOrExisted, true); |
| 174 } |
169 } | 175 } |
170 | 176 |
171 // If needed, start downloading the high-res avatars and migrate any legacy | 177 // If needed, start downloading the high-res avatars and migrate any legacy |
172 // profile names. | 178 // profile names. |
173 if (switches::IsNewAvatarMenu()) | 179 if (switches::IsNewAvatarMenu()) |
174 MigrateLegacyProfileNamesAndDownloadAvatars(); | 180 MigrateLegacyProfileNamesAndDownloadAvatars(); |
175 } | 181 } |
176 | 182 |
177 ProfileInfoCache::~ProfileInfoCache() { | 183 ProfileInfoCache::~ProfileInfoCache() { |
178 STLDeleteContainerPairSecondPointers( | 184 STLDeleteContainerPairSecondPointers( |
(...skipping 14 matching lines...) Expand all Loading... |
193 base::DictionaryValue* cache = update.Get(); | 199 base::DictionaryValue* cache = update.Get(); |
194 | 200 |
195 scoped_ptr<base::DictionaryValue> info(new base::DictionaryValue); | 201 scoped_ptr<base::DictionaryValue> info(new base::DictionaryValue); |
196 info->SetString(kNameKey, name); | 202 info->SetString(kNameKey, name); |
197 info->SetString(kUserNameKey, username); | 203 info->SetString(kUserNameKey, username); |
198 info->SetString(kAvatarIconKey, | 204 info->SetString(kAvatarIconKey, |
199 profiles::GetDefaultAvatarIconUrl(icon_index)); | 205 profiles::GetDefaultAvatarIconUrl(icon_index)); |
200 // Default value for whether background apps are running is false. | 206 // Default value for whether background apps are running is false. |
201 info->SetBoolean(kBackgroundAppsKey, false); | 207 info->SetBoolean(kBackgroundAppsKey, false); |
202 info->SetString(kSupervisedUserId, supervised_user_id); | 208 info->SetString(kSupervisedUserId, supervised_user_id); |
| 209 if (!supervised_user_id.empty()) |
| 210 prefs_->SetBoolean(prefs::kSupervisedUserExistsOrExisted, true); |
203 info->SetBoolean(kIsOmittedFromProfileListKey, !supervised_user_id.empty()); | 211 info->SetBoolean(kIsOmittedFromProfileListKey, !supervised_user_id.empty()); |
204 info->SetBoolean(kProfileIsEphemeral, false); | 212 info->SetBoolean(kProfileIsEphemeral, false); |
205 info->SetBoolean(kIsUsingDefaultNameKey, IsDefaultProfileName(name)); | 213 info->SetBoolean(kIsUsingDefaultNameKey, IsDefaultProfileName(name)); |
206 // Assume newly created profiles use a default avatar. | 214 // Assume newly created profiles use a default avatar. |
207 info->SetBoolean(kIsUsingDefaultAvatarKey, true); | 215 info->SetBoolean(kIsUsingDefaultAvatarKey, true); |
208 cache->SetWithoutPathExpansion(key, info.release()); | 216 cache->SetWithoutPathExpansion(key, info.release()); |
209 | 217 |
210 sorted_keys_.insert(FindPositionForProfile(key, name), key); | 218 sorted_keys_.insert(FindPositionForProfile(key, name), key); |
211 | 219 |
212 if (switches::IsNewAvatarMenu()) | 220 if (switches::IsNewAvatarMenu()) |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 size_t index, | 551 size_t index, |
544 const std::string& id) { | 552 const std::string& id) { |
545 if (GetSupervisedUserIdOfProfileAtIndex(index) == id) | 553 if (GetSupervisedUserIdOfProfileAtIndex(index) == id) |
546 return; | 554 return; |
547 scoped_ptr<base::DictionaryValue> info( | 555 scoped_ptr<base::DictionaryValue> info( |
548 GetInfoForProfileAtIndex(index)->DeepCopy()); | 556 GetInfoForProfileAtIndex(index)->DeepCopy()); |
549 info->SetString(kSupervisedUserId, id); | 557 info->SetString(kSupervisedUserId, id); |
550 // This takes ownership of |info|. | 558 // This takes ownership of |info|. |
551 SetInfoForProfileAtIndex(index, info.release()); | 559 SetInfoForProfileAtIndex(index, info.release()); |
552 | 560 |
| 561 if (!id.empty()) |
| 562 prefs_->SetBoolean(prefs::kSupervisedUserExistsOrExisted, true); |
| 563 |
553 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 564 base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
554 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 565 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
555 observer_list_, | 566 observer_list_, |
556 OnProfileSupervisedUserIdChanged(profile_path)); | 567 OnProfileSupervisedUserIdChanged(profile_path)); |
557 } | 568 } |
558 | 569 |
559 void ProfileInfoCache::SetLocalAuthCredentialsOfProfileAtIndex( | 570 void ProfileInfoCache::SetLocalAuthCredentialsOfProfileAtIndex( |
560 size_t index, | 571 size_t index, |
561 const std::string& credentials) { | 572 const std::string& credentials) { |
562 scoped_ptr<base::DictionaryValue> info( | 573 scoped_ptr<base::DictionaryValue> info( |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 std::vector<base::FilePath>::const_iterator it; | 1109 std::vector<base::FilePath>::const_iterator it; |
1099 for (it = profiles_to_rename.begin(); it != profiles_to_rename.end(); ++it) { | 1110 for (it = profiles_to_rename.begin(); it != profiles_to_rename.end(); ++it) { |
1100 size_t profile_index = GetIndexOfProfileWithPath(*it); | 1111 size_t profile_index = GetIndexOfProfileWithPath(*it); |
1101 SetProfileIsUsingDefaultNameAtIndex(profile_index, true); | 1112 SetProfileIsUsingDefaultNameAtIndex(profile_index, true); |
1102 // This will assign a new "Person %d" type name and re-sort the cache. | 1113 // This will assign a new "Person %d" type name and re-sort the cache. |
1103 SetNameOfProfileAtIndex(profile_index, ChooseNameForNewProfile( | 1114 SetNameOfProfileAtIndex(profile_index, ChooseNameForNewProfile( |
1104 GetAvatarIconIndexOfProfileAtIndex(profile_index))); | 1115 GetAvatarIconIndexOfProfileAtIndex(profile_index))); |
1105 } | 1116 } |
1106 #endif | 1117 #endif |
1107 } | 1118 } |
OLD | NEW |