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 kStatsBrowsingHistoryKey[] = "stats_browsing_history"; |
| 64 const char kStatsPasswordsKey[] = "stats_passwords"; |
| 65 const char kStatsBookmarksKey[] = "stats_bookmarks"; |
| 66 const char kStatsSettingsKey[] = "stats_settings"; |
63 | 67 |
64 // First eight are generic icons, which use IDS_NUMBERED_PROFILE_NAME. | 68 // First eight are generic icons, which use IDS_NUMBERED_PROFILE_NAME. |
65 const int kDefaultNames[] = { | 69 const int kDefaultNames[] = { |
66 IDS_DEFAULT_AVATAR_NAME_8, | 70 IDS_DEFAULT_AVATAR_NAME_8, |
67 IDS_DEFAULT_AVATAR_NAME_9, | 71 IDS_DEFAULT_AVATAR_NAME_9, |
68 IDS_DEFAULT_AVATAR_NAME_10, | 72 IDS_DEFAULT_AVATAR_NAME_10, |
69 IDS_DEFAULT_AVATAR_NAME_11, | 73 IDS_DEFAULT_AVATAR_NAME_11, |
70 IDS_DEFAULT_AVATAR_NAME_12, | 74 IDS_DEFAULT_AVATAR_NAME_12, |
71 IDS_DEFAULT_AVATAR_NAME_13, | 75 IDS_DEFAULT_AVATAR_NAME_13, |
72 IDS_DEFAULT_AVATAR_NAME_14, | 76 IDS_DEFAULT_AVATAR_NAME_14, |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 const { | 496 const { |
493 std::string icon_url; | 497 std::string icon_url; |
494 GetInfoForProfileAtIndex(index)->GetString(kAvatarIconKey, &icon_url); | 498 GetInfoForProfileAtIndex(index)->GetString(kAvatarIconKey, &icon_url); |
495 size_t icon_index = 0; | 499 size_t icon_index = 0; |
496 if (!profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index)) | 500 if (!profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index)) |
497 DLOG(WARNING) << "Unknown avatar icon: " << icon_url; | 501 DLOG(WARNING) << "Unknown avatar icon: " << icon_url; |
498 | 502 |
499 return icon_index; | 503 return icon_index; |
500 } | 504 } |
501 | 505 |
| 506 bool ProfileInfoCache::HasStatsBrowsingHistoryOfProfileAtIndex(size_t index) |
| 507 const { |
| 508 int value = 0; |
| 509 return GetInfoForProfileAtIndex(index)->GetInteger(kStatsBrowsingHistoryKey, |
| 510 &value); |
| 511 } |
| 512 |
| 513 int ProfileInfoCache::GetStatsBrowsingHistoryOfProfileAtIndex(size_t index) |
| 514 const { |
| 515 int value = 0; |
| 516 GetInfoForProfileAtIndex(index)->GetInteger(kStatsBrowsingHistoryKey, &value); |
| 517 return value; |
| 518 } |
| 519 |
| 520 bool ProfileInfoCache::HasStatsPasswordsOfProfileAtIndex(size_t index) const { |
| 521 int value = 0; |
| 522 return GetInfoForProfileAtIndex(index)->GetInteger(kStatsPasswordsKey, |
| 523 &value); |
| 524 } |
| 525 |
| 526 int ProfileInfoCache::GetStatsPasswordsOfProfileAtIndex(size_t index) const { |
| 527 int value = 0; |
| 528 GetInfoForProfileAtIndex(index)->GetInteger(kStatsPasswordsKey, &value); |
| 529 return value; |
| 530 } |
| 531 |
| 532 bool ProfileInfoCache::HasStatsBookmarksOfProfileAtIndex(size_t index) const { |
| 533 int value = 0; |
| 534 return GetInfoForProfileAtIndex(index)->GetInteger(kStatsBookmarksKey, |
| 535 &value); |
| 536 } |
| 537 |
| 538 int ProfileInfoCache::GetStatsBookmarksOfProfileAtIndex(size_t index) const { |
| 539 int value = 0; |
| 540 GetInfoForProfileAtIndex(index)->GetInteger(kStatsBookmarksKey, &value); |
| 541 return value; |
| 542 } |
| 543 |
| 544 bool ProfileInfoCache::HasStatsSettingsOfProfileAtIndex(size_t index) const { |
| 545 int value = 0; |
| 546 return GetInfoForProfileAtIndex(index)->GetInteger(kStatsSettingsKey, &value); |
| 547 } |
| 548 |
| 549 int ProfileInfoCache::GetStatsSettingsOfProfileAtIndex(size_t index) const { |
| 550 int value = 0; |
| 551 GetInfoForProfileAtIndex(index)->GetInteger(kStatsSettingsKey, &value); |
| 552 return value; |
| 553 } |
| 554 |
502 void ProfileInfoCache::SetProfileActiveTimeAtIndex(size_t index) { | 555 void ProfileInfoCache::SetProfileActiveTimeAtIndex(size_t index) { |
503 if (base::Time::Now() - GetProfileActiveTimeAtIndex(index) < | 556 if (base::Time::Now() - GetProfileActiveTimeAtIndex(index) < |
504 base::TimeDelta::FromHours(1)) { | 557 base::TimeDelta::FromHours(1)) { |
505 return; | 558 return; |
506 } | 559 } |
507 | 560 |
508 scoped_ptr<base::DictionaryValue> info( | 561 scoped_ptr<base::DictionaryValue> info( |
509 GetInfoForProfileAtIndex(index)->DeepCopy()); | 562 GetInfoForProfileAtIndex(index)->DeepCopy()); |
510 info->SetDouble(kActiveTimeKey, base::Time::Now().ToDoubleT()); | 563 info->SetDouble(kActiveTimeKey, base::Time::Now().ToDoubleT()); |
511 // This takes ownership of |info|. | 564 // 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)) | 955 if (ChooseAvatarIconIndexForNewProfile(true, true, &icon_index)) |
903 return icon_index; | 956 return icon_index; |
904 // Settle for any random icon, even if it's not unique. | 957 // Settle for any random icon, even if it's not unique. |
905 if (ChooseAvatarIconIndexForNewProfile(true, false, &icon_index)) | 958 if (ChooseAvatarIconIndexForNewProfile(true, false, &icon_index)) |
906 return icon_index; | 959 return icon_index; |
907 | 960 |
908 NOTREACHED(); | 961 NOTREACHED(); |
909 return 0; | 962 return 0; |
910 } | 963 } |
911 | 964 |
| 965 void ProfileInfoCache::SetStatsBrowsingHistoryOfProfileAtIndex(size_t index, |
| 966 int value) { |
| 967 scoped_ptr<base::DictionaryValue> info( |
| 968 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 969 info->SetInteger(kStatsBrowsingHistoryKey, value); |
| 970 // This takes ownership of |info|. |
| 971 SetInfoForProfileAtIndex(index, info.release()); |
| 972 } |
| 973 |
| 974 void ProfileInfoCache::SetStatsPasswordsOfProfileAtIndex(size_t index, |
| 975 int value) { |
| 976 scoped_ptr<base::DictionaryValue> info( |
| 977 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 978 info->SetInteger(kStatsPasswordsKey, value); |
| 979 // This takes ownership of |info|. |
| 980 SetInfoForProfileAtIndex(index, info.release()); |
| 981 } |
| 982 |
| 983 void ProfileInfoCache::SetStatsBookmarksOfProfileAtIndex(size_t index, |
| 984 int value) { |
| 985 scoped_ptr<base::DictionaryValue> info( |
| 986 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 987 info->SetInteger(kStatsBookmarksKey, value); |
| 988 // This takes ownership of |info|. |
| 989 SetInfoForProfileAtIndex(index, info.release()); |
| 990 } |
| 991 |
| 992 void ProfileInfoCache::SetStatsSettingsOfProfileAtIndex(size_t index, |
| 993 int value) { |
| 994 scoped_ptr<base::DictionaryValue> info( |
| 995 GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 996 info->SetInteger(kStatsSettingsKey, value); |
| 997 // This takes ownership of |info|. |
| 998 SetInfoForProfileAtIndex(index, info.release()); |
| 999 } |
| 1000 |
912 const base::FilePath& ProfileInfoCache::GetUserDataDir() const { | 1001 const base::FilePath& ProfileInfoCache::GetUserDataDir() const { |
913 return user_data_dir_; | 1002 return user_data_dir_; |
914 } | 1003 } |
915 | 1004 |
916 // static | 1005 // static |
917 void ProfileInfoCache::RegisterPrefs(PrefRegistrySimple* registry) { | 1006 void ProfileInfoCache::RegisterPrefs(PrefRegistrySimple* registry) { |
918 registry->RegisterDictionaryPref(prefs::kProfileInfoCache); | 1007 registry->RegisterDictionaryPref(prefs::kProfileInfoCache); |
919 } | 1008 } |
920 | 1009 |
921 void ProfileInfoCache::DownloadHighResAvatarIfNeeded( | 1010 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 | 1370 // The profile info is in the cache but its entry isn't created yet, insert |
1282 // it in the map. | 1371 // it in the map. |
1283 scoped_ptr<ProfileAttributesEntry> new_entry(new ProfileAttributesEntry()); | 1372 scoped_ptr<ProfileAttributesEntry> new_entry(new ProfileAttributesEntry()); |
1284 profile_attributes_entries_.add(path, new_entry.Pass()); | 1373 profile_attributes_entries_.add(path, new_entry.Pass()); |
1285 profile_attributes_entries_.get(path)->Initialize(this, path); | 1374 profile_attributes_entries_.get(path)->Initialize(this, path); |
1286 } | 1375 } |
1287 | 1376 |
1288 *entry = profile_attributes_entries_.get(path); | 1377 *entry = profile_attributes_entries_.get(path); |
1289 return true; | 1378 return true; |
1290 } | 1379 } |
OLD | NEW |