Chromium Code Reviews| 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 | 196 |
| 197 // A preference that stores the next threshold for displaying a notification | 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 | 198 // when an extension or app consumes excessive disk space. This will not be |
| 199 // set until the extension/app reaches the initial threshold. | 199 // set until the extension/app reaches the initial threshold. |
| 200 const char kPrefNextStorageThreshold[] = "next_storage_threshold"; | 200 const char kPrefNextStorageThreshold[] = "next_storage_threshold"; |
| 201 | 201 |
| 202 // If this preference is set to true, notifications will be suppressed when an | 202 // If this preference is set to true, notifications will be suppressed when an |
| 203 // extension or app consumes excessive disk space. | 203 // extension or app consumes excessive disk space. |
| 204 const char kPrefDisableStorageNotifications[] = "disable_storage_notifications"; | 204 const char kPrefDisableStorageNotifications[] = "disable_storage_notifications"; |
| 205 | 205 |
| 206 // A boolean preference that indicates whether the extension should not be | |
| 207 // synced. Default value is false. | |
| 208 const char kPrefDoNotSync[] = "do_not_sync"; | |
| 209 | |
| 206 // Provider of write access to a dictionary storing extension prefs. | 210 // Provider of write access to a dictionary storing extension prefs. |
| 207 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { | 211 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { |
| 208 public: | 212 public: |
| 209 ScopedExtensionPrefUpdate(PrefService* service, | 213 ScopedExtensionPrefUpdate(PrefService* service, |
| 210 const std::string& extension_id) : | 214 const std::string& extension_id) : |
| 211 DictionaryPrefUpdate(service, pref_names::kExtensions), | 215 DictionaryPrefUpdate(service, pref_names::kExtensions), |
| 212 extension_id_(extension_id) {} | 216 extension_id_(extension_id) {} |
| 213 | 217 |
| 214 virtual ~ScopedExtensionPrefUpdate() { | 218 virtual ~ScopedExtensionPrefUpdate() { |
| 215 } | 219 } |
| (...skipping 1520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1736 } | 1740 } |
| 1737 std::string install_time_str; | 1741 std::string install_time_str; |
| 1738 if (!extension->GetString(kPrefInstallTime, &install_time_str)) | 1742 if (!extension->GetString(kPrefInstallTime, &install_time_str)) |
| 1739 return base::Time(); | 1743 return base::Time(); |
| 1740 int64 install_time_i64 = 0; | 1744 int64 install_time_i64 = 0; |
| 1741 if (!base::StringToInt64(install_time_str, &install_time_i64)) | 1745 if (!base::StringToInt64(install_time_str, &install_time_i64)) |
| 1742 return base::Time(); | 1746 return base::Time(); |
| 1743 return base::Time::FromInternalValue(install_time_i64); | 1747 return base::Time::FromInternalValue(install_time_i64); |
| 1744 } | 1748 } |
| 1745 | 1749 |
| 1750 bool ExtensionPrefs::IsSyncable(const std::string& extension_id) const { | |
|
not at google - send to devlin
2014/06/06 19:37:16
i'd mildly prefer this to reflect the actual prefe
xiyuan
2014/06/09 20:59:59
Done.
| |
| 1751 bool do_not_sync; | |
| 1752 if (!ReadPrefAsBoolean(extension_id, kPrefDoNotSync, &do_not_sync)) | |
| 1753 return true; | |
| 1754 | |
| 1755 return !do_not_sync; | |
| 1756 } | |
| 1757 | |
| 1746 base::Time ExtensionPrefs::GetLastLaunchTime( | 1758 base::Time ExtensionPrefs::GetLastLaunchTime( |
| 1747 const std::string& extension_id) const { | 1759 const std::string& extension_id) const { |
| 1748 const base::DictionaryValue* extension = GetExtensionPref(extension_id); | 1760 const base::DictionaryValue* extension = GetExtensionPref(extension_id); |
| 1749 if (!extension) | 1761 if (!extension) |
| 1750 return base::Time(); | 1762 return base::Time(); |
| 1751 | 1763 |
| 1752 std::string launch_time_str; | 1764 std::string launch_time_str; |
| 1753 if (!extension->GetString(kPrefLastLaunchTime, &launch_time_str)) | 1765 if (!extension->GetString(kPrefLastLaunchTime, &launch_time_str)) |
| 1754 return base::Time(); | 1766 return base::Time(); |
| 1755 int64 launch_time_i64 = 0; | 1767 int64 launch_time_i64 = 0; |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2113 iter != strings.end(); ++iter) { | 2125 iter != strings.end(); ++iter) { |
| 2114 list_of_values->Append(new base::StringValue(*iter)); | 2126 list_of_values->Append(new base::StringValue(*iter)); |
| 2115 } | 2127 } |
| 2116 } | 2128 } |
| 2117 | 2129 |
| 2118 void ExtensionPrefs::PopulateExtensionInfoPrefs( | 2130 void ExtensionPrefs::PopulateExtensionInfoPrefs( |
| 2119 const Extension* extension, | 2131 const Extension* extension, |
| 2120 const base::Time install_time, | 2132 const base::Time install_time, |
| 2121 Extension::State initial_state, | 2133 Extension::State initial_state, |
| 2122 bool blacklisted_for_malware, | 2134 bool blacklisted_for_malware, |
| 2123 bool is_ephemeral, | 2135 bool is_ephemeral, |
|
not at google - send to devlin
2014/06/06 19:37:16
should be passing do_not_sync in here
xiyuan
2014/06/09 20:59:59
Done.
| |
| 2124 const std::string& install_parameter, | 2136 const std::string& install_parameter, |
| 2125 base::DictionaryValue* extension_dict) { | 2137 base::DictionaryValue* extension_dict) { |
| 2126 // Leave the state blank for component extensions so that old chrome versions | 2138 // Leave the state blank for component extensions so that old chrome versions |
| 2127 // loading new profiles do not fail in GetInstalledExtensionInfo. Older | 2139 // loading new profiles do not fail in GetInstalledExtensionInfo. Older |
| 2128 // Chrome versions would only check for an omitted state. | 2140 // Chrome versions would only check for an omitted state. |
| 2129 if (initial_state != Extension::ENABLED_COMPONENT) | 2141 if (initial_state != Extension::ENABLED_COMPONENT) |
| 2130 extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state)); | 2142 extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state)); |
| 2131 | 2143 |
| 2132 extension_dict->Set(kPrefLocation, | 2144 extension_dict->Set(kPrefLocation, |
| 2133 new base::FundamentalValue(extension->location())); | 2145 new base::FundamentalValue(extension->location())); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 2158 if (!install_parameter.empty()) { | 2170 if (!install_parameter.empty()) { |
| 2159 extension_dict->Set(kPrefInstallParam, | 2171 extension_dict->Set(kPrefInstallParam, |
| 2160 new base::StringValue(install_parameter)); | 2172 new base::StringValue(install_parameter)); |
| 2161 } | 2173 } |
| 2162 // We store prefs about LOAD extensions, but don't cache their manifest | 2174 // We store prefs about LOAD extensions, but don't cache their manifest |
| 2163 // since it may change on disk. | 2175 // since it may change on disk. |
| 2164 if (!Manifest::IsUnpackedLocation(extension->location())) { | 2176 if (!Manifest::IsUnpackedLocation(extension->location())) { |
| 2165 extension_dict->Set(kPrefManifest, | 2177 extension_dict->Set(kPrefManifest, |
| 2166 extension->manifest()->value()->DeepCopy()); | 2178 extension->manifest()->value()->DeepCopy()); |
| 2167 } | 2179 } |
| 2180 | |
| 2181 // Only writes kPrefDoNotSync when it is not the default. | |
| 2182 if (!extension->is_syncable()) | |
| 2183 extension_dict->Set(kPrefDoNotSync, new base::FundamentalValue(true)); | |
| 2168 } | 2184 } |
| 2169 | 2185 |
| 2170 void ExtensionPrefs::InitExtensionControlledPrefs( | 2186 void ExtensionPrefs::InitExtensionControlledPrefs( |
| 2171 ExtensionPrefValueMap* value_map) { | 2187 ExtensionPrefValueMap* value_map) { |
| 2172 ExtensionIdList extension_ids; | 2188 ExtensionIdList extension_ids; |
| 2173 GetExtensions(&extension_ids); | 2189 GetExtensions(&extension_ids); |
| 2174 | 2190 |
| 2175 for (ExtensionIdList::iterator extension_id = extension_ids.begin(); | 2191 for (ExtensionIdList::iterator extension_id = extension_ids.begin(); |
| 2176 extension_id != extension_ids.end(); | 2192 extension_id != extension_ids.end(); |
| 2177 ++extension_id) { | 2193 ++extension_id) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2261 extension_pref_value_map_->RegisterExtension( | 2277 extension_pref_value_map_->RegisterExtension( |
| 2262 extension_id, install_time, is_enabled, is_incognito_enabled); | 2278 extension_id, install_time, is_enabled, is_incognito_enabled); |
| 2263 | 2279 |
| 2264 FOR_EACH_OBSERVER( | 2280 FOR_EACH_OBSERVER( |
| 2265 ExtensionPrefsObserver, | 2281 ExtensionPrefsObserver, |
| 2266 observer_list_, | 2282 observer_list_, |
| 2267 OnExtensionRegistered(extension_id, install_time, is_enabled)); | 2283 OnExtensionRegistered(extension_id, install_time, is_enabled)); |
| 2268 } | 2284 } |
| 2269 | 2285 |
| 2270 } // namespace extensions | 2286 } // namespace extensions |
| OLD | NEW |