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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 const char kPasswordTokenKey[] = "gaia_password_token"; | 53 const char kPasswordTokenKey[] = "gaia_password_token"; |
54 const char kUseGAIAPictureKey[] = "use_gaia_picture"; | 54 const char kUseGAIAPictureKey[] = "use_gaia_picture"; |
55 const char kBackgroundAppsKey[] = "background_apps"; | 55 const char kBackgroundAppsKey[] = "background_apps"; |
56 const char kGAIAPictureFileNameKey[] = "gaia_picture_file_name"; | 56 const char kGAIAPictureFileNameKey[] = "gaia_picture_file_name"; |
57 const char kIsOmittedFromProfileListKey[] = "is_omitted_from_profile_list"; | 57 const char kIsOmittedFromProfileListKey[] = "is_omitted_from_profile_list"; |
58 const char kSigninRequiredKey[] = "signin_required"; | 58 const char kSigninRequiredKey[] = "signin_required"; |
59 const char kSupervisedUserId[] = "managed_user_id"; | 59 const char kSupervisedUserId[] = "managed_user_id"; |
60 const char kProfileIsEphemeral[] = "is_ephemeral"; | 60 const char kProfileIsEphemeral[] = "is_ephemeral"; |
61 const char kActiveTimeKey[] = "active_time"; | 61 const char kActiveTimeKey[] = "active_time"; |
62 const char kIsAuthErrorKey[] = "is_auth_error"; | 62 const char kIsAuthErrorKey[] = "is_auth_error"; |
63 const char kStatistics[] = "statistics"; | |
63 | 64 |
64 // First eight are generic icons, which use IDS_NUMBERED_PROFILE_NAME. | 65 // First eight are generic icons, which use IDS_NUMBERED_PROFILE_NAME. |
65 const int kDefaultNames[] = { | 66 const int kDefaultNames[] = { |
66 IDS_DEFAULT_AVATAR_NAME_8, | 67 IDS_DEFAULT_AVATAR_NAME_8, |
67 IDS_DEFAULT_AVATAR_NAME_9, | 68 IDS_DEFAULT_AVATAR_NAME_9, |
68 IDS_DEFAULT_AVATAR_NAME_10, | 69 IDS_DEFAULT_AVATAR_NAME_10, |
69 IDS_DEFAULT_AVATAR_NAME_11, | 70 IDS_DEFAULT_AVATAR_NAME_11, |
70 IDS_DEFAULT_AVATAR_NAME_12, | 71 IDS_DEFAULT_AVATAR_NAME_12, |
71 IDS_DEFAULT_AVATAR_NAME_13, | 72 IDS_DEFAULT_AVATAR_NAME_13, |
72 IDS_DEFAULT_AVATAR_NAME_14, | 73 IDS_DEFAULT_AVATAR_NAME_14, |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
492 const { | 493 const { |
493 std::string icon_url; | 494 std::string icon_url; |
494 GetInfoForProfileAtIndex(index)->GetString(kAvatarIconKey, &icon_url); | 495 GetInfoForProfileAtIndex(index)->GetString(kAvatarIconKey, &icon_url); |
495 size_t icon_index = 0; | 496 size_t icon_index = 0; |
496 if (!profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index)) | 497 if (!profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index)) |
497 DLOG(WARNING) << "Unknown avatar icon: " << icon_url; | 498 DLOG(WARNING) << "Unknown avatar icon: " << icon_url; |
498 | 499 |
499 return icon_index; | 500 return icon_index; |
500 } | 501 } |
501 | 502 |
503 bool ProfileInfoCache::GetStatisticOfProfileAtIndex(size_t index, | |
504 const std::string& category, int* out_value) const { | |
505 const base::DictionaryValue* statistics; | |
506 if (!GetInfoForProfileAtIndex(index)->GetDictionaryWithoutPathExpansion( | |
507 kStatistics, &statistics)) | |
508 return false; | |
509 | |
510 return statistics->GetIntegerWithoutPathExpansion(category, out_value); | |
511 } | |
512 | |
513 std::map<std::string, int> ProfileInfoCache::GetAllStatisticsOfProfileAtIndex( | |
514 size_t index) const { | |
515 const base::DictionaryValue* statistics; | |
516 std::map<std::string, int> out_value; | |
517 | |
518 if (!GetInfoForProfileAtIndex(index)->GetDictionaryWithoutPathExpansion( | |
519 kStatistics, &statistics)) | |
520 return out_value; // No statistics are set, so return an empty map. | |
521 | |
522 for (base::DictionaryValue::Iterator it(*statistics); !it.IsAtEnd(); | |
523 it.Advance()) { | |
524 int value; | |
525 if (it.value().GetAsInteger(&value)) { | |
526 out_value[it.key()] = value; | |
527 } | |
528 } | |
529 return out_value; | |
530 } | |
531 | |
532 scoped_ptr<base::DictionaryValue> | |
533 ProfileInfoCache::GetAllStatisticsOfProfileAtIndexAsDictionaryValue( | |
534 size_t index) const { | |
535 const base::DictionaryValue* statistics; | |
536 | |
537 if (!GetInfoForProfileAtIndex(index)->GetDictionaryWithoutPathExpansion( | |
538 kStatistics, &statistics)) | |
539 // No statistics are set, so return an empty map. | |
540 return make_scoped_ptr(new base::DictionaryValue()).Pass(); | |
541 | |
542 return statistics->CreateDeepCopy().Pass(); | |
543 } | |
544 | |
502 void ProfileInfoCache::SetProfileActiveTimeAtIndex(size_t index) { | 545 void ProfileInfoCache::SetProfileActiveTimeAtIndex(size_t index) { |
503 if (base::Time::Now() - GetProfileActiveTimeAtIndex(index) < | 546 if (base::Time::Now() - GetProfileActiveTimeAtIndex(index) < |
504 base::TimeDelta::FromHours(1)) { | 547 base::TimeDelta::FromHours(1)) { |
505 return; | 548 return; |
506 } | 549 } |
507 | 550 |
508 scoped_ptr<base::DictionaryValue> info( | 551 scoped_ptr<base::DictionaryValue> info( |
509 GetInfoForProfileAtIndex(index)->DeepCopy()); | 552 GetInfoForProfileAtIndex(index)->DeepCopy()); |
510 info->SetDouble(kActiveTimeKey, base::Time::Now().ToDoubleT()); | 553 info->SetDouble(kActiveTimeKey, base::Time::Now().ToDoubleT()); |
511 // This takes ownership of |info|. | 554 // This takes ownership of |info|. |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
902 if (ChooseAvatarIconIndexForNewProfile(true, true, &icon_index)) | 945 if (ChooseAvatarIconIndexForNewProfile(true, true, &icon_index)) |
903 return icon_index; | 946 return icon_index; |
904 // Settle for any random icon, even if it's not unique. | 947 // Settle for any random icon, even if it's not unique. |
905 if (ChooseAvatarIconIndexForNewProfile(true, false, &icon_index)) | 948 if (ChooseAvatarIconIndexForNewProfile(true, false, &icon_index)) |
906 return icon_index; | 949 return icon_index; |
907 | 950 |
908 NOTREACHED(); | 951 NOTREACHED(); |
909 return 0; | 952 return 0; |
910 } | 953 } |
911 | 954 |
955 void ProfileInfoCache::SetStatisticOfProfileAtIndex(size_t index, | |
956 const std::string& category, int value) { | |
957 scoped_ptr<base::DictionaryValue> info( | |
958 GetInfoForProfileAtIndex(index)->DeepCopy()); | |
959 base::DictionaryValue* statistics; | |
960 if (!info->GetDictionaryWithoutPathExpansion(kStatistics, &statistics)) { | |
961 statistics = new base::DictionaryValue(); | |
962 info->SetWithoutPathExpansion(kStatistics, make_scoped_ptr(statistics)); | |
963 } | |
964 | |
965 statistics->SetIntegerWithoutPathExpansion(category, value); | |
966 // This takes ownership of |info|. | |
967 SetInfoForProfileAtIndex(index, info.release()); | |
968 | |
969 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | |
970 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | |
Mike Lerman
2015/10/23 16:04:19
Why does changing the stats set OnProfileSigninReq
lwchkg
2015/10/24 02:02:32
Thanks for catching the mistake. We don't need an
| |
971 observer_list_, | |
972 OnProfileSigninRequiredChanged(profile_path)); | |
973 } | |
974 | |
912 const base::FilePath& ProfileInfoCache::GetUserDataDir() const { | 975 const base::FilePath& ProfileInfoCache::GetUserDataDir() const { |
913 return user_data_dir_; | 976 return user_data_dir_; |
914 } | 977 } |
915 | 978 |
916 // static | 979 // static |
917 void ProfileInfoCache::RegisterPrefs(PrefRegistrySimple* registry) { | 980 void ProfileInfoCache::RegisterPrefs(PrefRegistrySimple* registry) { |
918 registry->RegisterDictionaryPref(prefs::kProfileInfoCache); | 981 registry->RegisterDictionaryPref(prefs::kProfileInfoCache); |
919 } | 982 } |
920 | 983 |
921 void ProfileInfoCache::DownloadHighResAvatarIfNeeded( | 984 void ProfileInfoCache::DownloadHighResAvatarIfNeeded( |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1281 // The profile info is in the cache but its entry isn't created yet, insert | 1344 // The profile info is in the cache but its entry isn't created yet, insert |
1282 // it in the map. | 1345 // it in the map. |
1283 scoped_ptr<ProfileAttributesEntry> new_entry(new ProfileAttributesEntry()); | 1346 scoped_ptr<ProfileAttributesEntry> new_entry(new ProfileAttributesEntry()); |
1284 profile_attributes_entries_.add(path, new_entry.Pass()); | 1347 profile_attributes_entries_.add(path, new_entry.Pass()); |
1285 profile_attributes_entries_.get(path)->Initialize(this, path); | 1348 profile_attributes_entries_.get(path)->Initialize(this, path); |
1286 } | 1349 } |
1287 | 1350 |
1288 *entry = profile_attributes_entries_.get(path); | 1351 *entry = profile_attributes_entries_.get(path); |
1289 return true; | 1352 return true; |
1290 } | 1353 } |
OLD | NEW |