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

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

Issue 1254363004: Move ownership of AppSorting from ExtensionPrefs to ExtensionSystem (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix extensions_unittests Created 5 years, 4 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/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
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
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 if (app_sorting())
not at google - send to devlin 2015/08/03 21:12:08 Add "// null in tests" after this?
Marc Treib 2015/08/04 08:36:29 Not necessary anymore :)
1200 app_sorting()->ClearOrdinals(extension_id);
1206 1201
1207 // For external extensions, we save a preference reminding ourself not to try 1202 // For external extensions, we save a preference reminding ourself not to try
1208 // and install the extension anymore (except when |external_uninstall| is 1203 // and install the extension anymore (except when |external_uninstall| is
1209 // true, which signifies that the registry key was deleted or the pref file 1204 // true, which signifies that the registry key was deleted or the pref file
1210 // no longer lists the extension). 1205 // no longer lists the extension).
1211 if (!external_uninstall && Manifest::IsExternalLocation(location)) { 1206 if (!external_uninstall && Manifest::IsExternalLocation(location)) {
1212 UpdateExtensionPref(extension_id, kPrefState, 1207 UpdateExtensionPref(extension_id, kPrefState,
1213 new base::FundamentalValue( 1208 new base::FundamentalValue(
1214 Extension::EXTERNAL_EXTENSION_UNINSTALLED)); 1209 Extension::EXTERNAL_EXTENSION_UNINSTALLED));
1215 extension_pref_value_map_->SetExtensionState(extension_id, false); 1210 extension_pref_value_map_->SetExtensionState(extension_id, false);
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
1773 for (ExtensionIdList::iterator ext_id = extension_ids.begin(); 1768 for (ExtensionIdList::iterator ext_id = extension_ids.begin();
1774 ext_id != extension_ids.end(); ++ext_id) { 1769 ext_id != extension_ids.end(); ++ext_id) {
1775 ScopedExtensionPrefUpdate update(prefs_, *ext_id); 1770 ScopedExtensionPrefUpdate update(prefs_, *ext_id);
1776 // This creates an empty dictionary if none is stored. 1771 // This creates an empty dictionary if none is stored.
1777 update.Get(); 1772 update.Get();
1778 } 1773 }
1779 1774
1780 FixMissingPrefs(extension_ids); 1775 FixMissingPrefs(extension_ids);
1781 MigratePermissions(extension_ids); 1776 MigratePermissions(extension_ids);
1782 MigrateDisableReasons(extension_ids); 1777 MigrateDisableReasons(extension_ids);
1783 app_sorting_->Initialize(extension_ids);
1784 1778
1785 InitExtensionControlledPrefs(extension_pref_value_map_); 1779 InitExtensionControlledPrefs(extension_pref_value_map_);
1786 1780
1787 extension_pref_value_map_->NotifyInitializationCompleted(); 1781 extension_pref_value_map_->NotifyInitializationCompleted();
1788 } 1782 }
1789 1783
1790 bool ExtensionPrefs::HasIncognitoPrefValue(const std::string& pref_key) const { 1784 bool ExtensionPrefs::HasIncognitoPrefValue(const std::string& pref_key) const {
1791 bool has_incognito_pref_value = false; 1785 bool has_incognito_pref_value = false;
1792 extension_pref_value_map_->GetEffectivePrefValue(pref_key, 1786 extension_pref_value_map_->GetEffectivePrefValue(pref_key,
1793 true, 1787 true,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 return ReadPrefAsBooleanAndReturn(extension_id, kPrefNeedsSync); 1854 return ReadPrefAsBooleanAndReturn(extension_id, kPrefNeedsSync);
1861 } 1855 }
1862 1856
1863 void ExtensionPrefs::SetNeedsSync(const std::string& extension_id, 1857 void ExtensionPrefs::SetNeedsSync(const std::string& extension_id,
1864 bool needs_sync) { 1858 bool needs_sync) {
1865 UpdateExtensionPref(extension_id, kPrefNeedsSync, 1859 UpdateExtensionPref(extension_id, kPrefNeedsSync,
1866 needs_sync ? new base::FundamentalValue(true) : nullptr); 1860 needs_sync ? new base::FundamentalValue(true) : nullptr);
1867 } 1861 }
1868 1862
1869 ExtensionPrefs::ExtensionPrefs( 1863 ExtensionPrefs::ExtensionPrefs(
1864 content::BrowserContext* browser_context,
1870 PrefService* prefs, 1865 PrefService* prefs,
1871 const base::FilePath& root_dir, 1866 const base::FilePath& root_dir,
1872 ExtensionPrefValueMap* extension_pref_value_map, 1867 ExtensionPrefValueMap* extension_pref_value_map,
1873 scoped_ptr<AppSorting> app_sorting,
1874 scoped_ptr<TimeProvider> time_provider, 1868 scoped_ptr<TimeProvider> time_provider,
1875 bool extensions_disabled, 1869 bool extensions_disabled,
1876 const std::vector<ExtensionPrefsObserver*>& early_observers) 1870 const std::vector<ExtensionPrefsObserver*>& early_observers)
1877 : prefs_(prefs), 1871 : browser_context_(browser_context),
1872 prefs_(prefs),
1878 install_directory_(root_dir), 1873 install_directory_(root_dir),
1879 extension_pref_value_map_(extension_pref_value_map), 1874 extension_pref_value_map_(extension_pref_value_map),
1880 app_sorting_(app_sorting.Pass()),
1881 time_provider_(time_provider.Pass()), 1875 time_provider_(time_provider.Pass()),
1882 extensions_disabled_(extensions_disabled) { 1876 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(); 1877 MakePathsRelative();
1889 1878
1890 // Ensure that any early observers are watching before prefs are initialized. 1879 // Ensure that any early observers are watching before prefs are initialized.
1891 for (std::vector<ExtensionPrefsObserver*>::const_iterator iter = 1880 for (std::vector<ExtensionPrefsObserver*>::const_iterator iter =
1892 early_observers.begin(); 1881 early_observers.begin();
1893 iter != early_observers.end(); 1882 iter != early_observers.end();
1894 ++iter) { 1883 ++iter) {
1895 AddObserver(*iter); 1884 AddObserver(*iter);
1896 } 1885 }
1897 1886
1898 InitPrefStore(); 1887 InitPrefStore();
1899 } 1888 }
1900 1889
1890 AppSorting* ExtensionPrefs::app_sorting() const {
1891 // Can be null in some unit tests.
1892 if (!browser_context_)
1893 return nullptr;
1894 return ExtensionSystem::Get(browser_context_)->app_sorting();
1895 }
1896
1901 void ExtensionPrefs::SetNeedsStorageGarbageCollection(bool value) { 1897 void ExtensionPrefs::SetNeedsStorageGarbageCollection(bool value) {
1902 prefs_->SetBoolean(pref_names::kStorageGarbageCollect, value); 1898 prefs_->SetBoolean(pref_names::kStorageGarbageCollect, value);
1903 } 1899 }
1904 1900
1905 bool ExtensionPrefs::NeedsStorageGarbageCollection() const { 1901 bool ExtensionPrefs::NeedsStorageGarbageCollection() const {
1906 return prefs_->GetBoolean(pref_names::kStorageGarbageCollect); 1902 return prefs_->GetBoolean(pref_names::kStorageGarbageCollect);
1907 } 1903 }
1908 1904
1909 // static 1905 // static
1910 void ExtensionPrefs::RegisterProfilePrefs( 1906 void ExtensionPrefs::RegisterProfilePrefs(
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
2100 } 2096 }
2101 2097
2102 // If this point has been reached, any pending installs should be considered 2098 // If this point has been reached, any pending installs should be considered
2103 // out of date. 2099 // out of date.
2104 extension_dict->Remove(kDelayedInstallInfo, NULL); 2100 extension_dict->Remove(kDelayedInstallInfo, NULL);
2105 2101
2106 // Clear state that may be registered from a previous install. 2102 // Clear state that may be registered from a previous install.
2107 extension_dict->Remove(EventRouter::kRegisteredEvents, NULL); 2103 extension_dict->Remove(EventRouter::kRegisteredEvents, NULL);
2108 2104
2109 // FYI, all code below here races on sudden shutdown because |extension_dict|, 2105 // FYI, all code below here races on sudden shutdown because |extension_dict|,
2110 // |app_sorting_|, |extension_pref_value_map_|, and (potentially) observers 2106 // |app_sorting|, |extension_pref_value_map_|, and (potentially) observers
2111 // are updated non-transactionally. This is probably not fixable without 2107 // are updated non-transactionally. This is probably not fixable without
2112 // nested transactional updates to pref dictionaries. 2108 // nested transactional updates to pref dictionaries.
2113 if (needs_sort_ordinal) 2109 if (needs_sort_ordinal && app_sorting())
not at google - send to devlin 2015/08/03 21:12:08 another case of null-in-tests?
Marc Treib 2015/08/04 08:36:29 Also not necessary anymore.
2114 app_sorting_->EnsureValidOrdinals(extension_id, suggested_page_ordinal); 2110 app_sorting()->EnsureValidOrdinals(extension_id, suggested_page_ordinal);
2115 2111
2116 bool is_enabled = false; 2112 bool is_enabled = false;
2117 int initial_state; 2113 int initial_state;
2118 if (extension_dict->GetInteger(kPrefState, &initial_state)) { 2114 if (extension_dict->GetInteger(kPrefState, &initial_state)) {
2119 is_enabled = initial_state == Extension::ENABLED; 2115 is_enabled = initial_state == Extension::ENABLED;
2120 } 2116 }
2121 bool is_incognito_enabled = IsIncognitoEnabled(extension_id); 2117 bool is_incognito_enabled = IsIncognitoEnabled(extension_id);
2122 2118
2123 extension_pref_value_map_->RegisterExtension( 2119 extension_pref_value_map_->RegisterExtension(
2124 extension_id, install_time, is_enabled, is_incognito_enabled); 2120 extension_id, install_time, is_enabled, is_incognito_enabled);
2125 2121
2126 FOR_EACH_OBSERVER( 2122 FOR_EACH_OBSERVER(
2127 ExtensionPrefsObserver, 2123 ExtensionPrefsObserver,
2128 observer_list_, 2124 observer_list_,
2129 OnExtensionRegistered(extension_id, install_time, is_enabled)); 2125 OnExtensionRegistered(extension_id, install_time, is_enabled));
2130 } 2126 }
2131 2127
2132 } // namespace extensions 2128 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698