// synced. Default value is false.
const char kPrefDoNotSync[] = "do_not_sync";
+const char kCorruptedDisableCount[] = "extensions.corrupted_disable_count";
+
// Provider of write access to a dictionary storing extension prefs.
class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate {
public:
void ExtensionPrefs::SetWipeoutAcknowledged(
const std::string& extension_id,
bool value) {
- UpdateExtensionPref(extension_id, kPrefWipeoutAcknowledged,
- value ? base::Value::CreateBooleanValue(value) : NULL);
+ UpdateExtensionPref(extension_id,
+ kPrefWipeoutAcknowledged,
+ value ? new base::FundamentalValue(value) : NULL);
}
bool ExtensionPrefs::HasSettingsApiBubbleBeenAcknowledged(
bool value) {
UpdateExtensionPref(extension_id,
kPrefSettingsBubbleAcknowledged,
- value ? base::Value::CreateBooleanValue(value) : NULL);
+ value ? new base::FundamentalValue(value) : NULL);
}
bool ExtensionPrefs::HasNtpOverriddenBubbleBeenAcknowledged(
bool value) {
UpdateExtensionPref(extension_id,
kPrefNtpBubbleAcknowledged,
- value ? base::Value::CreateBooleanValue(value) : NULL);
+ value ? new base::FundamentalValue(value) : NULL);
}
bool ExtensionPrefs::HasProxyOverriddenBubbleBeenAcknowledged(
bool value) {
UpdateExtensionPref(extension_id,
kPrefProxyBubbleAcknowledged,
- value ? base::Value::CreateBooleanValue(value) : NULL);
+ value ? new base::FundamentalValue(value) : NULL);
}
bool ExtensionPrefs::SetAlertSystemFirstRun() {
// An extension's granted permissions need to be migrated if the
// full_access bit is present. This bit was always present in the previous
// scheme and is never present now.
- bool full_access;
+ bool full_access = false;
const base::DictionaryValue* ext = GetExtensionPref(*ext_id);
if (!ext || !ext->GetBoolean(kPrefOldGrantedFullAccess, &full_access))
continue;
SetExtensionPrefFromContainer(pref_names::kToolbar, extension_ids);
}
-bool ExtensionPrefs::GetKnownDisabled(ExtensionIdSet* id_set_out) {
- return GetUserExtensionPrefIntoContainer(pref_names::kKnownDisabled,
- id_set_out);
-}
-
-void ExtensionPrefs::SetKnownDisabled(const ExtensionIdSet& extension_ids) {
- SetExtensionPrefFromContainer(pref_names::kKnownDisabled, extension_ids);
-}
-
void ExtensionPrefs::OnExtensionInstalled(
const Extension* extension,
Extension::State initial_state,
install_flags,
install_parameter,
extension_dict);
- FinishExtensionInfoPrefs(extension->id(), install_time,
- extension->RequiresSortOrdinal(),
- page_ordinal, extension_dict);
+
+ bool requires_sort_ordinal = extension->RequiresSortOrdinal() &&
+ (install_flags & kInstallFlagIsEphemeral) == 0;
+ FinishExtensionInfoPrefs(extension->id(),
+ install_time,
+ requires_sort_ordinal,
+ page_ordinal,
+ extension_dict);
}
void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id,
if (IsExtensionBlacklisted(extension_id))
return BLACKLISTED_MALWARE;
const base::DictionaryValue* ext_prefs = GetExtensionPref(extension_id);
- int int_value;
+ int int_value = 0;
if (ext_prefs && ext_prefs->GetInteger(kPrefBlacklistState, &int_value))
return static_cast<BlacklistState>(int_value);
if (!extension->GetInteger(kPrefLocation, &location_value))
return scoped_ptr<ExtensionInfo>();
- base::FilePath::StringType path;
- if (!extension->GetString(kPrefPath, &path))
- return scoped_ptr<ExtensionInfo>();
-
- // Make path absolute. Unpacked extensions will already have absolute paths,
- // otherwise make it so.
Manifest::Location location = static_cast<Manifest::Location>(location_value);
-#if !defined(OS_CHROMEOS)
- if (!Manifest::IsUnpackedLocation(location)) {
- DCHECK(location == Manifest::COMPONENT ||
- !base::FilePath(path).IsAbsolute());
-#else
- // On Chrome OS some extensions can be installed to shared location and
- // thus use absolute paths in prefs.
- if (!base::FilePath(path).IsAbsolute()) {
-#endif // !defined(OS_CHROMEOS)
- path = install_directory_.Append(path).value();
+ if (location == Manifest::COMPONENT) {
+ // Component extensions are ignored. Component extensions may have data
+ // saved in preferences, but they are already loaded at this point (by
+ // ComponentLoader) and shouldn't be populated into the result of
+ // GetInstalledExtensionsInfo, otherwise InstalledLoader would also want to
+ // load them.
+ return scoped_ptr<ExtensionInfo>();
}
// Only the following extension types have data saved in the preferences.
// Just a warning for now.
}
+ base::FilePath::StringType path;
+ if (!extension->GetString(kPrefPath, &path))
+ return scoped_ptr<ExtensionInfo>();
+
+ // Make path absolute. Most (but not all) extension types have relative paths.
+ if (!base::FilePath(path).IsAbsolute())
+ path = install_directory_.Append(path).value();
+
return scoped_ptr<ExtensionInfo>(new ExtensionInfo(
manifest, extension_id, base::FilePath(path), location));
}
!extensions->GetDictionaryWithoutPathExpansion(extension_id, &ext))
return scoped_ptr<ExtensionInfo>();
int state_value;
- if (!ext->GetInteger(kPrefState, &state_value) ||
- state_value == Extension::ENABLED_COMPONENT) {
- // Old preferences files may not have kPrefState for component extensions.
- return scoped_ptr<ExtensionInfo>();
- }
-
- if (state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) {
+ if (ext->GetInteger(kPrefState, &state_value) &&
+ state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) {
LOG(WARNING) << "External extension with id " << extension_id
<< " has been uninstalled by the user";
return scoped_ptr<ExtensionInfo>();
// Add transient data that is needed by FinishDelayedInstallInfo(), but
// should not be in the final extension prefs. All entries here should have
// a corresponding Remove() call in FinishDelayedInstallInfo().
- if (extension->RequiresSortOrdinal()) {
+ if (extension->RequiresSortOrdinal() &&
+ (install_flags & kInstallFlagIsEphemeral) == 0) {
extension_dict->SetString(
kPrefSuggestedPageOrdinal,
page_ordinal.IsValid() ? page_ordinal.ToInternalValue()
new base::StringValue(
base::Int64ToString(install_time.ToInternalValue())));
+ // Some extension pref values are written conditionally. If they are not
+ // present in the delayed install data, they should be removed when the
+ // delayed install is committed.
+ extension_dict->Remove(kPrefEphemeralApp, NULL);
+
// Commit the delayed install data.
for (base::DictionaryValue::Iterator it(*pending_install_dict); !it.IsAtEnd();
it.Advance()) {
void ExtensionPrefs::OnEphemeralAppPromoted(const std::string& extension_id) {
DCHECK(IsEphemeralApp(extension_id));
- UpdateExtensionPref(
- extension_id, kPrefEphemeralApp, new base::FundamentalValue(false));
+ UpdateExtensionPref(extension_id, kPrefEphemeralApp, NULL);
+
+ // Ephemerality was previously stored in the creation flags, so ensure the bit
+ // is cleared.
+ int creation_flags = Extension::NO_FLAGS;
+ if (ReadPrefAsInteger(extension_id, kPrefCreationFlags, &creation_flags)) {
+ if (creation_flags & Extension::IS_EPHEMERAL) {
+ creation_flags &= ~static_cast<int>(Extension::IS_EPHEMERAL);
+ UpdateExtensionPref(extension_id,
+ kPrefCreationFlags,
+ new base::FundamentalValue(creation_flags));
+ }
+ }
}
bool ExtensionPrefs::WasAppDraggedByUser(const std::string& extension_id) {
new base::StringValue(install_parameter));
}
+int ExtensionPrefs::GetCorruptedDisableCount() {
+ return prefs_->GetInteger(kCorruptedDisableCount);
+}
+
+void ExtensionPrefs::IncrementCorruptedDisableCount() {
+ int count = prefs_->GetInteger(kCorruptedDisableCount);
+ prefs_->SetInteger(kCorruptedDisableCount, count + 1);
+}
+
ExtensionPrefs::ExtensionPrefs(
PrefService* prefs,
const base::FilePath& root_dir,
pref_names::kLastChromeVersion,
std::string(), // default value
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
- registry->RegisterListPref(pref_names::kKnownDisabled,
- user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
-#if defined(TOOLKIT_VIEWS)
- registry->RegisterIntegerPref(
- pref_names::kBrowserActionContainerWidth,
- 0,
- user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
-#endif
registry->RegisterDictionaryPref(
kInstallSignature,
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
pref_names::kNativeMessagingUserLevelHosts,
true, // default value
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
+ registry->RegisterIntegerPref(
+ kCorruptedDisableCount,
+ 0, // default value
+ user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
}
template <class ExtensionIdContainer>
int install_flags,
const std::string& install_parameter,
base::DictionaryValue* extension_dict) {
- // Leave the state blank for component extensions so that old chrome versions
- // loading new profiles do not fail in GetInstalledExtensionInfo. Older
- // Chrome versions would only check for an omitted state.
- if (initial_state != Extension::ENABLED_COMPONENT)
- extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state));
-
+ extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state));
extension_dict->Set(kPrefLocation,
new base::FundamentalValue(extension->location()));
extension_dict->Set(kPrefCreationFlags,
if (install_flags & kInstallFlagIsBlacklistedForMalware)
extension_dict->Set(kPrefBlacklist, new base::FundamentalValue(true));
- // TODO(tmdiep): Delete the pref if false, don't write false.
- bool is_ephemeral = (install_flags & kInstallFlagIsEphemeral) != 0;
- extension_dict->Set(kPrefEphemeralApp,
- new base::FundamentalValue(is_ephemeral));
+ if (install_flags & kInstallFlagIsEphemeral)
+ extension_dict->Set(kPrefEphemeralApp, new base::FundamentalValue(true));
+ else
+ extension_dict->Remove(kPrefEphemeralApp, NULL);
base::FilePath::StringType path = MakePathRelative(install_directory_,
extension->path());