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/prefs/pref_notifier.h" | 10 #include "base/prefs/pref_notifier.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/value_conversions.h" | 14 #include "base/value_conversions.h" |
15 #include "chrome/browser/extensions/api/content_settings/content_settings_store.
h" | |
16 #include "components/user_prefs/pref_registry_syncable.h" | 15 #include "components/user_prefs/pref_registry_syncable.h" |
17 #include "extensions/browser/admin_policy.h" | 16 #include "extensions/browser/admin_policy.h" |
18 #include "extensions/browser/app_sorting.h" | 17 #include "extensions/browser/app_sorting.h" |
19 #include "extensions/browser/event_router.h" | 18 #include "extensions/browser/event_router.h" |
20 #include "extensions/browser/extension_pref_store.h" | 19 #include "extensions/browser/extension_pref_store.h" |
21 #include "extensions/browser/extension_prefs_factory.h" | 20 #include "extensions/browser/extension_prefs_factory.h" |
| 21 #include "extensions/browser/extension_prefs_observer.h" |
22 #include "extensions/browser/pref_names.h" | 22 #include "extensions/browser/pref_names.h" |
23 #include "extensions/common/feature_switch.h" | 23 #include "extensions/common/feature_switch.h" |
24 #include "extensions/common/manifest.h" | 24 #include "extensions/common/manifest.h" |
25 #include "extensions/common/permissions/permission_set.h" | 25 #include "extensions/common/permissions/permission_set.h" |
26 #include "extensions/common/permissions/permissions_info.h" | 26 #include "extensions/common/permissions/permissions_info.h" |
27 #include "extensions/common/url_pattern.h" | 27 #include "extensions/common/url_pattern.h" |
28 #include "extensions/common/user_script.h" | 28 #include "extensions/common/user_script.h" |
29 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
30 | 30 |
31 using base::Value; | 31 using base::Value; |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 if (!source_dict->GetDictionary(key, &preferences)) | 251 if (!source_dict->GetDictionary(key, &preferences)) |
252 return; | 252 return; |
253 | 253 |
254 for (base::DictionaryValue::Iterator iter(*preferences); !iter.IsAtEnd(); | 254 for (base::DictionaryValue::Iterator iter(*preferences); !iter.IsAtEnd(); |
255 iter.Advance()) { | 255 iter.Advance()) { |
256 value_map->SetExtensionPref( | 256 value_map->SetExtensionPref( |
257 extension_id, iter.key(), scope, iter.value().DeepCopy()); | 257 extension_id, iter.key(), scope, iter.value().DeepCopy()); |
258 } | 258 } |
259 } | 259 } |
260 | 260 |
261 void InitExtensionControlledPrefs(ExtensionPrefs* prefs, | |
262 ExtensionPrefValueMap* value_map) { | |
263 ExtensionIdList extension_ids; | |
264 prefs->GetExtensions(&extension_ids); | |
265 | |
266 for (ExtensionIdList::iterator extension_id = extension_ids.begin(); | |
267 extension_id != extension_ids.end(); | |
268 ++extension_id) { | |
269 base::Time install_time = prefs->GetInstallTime(*extension_id); | |
270 bool is_enabled = !prefs->IsExtensionDisabled(*extension_id); | |
271 bool is_incognito_enabled = prefs->IsIncognitoEnabled(*extension_id); | |
272 value_map->RegisterExtension( | |
273 *extension_id, install_time, is_enabled, is_incognito_enabled); | |
274 prefs->content_settings_store()->RegisterExtension( | |
275 *extension_id, install_time, is_enabled); | |
276 | |
277 // Set regular extension controlled prefs. | |
278 LoadExtensionControlledPrefs( | |
279 prefs, value_map, *extension_id, kExtensionPrefsScopeRegular); | |
280 // Set incognito extension controlled prefs. | |
281 LoadExtensionControlledPrefs(prefs, | |
282 value_map, | |
283 *extension_id, | |
284 kExtensionPrefsScopeIncognitoPersistent); | |
285 // Set regular-only extension controlled prefs. | |
286 LoadExtensionControlledPrefs( | |
287 prefs, value_map, *extension_id, kExtensionPrefsScopeRegularOnly); | |
288 | |
289 // Set content settings. | |
290 const base::ListValue* content_settings = NULL; | |
291 if (prefs->ReadPrefAsList(*extension_id, | |
292 pref_names::kPrefContentSettings, | |
293 &content_settings)) { | |
294 prefs->content_settings_store()->SetExtensionContentSettingFromList( | |
295 *extension_id, content_settings, kExtensionPrefsScopeRegular); | |
296 } | |
297 if (prefs->ReadPrefAsList(*extension_id, | |
298 pref_names::kPrefIncognitoContentSettings, | |
299 &content_settings)) { | |
300 prefs->content_settings_store()->SetExtensionContentSettingFromList( | |
301 *extension_id, | |
302 content_settings, | |
303 kExtensionPrefsScopeIncognitoPersistent); | |
304 } | |
305 } | |
306 } | |
307 | |
308 } // namespace | 261 } // namespace |
309 | 262 |
310 // | 263 // |
311 // TimeProvider | 264 // TimeProvider |
312 // | 265 // |
313 | 266 |
314 ExtensionPrefs::TimeProvider::TimeProvider() { | 267 ExtensionPrefs::TimeProvider::TimeProvider() { |
315 } | 268 } |
316 | 269 |
317 ExtensionPrefs::TimeProvider::~TimeProvider() { | 270 ExtensionPrefs::TimeProvider::~TimeProvider() { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 // | 335 // |
383 // ExtensionPrefs | 336 // ExtensionPrefs |
384 // | 337 // |
385 | 338 |
386 // static | 339 // static |
387 ExtensionPrefs* ExtensionPrefs::Create( | 340 ExtensionPrefs* ExtensionPrefs::Create( |
388 PrefService* prefs, | 341 PrefService* prefs, |
389 const base::FilePath& root_dir, | 342 const base::FilePath& root_dir, |
390 ExtensionPrefValueMap* extension_pref_value_map, | 343 ExtensionPrefValueMap* extension_pref_value_map, |
391 scoped_ptr<AppSorting> app_sorting, | 344 scoped_ptr<AppSorting> app_sorting, |
392 bool extensions_disabled) { | 345 bool extensions_disabled, |
| 346 const std::vector<ExtensionPrefsObserver*>& early_observers) { |
393 return ExtensionPrefs::Create(prefs, | 347 return ExtensionPrefs::Create(prefs, |
394 root_dir, | 348 root_dir, |
395 extension_pref_value_map, | 349 extension_pref_value_map, |
396 app_sorting.Pass(), | 350 app_sorting.Pass(), |
397 extensions_disabled, | 351 extensions_disabled, |
| 352 early_observers, |
398 make_scoped_ptr(new TimeProvider())); | 353 make_scoped_ptr(new TimeProvider())); |
399 } | 354 } |
400 | 355 |
401 // static | 356 // static |
402 ExtensionPrefs* ExtensionPrefs::Create( | 357 ExtensionPrefs* ExtensionPrefs::Create( |
403 PrefService* pref_service, | 358 PrefService* pref_service, |
404 const base::FilePath& root_dir, | 359 const base::FilePath& root_dir, |
405 ExtensionPrefValueMap* extension_pref_value_map, | 360 ExtensionPrefValueMap* extension_pref_value_map, |
406 scoped_ptr<AppSorting> app_sorting, | 361 scoped_ptr<AppSorting> app_sorting, |
407 bool extensions_disabled, | 362 bool extensions_disabled, |
| 363 const std::vector<ExtensionPrefsObserver*>& early_observers, |
408 scoped_ptr<TimeProvider> time_provider) { | 364 scoped_ptr<TimeProvider> time_provider) { |
409 return new ExtensionPrefs(pref_service, | 365 return new ExtensionPrefs(pref_service, |
410 root_dir, | 366 root_dir, |
411 extension_pref_value_map, | 367 extension_pref_value_map, |
412 app_sorting.Pass(), | 368 app_sorting.Pass(), |
413 time_provider.Pass(), | 369 time_provider.Pass(), |
414 extensions_disabled); | 370 extensions_disabled, |
| 371 early_observers); |
415 } | 372 } |
416 | 373 |
417 ExtensionPrefs::~ExtensionPrefs() { | 374 ExtensionPrefs::~ExtensionPrefs() { |
418 } | 375 } |
419 | 376 |
420 // static | 377 // static |
421 ExtensionPrefs* ExtensionPrefs::Get(content::BrowserContext* context) { | 378 ExtensionPrefs* ExtensionPrefs::Get(content::BrowserContext* context) { |
422 return ExtensionPrefsFactory::GetInstance()->GetForBrowserContext(context); | 379 return ExtensionPrefsFactory::GetInstance()->GetForBrowserContext(context); |
423 } | 380 } |
424 | 381 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 } | 460 } |
504 ScopedExtensionPrefUpdate update(prefs_, extension_id); | 461 ScopedExtensionPrefUpdate update(prefs_, extension_id); |
505 if (data_value) | 462 if (data_value) |
506 update->Set(key, data_value); | 463 update->Set(key, data_value); |
507 else | 464 else |
508 update->Remove(key, NULL); | 465 update->Remove(key, NULL); |
509 } | 466 } |
510 | 467 |
511 void ExtensionPrefs::DeleteExtensionPrefs(const std::string& extension_id) { | 468 void ExtensionPrefs::DeleteExtensionPrefs(const std::string& extension_id) { |
512 extension_pref_value_map_->UnregisterExtension(extension_id); | 469 extension_pref_value_map_->UnregisterExtension(extension_id); |
513 content_settings_store_->UnregisterExtension(extension_id); | 470 FOR_EACH_OBSERVER(ExtensionPrefsObserver, |
| 471 observer_list_, |
| 472 OnExtensionPrefsDeleted(extension_id)); |
514 DictionaryPrefUpdate update(prefs_, pref_names::kExtensions); | 473 DictionaryPrefUpdate update(prefs_, pref_names::kExtensions); |
515 base::DictionaryValue* dict = update.Get(); | 474 base::DictionaryValue* dict = update.Get(); |
516 dict->Remove(extension_id, NULL); | 475 dict->Remove(extension_id, NULL); |
517 } | 476 } |
518 | 477 |
519 bool ExtensionPrefs::ReadPrefAsBoolean(const std::string& extension_id, | 478 bool ExtensionPrefs::ReadPrefAsBoolean(const std::string& extension_id, |
520 const std::string& pref_key, | 479 const std::string& pref_key, |
521 bool* out_value) const { | 480 bool* out_value) const { |
522 const base::DictionaryValue* ext = GetExtensionPref(extension_id); | 481 const base::DictionaryValue* ext = GetExtensionPref(extension_id); |
523 if (!ext || !ext->GetBoolean(pref_key, out_value)) | 482 if (!ext || !ext->GetBoolean(pref_key, out_value)) |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
850 return; | 809 return; |
851 | 810 |
852 if (new_value == Extension::DISABLE_NONE) { | 811 if (new_value == Extension::DISABLE_NONE) { |
853 UpdateExtensionPref(extension_id, kPrefDisableReasons, NULL); | 812 UpdateExtensionPref(extension_id, kPrefDisableReasons, NULL); |
854 } else { | 813 } else { |
855 UpdateExtensionPref(extension_id, | 814 UpdateExtensionPref(extension_id, |
856 kPrefDisableReasons, | 815 kPrefDisableReasons, |
857 new base::FundamentalValue(new_value)); | 816 new base::FundamentalValue(new_value)); |
858 } | 817 } |
859 | 818 |
860 FOR_EACH_OBSERVER(Observer, | 819 FOR_EACH_OBSERVER(ExtensionPrefsObserver, |
861 observer_list_, | 820 observer_list_, |
862 OnExtensionDisableReasonsChanged(extension_id, new_value)); | 821 OnExtensionDisableReasonsChanged(extension_id, new_value)); |
863 } | 822 } |
864 | 823 |
865 std::set<std::string> ExtensionPrefs::GetBlacklistedExtensions() { | 824 std::set<std::string> ExtensionPrefs::GetBlacklistedExtensions() { |
866 std::set<std::string> ids; | 825 std::set<std::string> ids; |
867 | 826 |
868 const base::DictionaryValue* extensions = | 827 const base::DictionaryValue* extensions = |
869 prefs_->GetDictionary(pref_names::kExtensions); | 828 prefs_->GetDictionary(pref_names::kExtensions); |
870 if (!extensions) | 829 if (!extensions) |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1250 | 1209 |
1251 // For external extensions, we save a preference reminding ourself not to try | 1210 // For external extensions, we save a preference reminding ourself not to try |
1252 // and install the extension anymore (except when |external_uninstall| is | 1211 // and install the extension anymore (except when |external_uninstall| is |
1253 // true, which signifies that the registry key was deleted or the pref file | 1212 // true, which signifies that the registry key was deleted or the pref file |
1254 // no longer lists the extension). | 1213 // no longer lists the extension). |
1255 if (!external_uninstall && Manifest::IsExternalLocation(location)) { | 1214 if (!external_uninstall && Manifest::IsExternalLocation(location)) { |
1256 UpdateExtensionPref(extension_id, kPrefState, | 1215 UpdateExtensionPref(extension_id, kPrefState, |
1257 new base::FundamentalValue( | 1216 new base::FundamentalValue( |
1258 Extension::EXTERNAL_EXTENSION_UNINSTALLED)); | 1217 Extension::EXTERNAL_EXTENSION_UNINSTALLED)); |
1259 extension_pref_value_map_->SetExtensionState(extension_id, false); | 1218 extension_pref_value_map_->SetExtensionState(extension_id, false); |
1260 content_settings_store_->SetExtensionState(extension_id, false); | 1219 FOR_EACH_OBSERVER(ExtensionPrefsObserver, |
| 1220 observer_list_, |
| 1221 OnExtensionStateChanged(extension_id, false)); |
1261 } else { | 1222 } else { |
1262 int creation_flags = GetCreationFlags(extension_id); | 1223 int creation_flags = GetCreationFlags(extension_id); |
1263 if (creation_flags & Extension::IS_EPHEMERAL) { | 1224 if (creation_flags & Extension::IS_EPHEMERAL) { |
1264 // Keep ephemeral apps around, but mark them as evicted. | 1225 // Keep ephemeral apps around, but mark them as evicted. |
1265 UpdateExtensionPref(extension_id, kPrefEvictedEphemeralApp, | 1226 UpdateExtensionPref(extension_id, kPrefEvictedEphemeralApp, |
1266 new base::FundamentalValue(true)); | 1227 new base::FundamentalValue(true)); |
1267 } else { | 1228 } else { |
1268 DeleteExtensionPrefs(extension_id); | 1229 DeleteExtensionPrefs(extension_id); |
1269 } | 1230 } |
1270 } | 1231 } |
1271 } | 1232 } |
1272 | 1233 |
1273 void ExtensionPrefs::SetExtensionState(const std::string& extension_id, | 1234 void ExtensionPrefs::SetExtensionState(const std::string& extension_id, |
1274 Extension::State state) { | 1235 Extension::State state) { |
1275 UpdateExtensionPref(extension_id, kPrefState, | 1236 UpdateExtensionPref(extension_id, kPrefState, |
1276 new base::FundamentalValue(state)); | 1237 new base::FundamentalValue(state)); |
1277 bool enabled = (state == Extension::ENABLED); | 1238 bool enabled = (state == Extension::ENABLED); |
1278 extension_pref_value_map_->SetExtensionState(extension_id, enabled); | 1239 extension_pref_value_map_->SetExtensionState(extension_id, enabled); |
1279 content_settings_store_->SetExtensionState(extension_id, enabled); | 1240 FOR_EACH_OBSERVER(ExtensionPrefsObserver, |
| 1241 observer_list_, |
| 1242 OnExtensionStateChanged(extension_id, enabled)); |
1280 } | 1243 } |
1281 | 1244 |
1282 void ExtensionPrefs::SetExtensionBlacklistState(const std::string& extension_id, | 1245 void ExtensionPrefs::SetExtensionBlacklistState(const std::string& extension_id, |
1283 BlacklistState state) { | 1246 BlacklistState state) { |
1284 SetExtensionBlacklisted(extension_id, state == BLACKLISTED_MALWARE); | 1247 SetExtensionBlacklisted(extension_id, state == BLACKLISTED_MALWARE); |
1285 UpdateExtensionPref(extension_id, kPrefBlacklistState, | 1248 UpdateExtensionPref(extension_id, kPrefBlacklistState, |
1286 new base::FundamentalValue(state)); | 1249 new base::FundamentalValue(state)); |
1287 } | 1250 } |
1288 | 1251 |
1289 BlacklistState ExtensionPrefs::GetExtensionBlacklistState( | 1252 BlacklistState ExtensionPrefs::GetExtensionBlacklistState( |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1768 if (!it.value().GetAsDictionary(&ext)) { | 1731 if (!it.value().GetAsDictionary(&ext)) { |
1769 NOTREACHED() << "Invalid pref for extension " << it.key(); | 1732 NOTREACHED() << "Invalid pref for extension " << it.key(); |
1770 continue; | 1733 continue; |
1771 } | 1734 } |
1772 if (!IsBlacklistBitSet(ext)) | 1735 if (!IsBlacklistBitSet(ext)) |
1773 result.push_back(it.key()); | 1736 result.push_back(it.key()); |
1774 } | 1737 } |
1775 return result; | 1738 return result; |
1776 } | 1739 } |
1777 | 1740 |
1778 void ExtensionPrefs::AddObserver(Observer* observer) { | 1741 void ExtensionPrefs::AddObserver(ExtensionPrefsObserver* observer) { |
1779 observer_list_.AddObserver(observer); | 1742 observer_list_.AddObserver(observer); |
1780 } | 1743 } |
1781 | 1744 |
1782 void ExtensionPrefs::RemoveObserver(Observer* observer) { | 1745 void ExtensionPrefs::RemoveObserver(ExtensionPrefsObserver* observer) { |
1783 observer_list_.RemoveObserver(observer); | 1746 observer_list_.RemoveObserver(observer); |
1784 } | 1747 } |
1785 | 1748 |
1786 void ExtensionPrefs::FixMissingPrefs(const ExtensionIdList& extension_ids) { | 1749 void ExtensionPrefs::FixMissingPrefs(const ExtensionIdList& extension_ids) { |
1787 // Fix old entries that did not get an installation time entry when they | 1750 // Fix old entries that did not get an installation time entry when they |
1788 // were installed or don't have a preferences field. | 1751 // were installed or don't have a preferences field. |
1789 for (ExtensionIdList::const_iterator ext_id = extension_ids.begin(); | 1752 for (ExtensionIdList::const_iterator ext_id = extension_ids.begin(); |
1790 ext_id != extension_ids.end(); ++ext_id) { | 1753 ext_id != extension_ids.end(); ++ext_id) { |
1791 if (GetInstallTime(*ext_id) == base::Time()) { | 1754 if (GetInstallTime(*ext_id) == base::Time()) { |
1792 VLOG(1) << "Could not parse installation time of extension " | 1755 VLOG(1) << "Could not parse installation time of extension " |
(...skipping 26 matching lines...) Expand all Loading... |
1819 ScopedExtensionPrefUpdate update(prefs_, *ext_id); | 1782 ScopedExtensionPrefUpdate update(prefs_, *ext_id); |
1820 // This creates an empty dictionary if none is stored. | 1783 // This creates an empty dictionary if none is stored. |
1821 update.Get(); | 1784 update.Get(); |
1822 } | 1785 } |
1823 | 1786 |
1824 FixMissingPrefs(extension_ids); | 1787 FixMissingPrefs(extension_ids); |
1825 MigratePermissions(extension_ids); | 1788 MigratePermissions(extension_ids); |
1826 MigrateDisableReasons(extension_ids); | 1789 MigrateDisableReasons(extension_ids); |
1827 app_sorting_->Initialize(extension_ids); | 1790 app_sorting_->Initialize(extension_ids); |
1828 | 1791 |
1829 InitExtensionControlledPrefs(this, extension_pref_value_map_); | 1792 InitExtensionControlledPrefs(extension_pref_value_map_); |
1830 | 1793 |
1831 extension_pref_value_map_->NotifyInitializationCompleted(); | 1794 extension_pref_value_map_->NotifyInitializationCompleted(); |
1832 } | 1795 } |
1833 | 1796 |
1834 bool ExtensionPrefs::HasIncognitoPrefValue(const std::string& pref_key) { | 1797 bool ExtensionPrefs::HasIncognitoPrefValue(const std::string& pref_key) { |
1835 bool has_incognito_pref_value = false; | 1798 bool has_incognito_pref_value = false; |
1836 extension_pref_value_map_->GetEffectivePrefValue(pref_key, | 1799 extension_pref_value_map_->GetEffectivePrefValue(pref_key, |
1837 true, | 1800 true, |
1838 &has_incognito_pref_value); | 1801 &has_incognito_pref_value); |
1839 return has_incognito_pref_value; | 1802 return has_incognito_pref_value; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1913 kPrefInstallParam, | 1876 kPrefInstallParam, |
1914 new base::StringValue(install_parameter)); | 1877 new base::StringValue(install_parameter)); |
1915 } | 1878 } |
1916 | 1879 |
1917 ExtensionPrefs::ExtensionPrefs( | 1880 ExtensionPrefs::ExtensionPrefs( |
1918 PrefService* prefs, | 1881 PrefService* prefs, |
1919 const base::FilePath& root_dir, | 1882 const base::FilePath& root_dir, |
1920 ExtensionPrefValueMap* extension_pref_value_map, | 1883 ExtensionPrefValueMap* extension_pref_value_map, |
1921 scoped_ptr<AppSorting> app_sorting, | 1884 scoped_ptr<AppSorting> app_sorting, |
1922 scoped_ptr<TimeProvider> time_provider, | 1885 scoped_ptr<TimeProvider> time_provider, |
1923 bool extensions_disabled) | 1886 bool extensions_disabled, |
| 1887 const std::vector<ExtensionPrefsObserver*>& early_observers) |
1924 : prefs_(prefs), | 1888 : prefs_(prefs), |
1925 install_directory_(root_dir), | 1889 install_directory_(root_dir), |
1926 extension_pref_value_map_(extension_pref_value_map), | 1890 extension_pref_value_map_(extension_pref_value_map), |
1927 app_sorting_(app_sorting.Pass()), | 1891 app_sorting_(app_sorting.Pass()), |
1928 content_settings_store_(new ContentSettingsStore()), | |
1929 time_provider_(time_provider.Pass()), | 1892 time_provider_(time_provider.Pass()), |
1930 extensions_disabled_(extensions_disabled) { | 1893 extensions_disabled_(extensions_disabled) { |
1931 app_sorting_->SetExtensionScopedPrefs(this); | 1894 app_sorting_->SetExtensionScopedPrefs(this); |
1932 MakePathsRelative(); | 1895 MakePathsRelative(); |
| 1896 |
| 1897 // Ensure that any early observers are watching before prefs are initialized. |
| 1898 for (std::vector<ExtensionPrefsObserver*>::const_iterator iter = |
| 1899 early_observers.begin(); |
| 1900 iter != early_observers.end(); |
| 1901 ++iter) { |
| 1902 AddObserver(*iter); |
| 1903 } |
| 1904 |
1933 InitPrefStore(); | 1905 InitPrefStore(); |
1934 } | 1906 } |
1935 | 1907 |
1936 void ExtensionPrefs::SetNeedsStorageGarbageCollection(bool value) { | 1908 void ExtensionPrefs::SetNeedsStorageGarbageCollection(bool value) { |
1937 prefs_->SetBoolean(pref_names::kStorageGarbageCollect, value); | 1909 prefs_->SetBoolean(pref_names::kStorageGarbageCollect, value); |
1938 } | 1910 } |
1939 | 1911 |
1940 bool ExtensionPrefs::NeedsStorageGarbageCollection() { | 1912 bool ExtensionPrefs::NeedsStorageGarbageCollection() { |
1941 return prefs_->GetBoolean(pref_names::kStorageGarbageCollect); | 1913 return prefs_->GetBoolean(pref_names::kStorageGarbageCollect); |
1942 } | 1914 } |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2084 new base::StringValue(install_parameter)); | 2056 new base::StringValue(install_parameter)); |
2085 } | 2057 } |
2086 // We store prefs about LOAD extensions, but don't cache their manifest | 2058 // We store prefs about LOAD extensions, but don't cache their manifest |
2087 // since it may change on disk. | 2059 // since it may change on disk. |
2088 if (!Manifest::IsUnpackedLocation(extension->location())) { | 2060 if (!Manifest::IsUnpackedLocation(extension->location())) { |
2089 extension_dict->Set(kPrefManifest, | 2061 extension_dict->Set(kPrefManifest, |
2090 extension->manifest()->value()->DeepCopy()); | 2062 extension->manifest()->value()->DeepCopy()); |
2091 } | 2063 } |
2092 } | 2064 } |
2093 | 2065 |
| 2066 void ExtensionPrefs::InitExtensionControlledPrefs( |
| 2067 ExtensionPrefValueMap* value_map) { |
| 2068 ExtensionIdList extension_ids; |
| 2069 GetExtensions(&extension_ids); |
| 2070 |
| 2071 for (ExtensionIdList::iterator extension_id = extension_ids.begin(); |
| 2072 extension_id != extension_ids.end(); |
| 2073 ++extension_id) { |
| 2074 base::Time install_time = GetInstallTime(*extension_id); |
| 2075 bool is_enabled = !IsExtensionDisabled(*extension_id); |
| 2076 bool is_incognito_enabled = IsIncognitoEnabled(*extension_id); |
| 2077 value_map->RegisterExtension( |
| 2078 *extension_id, install_time, is_enabled, is_incognito_enabled); |
| 2079 |
| 2080 FOR_EACH_OBSERVER( |
| 2081 ExtensionPrefsObserver, |
| 2082 observer_list_, |
| 2083 OnExtensionRegistered(*extension_id, install_time, is_enabled)); |
| 2084 |
| 2085 // Set regular extension controlled prefs. |
| 2086 LoadExtensionControlledPrefs( |
| 2087 this, value_map, *extension_id, kExtensionPrefsScopeRegular); |
| 2088 // Set incognito extension controlled prefs. |
| 2089 LoadExtensionControlledPrefs(this, |
| 2090 value_map, |
| 2091 *extension_id, |
| 2092 kExtensionPrefsScopeIncognitoPersistent); |
| 2093 // Set regular-only extension controlled prefs. |
| 2094 LoadExtensionControlledPrefs( |
| 2095 this, value_map, *extension_id, kExtensionPrefsScopeRegularOnly); |
| 2096 |
| 2097 FOR_EACH_OBSERVER(ExtensionPrefsObserver, |
| 2098 observer_list_, |
| 2099 OnExtensionPrefsLoaded(*extension_id)); |
| 2100 } |
| 2101 } |
| 2102 |
2094 void ExtensionPrefs::FinishExtensionInfoPrefs( | 2103 void ExtensionPrefs::FinishExtensionInfoPrefs( |
2095 const std::string& extension_id, | 2104 const std::string& extension_id, |
2096 const base::Time install_time, | 2105 const base::Time install_time, |
2097 bool needs_sort_ordinal, | 2106 bool needs_sort_ordinal, |
2098 const syncer::StringOrdinal& suggested_page_ordinal, | 2107 const syncer::StringOrdinal& suggested_page_ordinal, |
2099 base::DictionaryValue* extension_dict) { | 2108 base::DictionaryValue* extension_dict) { |
2100 // Reinitializes various preferences with empty dictionaries. | 2109 // Reinitializes various preferences with empty dictionaries. |
2101 if (!extension_dict->HasKey(pref_names::kPrefPreferences)) { | 2110 if (!extension_dict->HasKey(pref_names::kPrefPreferences)) { |
2102 extension_dict->Set(pref_names::kPrefPreferences, | 2111 extension_dict->Set(pref_names::kPrefPreferences, |
2103 new base::DictionaryValue); | 2112 new base::DictionaryValue); |
(...skipping 21 matching lines...) Expand all Loading... |
2125 // out of date. | 2134 // out of date. |
2126 extension_dict->Remove(kDelayedInstallInfo, NULL); | 2135 extension_dict->Remove(kDelayedInstallInfo, NULL); |
2127 | 2136 |
2128 // Clear state that may be registered from a previous install. | 2137 // Clear state that may be registered from a previous install. |
2129 extension_dict->Remove(EventRouter::kRegisteredEvents, NULL); | 2138 extension_dict->Remove(EventRouter::kRegisteredEvents, NULL); |
2130 | 2139 |
2131 // When evicted ephemeral apps are re-installed, this flag must be reset. | 2140 // When evicted ephemeral apps are re-installed, this flag must be reset. |
2132 extension_dict->Remove(kPrefEvictedEphemeralApp, NULL); | 2141 extension_dict->Remove(kPrefEvictedEphemeralApp, NULL); |
2133 | 2142 |
2134 // FYI, all code below here races on sudden shutdown because |extension_dict|, | 2143 // FYI, all code below here races on sudden shutdown because |extension_dict|, |
2135 // |app_sorting_|, |extension_pref_value_map_|, and |content_settings_store_| | 2144 // |app_sorting_|, |extension_pref_value_map_|, and (potentially) observers |
2136 // are updated non-transactionally. This is probably not fixable without | 2145 // are updated non-transactionally. This is probably not fixable without |
2137 // nested transactional updates to pref dictionaries. | 2146 // nested transactional updates to pref dictionaries. |
2138 if (needs_sort_ordinal) | 2147 if (needs_sort_ordinal) |
2139 app_sorting_->EnsureValidOrdinals(extension_id, suggested_page_ordinal); | 2148 app_sorting_->EnsureValidOrdinals(extension_id, suggested_page_ordinal); |
2140 | 2149 |
2141 bool is_enabled = false; | 2150 bool is_enabled = false; |
2142 int initial_state; | 2151 int initial_state; |
2143 if (extension_dict->GetInteger(kPrefState, &initial_state)) { | 2152 if (extension_dict->GetInteger(kPrefState, &initial_state)) { |
2144 is_enabled = initial_state == Extension::ENABLED; | 2153 is_enabled = initial_state == Extension::ENABLED; |
2145 } | 2154 } |
2146 bool is_incognito_enabled = IsIncognitoEnabled(extension_id); | 2155 bool is_incognito_enabled = IsIncognitoEnabled(extension_id); |
2147 | 2156 |
2148 extension_pref_value_map_->RegisterExtension( | 2157 extension_pref_value_map_->RegisterExtension( |
2149 extension_id, install_time, is_enabled, is_incognito_enabled); | 2158 extension_id, install_time, is_enabled, is_incognito_enabled); |
2150 content_settings_store_->RegisterExtension(extension_id, install_time, | 2159 |
2151 is_enabled); | 2160 FOR_EACH_OBSERVER( |
| 2161 ExtensionPrefsObserver, |
| 2162 observer_list_, |
| 2163 OnExtensionRegistered(extension_id, install_time, is_enabled)); |
2152 } | 2164 } |
2153 | 2165 |
2154 } // namespace extensions | 2166 } // namespace extensions |
OLD | NEW |