| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <iterator> | 10 #include <iterator> |
| (...skipping 1588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1599 } | 1599 } |
| 1600 | 1600 |
| 1601 void ExtensionPrefs::AddObserver(ExtensionPrefsObserver* observer) { | 1601 void ExtensionPrefs::AddObserver(ExtensionPrefsObserver* observer) { |
| 1602 observer_list_.AddObserver(observer); | 1602 observer_list_.AddObserver(observer); |
| 1603 } | 1603 } |
| 1604 | 1604 |
| 1605 void ExtensionPrefs::RemoveObserver(ExtensionPrefsObserver* observer) { | 1605 void ExtensionPrefs::RemoveObserver(ExtensionPrefsObserver* observer) { |
| 1606 observer_list_.RemoveObserver(observer); | 1606 observer_list_.RemoveObserver(observer); |
| 1607 } | 1607 } |
| 1608 | 1608 |
| 1609 void ExtensionPrefs::FixMissingPrefs(const ExtensionIdList& extension_ids) { | |
| 1610 // Fix old entries that did not get an installation time entry when they | |
| 1611 // were installed or don't have a preferences field. | |
| 1612 for (ExtensionIdList::const_iterator ext_id = extension_ids.begin(); | |
| 1613 ext_id != extension_ids.end(); ++ext_id) { | |
| 1614 if (GetInstallTime(*ext_id) == base::Time()) { | |
| 1615 VLOG(1) << "Could not parse installation time of extension " | |
| 1616 << *ext_id << ". It was probably installed before setting " | |
| 1617 << kPrefInstallTime << " was introduced. Updating " | |
| 1618 << kPrefInstallTime << " to the current time."; | |
| 1619 const base::Time install_time = time_provider_->GetCurrentTime(); | |
| 1620 UpdateExtensionPref(*ext_id, | |
| 1621 kPrefInstallTime, | |
| 1622 new base::StringValue(base::Int64ToString( | |
| 1623 install_time.ToInternalValue()))); | |
| 1624 } | |
| 1625 } | |
| 1626 } | |
| 1627 | |
| 1628 void ExtensionPrefs::InitPrefStore() { | 1609 void ExtensionPrefs::InitPrefStore() { |
| 1629 TRACE_EVENT0("browser,startup", "ExtensionPrefs::InitPrefStore") | 1610 TRACE_EVENT0("browser,startup", "ExtensionPrefs::InitPrefStore") |
| 1630 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.InitPrefStoreTime"); | 1611 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.InitPrefStoreTime"); |
| 1631 | 1612 |
| 1632 if (extensions_disabled_) { | 1613 if (extensions_disabled_) { |
| 1633 extension_pref_value_map_->NotifyInitializationCompleted(); | 1614 extension_pref_value_map_->NotifyInitializationCompleted(); |
| 1634 return; | 1615 return; |
| 1635 } | 1616 } |
| 1636 | 1617 |
| 1637 // When this is called, the PrefService is initialized and provides access | 1618 // When this is called, the PrefService is initialized and provides access |
| 1638 // to the user preferences stored in a JSON file. | 1619 // to the user preferences stored in a JSON file. |
| 1639 ExtensionIdList extension_ids; | 1620 ExtensionIdList extension_ids; |
| 1640 { | 1621 { |
| 1641 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.InitPrefGetExtensionsTime"); | 1622 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.InitPrefGetExtensionsTime"); |
| 1642 GetExtensions(&extension_ids); | 1623 GetExtensions(&extension_ids); |
| 1643 } | 1624 } |
| 1644 // Create empty preferences dictionary for each extension (these dictionaries | 1625 // Create empty preferences dictionary for each extension (these dictionaries |
| 1645 // are pruned when persisting the preferences to disk). | 1626 // are pruned when persisting the preferences to disk). |
| 1646 for (ExtensionIdList::iterator ext_id = extension_ids.begin(); | 1627 for (ExtensionIdList::iterator ext_id = extension_ids.begin(); |
| 1647 ext_id != extension_ids.end(); ++ext_id) { | 1628 ext_id != extension_ids.end(); ++ext_id) { |
| 1648 ScopedExtensionPrefUpdate update(prefs_, *ext_id); | 1629 ScopedExtensionPrefUpdate update(prefs_, *ext_id); |
| 1649 // This creates an empty dictionary if none is stored. | 1630 // This creates an empty dictionary if none is stored. |
| 1650 update.Get(); | 1631 update.Get(); |
| 1651 } | 1632 } |
| 1652 | 1633 |
| 1653 FixMissingPrefs(extension_ids); | |
| 1654 | |
| 1655 InitExtensionControlledPrefs(extension_pref_value_map_); | 1634 InitExtensionControlledPrefs(extension_pref_value_map_); |
| 1656 | 1635 |
| 1657 extension_pref_value_map_->NotifyInitializationCompleted(); | 1636 extension_pref_value_map_->NotifyInitializationCompleted(); |
| 1658 } | 1637 } |
| 1659 | 1638 |
| 1660 bool ExtensionPrefs::HasIncognitoPrefValue(const std::string& pref_key) const { | 1639 bool ExtensionPrefs::HasIncognitoPrefValue(const std::string& pref_key) const { |
| 1661 bool has_incognito_pref_value = false; | 1640 bool has_incognito_pref_value = false; |
| 1662 extension_pref_value_map_->GetEffectivePrefValue(pref_key, | 1641 extension_pref_value_map_->GetEffectivePrefValue(pref_key, |
| 1663 true, | 1642 true, |
| 1664 &has_incognito_pref_value); | 1643 &has_incognito_pref_value); |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1987 extension_pref_value_map_->RegisterExtension( | 1966 extension_pref_value_map_->RegisterExtension( |
| 1988 extension_id, install_time, is_enabled, is_incognito_enabled); | 1967 extension_id, install_time, is_enabled, is_incognito_enabled); |
| 1989 | 1968 |
| 1990 FOR_EACH_OBSERVER( | 1969 FOR_EACH_OBSERVER( |
| 1991 ExtensionPrefsObserver, | 1970 ExtensionPrefsObserver, |
| 1992 observer_list_, | 1971 observer_list_, |
| 1993 OnExtensionRegistered(extension_id, install_time, is_enabled)); | 1972 OnExtensionRegistered(extension_id, install_time, is_enabled)); |
| 1994 } | 1973 } |
| 1995 | 1974 |
| 1996 } // namespace extensions | 1975 } // namespace extensions |
| OLD | NEW |