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

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: review1 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
« no previous file with comments | « extensions/browser/extension_prefs.h ('k') | extensions/browser/extension_prefs_factory.cc » ('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/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 // A boolean preference that indicates whether the extension should not be 189 // A boolean preference that indicates whether the extension should not be
190 // synced. Default value is false. 190 // synced. Default value is false.
191 const char kPrefDoNotSync[] = "do_not_sync"; 191 const char kPrefDoNotSync[] = "do_not_sync";
192 192
193 const char kCorruptedDisableCount[] = "extensions.corrupted_disable_count"; 193 const char kCorruptedDisableCount[] = "extensions.corrupted_disable_count";
194 194
195 // A boolean preference that indicates whether the extension has local changes 195 // A boolean preference that indicates whether the extension has local changes
196 // that need to be synced. Default value is false. 196 // that need to be synced. Default value is false.
197 const char kPrefNeedsSync[] = "needs_sync"; 197 const char kPrefNeedsSync[] = "needs_sync";
198 198
199 ExtensionPrefs* g_instance_for_testing = nullptr;
200
199 // Provider of write access to a dictionary storing extension prefs. 201 // Provider of write access to a dictionary storing extension prefs.
200 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { 202 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate {
201 public: 203 public:
202 ScopedExtensionPrefUpdate(PrefService* service, 204 ScopedExtensionPrefUpdate(PrefService* service,
203 const std::string& extension_id) : 205 const std::string& extension_id) :
204 DictionaryPrefUpdate(service, pref_names::kExtensions), 206 DictionaryPrefUpdate(service, pref_names::kExtensions),
205 extension_id_(extension_id) {} 207 extension_id_(extension_id) {}
206 208
207 ~ScopedExtensionPrefUpdate() override {} 209 ~ScopedExtensionPrefUpdate() override {}
208 210
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 336
335 // 337 //
336 // ExtensionPrefs 338 // ExtensionPrefs
337 // 339 //
338 340
339 // static 341 // static
340 ExtensionPrefs* ExtensionPrefs::Create( 342 ExtensionPrefs* ExtensionPrefs::Create(
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(prefs,
348 root_dir, 349 root_dir,
349 extension_pref_value_map, 350 extension_pref_value_map,
350 app_sorting.Pass(),
351 extensions_disabled, 351 extensions_disabled,
352 early_observers, 352 early_observers,
353 make_scoped_ptr(new TimeProvider())); 353 make_scoped_ptr(new TimeProvider()));
354 } 354 }
355 355
356 // static 356 // static
357 ExtensionPrefs* ExtensionPrefs::Create( 357 ExtensionPrefs* ExtensionPrefs::Create(
358 PrefService* pref_service, 358 PrefService* pref_service,
359 const base::FilePath& root_dir, 359 const base::FilePath& root_dir,
360 ExtensionPrefValueMap* extension_pref_value_map, 360 ExtensionPrefValueMap* extension_pref_value_map,
361 scoped_ptr<AppSorting> app_sorting,
362 bool extensions_disabled, 361 bool extensions_disabled,
363 const std::vector<ExtensionPrefsObserver*>& early_observers, 362 const std::vector<ExtensionPrefsObserver*>& early_observers,
364 scoped_ptr<TimeProvider> time_provider) { 363 scoped_ptr<TimeProvider> time_provider) {
365 return new ExtensionPrefs(pref_service, 364 return new ExtensionPrefs(pref_service,
366 root_dir, 365 root_dir,
367 extension_pref_value_map, 366 extension_pref_value_map,
368 app_sorting.Pass(),
369 time_provider.Pass(), 367 time_provider.Pass(),
370 extensions_disabled, 368 extensions_disabled,
371 early_observers); 369 early_observers);
372 } 370 }
373 371
374 ExtensionPrefs::~ExtensionPrefs() { 372 ExtensionPrefs::~ExtensionPrefs() {
375 } 373 }
376 374
377 // static 375 // static
378 ExtensionPrefs* ExtensionPrefs::Get(content::BrowserContext* context) { 376 ExtensionPrefs* ExtensionPrefs::Get(content::BrowserContext* context) {
377 if (g_instance_for_testing)
378 return g_instance_for_testing;
Marc Treib 2015/07/30 14:04:12 This is super-hacky. We should really go through t
379 return ExtensionPrefsFactory::GetInstance()->GetForBrowserContext(context); 379 return ExtensionPrefsFactory::GetInstance()->GetForBrowserContext(context);
380 } 380 }
381 381
382 // static
383 void ExtensionPrefs::SetInstanceForTesting(ExtensionPrefs* prefs) {
384 g_instance_for_testing = prefs;
385 }
386
382 static base::FilePath::StringType MakePathRelative(const base::FilePath& parent, 387 static base::FilePath::StringType MakePathRelative(const base::FilePath& parent,
383 const base::FilePath& child) { 388 const base::FilePath& child) {
384 if (!parent.IsParent(child)) 389 if (!parent.IsParent(child))
385 return child.value(); 390 return child.value();
386 391
387 base::FilePath::StringType retval = child.value().substr( 392 base::FilePath::StringType retval = child.value().substr(
388 parent.value().length()); 393 parent.value().length());
389 if (base::FilePath::IsSeparator(retval[0])) 394 if (base::FilePath::IsSeparator(retval[0]))
390 return retval.substr(1); 395 return retval.substr(1);
391 else 396 else
(...skipping 1381 matching lines...) Expand 10 before | Expand all | Expand 10 after
1773 for (ExtensionIdList::iterator ext_id = extension_ids.begin(); 1778 for (ExtensionIdList::iterator ext_id = extension_ids.begin();
1774 ext_id != extension_ids.end(); ++ext_id) { 1779 ext_id != extension_ids.end(); ++ext_id) {
1775 ScopedExtensionPrefUpdate update(prefs_, *ext_id); 1780 ScopedExtensionPrefUpdate update(prefs_, *ext_id);
1776 // This creates an empty dictionary if none is stored. 1781 // This creates an empty dictionary if none is stored.
1777 update.Get(); 1782 update.Get();
1778 } 1783 }
1779 1784
1780 FixMissingPrefs(extension_ids); 1785 FixMissingPrefs(extension_ids);
1781 MigratePermissions(extension_ids); 1786 MigratePermissions(extension_ids);
1782 MigrateDisableReasons(extension_ids); 1787 MigrateDisableReasons(extension_ids);
1783 app_sorting_->Initialize(extension_ids);
1784 1788
1785 InitExtensionControlledPrefs(extension_pref_value_map_); 1789 InitExtensionControlledPrefs(extension_pref_value_map_);
1786 1790
1787 extension_pref_value_map_->NotifyInitializationCompleted(); 1791 extension_pref_value_map_->NotifyInitializationCompleted();
1788 } 1792 }
1789 1793
1790 bool ExtensionPrefs::HasIncognitoPrefValue(const std::string& pref_key) const { 1794 bool ExtensionPrefs::HasIncognitoPrefValue(const std::string& pref_key) const {
1791 bool has_incognito_pref_value = false; 1795 bool has_incognito_pref_value = false;
1792 extension_pref_value_map_->GetEffectivePrefValue(pref_key, 1796 extension_pref_value_map_->GetEffectivePrefValue(pref_key,
1793 true, 1797 true,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1863 void ExtensionPrefs::SetNeedsSync(const std::string& extension_id, 1867 void ExtensionPrefs::SetNeedsSync(const std::string& extension_id,
1864 bool needs_sync) { 1868 bool needs_sync) {
1865 UpdateExtensionPref(extension_id, kPrefNeedsSync, 1869 UpdateExtensionPref(extension_id, kPrefNeedsSync,
1866 needs_sync ? new base::FundamentalValue(true) : nullptr); 1870 needs_sync ? new base::FundamentalValue(true) : nullptr);
1867 } 1871 }
1868 1872
1869 ExtensionPrefs::ExtensionPrefs( 1873 ExtensionPrefs::ExtensionPrefs(
1870 PrefService* prefs, 1874 PrefService* prefs,
1871 const base::FilePath& root_dir, 1875 const base::FilePath& root_dir,
1872 ExtensionPrefValueMap* extension_pref_value_map, 1876 ExtensionPrefValueMap* extension_pref_value_map,
1873 scoped_ptr<AppSorting> app_sorting,
1874 scoped_ptr<TimeProvider> time_provider, 1877 scoped_ptr<TimeProvider> time_provider,
1875 bool extensions_disabled, 1878 bool extensions_disabled,
1876 const std::vector<ExtensionPrefsObserver*>& early_observers) 1879 const std::vector<ExtensionPrefsObserver*>& early_observers)
1877 : prefs_(prefs), 1880 : prefs_(prefs),
1878 install_directory_(root_dir), 1881 install_directory_(root_dir),
1879 extension_pref_value_map_(extension_pref_value_map), 1882 extension_pref_value_map_(extension_pref_value_map),
1880 app_sorting_(app_sorting.Pass()), 1883 app_sorting_(nullptr),
1881 time_provider_(time_provider.Pass()), 1884 time_provider_(time_provider.Pass()),
1882 extensions_disabled_(extensions_disabled) { 1885 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(); 1886 MakePathsRelative();
1889 1887
1890 // Ensure that any early observers are watching before prefs are initialized. 1888 // Ensure that any early observers are watching before prefs are initialized.
1891 for (std::vector<ExtensionPrefsObserver*>::const_iterator iter = 1889 for (std::vector<ExtensionPrefsObserver*>::const_iterator iter =
1892 early_observers.begin(); 1890 early_observers.begin();
1893 iter != early_observers.end(); 1891 iter != early_observers.end();
1894 ++iter) { 1892 ++iter) {
1895 AddObserver(*iter); 1893 AddObserver(*iter);
1896 } 1894 }
1897 1895
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
2123 extension_pref_value_map_->RegisterExtension( 2121 extension_pref_value_map_->RegisterExtension(
2124 extension_id, install_time, is_enabled, is_incognito_enabled); 2122 extension_id, install_time, is_enabled, is_incognito_enabled);
2125 2123
2126 FOR_EACH_OBSERVER( 2124 FOR_EACH_OBSERVER(
2127 ExtensionPrefsObserver, 2125 ExtensionPrefsObserver,
2128 observer_list_, 2126 observer_list_,
2129 OnExtensionRegistered(extension_id, install_time, is_enabled)); 2127 OnExtensionRegistered(extension_id, install_time, is_enabled));
2130 } 2128 }
2131 2129
2132 } // namespace extensions 2130 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/extension_prefs.h ('k') | extensions/browser/extension_prefs_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698