| 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/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/i18n/case_conversion.h" | 10 #include "base/i18n/case_conversion.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 const char kAvatarIconKey[] = "avatar_icon"; | 46 const char kAvatarIconKey[] = "avatar_icon"; |
| 47 const char kAuthCredentialsKey[] = "local_auth_credentials"; | 47 const char kAuthCredentialsKey[] = "local_auth_credentials"; |
| 48 const char kUseGAIAPictureKey[] = "use_gaia_picture"; | 48 const char kUseGAIAPictureKey[] = "use_gaia_picture"; |
| 49 const char kBackgroundAppsKey[] = "background_apps"; | 49 const char kBackgroundAppsKey[] = "background_apps"; |
| 50 const char kHasMigratedToGAIAInfoKey[] = "has_migrated_to_gaia_info"; | 50 const char kHasMigratedToGAIAInfoKey[] = "has_migrated_to_gaia_info"; |
| 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 kIsManagedKey[] = "is_managed"; |
| 53 const char kSigninRequiredKey[] = "signin_required"; | 53 const char kSigninRequiredKey[] = "signin_required"; |
| 54 const char kManagedUserId[] = "managed_user_id"; | 54 const char kManagedUserId[] = "managed_user_id"; |
| 55 const char kProfileIsEphemeral[] = "is_ephemeral"; | 55 const char kProfileIsEphemeral[] = "is_ephemeral"; |
| 56 const char kActiveTimeKey[] = "active_time"; |
| 56 | 57 |
| 57 const char kDefaultUrlPrefix[] = "chrome://theme/IDR_PROFILE_AVATAR_"; | 58 const char kDefaultUrlPrefix[] = "chrome://theme/IDR_PROFILE_AVATAR_"; |
| 58 const char kGAIAPictureFileName[] = "Google Profile Picture.png"; | 59 const char kGAIAPictureFileName[] = "Google Profile Picture.png"; |
| 59 | 60 |
| 60 const int kDefaultAvatarIconResources[] = { | 61 const int kDefaultAvatarIconResources[] = { |
| 61 IDR_PROFILE_AVATAR_0, | 62 IDR_PROFILE_AVATAR_0, |
| 62 IDR_PROFILE_AVATAR_1, | 63 IDR_PROFILE_AVATAR_1, |
| 63 IDR_PROFILE_AVATAR_2, | 64 IDR_PROFILE_AVATAR_2, |
| 64 IDR_PROFILE_AVATAR_3, | 65 IDR_PROFILE_AVATAR_3, |
| 65 IDR_PROFILE_AVATAR_4, | 66 IDR_PROFILE_AVATAR_4, |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 base::string16 shortcut_name; | 303 base::string16 shortcut_name; |
| 303 GetInfoForProfileAtIndex(index)->GetString( | 304 GetInfoForProfileAtIndex(index)->GetString( |
| 304 kShortcutNameKey, &shortcut_name); | 305 kShortcutNameKey, &shortcut_name); |
| 305 return shortcut_name; | 306 return shortcut_name; |
| 306 } | 307 } |
| 307 | 308 |
| 308 base::FilePath ProfileInfoCache::GetPathOfProfileAtIndex(size_t index) const { | 309 base::FilePath ProfileInfoCache::GetPathOfProfileAtIndex(size_t index) const { |
| 309 return user_data_dir_.AppendASCII(sorted_keys_[index]); | 310 return user_data_dir_.AppendASCII(sorted_keys_[index]); |
| 310 } | 311 } |
| 311 | 312 |
| 313 base::Time ProfileInfoCache::GetProfileActiveTimeAtIndex(size_t index) const { |
| 314 double dt; |
| 315 if (GetInfoForProfileAtIndex(index)->GetDouble(kActiveTimeKey, &dt)) { |
| 316 return base::Time::FromDoubleT(dt); |
| 317 } else { |
| 318 return base::Time(); |
| 319 } |
| 320 } |
| 321 |
| 312 base::string16 ProfileInfoCache::GetUserNameOfProfileAtIndex( | 322 base::string16 ProfileInfoCache::GetUserNameOfProfileAtIndex( |
| 313 size_t index) const { | 323 size_t index) const { |
| 314 base::string16 user_name; | 324 base::string16 user_name; |
| 315 GetInfoForProfileAtIndex(index)->GetString(kUserNameKey, &user_name); | 325 GetInfoForProfileAtIndex(index)->GetString(kUserNameKey, &user_name); |
| 316 return user_name; | 326 return user_name; |
| 317 } | 327 } |
| 318 | 328 |
| 319 const gfx::Image& ProfileInfoCache::GetAvatarIconOfProfileAtIndex( | 329 const gfx::Image& ProfileInfoCache::GetAvatarIconOfProfileAtIndex( |
| 320 size_t index) const { | 330 size_t index) const { |
| 321 if (IsUsingGAIAPictureOfProfileAtIndex(index)) { | 331 if (IsUsingGAIAPictureOfProfileAtIndex(index)) { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 const { | 477 const { |
| 468 std::string icon_url; | 478 std::string icon_url; |
| 469 GetInfoForProfileAtIndex(index)->GetString(kAvatarIconKey, &icon_url); | 479 GetInfoForProfileAtIndex(index)->GetString(kAvatarIconKey, &icon_url); |
| 470 size_t icon_index = 0; | 480 size_t icon_index = 0; |
| 471 if (!IsDefaultAvatarIconUrl(icon_url, &icon_index)) | 481 if (!IsDefaultAvatarIconUrl(icon_url, &icon_index)) |
| 472 DLOG(WARNING) << "Unknown avatar icon: " << icon_url; | 482 DLOG(WARNING) << "Unknown avatar icon: " << icon_url; |
| 473 | 483 |
| 474 return icon_index; | 484 return icon_index; |
| 475 } | 485 } |
| 476 | 486 |
| 487 void ProfileInfoCache::SetProfileActiveTimeAtIndex(size_t index) { |
| 488 scoped_ptr<base::DictionaryValue> info( |
| 489 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 490 info->SetDouble(kActiveTimeKey, base::Time::Now().ToDoubleT()); |
| 491 // This takes ownership of |info|. |
| 492 SetInfoQuietlyForProfileAtIndex(index, info.release()); |
| 493 } |
| 494 |
| 477 void ProfileInfoCache::SetNameOfProfileAtIndex(size_t index, | 495 void ProfileInfoCache::SetNameOfProfileAtIndex(size_t index, |
| 478 const base::string16& name) { | 496 const base::string16& name) { |
| 479 scoped_ptr<base::DictionaryValue> info( | 497 scoped_ptr<base::DictionaryValue> info( |
| 480 GetInfoForProfileAtIndex(index)->DeepCopy()); | 498 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 481 base::string16 current_name; | 499 base::string16 current_name; |
| 482 info->GetString(kNameKey, ¤t_name); | 500 info->GetString(kNameKey, ¤t_name); |
| 483 if (name == current_name) | 501 if (name == current_name) |
| 484 return; | 502 return; |
| 485 | 503 |
| 486 base::string16 old_display_name = GetNameOfProfileAtIndex(index); | 504 base::string16 old_display_name = GetNameOfProfileAtIndex(index); |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 const base::DictionaryValue* ProfileInfoCache::GetInfoForProfileAtIndex( | 880 const base::DictionaryValue* ProfileInfoCache::GetInfoForProfileAtIndex( |
| 863 size_t index) const { | 881 size_t index) const { |
| 864 DCHECK_LT(index, GetNumberOfProfiles()); | 882 DCHECK_LT(index, GetNumberOfProfiles()); |
| 865 const base::DictionaryValue* cache = | 883 const base::DictionaryValue* cache = |
| 866 prefs_->GetDictionary(prefs::kProfileInfoCache); | 884 prefs_->GetDictionary(prefs::kProfileInfoCache); |
| 867 const base::DictionaryValue* info = NULL; | 885 const base::DictionaryValue* info = NULL; |
| 868 cache->GetDictionaryWithoutPathExpansion(sorted_keys_[index], &info); | 886 cache->GetDictionaryWithoutPathExpansion(sorted_keys_[index], &info); |
| 869 return info; | 887 return info; |
| 870 } | 888 } |
| 871 | 889 |
| 872 void ProfileInfoCache::SetInfoForProfileAtIndex(size_t index, | 890 void ProfileInfoCache::SetInfoQuietlyForProfileAtIndex( |
| 873 base::DictionaryValue* info) { | 891 size_t index, base::DictionaryValue* info) { |
| 874 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); | 892 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); |
| 875 base::DictionaryValue* cache = update.Get(); | 893 base::DictionaryValue* cache = update.Get(); |
| 876 cache->SetWithoutPathExpansion(sorted_keys_[index], info); | 894 cache->SetWithoutPathExpansion(sorted_keys_[index], info); |
| 895 } |
| 896 |
| 897 // TODO(noms): Switch to newer notification system. |
| 898 void ProfileInfoCache::SetInfoForProfileAtIndex(size_t index, |
| 899 base::DictionaryValue* info) { |
| 900 SetInfoQuietlyForProfileAtIndex(index, info); |
| 877 | 901 |
| 878 content::NotificationService::current()->Notify( | 902 content::NotificationService::current()->Notify( |
| 879 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | 903 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
| 880 content::NotificationService::AllSources(), | 904 content::NotificationService::AllSources(), |
| 881 content::NotificationService::NoDetails()); | 905 content::NotificationService::NoDetails()); |
| 882 } | 906 } |
| 883 | 907 |
| 884 std::string ProfileInfoCache::CacheKeyFromProfilePath( | 908 std::string ProfileInfoCache::CacheKeyFromProfilePath( |
| 885 const base::FilePath& profile_path) const { | 909 const base::FilePath& profile_path) const { |
| 886 DCHECK(user_data_dir_ == profile_path.DirName()); | 910 DCHECK(user_data_dir_ == profile_path.DirName()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 info->GetString(kNameKey, &name); | 961 info->GetString(kNameKey, &name); |
| 938 names.push_back(name); | 962 names.push_back(name); |
| 939 } | 963 } |
| 940 return names; | 964 return names; |
| 941 } | 965 } |
| 942 | 966 |
| 943 // static | 967 // static |
| 944 void ProfileInfoCache::RegisterPrefs(PrefRegistrySimple* registry) { | 968 void ProfileInfoCache::RegisterPrefs(PrefRegistrySimple* registry) { |
| 945 registry->RegisterDictionaryPref(prefs::kProfileInfoCache); | 969 registry->RegisterDictionaryPref(prefs::kProfileInfoCache); |
| 946 } | 970 } |
| OLD | NEW |