| 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 187 |
| 188 // A preference indicating whether the extension is an ephemeral app. | 188 // A preference indicating whether the extension is an ephemeral app. |
| 189 const char kPrefEphemeralApp[] = "ephemeral_app"; | 189 const char kPrefEphemeralApp[] = "ephemeral_app"; |
| 190 | 190 |
| 191 // Am installation parameter bundled with an extension. | 191 // Am installation parameter bundled with an extension. |
| 192 const char kPrefInstallParam[] = "install_parameter"; | 192 const char kPrefInstallParam[] = "install_parameter"; |
| 193 | 193 |
| 194 // A list of installed ids and a signature. | 194 // A list of installed ids and a signature. |
| 195 const char kInstallSignature[] = "extensions.install_signature"; | 195 const char kInstallSignature[] = "extensions.install_signature"; |
| 196 | 196 |
| 197 // A preference that stores the next threshold for displaying a notification | |
| 198 // when an extension or app consumes excessive disk space. This will not be | |
| 199 // set until the extension/app reaches the initial threshold. | |
| 200 const char kPrefNextStorageThreshold[] = "next_storage_threshold"; | |
| 201 | |
| 202 // If this preference is set to true, notifications will be suppressed when an | |
| 203 // extension or app consumes excessive disk space. | |
| 204 const char kPrefDisableStorageNotifications[] = "disable_storage_notifications"; | |
| 205 | |
| 206 // Provider of write access to a dictionary storing extension prefs. | 197 // Provider of write access to a dictionary storing extension prefs. |
| 207 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { | 198 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { |
| 208 public: | 199 public: |
| 209 ScopedExtensionPrefUpdate(PrefService* service, | 200 ScopedExtensionPrefUpdate(PrefService* service, |
| 210 const std::string& extension_id) : | 201 const std::string& extension_id) : |
| 211 DictionaryPrefUpdate(service, pref_names::kExtensions), | 202 DictionaryPrefUpdate(service, pref_names::kExtensions), |
| 212 extension_id_(extension_id) {} | 203 extension_id_(extension_id) {} |
| 213 | 204 |
| 214 virtual ~ScopedExtensionPrefUpdate() { | 205 virtual ~ScopedExtensionPrefUpdate() { |
| 215 } | 206 } |
| (...skipping 1716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1932 return install_parameter; | 1923 return install_parameter; |
| 1933 } | 1924 } |
| 1934 | 1925 |
| 1935 void ExtensionPrefs::SetInstallParam(const std::string& extension_id, | 1926 void ExtensionPrefs::SetInstallParam(const std::string& extension_id, |
| 1936 const std::string& install_parameter) { | 1927 const std::string& install_parameter) { |
| 1937 UpdateExtensionPref(extension_id, | 1928 UpdateExtensionPref(extension_id, |
| 1938 kPrefInstallParam, | 1929 kPrefInstallParam, |
| 1939 new base::StringValue(install_parameter)); | 1930 new base::StringValue(install_parameter)); |
| 1940 } | 1931 } |
| 1941 | 1932 |
| 1942 int64 ExtensionPrefs::GetNextStorageThreshold( | |
| 1943 const std::string& extension_id) const { | |
| 1944 int64 next_threshold; | |
| 1945 if (ReadInt64(GetExtensionPref(extension_id), | |
| 1946 kPrefNextStorageThreshold, | |
| 1947 &next_threshold)) { | |
| 1948 return next_threshold; | |
| 1949 } | |
| 1950 | |
| 1951 return 0; | |
| 1952 } | |
| 1953 | |
| 1954 void ExtensionPrefs::SetNextStorageThreshold(const std::string& extension_id, | |
| 1955 int64 next_threshold) { | |
| 1956 ScopedExtensionPrefUpdate update(prefs_, extension_id); | |
| 1957 SaveInt64(update.Get(), kPrefNextStorageThreshold, next_threshold); | |
| 1958 } | |
| 1959 | |
| 1960 bool ExtensionPrefs::IsStorageNotificationEnabled( | |
| 1961 const std::string& extension_id) const { | |
| 1962 bool disable_notifications; | |
| 1963 if (ReadPrefAsBoolean(extension_id, | |
| 1964 kPrefDisableStorageNotifications, | |
| 1965 &disable_notifications)) { | |
| 1966 return !disable_notifications; | |
| 1967 } | |
| 1968 | |
| 1969 return true; | |
| 1970 } | |
| 1971 | |
| 1972 void ExtensionPrefs::SetStorageNotificationEnabled( | |
| 1973 const std::string& extension_id, bool enable_notifications) { | |
| 1974 UpdateExtensionPref( | |
| 1975 extension_id, | |
| 1976 kPrefDisableStorageNotifications, | |
| 1977 enable_notifications ? NULL : new base::FundamentalValue(true)); | |
| 1978 } | |
| 1979 | |
| 1980 ExtensionPrefs::ExtensionPrefs( | 1933 ExtensionPrefs::ExtensionPrefs( |
| 1981 PrefService* prefs, | 1934 PrefService* prefs, |
| 1982 const base::FilePath& root_dir, | 1935 const base::FilePath& root_dir, |
| 1983 ExtensionPrefValueMap* extension_pref_value_map, | 1936 ExtensionPrefValueMap* extension_pref_value_map, |
| 1984 scoped_ptr<AppSorting> app_sorting, | 1937 scoped_ptr<AppSorting> app_sorting, |
| 1985 scoped_ptr<TimeProvider> time_provider, | 1938 scoped_ptr<TimeProvider> time_provider, |
| 1986 bool extensions_disabled, | 1939 bool extensions_disabled, |
| 1987 const std::vector<ExtensionPrefsObserver*>& early_observers) | 1940 const std::vector<ExtensionPrefsObserver*>& early_observers) |
| 1988 : prefs_(prefs), | 1941 : prefs_(prefs), |
| 1989 install_directory_(root_dir), | 1942 install_directory_(root_dir), |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2261 extension_pref_value_map_->RegisterExtension( | 2214 extension_pref_value_map_->RegisterExtension( |
| 2262 extension_id, install_time, is_enabled, is_incognito_enabled); | 2215 extension_id, install_time, is_enabled, is_incognito_enabled); |
| 2263 | 2216 |
| 2264 FOR_EACH_OBSERVER( | 2217 FOR_EACH_OBSERVER( |
| 2265 ExtensionPrefsObserver, | 2218 ExtensionPrefsObserver, |
| 2266 observer_list_, | 2219 observer_list_, |
| 2267 OnExtensionRegistered(extension_id, install_time, is_enabled)); | 2220 OnExtensionRegistered(extension_id, install_time, is_enabled)); |
| 2268 } | 2221 } |
| 2269 | 2222 |
| 2270 } // namespace extensions | 2223 } // namespace extensions |
| OLD | NEW |