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/file_util.h" | 8 #include "base/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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 const char kShortcutNameKey[] = "shortcut_name"; | 42 const char kShortcutNameKey[] = "shortcut_name"; |
43 const char kGAIANameKey[] = "gaia_name"; | 43 const char kGAIANameKey[] = "gaia_name"; |
44 const char kGAIAGivenNameKey[] = "gaia_given_name"; | 44 const char kGAIAGivenNameKey[] = "gaia_given_name"; |
45 const char kUserNameKey[] = "user_name"; | 45 const char kUserNameKey[] = "user_name"; |
46 const char kIsUsingDefaultName[] = "is_using_default_name"; | 46 const char kIsUsingDefaultName[] = "is_using_default_name"; |
47 const char kAvatarIconKey[] = "avatar_icon"; | 47 const char kAvatarIconKey[] = "avatar_icon"; |
48 const char kAuthCredentialsKey[] = "local_auth_credentials"; | 48 const char kAuthCredentialsKey[] = "local_auth_credentials"; |
49 const char kUseGAIAPictureKey[] = "use_gaia_picture"; | 49 const char kUseGAIAPictureKey[] = "use_gaia_picture"; |
50 const char kBackgroundAppsKey[] = "background_apps"; | 50 const char kBackgroundAppsKey[] = "background_apps"; |
51 const char kGAIAPictureFileNameKey[] = "gaia_picture_file_name"; | 51 const char kGAIAPictureFileNameKey[] = "gaia_picture_file_name"; |
52 const char kIsManagedKey[] = "is_managed"; | 52 const char kIsSupervisedKey[] = "is_managed"; |
53 const char kIsOmittedFromProfileListKey[] = "is_omitted_from_profile_list"; | 53 const char kIsOmittedFromProfileListKey[] = "is_omitted_from_profile_list"; |
54 const char kSigninRequiredKey[] = "signin_required"; | 54 const char kSigninRequiredKey[] = "signin_required"; |
55 const char kManagedUserId[] = "managed_user_id"; | 55 const char kSupervisedUserId[] = "managed_user_id"; |
56 const char kProfileIsEphemeral[] = "is_ephemeral"; | 56 const char kProfileIsEphemeral[] = "is_ephemeral"; |
57 const char kActiveTimeKey[] = "active_time"; | 57 const char kActiveTimeKey[] = "active_time"; |
58 | 58 |
59 // First eight are generic icons, which use IDS_NUMBERED_PROFILE_NAME. | 59 // First eight are generic icons, which use IDS_NUMBERED_PROFILE_NAME. |
60 const int kDefaultNames[] = { | 60 const int kDefaultNames[] = { |
61 IDS_DEFAULT_AVATAR_NAME_8, | 61 IDS_DEFAULT_AVATAR_NAME_8, |
62 IDS_DEFAULT_AVATAR_NAME_9, | 62 IDS_DEFAULT_AVATAR_NAME_9, |
63 IDS_DEFAULT_AVATAR_NAME_10, | 63 IDS_DEFAULT_AVATAR_NAME_10, |
64 IDS_DEFAULT_AVATAR_NAME_11, | 64 IDS_DEFAULT_AVATAR_NAME_11, |
65 IDS_DEFAULT_AVATAR_NAME_12, | 65 IDS_DEFAULT_AVATAR_NAME_12, |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 base::DictionaryValue* cache = update.Get(); | 171 base::DictionaryValue* cache = update.Get(); |
172 for (base::DictionaryValue::Iterator it(*cache); | 172 for (base::DictionaryValue::Iterator it(*cache); |
173 !it.IsAtEnd(); it.Advance()) { | 173 !it.IsAtEnd(); it.Advance()) { |
174 base::DictionaryValue* info = NULL; | 174 base::DictionaryValue* info = NULL; |
175 cache->GetDictionaryWithoutPathExpansion(it.key(), &info); | 175 cache->GetDictionaryWithoutPathExpansion(it.key(), &info); |
176 base::string16 name; | 176 base::string16 name; |
177 info->GetString(kNameKey, &name); | 177 info->GetString(kNameKey, &name); |
178 sorted_keys_.insert(FindPositionForProfile(it.key(), name), it.key()); | 178 sorted_keys_.insert(FindPositionForProfile(it.key(), name), it.key()); |
179 // TODO(ibraaaa): delete this when 97% of our users are using M31. | 179 // TODO(ibraaaa): delete this when 97% of our users are using M31. |
180 // http://crbug.com/276163 | 180 // http://crbug.com/276163 |
181 bool is_managed = false; | 181 bool is_supervised = false; |
182 if (info->GetBoolean(kIsManagedKey, &is_managed)) { | 182 if (info->GetBoolean(kIsSupervisedKey, &is_supervised)) { |
183 info->Remove(kIsManagedKey, NULL); | 183 info->Remove(kIsSupervisedKey, NULL); |
184 info->SetString(kManagedUserId, is_managed ? "DUMMY_ID" : std::string()); | 184 info->SetString(kSupervisedUserId, |
| 185 is_supervised ? "DUMMY_ID" : std::string()); |
185 } | 186 } |
186 info->SetBoolean(kIsUsingDefaultName, IsDefaultName(name)); | 187 info->SetBoolean(kIsUsingDefaultName, IsDefaultName(name)); |
187 } | 188 } |
188 | 189 |
189 // If needed, start downloading the high-res avatars. | 190 // If needed, start downloading the high-res avatars. |
190 if (switches::IsNewAvatarMenu()) { | 191 if (switches::IsNewAvatarMenu()) { |
191 for (size_t i = 0; i < GetNumberOfProfiles(); i++) { | 192 for (size_t i = 0; i < GetNumberOfProfiles(); i++) { |
192 DownloadHighResAvatar(GetAvatarIconIndexOfProfileAtIndex(i), | 193 DownloadHighResAvatar(GetAvatarIconIndexOfProfileAtIndex(i), |
193 GetPathOfProfileAtIndex(i)); | 194 GetPathOfProfileAtIndex(i)); |
194 } | 195 } |
195 } | 196 } |
196 } | 197 } |
197 | 198 |
198 ProfileInfoCache::~ProfileInfoCache() { | 199 ProfileInfoCache::~ProfileInfoCache() { |
199 STLDeleteContainerPairSecondPointers( | 200 STLDeleteContainerPairSecondPointers( |
200 cached_avatar_images_.begin(), cached_avatar_images_.end()); | 201 cached_avatar_images_.begin(), cached_avatar_images_.end()); |
201 STLDeleteContainerPairSecondPointers( | 202 STLDeleteContainerPairSecondPointers( |
202 avatar_images_downloads_in_progress_.begin(), | 203 avatar_images_downloads_in_progress_.begin(), |
203 avatar_images_downloads_in_progress_.end()); | 204 avatar_images_downloads_in_progress_.end()); |
204 } | 205 } |
205 | 206 |
206 void ProfileInfoCache::AddProfileToCache(const base::FilePath& profile_path, | 207 void ProfileInfoCache::AddProfileToCache( |
207 const base::string16& name, | 208 const base::FilePath& profile_path, |
208 const base::string16& username, | 209 const base::string16& name, |
209 size_t icon_index, | 210 const base::string16& username, |
210 const std::string& managed_user_id) { | 211 size_t icon_index, |
| 212 const std::string& supervised_user_id) { |
211 std::string key = CacheKeyFromProfilePath(profile_path); | 213 std::string key = CacheKeyFromProfilePath(profile_path); |
212 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); | 214 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); |
213 base::DictionaryValue* cache = update.Get(); | 215 base::DictionaryValue* cache = update.Get(); |
214 | 216 |
215 scoped_ptr<base::DictionaryValue> info(new base::DictionaryValue); | 217 scoped_ptr<base::DictionaryValue> info(new base::DictionaryValue); |
216 info->SetString(kNameKey, name); | 218 info->SetString(kNameKey, name); |
217 info->SetString(kUserNameKey, username); | 219 info->SetString(kUserNameKey, username); |
218 info->SetString(kAvatarIconKey, | 220 info->SetString(kAvatarIconKey, |
219 profiles::GetDefaultAvatarIconUrl(icon_index)); | 221 profiles::GetDefaultAvatarIconUrl(icon_index)); |
220 // Default value for whether background apps are running is false. | 222 // Default value for whether background apps are running is false. |
221 info->SetBoolean(kBackgroundAppsKey, false); | 223 info->SetBoolean(kBackgroundAppsKey, false); |
222 info->SetString(kManagedUserId, managed_user_id); | 224 info->SetString(kSupervisedUserId, supervised_user_id); |
223 info->SetBoolean(kIsOmittedFromProfileListKey, !managed_user_id.empty()); | 225 info->SetBoolean(kIsOmittedFromProfileListKey, !supervised_user_id.empty()); |
224 info->SetBoolean(kProfileIsEphemeral, false); | 226 info->SetBoolean(kProfileIsEphemeral, false); |
225 info->SetBoolean(kIsUsingDefaultName, IsDefaultName(name)); | 227 info->SetBoolean(kIsUsingDefaultName, IsDefaultName(name)); |
226 cache->SetWithoutPathExpansion(key, info.release()); | 228 cache->SetWithoutPathExpansion(key, info.release()); |
227 | 229 |
228 sorted_keys_.insert(FindPositionForProfile(key, name), key); | 230 sorted_keys_.insert(FindPositionForProfile(key, name), key); |
229 | 231 |
230 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 232 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
231 observer_list_, | 233 observer_list_, |
232 OnProfileAdded(profile_path)); | 234 OnProfileAdded(profile_path)); |
233 | 235 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 base::FilePath image_path = path.AppendASCII(file_name); | 400 base::FilePath image_path = path.AppendASCII(file_name); |
399 return LoadAvatarPictureFromPath(key, image_path); | 401 return LoadAvatarPictureFromPath(key, image_path); |
400 } | 402 } |
401 | 403 |
402 bool ProfileInfoCache::IsUsingGAIAPictureOfProfileAtIndex(size_t index) const { | 404 bool ProfileInfoCache::IsUsingGAIAPictureOfProfileAtIndex(size_t index) const { |
403 bool value = false; | 405 bool value = false; |
404 GetInfoForProfileAtIndex(index)->GetBoolean(kUseGAIAPictureKey, &value); | 406 GetInfoForProfileAtIndex(index)->GetBoolean(kUseGAIAPictureKey, &value); |
405 return value; | 407 return value; |
406 } | 408 } |
407 | 409 |
408 bool ProfileInfoCache::ProfileIsManagedAtIndex(size_t index) const { | 410 bool ProfileInfoCache::ProfileIsSupervisedAtIndex(size_t index) const { |
409 return !GetManagedUserIdOfProfileAtIndex(index).empty(); | 411 return !GetSupervisedUserIdOfProfileAtIndex(index).empty(); |
410 } | 412 } |
411 | 413 |
412 bool ProfileInfoCache::IsOmittedProfileAtIndex(size_t index) const { | 414 bool ProfileInfoCache::IsOmittedProfileAtIndex(size_t index) const { |
413 bool value = false; | 415 bool value = false; |
414 GetInfoForProfileAtIndex(index)->GetBoolean(kIsOmittedFromProfileListKey, | 416 GetInfoForProfileAtIndex(index)->GetBoolean(kIsOmittedFromProfileListKey, |
415 &value); | 417 &value); |
416 return value; | 418 return value; |
417 } | 419 } |
418 | 420 |
419 bool ProfileInfoCache::ProfileIsSigninRequiredAtIndex(size_t index) const { | 421 bool ProfileInfoCache::ProfileIsSigninRequiredAtIndex(size_t index) const { |
420 bool value = false; | 422 bool value = false; |
421 GetInfoForProfileAtIndex(index)->GetBoolean(kSigninRequiredKey, &value); | 423 GetInfoForProfileAtIndex(index)->GetBoolean(kSigninRequiredKey, &value); |
422 return value; | 424 return value; |
423 } | 425 } |
424 | 426 |
425 std::string ProfileInfoCache::GetManagedUserIdOfProfileAtIndex( | 427 std::string ProfileInfoCache::GetSupervisedUserIdOfProfileAtIndex( |
426 size_t index) const { | 428 size_t index) const { |
427 std::string managed_user_id; | 429 std::string supervised_user_id; |
428 GetInfoForProfileAtIndex(index)->GetString(kManagedUserId, &managed_user_id); | 430 GetInfoForProfileAtIndex(index)->GetString(kSupervisedUserId, |
429 return managed_user_id; | 431 &supervised_user_id); |
| 432 return supervised_user_id; |
430 } | 433 } |
431 | 434 |
432 bool ProfileInfoCache::ProfileIsEphemeralAtIndex(size_t index) const { | 435 bool ProfileInfoCache::ProfileIsEphemeralAtIndex(size_t index) const { |
433 bool value = false; | 436 bool value = false; |
434 GetInfoForProfileAtIndex(index)->GetBoolean(kProfileIsEphemeral, &value); | 437 GetInfoForProfileAtIndex(index)->GetBoolean(kProfileIsEphemeral, &value); |
435 return value; | 438 return value; |
436 } | 439 } |
437 | 440 |
438 bool ProfileInfoCache::ProfileIsUsingDefaultNameAtIndex(size_t index) const { | 441 bool ProfileInfoCache::ProfileIsUsingDefaultNameAtIndex(size_t index) const { |
439 bool value = false; | 442 bool value = false; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 bool is_omitted) { | 537 bool is_omitted) { |
535 if (IsOmittedProfileAtIndex(index) == is_omitted) | 538 if (IsOmittedProfileAtIndex(index) == is_omitted) |
536 return; | 539 return; |
537 scoped_ptr<base::DictionaryValue> info( | 540 scoped_ptr<base::DictionaryValue> info( |
538 GetInfoForProfileAtIndex(index)->DeepCopy()); | 541 GetInfoForProfileAtIndex(index)->DeepCopy()); |
539 info->SetBoolean(kIsOmittedFromProfileListKey, is_omitted); | 542 info->SetBoolean(kIsOmittedFromProfileListKey, is_omitted); |
540 // This takes ownership of |info|. | 543 // This takes ownership of |info|. |
541 SetInfoForProfileAtIndex(index, info.release()); | 544 SetInfoForProfileAtIndex(index, info.release()); |
542 } | 545 } |
543 | 546 |
544 void ProfileInfoCache::SetManagedUserIdOfProfileAtIndex(size_t index, | 547 void ProfileInfoCache::SetSupervisedUserIdOfProfileAtIndex( |
545 const std::string& id) { | 548 size_t index, |
546 if (GetManagedUserIdOfProfileAtIndex(index) == id) | 549 const std::string& id) { |
| 550 if (GetSupervisedUserIdOfProfileAtIndex(index) == id) |
547 return; | 551 return; |
548 scoped_ptr<base::DictionaryValue> info( | 552 scoped_ptr<base::DictionaryValue> info( |
549 GetInfoForProfileAtIndex(index)->DeepCopy()); | 553 GetInfoForProfileAtIndex(index)->DeepCopy()); |
550 info->SetString(kManagedUserId, id); | 554 info->SetString(kSupervisedUserId, id); |
551 // This takes ownership of |info|. | 555 // This takes ownership of |info|. |
552 SetInfoForProfileAtIndex(index, info.release()); | 556 SetInfoForProfileAtIndex(index, info.release()); |
553 } | 557 } |
554 | 558 |
555 void ProfileInfoCache::SetLocalAuthCredentialsOfProfileAtIndex( | 559 void ProfileInfoCache::SetLocalAuthCredentialsOfProfileAtIndex( |
556 size_t index, | 560 size_t index, |
557 const std::string& credentials) { | 561 const std::string& credentials) { |
558 scoped_ptr<base::DictionaryValue> info( | 562 scoped_ptr<base::DictionaryValue> info( |
559 GetInfoForProfileAtIndex(index)->DeepCopy()); | 563 GetInfoForProfileAtIndex(index)->DeepCopy()); |
560 info->SetString(kAuthCredentialsKey, credentials); | 564 info->SetString(kAuthCredentialsKey, credentials); |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 OnProfileAvatarChanged(profile_path)); | 1005 OnProfileAvatarChanged(profile_path)); |
1002 | 1006 |
1003 // Remove the file from the list of downloads in progress. Note that this list | 1007 // Remove the file from the list of downloads in progress. Note that this list |
1004 // only contains the high resolution avatars, and not the Gaia profile images. | 1008 // only contains the high resolution avatars, and not the Gaia profile images. |
1005 if (!avatar_images_downloads_in_progress_[file_name]) | 1009 if (!avatar_images_downloads_in_progress_[file_name]) |
1006 return; | 1010 return; |
1007 | 1011 |
1008 delete avatar_images_downloads_in_progress_[file_name]; | 1012 delete avatar_images_downloads_in_progress_[file_name]; |
1009 avatar_images_downloads_in_progress_[file_name] = NULL; | 1013 avatar_images_downloads_in_progress_[file_name] = NULL; |
1010 } | 1014 } |
OLD | NEW |