Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: extensions/browser/extension_prefs.cc

Issue 282103003: Moved IS_EPHEMERAL flag to extension prefs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 const char kPrefGeometryCache[] = "geometry_cache"; 178 const char kPrefGeometryCache[] = "geometry_cache";
179 179
180 // A preference that indicates when an extension is last launched. 180 // A preference that indicates when an extension is last launched.
181 const char kPrefLastLaunchTime[] = "last_launch_time"; 181 const char kPrefLastLaunchTime[] = "last_launch_time";
182 182
183 // A preference that marks an ephemeral app that was evicted from the cache. 183 // A preference that marks an ephemeral app that was evicted from the cache.
184 // Their data is retained and garbage collected when inactive for a long period 184 // Their data is retained and garbage collected when inactive for a long period
185 // of time. 185 // of time.
186 const char kPrefEvictedEphemeralApp[] = "evicted_ephemeral_app"; 186 const char kPrefEvictedEphemeralApp[] = "evicted_ephemeral_app";
187 187
188 // A preference indicating whether the extension is an ephemeral app.
189 const char kPrefEphemeralApp[] = "ephemeral_app";
190
188 // Am installation parameter bundled with an extension. 191 // Am installation parameter bundled with an extension.
189 const char kPrefInstallParam[] = "install_parameter"; 192 const char kPrefInstallParam[] = "install_parameter";
190 193
191 // A list of installed ids and a signature. 194 // A list of installed ids and a signature.
192 const char kInstallSignature[] = "extensions.install_signature"; 195 const char kInstallSignature[] = "extensions.install_signature";
193 196
194 // A preference that stores the next threshold for displaying a notification 197 // A preference that stores the next threshold for displaying a notification
195 // 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
196 // set until the extension/app reaches the initial threshold. 199 // set until the extension/app reaches the initial threshold.
197 const char kPrefNextStorageThreshold[] = "next_storage_threshold"; 200 const char kPrefNextStorageThreshold[] = "next_storage_threshold";
(...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 } 1222 }
1220 1223
1221 void ExtensionPrefs::SetKnownDisabled(const ExtensionIdSet& extension_ids) { 1224 void ExtensionPrefs::SetKnownDisabled(const ExtensionIdSet& extension_ids) {
1222 SetExtensionPrefFromContainer(pref_names::kKnownDisabled, extension_ids); 1225 SetExtensionPrefFromContainer(pref_names::kKnownDisabled, extension_ids);
1223 } 1226 }
1224 1227
1225 void ExtensionPrefs::OnExtensionInstalled( 1228 void ExtensionPrefs::OnExtensionInstalled(
1226 const Extension* extension, 1229 const Extension* extension,
1227 Extension::State initial_state, 1230 Extension::State initial_state,
1228 bool blacklisted_for_malware, 1231 bool blacklisted_for_malware,
1232 bool is_ephemeral,
1229 const syncer::StringOrdinal& page_ordinal, 1233 const syncer::StringOrdinal& page_ordinal,
1230 const std::string& install_parameter) { 1234 const std::string& install_parameter) {
1231 ScopedExtensionPrefUpdate update(prefs_, extension->id()); 1235 ScopedExtensionPrefUpdate update(prefs_, extension->id());
1232 base::DictionaryValue* extension_dict = update.Get(); 1236 base::DictionaryValue* extension_dict = update.Get();
1233 const base::Time install_time = time_provider_->GetCurrentTime(); 1237 const base::Time install_time = time_provider_->GetCurrentTime();
1234 PopulateExtensionInfoPrefs(extension, 1238 PopulateExtensionInfoPrefs(extension,
1235 install_time, 1239 install_time,
1236 initial_state, 1240 initial_state,
1237 blacklisted_for_malware, 1241 blacklisted_for_malware,
1242 is_ephemeral,
1238 install_parameter, 1243 install_parameter,
1239 extension_dict); 1244 extension_dict);
1240 FinishExtensionInfoPrefs(extension->id(), install_time, 1245 FinishExtensionInfoPrefs(extension->id(), install_time,
1241 extension->RequiresSortOrdinal(), 1246 extension->RequiresSortOrdinal(),
1242 page_ordinal, extension_dict); 1247 page_ordinal, extension_dict);
1243 } 1248 }
1244 1249
1245 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, 1250 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id,
1246 const Manifest::Location& location, 1251 const Manifest::Location& location,
1247 bool external_uninstall) { 1252 bool external_uninstall) {
1248 app_sorting_->ClearOrdinals(extension_id); 1253 app_sorting_->ClearOrdinals(extension_id);
1249 1254
1250 // For external extensions, we save a preference reminding ourself not to try 1255 // For external extensions, we save a preference reminding ourself not to try
1251 // and install the extension anymore (except when |external_uninstall| is 1256 // and install the extension anymore (except when |external_uninstall| is
1252 // true, which signifies that the registry key was deleted or the pref file 1257 // true, which signifies that the registry key was deleted or the pref file
1253 // no longer lists the extension). 1258 // no longer lists the extension).
1254 if (!external_uninstall && Manifest::IsExternalLocation(location)) { 1259 if (!external_uninstall && Manifest::IsExternalLocation(location)) {
1255 UpdateExtensionPref(extension_id, kPrefState, 1260 UpdateExtensionPref(extension_id, kPrefState,
1256 new base::FundamentalValue( 1261 new base::FundamentalValue(
1257 Extension::EXTERNAL_EXTENSION_UNINSTALLED)); 1262 Extension::EXTERNAL_EXTENSION_UNINSTALLED));
1258 extension_pref_value_map_->SetExtensionState(extension_id, false); 1263 extension_pref_value_map_->SetExtensionState(extension_id, false);
1259 FOR_EACH_OBSERVER(ExtensionPrefsObserver, 1264 FOR_EACH_OBSERVER(ExtensionPrefsObserver,
1260 observer_list_, 1265 observer_list_,
1261 OnExtensionStateChanged(extension_id, false)); 1266 OnExtensionStateChanged(extension_id, false));
1262 } else { 1267 } else {
1263 int creation_flags = GetCreationFlags(extension_id); 1268 if (IsEphemeralApp(extension_id)) {
1264 if (creation_flags & Extension::IS_EPHEMERAL) {
1265 // Keep ephemeral apps around, but mark them as evicted. 1269 // Keep ephemeral apps around, but mark them as evicted.
1266 UpdateExtensionPref(extension_id, kPrefEvictedEphemeralApp, 1270 UpdateExtensionPref(extension_id, kPrefEvictedEphemeralApp,
1267 new base::FundamentalValue(true)); 1271 new base::FundamentalValue(true));
1268 } else { 1272 } else {
1269 DeleteExtensionPrefs(extension_id); 1273 DeleteExtensionPrefs(extension_id);
1270 } 1274 }
1271 } 1275 }
1272 } 1276 }
1273 1277
1274 void ExtensionPrefs::SetExtensionState(const std::string& extension_id, 1278 void ExtensionPrefs::SetExtensionState(const std::string& extension_id,
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1450 extensions_info->push_back(linked_ptr<ExtensionInfo>(info.release())); 1454 extensions_info->push_back(linked_ptr<ExtensionInfo>(info.release()));
1451 } 1455 }
1452 1456
1453 return extensions_info.Pass(); 1457 return extensions_info.Pass();
1454 } 1458 }
1455 1459
1456 void ExtensionPrefs::SetDelayedInstallInfo( 1460 void ExtensionPrefs::SetDelayedInstallInfo(
1457 const Extension* extension, 1461 const Extension* extension,
1458 Extension::State initial_state, 1462 Extension::State initial_state,
1459 bool blacklisted_for_malware, 1463 bool blacklisted_for_malware,
1464 bool is_ephemeral,
1460 DelayReason delay_reason, 1465 DelayReason delay_reason,
1461 const syncer::StringOrdinal& page_ordinal, 1466 const syncer::StringOrdinal& page_ordinal,
1462 const std::string& install_parameter) { 1467 const std::string& install_parameter) {
1463 base::DictionaryValue* extension_dict = new base::DictionaryValue(); 1468 base::DictionaryValue* extension_dict = new base::DictionaryValue();
1464 PopulateExtensionInfoPrefs(extension, 1469 PopulateExtensionInfoPrefs(extension,
1465 time_provider_->GetCurrentTime(), 1470 time_provider_->GetCurrentTime(),
1466 initial_state, 1471 initial_state,
1467 blacklisted_for_malware, 1472 blacklisted_for_malware,
1473 is_ephemeral,
1468 install_parameter, 1474 install_parameter,
1469 extension_dict); 1475 extension_dict);
1470 1476
1471 // Add transient data that is needed by FinishDelayedInstallInfo(), but 1477 // Add transient data that is needed by FinishDelayedInstallInfo(), but
1472 // should not be in the final extension prefs. All entries here should have 1478 // should not be in the final extension prefs. All entries here should have
1473 // a corresponding Remove() call in FinishDelayedInstallInfo(). 1479 // a corresponding Remove() call in FinishDelayedInstallInfo().
1474 if (extension->RequiresSortOrdinal()) { 1480 if (extension->RequiresSortOrdinal()) {
1475 extension_dict->SetString( 1481 extension_dict->SetString(
1476 kPrefSuggestedPageOrdinal, 1482 kPrefSuggestedPageOrdinal,
1477 page_ordinal.IsValid() ? page_ordinal.ToInternalValue() 1483 page_ordinal.IsValid() ? page_ordinal.ToInternalValue()
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 return scoped_ptr<ExtensionInfo>(); 1622 return scoped_ptr<ExtensionInfo>();
1617 1623
1618 if (!IsEvictedEphemeralApp(extension_prefs)) 1624 if (!IsEvictedEphemeralApp(extension_prefs))
1619 return scoped_ptr<ExtensionInfo>(); 1625 return scoped_ptr<ExtensionInfo>();
1620 1626
1621 return GetInstalledInfoHelper(extension_id, extension_prefs); 1627 return GetInstalledInfoHelper(extension_id, extension_prefs);
1622 } 1628 }
1623 1629
1624 void ExtensionPrefs::RemoveEvictedEphemeralApp( 1630 void ExtensionPrefs::RemoveEvictedEphemeralApp(
1625 const std::string& extension_id) { 1631 const std::string& extension_id) {
1626 bool evicted_ephemeral_app = false; 1632 if (ReadPrefAsBooleanAndReturn(extension_id, kPrefEvictedEphemeralApp))
1627 if (ReadPrefAsBoolean(extension_id,
1628 kPrefEvictedEphemeralApp,
1629 &evicted_ephemeral_app) && evicted_ephemeral_app) {
1630 DeleteExtensionPrefs(extension_id); 1633 DeleteExtensionPrefs(extension_id);
1631 } 1634 }
1635
1636 bool ExtensionPrefs::IsEphemeralApp(const std::string& extension_id) const {
1637 if (ReadPrefAsBooleanAndReturn(extension_id, kPrefEphemeralApp))
1638 return true;
1639
1640 // Ephemerality was previously stored in the creation flags, so we must also
1641 // check it for backcompatibility.
1642 return (GetCreationFlags(extension_id) & Extension::IS_EPHEMERAL) != 0;
1632 } 1643 }
1633 1644
1634 bool ExtensionPrefs::WasAppDraggedByUser(const std::string& extension_id) { 1645 bool ExtensionPrefs::WasAppDraggedByUser(const std::string& extension_id) {
1635 return ReadPrefAsBooleanAndReturn(extension_id, kPrefUserDraggedApp); 1646 return ReadPrefAsBooleanAndReturn(extension_id, kPrefUserDraggedApp);
1636 } 1647 }
1637 1648
1638 void ExtensionPrefs::SetAppDraggedByUser(const std::string& extension_id) { 1649 void ExtensionPrefs::SetAppDraggedByUser(const std::string& extension_id) {
1639 UpdateExtensionPref(extension_id, kPrefUserDraggedApp, 1650 UpdateExtensionPref(extension_id, kPrefUserDraggedApp,
1640 new base::FundamentalValue(true)); 1651 new base::FundamentalValue(true));
1641 } 1652 }
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
2089 iter != strings.end(); ++iter) { 2100 iter != strings.end(); ++iter) {
2090 list_of_values->Append(new base::StringValue(*iter)); 2101 list_of_values->Append(new base::StringValue(*iter));
2091 } 2102 }
2092 } 2103 }
2093 2104
2094 void ExtensionPrefs::PopulateExtensionInfoPrefs( 2105 void ExtensionPrefs::PopulateExtensionInfoPrefs(
2095 const Extension* extension, 2106 const Extension* extension,
2096 const base::Time install_time, 2107 const base::Time install_time,
2097 Extension::State initial_state, 2108 Extension::State initial_state,
2098 bool blacklisted_for_malware, 2109 bool blacklisted_for_malware,
2110 bool is_ephemeral,
2099 const std::string& install_parameter, 2111 const std::string& install_parameter,
2100 base::DictionaryValue* extension_dict) { 2112 base::DictionaryValue* extension_dict) {
2101 // Leave the state blank for component extensions so that old chrome versions 2113 // Leave the state blank for component extensions so that old chrome versions
2102 // loading new profiles do not fail in GetInstalledExtensionInfo. Older 2114 // loading new profiles do not fail in GetInstalledExtensionInfo. Older
2103 // Chrome versions would only check for an omitted state. 2115 // Chrome versions would only check for an omitted state.
2104 if (initial_state != Extension::ENABLED_COMPONENT) 2116 if (initial_state != Extension::ENABLED_COMPONENT)
2105 extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state)); 2117 extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state));
2106 2118
2107 extension_dict->Set(kPrefLocation, 2119 extension_dict->Set(kPrefLocation,
2108 new base::FundamentalValue(extension->location())); 2120 new base::FundamentalValue(extension->location()));
2109 extension_dict->Set(kPrefCreationFlags, 2121 extension_dict->Set(kPrefCreationFlags,
2110 new base::FundamentalValue(extension->creation_flags())); 2122 new base::FundamentalValue(extension->creation_flags()));
2111 extension_dict->Set(kPrefFromWebStore, 2123 extension_dict->Set(kPrefFromWebStore,
2112 new base::FundamentalValue(extension->from_webstore())); 2124 new base::FundamentalValue(extension->from_webstore()));
2113 extension_dict->Set(kPrefFromBookmark, 2125 extension_dict->Set(kPrefFromBookmark,
2114 new base::FundamentalValue(extension->from_bookmark())); 2126 new base::FundamentalValue(extension->from_bookmark()));
2115 extension_dict->Set( 2127 extension_dict->Set(
2116 kPrefWasInstalledByDefault, 2128 kPrefWasInstalledByDefault,
2117 new base::FundamentalValue(extension->was_installed_by_default())); 2129 new base::FundamentalValue(extension->was_installed_by_default()));
2118 extension_dict->Set( 2130 extension_dict->Set(
2119 kPrefWasInstalledByOem, 2131 kPrefWasInstalledByOem,
2120 new base::FundamentalValue(extension->was_installed_by_oem())); 2132 new base::FundamentalValue(extension->was_installed_by_oem()));
2121 extension_dict->Set(kPrefInstallTime, 2133 extension_dict->Set(kPrefInstallTime,
2122 new base::StringValue( 2134 new base::StringValue(
2123 base::Int64ToString(install_time.ToInternalValue()))); 2135 base::Int64ToString(install_time.ToInternalValue())));
2136 extension_dict->Set(kPrefEphemeralApp,
2137 new base::FundamentalValue(is_ephemeral));
2124 if (blacklisted_for_malware) 2138 if (blacklisted_for_malware)
2125 extension_dict->Set(kPrefBlacklist, new base::FundamentalValue(true)); 2139 extension_dict->Set(kPrefBlacklist, new base::FundamentalValue(true));
2126 2140
2127 base::FilePath::StringType path = MakePathRelative(install_directory_, 2141 base::FilePath::StringType path = MakePathRelative(install_directory_,
2128 extension->path()); 2142 extension->path());
2129 extension_dict->Set(kPrefPath, new base::StringValue(path)); 2143 extension_dict->Set(kPrefPath, new base::StringValue(path));
2130 if (!install_parameter.empty()) { 2144 if (!install_parameter.empty()) {
2131 extension_dict->Set(kPrefInstallParam, 2145 extension_dict->Set(kPrefInstallParam,
2132 new base::StringValue(install_parameter)); 2146 new base::StringValue(install_parameter));
2133 } 2147 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
2233 extension_pref_value_map_->RegisterExtension( 2247 extension_pref_value_map_->RegisterExtension(
2234 extension_id, install_time, is_enabled, is_incognito_enabled); 2248 extension_id, install_time, is_enabled, is_incognito_enabled);
2235 2249
2236 FOR_EACH_OBSERVER( 2250 FOR_EACH_OBSERVER(
2237 ExtensionPrefsObserver, 2251 ExtensionPrefsObserver,
2238 observer_list_, 2252 observer_list_,
2239 OnExtensionRegistered(extension_id, install_time, is_enabled)); 2253 OnExtensionRegistered(extension_id, install_time, is_enabled));
2240 } 2254 }
2241 2255
2242 } // namespace extensions 2256 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698