| 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 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1870 return install_parameter; | 1896 return install_parameter; |
| 1871 } | 1897 } |
| 1872 | 1898 |
| 1873 void ExtensionPrefs::SetInstallParam(const std::string& extension_id, | 1899 void ExtensionPrefs::SetInstallParam(const std::string& extension_id, |
| 1874 const std::string& install_parameter) { | 1900 const std::string& install_parameter) { |
| 1875 UpdateExtensionPref(extension_id, | 1901 UpdateExtensionPref(extension_id, |
| 1876 kPrefInstallParam, | 1902 kPrefInstallParam, |
| 1877 new base::StringValue(install_parameter)); | 1903 new base::StringValue(install_parameter)); |
| 1878 } | 1904 } |
| 1879 | 1905 |
| 1906 int64 ExtensionPrefs::GetNextStorageThreshold( |
| 1907 const std::string& extension_id) const { |
| 1908 int64 next_threshold; |
| 1909 if (ReadInt64(GetExtensionPref(extension_id), |
| 1910 kPrefNextStorageThreshold, |
| 1911 &next_threshold)) { |
| 1912 return next_threshold; |
| 1913 } |
| 1914 |
| 1915 return 0; |
| 1916 } |
| 1917 |
| 1918 void ExtensionPrefs::SetNextStorageThreshold(const std::string& extension_id, |
| 1919 int64 next_threshold) { |
| 1920 |
| 1921 ScopedExtensionPrefUpdate update(prefs_, extension_id); |
| 1922 SaveInt64(update.Get(), kPrefNextStorageThreshold, next_threshold); |
| 1923 } |
| 1924 |
| 1925 bool ExtensionPrefs::IsStorageNotificationEnabled( |
| 1926 const std::string& extension_id) const { |
| 1927 bool disable_notifications; |
| 1928 if (ReadPrefAsBoolean(extension_id, |
| 1929 kPrefDisableStorageNotifications, |
| 1930 &disable_notifications)) { |
| 1931 return !disable_notifications; |
| 1932 } |
| 1933 |
| 1934 return true; |
| 1935 } |
| 1936 |
| 1937 void ExtensionPrefs::SetStorageNotificationEnabled( |
| 1938 const std::string& extension_id, bool enable_notifications) { |
| 1939 UpdateExtensionPref( |
| 1940 extension_id, |
| 1941 kPrefDisableStorageNotifications, |
| 1942 enable_notifications ? NULL : new base::FundamentalValue(true)); |
| 1943 } |
| 1944 |
| 1880 ExtensionPrefs::ExtensionPrefs( | 1945 ExtensionPrefs::ExtensionPrefs( |
| 1881 PrefService* prefs, | 1946 PrefService* prefs, |
| 1882 const base::FilePath& root_dir, | 1947 const base::FilePath& root_dir, |
| 1883 ExtensionPrefValueMap* extension_pref_value_map, | 1948 ExtensionPrefValueMap* extension_pref_value_map, |
| 1884 scoped_ptr<AppSorting> app_sorting, | 1949 scoped_ptr<AppSorting> app_sorting, |
| 1885 scoped_ptr<TimeProvider> time_provider, | 1950 scoped_ptr<TimeProvider> time_provider, |
| 1886 bool extensions_disabled, | 1951 bool extensions_disabled, |
| 1887 const std::vector<ExtensionPrefsObserver*>& early_observers) | 1952 const std::vector<ExtensionPrefsObserver*>& early_observers) |
| 1888 : prefs_(prefs), | 1953 : prefs_(prefs), |
| 1889 install_directory_(root_dir), | 1954 install_directory_(root_dir), |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2157 extension_pref_value_map_->RegisterExtension( | 2222 extension_pref_value_map_->RegisterExtension( |
| 2158 extension_id, install_time, is_enabled, is_incognito_enabled); | 2223 extension_id, install_time, is_enabled, is_incognito_enabled); |
| 2159 | 2224 |
| 2160 FOR_EACH_OBSERVER( | 2225 FOR_EACH_OBSERVER( |
| 2161 ExtensionPrefsObserver, | 2226 ExtensionPrefsObserver, |
| 2162 observer_list_, | 2227 observer_list_, |
| 2163 OnExtensionRegistered(extension_id, install_time, is_enabled)); | 2228 OnExtensionRegistered(extension_id, install_time, is_enabled)); |
| 2164 } | 2229 } |
| 2165 | 2230 |
| 2166 } // namespace extensions | 2231 } // namespace extensions |
| OLD | NEW |