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

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: Fix up file header 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
« no previous file with comments | « extensions/browser/extension_prefs.h ('k') | extensions/browser/extension_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 } 1228 }
1226 1229
1227 void ExtensionPrefs::SetKnownDisabled(const ExtensionIdSet& extension_ids) { 1230 void ExtensionPrefs::SetKnownDisabled(const ExtensionIdSet& extension_ids) {
1228 SetExtensionPrefFromContainer(pref_names::kKnownDisabled, extension_ids); 1231 SetExtensionPrefFromContainer(pref_names::kKnownDisabled, extension_ids);
1229 } 1232 }
1230 1233
1231 void ExtensionPrefs::OnExtensionInstalled( 1234 void ExtensionPrefs::OnExtensionInstalled(
1232 const Extension* extension, 1235 const Extension* extension,
1233 Extension::State initial_state, 1236 Extension::State initial_state,
1234 bool blacklisted_for_malware, 1237 bool blacklisted_for_malware,
1238 bool is_ephemeral,
1235 const syncer::StringOrdinal& page_ordinal, 1239 const syncer::StringOrdinal& page_ordinal,
1236 const std::string& install_parameter) { 1240 const std::string& install_parameter) {
1237 ScopedExtensionPrefUpdate update(prefs_, extension->id()); 1241 ScopedExtensionPrefUpdate update(prefs_, extension->id());
1238 base::DictionaryValue* extension_dict = update.Get(); 1242 base::DictionaryValue* extension_dict = update.Get();
1239 const base::Time install_time = time_provider_->GetCurrentTime(); 1243 const base::Time install_time = time_provider_->GetCurrentTime();
1240 PopulateExtensionInfoPrefs(extension, 1244 PopulateExtensionInfoPrefs(extension,
1241 install_time, 1245 install_time,
1242 initial_state, 1246 initial_state,
1243 blacklisted_for_malware, 1247 blacklisted_for_malware,
1248 is_ephemeral,
1244 install_parameter, 1249 install_parameter,
1245 extension_dict); 1250 extension_dict);
1246 FinishExtensionInfoPrefs(extension->id(), install_time, 1251 FinishExtensionInfoPrefs(extension->id(), install_time,
1247 extension->RequiresSortOrdinal(), 1252 extension->RequiresSortOrdinal(),
1248 page_ordinal, extension_dict); 1253 page_ordinal, extension_dict);
1249 } 1254 }
1250 1255
1251 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, 1256 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id,
1252 const Manifest::Location& location, 1257 const Manifest::Location& location,
1253 bool external_uninstall) { 1258 bool external_uninstall) {
1254 app_sorting_->ClearOrdinals(extension_id); 1259 app_sorting_->ClearOrdinals(extension_id);
1255 1260
1256 // For external extensions, we save a preference reminding ourself not to try 1261 // For external extensions, we save a preference reminding ourself not to try
1257 // and install the extension anymore (except when |external_uninstall| is 1262 // and install the extension anymore (except when |external_uninstall| is
1258 // true, which signifies that the registry key was deleted or the pref file 1263 // true, which signifies that the registry key was deleted or the pref file
1259 // no longer lists the extension). 1264 // no longer lists the extension).
1260 if (!external_uninstall && Manifest::IsExternalLocation(location)) { 1265 if (!external_uninstall && Manifest::IsExternalLocation(location)) {
1261 UpdateExtensionPref(extension_id, kPrefState, 1266 UpdateExtensionPref(extension_id, kPrefState,
1262 new base::FundamentalValue( 1267 new base::FundamentalValue(
1263 Extension::EXTERNAL_EXTENSION_UNINSTALLED)); 1268 Extension::EXTERNAL_EXTENSION_UNINSTALLED));
1264 extension_pref_value_map_->SetExtensionState(extension_id, false); 1269 extension_pref_value_map_->SetExtensionState(extension_id, false);
1265 FOR_EACH_OBSERVER(ExtensionPrefsObserver, 1270 FOR_EACH_OBSERVER(ExtensionPrefsObserver,
1266 observer_list_, 1271 observer_list_,
1267 OnExtensionStateChanged(extension_id, false)); 1272 OnExtensionStateChanged(extension_id, false));
1268 } else { 1273 } else {
1269 int creation_flags = GetCreationFlags(extension_id); 1274 if (IsEphemeralApp(extension_id)) {
1270 if (creation_flags & Extension::IS_EPHEMERAL) {
1271 // Keep ephemeral apps around, but mark them as evicted. 1275 // Keep ephemeral apps around, but mark them as evicted.
1272 UpdateExtensionPref(extension_id, kPrefEvictedEphemeralApp, 1276 UpdateExtensionPref(extension_id, kPrefEvictedEphemeralApp,
1273 new base::FundamentalValue(true)); 1277 new base::FundamentalValue(true));
1274 } else { 1278 } else {
1275 DeleteExtensionPrefs(extension_id); 1279 DeleteExtensionPrefs(extension_id);
1276 } 1280 }
1277 } 1281 }
1278 } 1282 }
1279 1283
1280 void ExtensionPrefs::SetExtensionState(const std::string& extension_id, 1284 void ExtensionPrefs::SetExtensionState(const std::string& extension_id,
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 extensions_info->push_back(linked_ptr<ExtensionInfo>(info.release())); 1460 extensions_info->push_back(linked_ptr<ExtensionInfo>(info.release()));
1457 } 1461 }
1458 1462
1459 return extensions_info.Pass(); 1463 return extensions_info.Pass();
1460 } 1464 }
1461 1465
1462 void ExtensionPrefs::SetDelayedInstallInfo( 1466 void ExtensionPrefs::SetDelayedInstallInfo(
1463 const Extension* extension, 1467 const Extension* extension,
1464 Extension::State initial_state, 1468 Extension::State initial_state,
1465 bool blacklisted_for_malware, 1469 bool blacklisted_for_malware,
1470 bool is_ephemeral,
1466 DelayReason delay_reason, 1471 DelayReason delay_reason,
1467 const syncer::StringOrdinal& page_ordinal, 1472 const syncer::StringOrdinal& page_ordinal,
1468 const std::string& install_parameter) { 1473 const std::string& install_parameter) {
1469 base::DictionaryValue* extension_dict = new base::DictionaryValue(); 1474 base::DictionaryValue* extension_dict = new base::DictionaryValue();
1470 PopulateExtensionInfoPrefs(extension, 1475 PopulateExtensionInfoPrefs(extension,
1471 time_provider_->GetCurrentTime(), 1476 time_provider_->GetCurrentTime(),
1472 initial_state, 1477 initial_state,
1473 blacklisted_for_malware, 1478 blacklisted_for_malware,
1479 is_ephemeral,
1474 install_parameter, 1480 install_parameter,
1475 extension_dict); 1481 extension_dict);
1476 1482
1477 // Add transient data that is needed by FinishDelayedInstallInfo(), but 1483 // Add transient data that is needed by FinishDelayedInstallInfo(), but
1478 // should not be in the final extension prefs. All entries here should have 1484 // should not be in the final extension prefs. All entries here should have
1479 // a corresponding Remove() call in FinishDelayedInstallInfo(). 1485 // a corresponding Remove() call in FinishDelayedInstallInfo().
1480 if (extension->RequiresSortOrdinal()) { 1486 if (extension->RequiresSortOrdinal()) {
1481 extension_dict->SetString( 1487 extension_dict->SetString(
1482 kPrefSuggestedPageOrdinal, 1488 kPrefSuggestedPageOrdinal,
1483 page_ordinal.IsValid() ? page_ordinal.ToInternalValue() 1489 page_ordinal.IsValid() ? page_ordinal.ToInternalValue()
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1622 return scoped_ptr<ExtensionInfo>(); 1628 return scoped_ptr<ExtensionInfo>();
1623 1629
1624 if (!IsEvictedEphemeralApp(extension_prefs)) 1630 if (!IsEvictedEphemeralApp(extension_prefs))
1625 return scoped_ptr<ExtensionInfo>(); 1631 return scoped_ptr<ExtensionInfo>();
1626 1632
1627 return GetInstalledInfoHelper(extension_id, extension_prefs); 1633 return GetInstalledInfoHelper(extension_id, extension_prefs);
1628 } 1634 }
1629 1635
1630 void ExtensionPrefs::RemoveEvictedEphemeralApp( 1636 void ExtensionPrefs::RemoveEvictedEphemeralApp(
1631 const std::string& extension_id) { 1637 const std::string& extension_id) {
1632 bool evicted_ephemeral_app = false; 1638 if (ReadPrefAsBooleanAndReturn(extension_id, kPrefEvictedEphemeralApp))
1633 if (ReadPrefAsBoolean(extension_id,
1634 kPrefEvictedEphemeralApp,
1635 &evicted_ephemeral_app) && evicted_ephemeral_app) {
1636 DeleteExtensionPrefs(extension_id); 1639 DeleteExtensionPrefs(extension_id);
1637 } 1640 }
1641
1642 bool ExtensionPrefs::IsEphemeralApp(const std::string& extension_id) const {
1643 if (ReadPrefAsBooleanAndReturn(extension_id, kPrefEphemeralApp))
1644 return true;
1645
1646 // Ephemerality was previously stored in the creation flags, so we must also
1647 // check it for backcompatibility.
1648 return (GetCreationFlags(extension_id) & Extension::IS_EPHEMERAL) != 0;
1638 } 1649 }
1639 1650
1640 bool ExtensionPrefs::WasAppDraggedByUser(const std::string& extension_id) { 1651 bool ExtensionPrefs::WasAppDraggedByUser(const std::string& extension_id) {
1641 return ReadPrefAsBooleanAndReturn(extension_id, kPrefUserDraggedApp); 1652 return ReadPrefAsBooleanAndReturn(extension_id, kPrefUserDraggedApp);
1642 } 1653 }
1643 1654
1644 void ExtensionPrefs::SetAppDraggedByUser(const std::string& extension_id) { 1655 void ExtensionPrefs::SetAppDraggedByUser(const std::string& extension_id) {
1645 UpdateExtensionPref(extension_id, kPrefUserDraggedApp, 1656 UpdateExtensionPref(extension_id, kPrefUserDraggedApp,
1646 new base::FundamentalValue(true)); 1657 new base::FundamentalValue(true));
1647 } 1658 }
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
2095 iter != strings.end(); ++iter) { 2106 iter != strings.end(); ++iter) {
2096 list_of_values->Append(new base::StringValue(*iter)); 2107 list_of_values->Append(new base::StringValue(*iter));
2097 } 2108 }
2098 } 2109 }
2099 2110
2100 void ExtensionPrefs::PopulateExtensionInfoPrefs( 2111 void ExtensionPrefs::PopulateExtensionInfoPrefs(
2101 const Extension* extension, 2112 const Extension* extension,
2102 const base::Time install_time, 2113 const base::Time install_time,
2103 Extension::State initial_state, 2114 Extension::State initial_state,
2104 bool blacklisted_for_malware, 2115 bool blacklisted_for_malware,
2116 bool is_ephemeral,
2105 const std::string& install_parameter, 2117 const std::string& install_parameter,
2106 base::DictionaryValue* extension_dict) { 2118 base::DictionaryValue* extension_dict) {
2107 // Leave the state blank for component extensions so that old chrome versions 2119 // Leave the state blank for component extensions so that old chrome versions
2108 // loading new profiles do not fail in GetInstalledExtensionInfo. Older 2120 // loading new profiles do not fail in GetInstalledExtensionInfo. Older
2109 // Chrome versions would only check for an omitted state. 2121 // Chrome versions would only check for an omitted state.
2110 if (initial_state != Extension::ENABLED_COMPONENT) 2122 if (initial_state != Extension::ENABLED_COMPONENT)
2111 extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state)); 2123 extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state));
2112 2124
2113 extension_dict->Set(kPrefLocation, 2125 extension_dict->Set(kPrefLocation,
2114 new base::FundamentalValue(extension->location())); 2126 new base::FundamentalValue(extension->location()));
2115 extension_dict->Set(kPrefCreationFlags, 2127 extension_dict->Set(kPrefCreationFlags,
2116 new base::FundamentalValue(extension->creation_flags())); 2128 new base::FundamentalValue(extension->creation_flags()));
2117 extension_dict->Set(kPrefFromWebStore, 2129 extension_dict->Set(kPrefFromWebStore,
2118 new base::FundamentalValue(extension->from_webstore())); 2130 new base::FundamentalValue(extension->from_webstore()));
2119 extension_dict->Set(kPrefFromBookmark, 2131 extension_dict->Set(kPrefFromBookmark,
2120 new base::FundamentalValue(extension->from_bookmark())); 2132 new base::FundamentalValue(extension->from_bookmark()));
2121 extension_dict->Set( 2133 extension_dict->Set(
2122 kPrefWasInstalledByDefault, 2134 kPrefWasInstalledByDefault,
2123 new base::FundamentalValue(extension->was_installed_by_default())); 2135 new base::FundamentalValue(extension->was_installed_by_default()));
2124 extension_dict->Set( 2136 extension_dict->Set(
2125 kPrefWasInstalledByOem, 2137 kPrefWasInstalledByOem,
2126 new base::FundamentalValue(extension->was_installed_by_oem())); 2138 new base::FundamentalValue(extension->was_installed_by_oem()));
2127 extension_dict->Set(kPrefInstallTime, 2139 extension_dict->Set(kPrefInstallTime,
2128 new base::StringValue( 2140 new base::StringValue(
2129 base::Int64ToString(install_time.ToInternalValue()))); 2141 base::Int64ToString(install_time.ToInternalValue())));
2130 if (blacklisted_for_malware) 2142 if (blacklisted_for_malware)
2131 extension_dict->Set(kPrefBlacklist, new base::FundamentalValue(true)); 2143 extension_dict->Set(kPrefBlacklist, new base::FundamentalValue(true));
2132 2144
2145 if (is_ephemeral)
2146 extension_dict->Set(kPrefEphemeralApp, new base::FundamentalValue(true));
2147 else
2148 extension_dict->Remove(kPrefEphemeralApp, NULL);
2149
2133 base::FilePath::StringType path = MakePathRelative(install_directory_, 2150 base::FilePath::StringType path = MakePathRelative(install_directory_,
2134 extension->path()); 2151 extension->path());
2135 extension_dict->Set(kPrefPath, new base::StringValue(path)); 2152 extension_dict->Set(kPrefPath, new base::StringValue(path));
2136 if (!install_parameter.empty()) { 2153 if (!install_parameter.empty()) {
2137 extension_dict->Set(kPrefInstallParam, 2154 extension_dict->Set(kPrefInstallParam,
2138 new base::StringValue(install_parameter)); 2155 new base::StringValue(install_parameter));
2139 } 2156 }
2140 // We store prefs about LOAD extensions, but don't cache their manifest 2157 // We store prefs about LOAD extensions, but don't cache their manifest
2141 // since it may change on disk. 2158 // since it may change on disk.
2142 if (!Manifest::IsUnpackedLocation(extension->location())) { 2159 if (!Manifest::IsUnpackedLocation(extension->location())) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
2239 extension_pref_value_map_->RegisterExtension( 2256 extension_pref_value_map_->RegisterExtension(
2240 extension_id, install_time, is_enabled, is_incognito_enabled); 2257 extension_id, install_time, is_enabled, is_incognito_enabled);
2241 2258
2242 FOR_EACH_OBSERVER( 2259 FOR_EACH_OBSERVER(
2243 ExtensionPrefsObserver, 2260 ExtensionPrefsObserver,
2244 observer_list_, 2261 observer_list_,
2245 OnExtensionRegistered(extension_id, install_time, is_enabled)); 2262 OnExtensionRegistered(extension_id, install_time, is_enabled));
2246 } 2263 }
2247 2264
2248 } // namespace extensions 2265 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/extension_prefs.h ('k') | extensions/browser/extension_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698