OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/extension_prefs.h" | 5 #include "extensions/browser/extension_prefs.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
7 #include <iterator> | 10 #include <iterator> |
8 #include <utility> | 11 #include <utility> |
9 | 12 |
| 13 #include "base/macros.h" |
10 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
11 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
12 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
14 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
| 19 #include "build/build_config.h" |
15 #include "components/crx_file/id_util.h" | 20 #include "components/crx_file/id_util.h" |
16 #include "components/pref_registry/pref_registry_syncable.h" | 21 #include "components/pref_registry/pref_registry_syncable.h" |
17 #include "extensions/browser/app_sorting.h" | 22 #include "extensions/browser/app_sorting.h" |
18 #include "extensions/browser/event_router.h" | 23 #include "extensions/browser/event_router.h" |
19 #include "extensions/browser/extension_pref_store.h" | 24 #include "extensions/browser/extension_pref_store.h" |
20 #include "extensions/browser/extension_prefs_factory.h" | 25 #include "extensions/browser/extension_prefs_factory.h" |
21 #include "extensions/browser/extension_prefs_observer.h" | 26 #include "extensions/browser/extension_prefs_observer.h" |
22 #include "extensions/browser/extension_system.h" | 27 #include "extensions/browser/extension_system.h" |
23 #include "extensions/browser/install_flag.h" | 28 #include "extensions/browser/install_flag.h" |
24 #include "extensions/browser/pref_names.h" | 29 #include "extensions/browser/pref_names.h" |
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& id) const { | 850 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& id) const { |
846 const base::DictionaryValue* ext_prefs = GetExtensionPref(id); | 851 const base::DictionaryValue* ext_prefs = GetExtensionPref(id); |
847 return ext_prefs && IsBlacklistBitSet(ext_prefs); | 852 return ext_prefs && IsBlacklistBitSet(ext_prefs); |
848 } | 853 } |
849 | 854 |
850 namespace { | 855 namespace { |
851 | 856 |
852 // Serializes a 64bit integer as a string value. | 857 // Serializes a 64bit integer as a string value. |
853 void SaveInt64(base::DictionaryValue* dictionary, | 858 void SaveInt64(base::DictionaryValue* dictionary, |
854 const char* key, | 859 const char* key, |
855 const int64 value) { | 860 const int64_t value) { |
856 if (!dictionary) | 861 if (!dictionary) |
857 return; | 862 return; |
858 | 863 |
859 std::string string_value = base::Int64ToString(value); | 864 std::string string_value = base::Int64ToString(value); |
860 dictionary->SetString(key, string_value); | 865 dictionary->SetString(key, string_value); |
861 } | 866 } |
862 | 867 |
863 // Deserializes a 64bit integer stored as a string value. | 868 // Deserializes a 64bit integer stored as a string value. |
864 bool ReadInt64(const base::DictionaryValue* dictionary, | 869 bool ReadInt64(const base::DictionaryValue* dictionary, |
865 const char* key, | 870 const char* key, |
866 int64* value) { | 871 int64_t* value) { |
867 if (!dictionary) | 872 if (!dictionary) |
868 return false; | 873 return false; |
869 | 874 |
870 std::string string_value; | 875 std::string string_value; |
871 if (!dictionary->GetString(key, &string_value)) | 876 if (!dictionary->GetString(key, &string_value)) |
872 return false; | 877 return false; |
873 | 878 |
874 return base::StringToInt64(string_value, value); | 879 return base::StringToInt64(string_value, value); |
875 } | 880 } |
876 | 881 |
877 // Serializes |time| as a string value mapped to |key| in |dictionary|. | 882 // Serializes |time| as a string value mapped to |key| in |dictionary|. |
878 void SaveTime(base::DictionaryValue* dictionary, | 883 void SaveTime(base::DictionaryValue* dictionary, |
879 const char* key, | 884 const char* key, |
880 const base::Time& time) { | 885 const base::Time& time) { |
881 SaveInt64(dictionary, key, time.ToInternalValue()); | 886 SaveInt64(dictionary, key, time.ToInternalValue()); |
882 } | 887 } |
883 | 888 |
884 // The opposite of SaveTime. If |key| is not found, this returns an empty Time | 889 // The opposite of SaveTime. If |key| is not found, this returns an empty Time |
885 // (is_null() will return true). | 890 // (is_null() will return true). |
886 base::Time ReadTime(const base::DictionaryValue* dictionary, const char* key) { | 891 base::Time ReadTime(const base::DictionaryValue* dictionary, const char* key) { |
887 int64 value; | 892 int64_t value; |
888 if (ReadInt64(dictionary, key, &value)) | 893 if (ReadInt64(dictionary, key, &value)) |
889 return base::Time::FromInternalValue(value); | 894 return base::Time::FromInternalValue(value); |
890 | 895 |
891 return base::Time(); | 896 return base::Time(); |
892 } | 897 } |
893 | 898 |
894 } // namespace | 899 } // namespace |
895 | 900 |
896 base::Time ExtensionPrefs::LastPingDay(const std::string& extension_id) const { | 901 base::Time ExtensionPrefs::LastPingDay(const std::string& extension_id) const { |
897 DCHECK(crx_file::id_util::IdIsValid(extension_id)); | 902 DCHECK(crx_file::id_util::IdIsValid(extension_id)); |
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1580 base::Time ExtensionPrefs::GetInstallTime( | 1585 base::Time ExtensionPrefs::GetInstallTime( |
1581 const std::string& extension_id) const { | 1586 const std::string& extension_id) const { |
1582 const base::DictionaryValue* extension = GetExtensionPref(extension_id); | 1587 const base::DictionaryValue* extension = GetExtensionPref(extension_id); |
1583 if (!extension) { | 1588 if (!extension) { |
1584 NOTREACHED(); | 1589 NOTREACHED(); |
1585 return base::Time(); | 1590 return base::Time(); |
1586 } | 1591 } |
1587 std::string install_time_str; | 1592 std::string install_time_str; |
1588 if (!extension->GetString(kPrefInstallTime, &install_time_str)) | 1593 if (!extension->GetString(kPrefInstallTime, &install_time_str)) |
1589 return base::Time(); | 1594 return base::Time(); |
1590 int64 install_time_i64 = 0; | 1595 int64_t install_time_i64 = 0; |
1591 if (!base::StringToInt64(install_time_str, &install_time_i64)) | 1596 if (!base::StringToInt64(install_time_str, &install_time_i64)) |
1592 return base::Time(); | 1597 return base::Time(); |
1593 return base::Time::FromInternalValue(install_time_i64); | 1598 return base::Time::FromInternalValue(install_time_i64); |
1594 } | 1599 } |
1595 | 1600 |
1596 bool ExtensionPrefs::DoNotSync(const std::string& extension_id) const { | 1601 bool ExtensionPrefs::DoNotSync(const std::string& extension_id) const { |
1597 bool do_not_sync; | 1602 bool do_not_sync; |
1598 if (!ReadPrefAsBoolean(extension_id, kPrefDoNotSync, &do_not_sync)) | 1603 if (!ReadPrefAsBoolean(extension_id, kPrefDoNotSync, &do_not_sync)) |
1599 return false; | 1604 return false; |
1600 | 1605 |
1601 return do_not_sync; | 1606 return do_not_sync; |
1602 } | 1607 } |
1603 | 1608 |
1604 base::Time ExtensionPrefs::GetLastLaunchTime( | 1609 base::Time ExtensionPrefs::GetLastLaunchTime( |
1605 const std::string& extension_id) const { | 1610 const std::string& extension_id) const { |
1606 const base::DictionaryValue* extension = GetExtensionPref(extension_id); | 1611 const base::DictionaryValue* extension = GetExtensionPref(extension_id); |
1607 if (!extension) | 1612 if (!extension) |
1608 return base::Time(); | 1613 return base::Time(); |
1609 | 1614 |
1610 std::string launch_time_str; | 1615 std::string launch_time_str; |
1611 if (!extension->GetString(kPrefLastLaunchTime, &launch_time_str)) | 1616 if (!extension->GetString(kPrefLastLaunchTime, &launch_time_str)) |
1612 return base::Time(); | 1617 return base::Time(); |
1613 int64 launch_time_i64 = 0; | 1618 int64_t launch_time_i64 = 0; |
1614 if (!base::StringToInt64(launch_time_str, &launch_time_i64)) | 1619 if (!base::StringToInt64(launch_time_str, &launch_time_i64)) |
1615 return base::Time(); | 1620 return base::Time(); |
1616 return base::Time::FromInternalValue(launch_time_i64); | 1621 return base::Time::FromInternalValue(launch_time_i64); |
1617 } | 1622 } |
1618 | 1623 |
1619 void ExtensionPrefs::SetLastLaunchTime(const std::string& extension_id, | 1624 void ExtensionPrefs::SetLastLaunchTime(const std::string& extension_id, |
1620 const base::Time& time) { | 1625 const base::Time& time) { |
1621 DCHECK(crx_file::id_util::IdIsValid(extension_id)); | 1626 DCHECK(crx_file::id_util::IdIsValid(extension_id)); |
1622 ScopedExtensionPrefUpdate update(prefs_, extension_id); | 1627 ScopedExtensionPrefUpdate update(prefs_, extension_id); |
1623 SaveTime(update.Get(), kPrefLastLaunchTime, time); | 1628 SaveTime(update.Get(), kPrefLastLaunchTime, time); |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2071 extension_pref_value_map_->RegisterExtension( | 2076 extension_pref_value_map_->RegisterExtension( |
2072 extension_id, install_time, is_enabled, is_incognito_enabled); | 2077 extension_id, install_time, is_enabled, is_incognito_enabled); |
2073 | 2078 |
2074 FOR_EACH_OBSERVER( | 2079 FOR_EACH_OBSERVER( |
2075 ExtensionPrefsObserver, | 2080 ExtensionPrefsObserver, |
2076 observer_list_, | 2081 observer_list_, |
2077 OnExtensionRegistered(extension_id, install_time, is_enabled)); | 2082 OnExtensionRegistered(extension_id, install_time, is_enabled)); |
2078 } | 2083 } |
2079 | 2084 |
2080 } // namespace extensions | 2085 } // namespace extensions |
OLD | NEW |