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 <iterator> | 7 #include <iterator> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/prefs/pref_notifier.h" | 10 #include "base/prefs/pref_notifier.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 // Their data is retained and garbage collected when inactive for a long period | 183 // Their data is retained and garbage collected when inactive for a long period |
184 // of time. | 184 // of time. |
185 const char kPrefEvictedEphemeralApp[] = "evicted_ephemeral_app"; | 185 const char kPrefEvictedEphemeralApp[] = "evicted_ephemeral_app"; |
186 | 186 |
187 // Am installation parameter bundled with an extension. | 187 // Am installation parameter bundled with an extension. |
188 const char kPrefInstallParam[] = "install_parameter"; | 188 const char kPrefInstallParam[] = "install_parameter"; |
189 | 189 |
190 // A list of installed ids and a signature. | 190 // A list of installed ids and a signature. |
191 const char kInstallSignature[] = "extensions.install_signature"; | 191 const char kInstallSignature[] = "extensions.install_signature"; |
192 | 192 |
| 193 // A preference that stores the next threshold for displaying a notification |
| 194 // when an extension or app consumes excessive disk space. This will not be |
| 195 // set until the extension/app reaches the initial threshold. |
| 196 const char kPrefNextStorageThreshold[] = "next_storage_threshold"; |
| 197 |
| 198 // If this preference is set to true, notifications will be suppressed when an |
| 199 // extension or app consumes excessive disk space. |
| 200 const char kPrefDisableStorageNotifications[] = "disable_storage_notifications"; |
| 201 |
193 // Provider of write access to a dictionary storing extension prefs. | 202 // Provider of write access to a dictionary storing extension prefs. |
194 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { | 203 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { |
195 public: | 204 public: |
196 ScopedExtensionPrefUpdate(PrefService* service, | 205 ScopedExtensionPrefUpdate(PrefService* service, |
197 const std::string& extension_id) : | 206 const std::string& extension_id) : |
198 DictionaryPrefUpdate(service, pref_names::kExtensions), | 207 DictionaryPrefUpdate(service, pref_names::kExtensions), |
199 extension_id_(extension_id) {} | 208 extension_id_(extension_id) {} |
200 | 209 |
201 virtual ~ScopedExtensionPrefUpdate() { | 210 virtual ~ScopedExtensionPrefUpdate() { |
202 } | 211 } |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 } | 875 } |
867 } | 876 } |
868 | 877 |
869 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& id) const { | 878 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& id) const { |
870 const base::DictionaryValue* ext_prefs = GetExtensionPref(id); | 879 const base::DictionaryValue* ext_prefs = GetExtensionPref(id); |
871 return ext_prefs && IsBlacklistBitSet(ext_prefs); | 880 return ext_prefs && IsBlacklistBitSet(ext_prefs); |
872 } | 881 } |
873 | 882 |
874 namespace { | 883 namespace { |
875 | 884 |
| 885 // Serializes a 64bit integer as a string value. |
| 886 void SaveInt64(base::DictionaryValue* dictionary, |
| 887 const char* key, |
| 888 const int64 value) { |
| 889 if (!dictionary) |
| 890 return; |
| 891 |
| 892 std::string string_value = base::Int64ToString(value); |
| 893 dictionary->SetString(key, string_value); |
| 894 } |
| 895 |
| 896 // Deserializes a 64bit integer stored as a string value. |
| 897 bool ReadInt64(const base::DictionaryValue* dictionary, |
| 898 const char* key, |
| 899 int64* value) { |
| 900 if (!dictionary) |
| 901 return false; |
| 902 |
| 903 std::string string_value; |
| 904 if (!dictionary->GetString(key, &string_value)) |
| 905 return false; |
| 906 |
| 907 return base::StringToInt64(string_value, value); |
| 908 } |
| 909 |
876 // Serializes |time| as a string value mapped to |key| in |dictionary|. | 910 // Serializes |time| as a string value mapped to |key| in |dictionary|. |
877 void SaveTime(base::DictionaryValue* dictionary, | 911 void SaveTime(base::DictionaryValue* dictionary, |
878 const char* key, | 912 const char* key, |
879 const base::Time& time) { | 913 const base::Time& time) { |
880 if (!dictionary) | 914 SaveInt64(dictionary, key, time.ToInternalValue()); |
881 return; | |
882 std::string string_value = base::Int64ToString(time.ToInternalValue()); | |
883 dictionary->SetString(key, string_value); | |
884 } | 915 } |
885 | 916 |
886 // The opposite of SaveTime. If |key| is not found, this returns an empty Time | 917 // The opposite of SaveTime. If |key| is not found, this returns an empty Time |
887 // (is_null() will return true). | 918 // (is_null() will return true). |
888 base::Time ReadTime(const base::DictionaryValue* dictionary, const char* key) { | 919 base::Time ReadTime(const base::DictionaryValue* dictionary, const char* key) { |
889 if (!dictionary) | |
890 return base::Time(); | |
891 std::string string_value; | |
892 int64 value; | 920 int64 value; |
893 if (dictionary->GetString(key, &string_value)) { | 921 if (ReadInt64(dictionary, key, &value)) |
894 if (base::StringToInt64(string_value, &value)) { | 922 return base::Time::FromInternalValue(value); |
895 return base::Time::FromInternalValue(value); | 923 |
896 } | |
897 } | |
898 return base::Time(); | 924 return base::Time(); |
899 } | 925 } |
900 | 926 |
901 } // namespace | 927 } // namespace |
902 | 928 |
903 base::Time ExtensionPrefs::LastPingDay(const std::string& extension_id) const { | 929 base::Time ExtensionPrefs::LastPingDay(const std::string& extension_id) const { |
904 DCHECK(Extension::IdIsValid(extension_id)); | 930 DCHECK(Extension::IdIsValid(extension_id)); |
905 return ReadTime(GetExtensionPref(extension_id), kLastPingDay); | 931 return ReadTime(GetExtensionPref(extension_id), kLastPingDay); |
906 } | 932 } |
907 | 933 |
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1868 return install_parameter; | 1894 return install_parameter; |
1869 } | 1895 } |
1870 | 1896 |
1871 void ExtensionPrefs::SetInstallParam(const std::string& extension_id, | 1897 void ExtensionPrefs::SetInstallParam(const std::string& extension_id, |
1872 const std::string& install_parameter) { | 1898 const std::string& install_parameter) { |
1873 UpdateExtensionPref(extension_id, | 1899 UpdateExtensionPref(extension_id, |
1874 kPrefInstallParam, | 1900 kPrefInstallParam, |
1875 new base::StringValue(install_parameter)); | 1901 new base::StringValue(install_parameter)); |
1876 } | 1902 } |
1877 | 1903 |
| 1904 int64 ExtensionPrefs::GetNextStorageThreshold( |
| 1905 const std::string& extension_id) const { |
| 1906 int64 next_threshold; |
| 1907 if (ReadInt64(GetExtensionPref(extension_id), |
| 1908 kPrefNextStorageThreshold, |
| 1909 &next_threshold)) { |
| 1910 return next_threshold; |
| 1911 } |
| 1912 |
| 1913 return 0; |
| 1914 } |
| 1915 |
| 1916 void ExtensionPrefs::SetNextStorageThreshold(const std::string& extension_id, |
| 1917 int64 next_threshold) { |
| 1918 |
| 1919 ScopedExtensionPrefUpdate update(prefs_, extension_id); |
| 1920 SaveInt64(update.Get(), kPrefNextStorageThreshold, next_threshold); |
| 1921 } |
| 1922 |
| 1923 bool ExtensionPrefs::IsStorageNotificationEnabled( |
| 1924 const std::string& extension_id) const { |
| 1925 bool disable_notifications; |
| 1926 if (ReadPrefAsBoolean(extension_id, |
| 1927 kPrefDisableStorageNotifications, |
| 1928 &disable_notifications)) { |
| 1929 return !disable_notifications; |
| 1930 } |
| 1931 |
| 1932 return true; |
| 1933 } |
| 1934 |
| 1935 void ExtensionPrefs::SetStorageNotificationEnabled( |
| 1936 const std::string& extension_id, bool enable_notifications) { |
| 1937 UpdateExtensionPref( |
| 1938 extension_id, |
| 1939 kPrefDisableStorageNotifications, |
| 1940 enable_notifications ? NULL : new base::FundamentalValue(true)); |
| 1941 } |
| 1942 |
1878 ExtensionPrefs::ExtensionPrefs( | 1943 ExtensionPrefs::ExtensionPrefs( |
1879 PrefService* prefs, | 1944 PrefService* prefs, |
1880 const base::FilePath& root_dir, | 1945 const base::FilePath& root_dir, |
1881 ExtensionPrefValueMap* extension_pref_value_map, | 1946 ExtensionPrefValueMap* extension_pref_value_map, |
1882 scoped_ptr<AppSorting> app_sorting, | 1947 scoped_ptr<AppSorting> app_sorting, |
1883 scoped_ptr<TimeProvider> time_provider, | 1948 scoped_ptr<TimeProvider> time_provider, |
1884 bool extensions_disabled, | 1949 bool extensions_disabled, |
1885 const std::vector<ExtensionPrefsObserver*>& early_observers) | 1950 const std::vector<ExtensionPrefsObserver*>& early_observers) |
1886 : prefs_(prefs), | 1951 : prefs_(prefs), |
1887 install_directory_(root_dir), | 1952 install_directory_(root_dir), |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2155 extension_pref_value_map_->RegisterExtension( | 2220 extension_pref_value_map_->RegisterExtension( |
2156 extension_id, install_time, is_enabled, is_incognito_enabled); | 2221 extension_id, install_time, is_enabled, is_incognito_enabled); |
2157 | 2222 |
2158 FOR_EACH_OBSERVER( | 2223 FOR_EACH_OBSERVER( |
2159 ExtensionPrefsObserver, | 2224 ExtensionPrefsObserver, |
2160 observer_list_, | 2225 observer_list_, |
2161 OnExtensionRegistered(extension_id, install_time, is_enabled)); | 2226 OnExtensionRegistered(extension_id, install_time, is_enabled)); |
2162 } | 2227 } |
2163 | 2228 |
2164 } // namespace extensions | 2229 } // namespace extensions |
OLD | NEW |