| 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::GetProfileActive(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::SetProfileActive(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 SetInfoForProfileAtIndex(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 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 info->GetString(kNameKey, &name); | 955 info->GetString(kNameKey, &name); |
| 938 names.push_back(name); | 956 names.push_back(name); |
| 939 } | 957 } |
| 940 return names; | 958 return names; |
| 941 } | 959 } |
| 942 | 960 |
| 943 // static | 961 // static |
| 944 void ProfileInfoCache::RegisterPrefs(PrefRegistrySimple* registry) { | 962 void ProfileInfoCache::RegisterPrefs(PrefRegistrySimple* registry) { |
| 945 registry->RegisterDictionaryPref(prefs::kProfileInfoCache); | 963 registry->RegisterDictionaryPref(prefs::kProfileInfoCache); |
| 946 } | 964 } |
| OLD | NEW |