| 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/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/prefs/pref_notifier.h" | 11 #include "base/prefs/pref_notifier.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 16 #include "base/value_conversions.h" | 16 #include "base/value_conversions.h" |
| 17 #include "components/crx_file/id_util.h" | 17 #include "components/crx_file/id_util.h" |
| 18 #include "components/pref_registry/pref_registry_syncable.h" | 18 #include "components/pref_registry/pref_registry_syncable.h" |
| 19 #include "extensions/browser/app_sorting.h" | 19 #include "extensions/browser/app_sorting.h" |
| 20 #include "extensions/browser/event_router.h" | 20 #include "extensions/browser/event_router.h" |
| 21 #include "extensions/browser/extension_pref_store.h" | 21 #include "extensions/browser/extension_pref_store.h" |
| 22 #include "extensions/browser/extension_prefs_factory.h" | 22 #include "extensions/browser/extension_prefs_factory.h" |
| 23 #include "extensions/browser/extension_prefs_observer.h" | 23 #include "extensions/browser/extension_prefs_observer.h" |
| 24 #include "extensions/browser/extension_system.h" |
| 24 #include "extensions/browser/install_flag.h" | 25 #include "extensions/browser/install_flag.h" |
| 25 #include "extensions/browser/pref_names.h" | 26 #include "extensions/browser/pref_names.h" |
| 26 #include "extensions/common/feature_switch.h" | 27 #include "extensions/common/feature_switch.h" |
| 27 #include "extensions/common/manifest.h" | 28 #include "extensions/common/manifest.h" |
| 28 #include "extensions/common/permissions/permission_set.h" | 29 #include "extensions/common/permissions/permission_set.h" |
| 29 #include "extensions/common/permissions/permissions_info.h" | 30 #include "extensions/common/permissions/permissions_info.h" |
| 30 #include "extensions/common/url_pattern.h" | 31 #include "extensions/common/url_pattern.h" |
| 31 #include "extensions/common/user_script.h" | 32 #include "extensions/common/user_script.h" |
| 32 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 33 | 34 |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 base::Value::TYPE_DICTIONARY>; | 332 base::Value::TYPE_DICTIONARY>; |
| 332 template class ExtensionPrefs::ScopedUpdate<base::ListValue, | 333 template class ExtensionPrefs::ScopedUpdate<base::ListValue, |
| 333 base::Value::TYPE_LIST>; | 334 base::Value::TYPE_LIST>; |
| 334 | 335 |
| 335 // | 336 // |
| 336 // ExtensionPrefs | 337 // ExtensionPrefs |
| 337 // | 338 // |
| 338 | 339 |
| 339 // static | 340 // static |
| 340 ExtensionPrefs* ExtensionPrefs::Create( | 341 ExtensionPrefs* ExtensionPrefs::Create( |
| 342 content::BrowserContext* browser_context, |
| 341 PrefService* prefs, | 343 PrefService* prefs, |
| 342 const base::FilePath& root_dir, | 344 const base::FilePath& root_dir, |
| 343 ExtensionPrefValueMap* extension_pref_value_map, | 345 ExtensionPrefValueMap* extension_pref_value_map, |
| 344 scoped_ptr<AppSorting> app_sorting, | |
| 345 bool extensions_disabled, | 346 bool extensions_disabled, |
| 346 const std::vector<ExtensionPrefsObserver*>& early_observers) { | 347 const std::vector<ExtensionPrefsObserver*>& early_observers) { |
| 347 return ExtensionPrefs::Create(prefs, | 348 return ExtensionPrefs::Create(browser_context, prefs, root_dir, |
| 348 root_dir, | 349 extension_pref_value_map, extensions_disabled, |
| 349 extension_pref_value_map, | |
| 350 app_sorting.Pass(), | |
| 351 extensions_disabled, | |
| 352 early_observers, | 350 early_observers, |
| 353 make_scoped_ptr(new TimeProvider())); | 351 make_scoped_ptr(new TimeProvider())); |
| 354 } | 352 } |
| 355 | 353 |
| 356 // static | 354 // static |
| 357 ExtensionPrefs* ExtensionPrefs::Create( | 355 ExtensionPrefs* ExtensionPrefs::Create( |
| 356 content::BrowserContext* browser_context, |
| 358 PrefService* pref_service, | 357 PrefService* pref_service, |
| 359 const base::FilePath& root_dir, | 358 const base::FilePath& root_dir, |
| 360 ExtensionPrefValueMap* extension_pref_value_map, | 359 ExtensionPrefValueMap* extension_pref_value_map, |
| 361 scoped_ptr<AppSorting> app_sorting, | |
| 362 bool extensions_disabled, | 360 bool extensions_disabled, |
| 363 const std::vector<ExtensionPrefsObserver*>& early_observers, | 361 const std::vector<ExtensionPrefsObserver*>& early_observers, |
| 364 scoped_ptr<TimeProvider> time_provider) { | 362 scoped_ptr<TimeProvider> time_provider) { |
| 365 return new ExtensionPrefs(pref_service, | 363 return new ExtensionPrefs(browser_context, pref_service, root_dir, |
| 366 root_dir, | 364 extension_pref_value_map, time_provider.Pass(), |
| 367 extension_pref_value_map, | 365 extensions_disabled, early_observers); |
| 368 app_sorting.Pass(), | |
| 369 time_provider.Pass(), | |
| 370 extensions_disabled, | |
| 371 early_observers); | |
| 372 } | 366 } |
| 373 | 367 |
| 374 ExtensionPrefs::~ExtensionPrefs() { | 368 ExtensionPrefs::~ExtensionPrefs() { |
| 375 } | 369 } |
| 376 | 370 |
| 377 // static | 371 // static |
| 378 ExtensionPrefs* ExtensionPrefs::Get(content::BrowserContext* context) { | 372 ExtensionPrefs* ExtensionPrefs::Get(content::BrowserContext* context) { |
| 379 return ExtensionPrefsFactory::GetInstance()->GetForBrowserContext(context); | 373 return ExtensionPrefsFactory::GetInstance()->GetForBrowserContext(context); |
| 380 } | 374 } |
| 381 | 375 |
| (...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 FinishExtensionInfoPrefs(extension->id(), | 1189 FinishExtensionInfoPrefs(extension->id(), |
| 1196 install_time, | 1190 install_time, |
| 1197 requires_sort_ordinal, | 1191 requires_sort_ordinal, |
| 1198 page_ordinal, | 1192 page_ordinal, |
| 1199 extension_dict); | 1193 extension_dict); |
| 1200 } | 1194 } |
| 1201 | 1195 |
| 1202 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, | 1196 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, |
| 1203 const Manifest::Location& location, | 1197 const Manifest::Location& location, |
| 1204 bool external_uninstall) { | 1198 bool external_uninstall) { |
| 1205 app_sorting_->ClearOrdinals(extension_id); | 1199 app_sorting()->ClearOrdinals(extension_id); |
| 1206 | 1200 |
| 1207 // For external extensions, we save a preference reminding ourself not to try | 1201 // For external extensions, we save a preference reminding ourself not to try |
| 1208 // and install the extension anymore (except when |external_uninstall| is | 1202 // and install the extension anymore (except when |external_uninstall| is |
| 1209 // true, which signifies that the registry key was deleted or the pref file | 1203 // true, which signifies that the registry key was deleted or the pref file |
| 1210 // no longer lists the extension). | 1204 // no longer lists the extension). |
| 1211 if (!external_uninstall && Manifest::IsExternalLocation(location)) { | 1205 if (!external_uninstall && Manifest::IsExternalLocation(location)) { |
| 1212 UpdateExtensionPref(extension_id, kPrefState, | 1206 UpdateExtensionPref(extension_id, kPrefState, |
| 1213 new base::FundamentalValue( | 1207 new base::FundamentalValue( |
| 1214 Extension::EXTERNAL_EXTENSION_UNINSTALLED)); | 1208 Extension::EXTERNAL_EXTENSION_UNINSTALLED)); |
| 1215 extension_pref_value_map_->SetExtensionState(extension_id, false); | 1209 extension_pref_value_map_->SetExtensionState(extension_id, false); |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1773 for (ExtensionIdList::iterator ext_id = extension_ids.begin(); | 1767 for (ExtensionIdList::iterator ext_id = extension_ids.begin(); |
| 1774 ext_id != extension_ids.end(); ++ext_id) { | 1768 ext_id != extension_ids.end(); ++ext_id) { |
| 1775 ScopedExtensionPrefUpdate update(prefs_, *ext_id); | 1769 ScopedExtensionPrefUpdate update(prefs_, *ext_id); |
| 1776 // This creates an empty dictionary if none is stored. | 1770 // This creates an empty dictionary if none is stored. |
| 1777 update.Get(); | 1771 update.Get(); |
| 1778 } | 1772 } |
| 1779 | 1773 |
| 1780 FixMissingPrefs(extension_ids); | 1774 FixMissingPrefs(extension_ids); |
| 1781 MigratePermissions(extension_ids); | 1775 MigratePermissions(extension_ids); |
| 1782 MigrateDisableReasons(extension_ids); | 1776 MigrateDisableReasons(extension_ids); |
| 1783 app_sorting_->Initialize(extension_ids); | |
| 1784 | 1777 |
| 1785 InitExtensionControlledPrefs(extension_pref_value_map_); | 1778 InitExtensionControlledPrefs(extension_pref_value_map_); |
| 1786 | 1779 |
| 1787 extension_pref_value_map_->NotifyInitializationCompleted(); | 1780 extension_pref_value_map_->NotifyInitializationCompleted(); |
| 1788 } | 1781 } |
| 1789 | 1782 |
| 1790 bool ExtensionPrefs::HasIncognitoPrefValue(const std::string& pref_key) const { | 1783 bool ExtensionPrefs::HasIncognitoPrefValue(const std::string& pref_key) const { |
| 1791 bool has_incognito_pref_value = false; | 1784 bool has_incognito_pref_value = false; |
| 1792 extension_pref_value_map_->GetEffectivePrefValue(pref_key, | 1785 extension_pref_value_map_->GetEffectivePrefValue(pref_key, |
| 1793 true, | 1786 true, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1860 return ReadPrefAsBooleanAndReturn(extension_id, kPrefNeedsSync); | 1853 return ReadPrefAsBooleanAndReturn(extension_id, kPrefNeedsSync); |
| 1861 } | 1854 } |
| 1862 | 1855 |
| 1863 void ExtensionPrefs::SetNeedsSync(const std::string& extension_id, | 1856 void ExtensionPrefs::SetNeedsSync(const std::string& extension_id, |
| 1864 bool needs_sync) { | 1857 bool needs_sync) { |
| 1865 UpdateExtensionPref(extension_id, kPrefNeedsSync, | 1858 UpdateExtensionPref(extension_id, kPrefNeedsSync, |
| 1866 needs_sync ? new base::FundamentalValue(true) : nullptr); | 1859 needs_sync ? new base::FundamentalValue(true) : nullptr); |
| 1867 } | 1860 } |
| 1868 | 1861 |
| 1869 ExtensionPrefs::ExtensionPrefs( | 1862 ExtensionPrefs::ExtensionPrefs( |
| 1863 content::BrowserContext* browser_context, |
| 1870 PrefService* prefs, | 1864 PrefService* prefs, |
| 1871 const base::FilePath& root_dir, | 1865 const base::FilePath& root_dir, |
| 1872 ExtensionPrefValueMap* extension_pref_value_map, | 1866 ExtensionPrefValueMap* extension_pref_value_map, |
| 1873 scoped_ptr<AppSorting> app_sorting, | |
| 1874 scoped_ptr<TimeProvider> time_provider, | 1867 scoped_ptr<TimeProvider> time_provider, |
| 1875 bool extensions_disabled, | 1868 bool extensions_disabled, |
| 1876 const std::vector<ExtensionPrefsObserver*>& early_observers) | 1869 const std::vector<ExtensionPrefsObserver*>& early_observers) |
| 1877 : prefs_(prefs), | 1870 : browser_context_(browser_context), |
| 1871 prefs_(prefs), |
| 1878 install_directory_(root_dir), | 1872 install_directory_(root_dir), |
| 1879 extension_pref_value_map_(extension_pref_value_map), | 1873 extension_pref_value_map_(extension_pref_value_map), |
| 1880 app_sorting_(app_sorting.Pass()), | |
| 1881 time_provider_(time_provider.Pass()), | 1874 time_provider_(time_provider.Pass()), |
| 1882 extensions_disabled_(extensions_disabled) { | 1875 extensions_disabled_(extensions_disabled) { |
| 1883 // TODO(mgiuca): Added these checks to try and diagnose | |
| 1884 // http://crbug.com/476648. Remove them after the investigation is concluded. | |
| 1885 CHECK(this); | |
| 1886 app_sorting_->SetExtensionScopedPrefs(this); | |
| 1887 app_sorting_->CheckExtensionScopedPrefs(); | |
| 1888 MakePathsRelative(); | 1876 MakePathsRelative(); |
| 1889 | 1877 |
| 1890 // Ensure that any early observers are watching before prefs are initialized. | 1878 // Ensure that any early observers are watching before prefs are initialized. |
| 1891 for (std::vector<ExtensionPrefsObserver*>::const_iterator iter = | 1879 for (std::vector<ExtensionPrefsObserver*>::const_iterator iter = |
| 1892 early_observers.begin(); | 1880 early_observers.begin(); |
| 1893 iter != early_observers.end(); | 1881 iter != early_observers.end(); |
| 1894 ++iter) { | 1882 ++iter) { |
| 1895 AddObserver(*iter); | 1883 AddObserver(*iter); |
| 1896 } | 1884 } |
| 1897 | 1885 |
| 1898 InitPrefStore(); | 1886 InitPrefStore(); |
| 1899 } | 1887 } |
| 1900 | 1888 |
| 1889 AppSorting* ExtensionPrefs::app_sorting() const { |
| 1890 return ExtensionSystem::Get(browser_context_)->app_sorting(); |
| 1891 } |
| 1892 |
| 1901 void ExtensionPrefs::SetNeedsStorageGarbageCollection(bool value) { | 1893 void ExtensionPrefs::SetNeedsStorageGarbageCollection(bool value) { |
| 1902 prefs_->SetBoolean(pref_names::kStorageGarbageCollect, value); | 1894 prefs_->SetBoolean(pref_names::kStorageGarbageCollect, value); |
| 1903 } | 1895 } |
| 1904 | 1896 |
| 1905 bool ExtensionPrefs::NeedsStorageGarbageCollection() const { | 1897 bool ExtensionPrefs::NeedsStorageGarbageCollection() const { |
| 1906 return prefs_->GetBoolean(pref_names::kStorageGarbageCollect); | 1898 return prefs_->GetBoolean(pref_names::kStorageGarbageCollect); |
| 1907 } | 1899 } |
| 1908 | 1900 |
| 1909 // static | 1901 // static |
| 1910 void ExtensionPrefs::RegisterProfilePrefs( | 1902 void ExtensionPrefs::RegisterProfilePrefs( |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2100 } | 2092 } |
| 2101 | 2093 |
| 2102 // If this point has been reached, any pending installs should be considered | 2094 // If this point has been reached, any pending installs should be considered |
| 2103 // out of date. | 2095 // out of date. |
| 2104 extension_dict->Remove(kDelayedInstallInfo, NULL); | 2096 extension_dict->Remove(kDelayedInstallInfo, NULL); |
| 2105 | 2097 |
| 2106 // Clear state that may be registered from a previous install. | 2098 // Clear state that may be registered from a previous install. |
| 2107 extension_dict->Remove(EventRouter::kRegisteredEvents, NULL); | 2099 extension_dict->Remove(EventRouter::kRegisteredEvents, NULL); |
| 2108 | 2100 |
| 2109 // FYI, all code below here races on sudden shutdown because |extension_dict|, | 2101 // FYI, all code below here races on sudden shutdown because |extension_dict|, |
| 2110 // |app_sorting_|, |extension_pref_value_map_|, and (potentially) observers | 2102 // |app_sorting|, |extension_pref_value_map_|, and (potentially) observers |
| 2111 // are updated non-transactionally. This is probably not fixable without | 2103 // are updated non-transactionally. This is probably not fixable without |
| 2112 // nested transactional updates to pref dictionaries. | 2104 // nested transactional updates to pref dictionaries. |
| 2113 if (needs_sort_ordinal) | 2105 if (needs_sort_ordinal) |
| 2114 app_sorting_->EnsureValidOrdinals(extension_id, suggested_page_ordinal); | 2106 app_sorting()->EnsureValidOrdinals(extension_id, suggested_page_ordinal); |
| 2115 | 2107 |
| 2116 bool is_enabled = false; | 2108 bool is_enabled = false; |
| 2117 int initial_state; | 2109 int initial_state; |
| 2118 if (extension_dict->GetInteger(kPrefState, &initial_state)) { | 2110 if (extension_dict->GetInteger(kPrefState, &initial_state)) { |
| 2119 is_enabled = initial_state == Extension::ENABLED; | 2111 is_enabled = initial_state == Extension::ENABLED; |
| 2120 } | 2112 } |
| 2121 bool is_incognito_enabled = IsIncognitoEnabled(extension_id); | 2113 bool is_incognito_enabled = IsIncognitoEnabled(extension_id); |
| 2122 | 2114 |
| 2123 extension_pref_value_map_->RegisterExtension( | 2115 extension_pref_value_map_->RegisterExtension( |
| 2124 extension_id, install_time, is_enabled, is_incognito_enabled); | 2116 extension_id, install_time, is_enabled, is_incognito_enabled); |
| 2125 | 2117 |
| 2126 FOR_EACH_OBSERVER( | 2118 FOR_EACH_OBSERVER( |
| 2127 ExtensionPrefsObserver, | 2119 ExtensionPrefsObserver, |
| 2128 observer_list_, | 2120 observer_list_, |
| 2129 OnExtensionRegistered(extension_id, install_time, is_enabled)); | 2121 OnExtensionRegistered(extension_id, install_time, is_enabled)); |
| 2130 } | 2122 } |
| 2131 | 2123 |
| 2132 } // namespace extensions | 2124 } // namespace extensions |
| OLD | NEW |