| 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" |
| 22 #include "extensions/browser/pref_names.h" | 21 #include "extensions/browser/pref_names.h" |
| 23 #include "extensions/common/feature_switch.h" | 22 #include "extensions/common/feature_switch.h" |
| 24 #include "extensions/common/manifest.h" | 23 #include "extensions/common/manifest.h" |
| 25 #include "extensions/common/permissions/permission_set.h" | 24 #include "extensions/common/permissions/permission_set.h" |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 if (!source_dict->GetDictionary(key, &preferences)) | 250 if (!source_dict->GetDictionary(key, &preferences)) |
| 252 return; | 251 return; |
| 253 | 252 |
| 254 for (base::DictionaryValue::Iterator iter(*preferences); !iter.IsAtEnd(); | 253 for (base::DictionaryValue::Iterator iter(*preferences); !iter.IsAtEnd(); |
| 255 iter.Advance()) { | 254 iter.Advance()) { |
| 256 value_map->SetExtensionPref( | 255 value_map->SetExtensionPref( |
| 257 extension_id, iter.key(), scope, iter.value().DeepCopy()); | 256 extension_id, iter.key(), scope, iter.value().DeepCopy()); |
| 258 } | 257 } |
| 259 } | 258 } |
| 260 | 259 |
| 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 | 260 } // namespace |
| 309 | 261 |
| 310 // | 262 // |
| 311 // TimeProvider | 263 // TimeProvider |
| 312 // | 264 // |
| 313 | 265 |
| 314 ExtensionPrefs::TimeProvider::TimeProvider() { | 266 ExtensionPrefs::TimeProvider::TimeProvider() { |
| 315 } | 267 } |
| 316 | 268 |
| 317 ExtensionPrefs::TimeProvider::~TimeProvider() { | 269 ExtensionPrefs::TimeProvider::~TimeProvider() { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 // | 334 // |
| 383 // ExtensionPrefs | 335 // ExtensionPrefs |
| 384 // | 336 // |
| 385 | 337 |
| 386 // static | 338 // static |
| 387 ExtensionPrefs* ExtensionPrefs::Create( | 339 ExtensionPrefs* ExtensionPrefs::Create( |
| 388 PrefService* prefs, | 340 PrefService* prefs, |
| 389 const base::FilePath& root_dir, | 341 const base::FilePath& root_dir, |
| 390 ExtensionPrefValueMap* extension_pref_value_map, | 342 ExtensionPrefValueMap* extension_pref_value_map, |
| 391 scoped_ptr<AppSorting> app_sorting, | 343 scoped_ptr<AppSorting> app_sorting, |
| 392 bool extensions_disabled) { | 344 bool extensions_disabled, |
| 345 const std::vector<Observer*>& early_observers) { |
| 393 return ExtensionPrefs::Create(prefs, | 346 return ExtensionPrefs::Create(prefs, |
| 394 root_dir, | 347 root_dir, |
| 395 extension_pref_value_map, | 348 extension_pref_value_map, |
| 396 app_sorting.Pass(), | 349 app_sorting.Pass(), |
| 397 extensions_disabled, | 350 extensions_disabled, |
| 351 early_observers, |
| 398 make_scoped_ptr(new TimeProvider())); | 352 make_scoped_ptr(new TimeProvider())); |
| 399 } | 353 } |
| 400 | 354 |
| 401 // static | 355 // static |
| 402 ExtensionPrefs* ExtensionPrefs::Create( | 356 ExtensionPrefs* ExtensionPrefs::Create( |
| 403 PrefService* pref_service, | 357 PrefService* pref_service, |
| 404 const base::FilePath& root_dir, | 358 const base::FilePath& root_dir, |
| 405 ExtensionPrefValueMap* extension_pref_value_map, | 359 ExtensionPrefValueMap* extension_pref_value_map, |
| 406 scoped_ptr<AppSorting> app_sorting, | 360 scoped_ptr<AppSorting> app_sorting, |
| 407 bool extensions_disabled, | 361 bool extensions_disabled, |
| 362 const std::vector<Observer*>& early_observers, |
| 408 scoped_ptr<TimeProvider> time_provider) { | 363 scoped_ptr<TimeProvider> time_provider) { |
| 409 return new ExtensionPrefs(pref_service, | 364 return new ExtensionPrefs(pref_service, |
| 410 root_dir, | 365 root_dir, |
| 411 extension_pref_value_map, | 366 extension_pref_value_map, |
| 412 app_sorting.Pass(), | 367 app_sorting.Pass(), |
| 413 time_provider.Pass(), | 368 time_provider.Pass(), |
| 414 extensions_disabled); | 369 extensions_disabled, |
| 370 early_observers); |
| 415 } | 371 } |
| 416 | 372 |
| 417 ExtensionPrefs::~ExtensionPrefs() { | 373 ExtensionPrefs::~ExtensionPrefs() { |
| 418 } | 374 } |
| 419 | 375 |
| 420 // static | 376 // static |
| 421 ExtensionPrefs* ExtensionPrefs::Get(content::BrowserContext* context) { | 377 ExtensionPrefs* ExtensionPrefs::Get(content::BrowserContext* context) { |
| 422 return ExtensionPrefsFactory::GetInstance()->GetForBrowserContext(context); | 378 return ExtensionPrefsFactory::GetInstance()->GetForBrowserContext(context); |
| 423 } | 379 } |
| 424 | 380 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 } | 459 } |
| 504 ScopedExtensionPrefUpdate update(prefs_, extension_id); | 460 ScopedExtensionPrefUpdate update(prefs_, extension_id); |
| 505 if (data_value) | 461 if (data_value) |
| 506 update->Set(key, data_value); | 462 update->Set(key, data_value); |
| 507 else | 463 else |
| 508 update->Remove(key, NULL); | 464 update->Remove(key, NULL); |
| 509 } | 465 } |
| 510 | 466 |
| 511 void ExtensionPrefs::DeleteExtensionPrefs(const std::string& extension_id) { | 467 void ExtensionPrefs::DeleteExtensionPrefs(const std::string& extension_id) { |
| 512 extension_pref_value_map_->UnregisterExtension(extension_id); | 468 extension_pref_value_map_->UnregisterExtension(extension_id); |
| 513 content_settings_store_->UnregisterExtension(extension_id); | 469 FOR_EACH_OBSERVER( |
| 470 Observer, observer_list_, OnExtensionPrefsDeleted(extension_id)); |
| 514 DictionaryPrefUpdate update(prefs_, pref_names::kExtensions); | 471 DictionaryPrefUpdate update(prefs_, pref_names::kExtensions); |
| 515 base::DictionaryValue* dict = update.Get(); | 472 base::DictionaryValue* dict = update.Get(); |
| 516 dict->Remove(extension_id, NULL); | 473 dict->Remove(extension_id, NULL); |
| 517 } | 474 } |
| 518 | 475 |
| 519 bool ExtensionPrefs::ReadPrefAsBoolean(const std::string& extension_id, | 476 bool ExtensionPrefs::ReadPrefAsBoolean(const std::string& extension_id, |
| 520 const std::string& pref_key, | 477 const std::string& pref_key, |
| 521 bool* out_value) const { | 478 bool* out_value) const { |
| 522 const base::DictionaryValue* ext = GetExtensionPref(extension_id); | 479 const base::DictionaryValue* ext = GetExtensionPref(extension_id); |
| 523 if (!ext || !ext->GetBoolean(pref_key, out_value)) | 480 if (!ext || !ext->GetBoolean(pref_key, out_value)) |
| (...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1250 | 1207 |
| 1251 // For external extensions, we save a preference reminding ourself not to try | 1208 // For external extensions, we save a preference reminding ourself not to try |
| 1252 // and install the extension anymore (except when |external_uninstall| is | 1209 // and install the extension anymore (except when |external_uninstall| is |
| 1253 // true, which signifies that the registry key was deleted or the pref file | 1210 // true, which signifies that the registry key was deleted or the pref file |
| 1254 // no longer lists the extension). | 1211 // no longer lists the extension). |
| 1255 if (!external_uninstall && Manifest::IsExternalLocation(location)) { | 1212 if (!external_uninstall && Manifest::IsExternalLocation(location)) { |
| 1256 UpdateExtensionPref(extension_id, kPrefState, | 1213 UpdateExtensionPref(extension_id, kPrefState, |
| 1257 new base::FundamentalValue( | 1214 new base::FundamentalValue( |
| 1258 Extension::EXTERNAL_EXTENSION_UNINSTALLED)); | 1215 Extension::EXTERNAL_EXTENSION_UNINSTALLED)); |
| 1259 extension_pref_value_map_->SetExtensionState(extension_id, false); | 1216 extension_pref_value_map_->SetExtensionState(extension_id, false); |
| 1260 content_settings_store_->SetExtensionState(extension_id, false); | 1217 FOR_EACH_OBSERVER( |
| 1218 Observer, observer_list_, OnExtensionStateChanged(extension_id, false)); |
| 1261 } else { | 1219 } else { |
| 1262 int creation_flags = GetCreationFlags(extension_id); | 1220 int creation_flags = GetCreationFlags(extension_id); |
| 1263 if (creation_flags & Extension::IS_EPHEMERAL) { | 1221 if (creation_flags & Extension::IS_EPHEMERAL) { |
| 1264 // Keep ephemeral apps around, but mark them as evicted. | 1222 // Keep ephemeral apps around, but mark them as evicted. |
| 1265 UpdateExtensionPref(extension_id, kPrefEvictedEphemeralApp, | 1223 UpdateExtensionPref(extension_id, kPrefEvictedEphemeralApp, |
| 1266 new base::FundamentalValue(true)); | 1224 new base::FundamentalValue(true)); |
| 1267 } else { | 1225 } else { |
| 1268 DeleteExtensionPrefs(extension_id); | 1226 DeleteExtensionPrefs(extension_id); |
| 1269 } | 1227 } |
| 1270 } | 1228 } |
| 1271 } | 1229 } |
| 1272 | 1230 |
| 1273 void ExtensionPrefs::SetExtensionState(const std::string& extension_id, | 1231 void ExtensionPrefs::SetExtensionState(const std::string& extension_id, |
| 1274 Extension::State state) { | 1232 Extension::State state) { |
| 1275 UpdateExtensionPref(extension_id, kPrefState, | 1233 UpdateExtensionPref(extension_id, kPrefState, |
| 1276 new base::FundamentalValue(state)); | 1234 new base::FundamentalValue(state)); |
| 1277 bool enabled = (state == Extension::ENABLED); | 1235 bool enabled = (state == Extension::ENABLED); |
| 1278 extension_pref_value_map_->SetExtensionState(extension_id, enabled); | 1236 extension_pref_value_map_->SetExtensionState(extension_id, enabled); |
| 1279 content_settings_store_->SetExtensionState(extension_id, enabled); | 1237 FOR_EACH_OBSERVER( |
| 1238 Observer, observer_list_, OnExtensionStateChanged(extension_id, enabled)); |
| 1280 } | 1239 } |
| 1281 | 1240 |
| 1282 void ExtensionPrefs::SetExtensionBlacklistState(const std::string& extension_id, | 1241 void ExtensionPrefs::SetExtensionBlacklistState(const std::string& extension_id, |
| 1283 BlacklistState state) { | 1242 BlacklistState state) { |
| 1284 SetExtensionBlacklisted(extension_id, state == BLACKLISTED_MALWARE); | 1243 SetExtensionBlacklisted(extension_id, state == BLACKLISTED_MALWARE); |
| 1285 UpdateExtensionPref(extension_id, kPrefBlacklistState, | 1244 UpdateExtensionPref(extension_id, kPrefBlacklistState, |
| 1286 new base::FundamentalValue(state)); | 1245 new base::FundamentalValue(state)); |
| 1287 } | 1246 } |
| 1288 | 1247 |
| 1289 BlacklistState ExtensionPrefs::GetExtensionBlacklistState( | 1248 BlacklistState ExtensionPrefs::GetExtensionBlacklistState( |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1819 ScopedExtensionPrefUpdate update(prefs_, *ext_id); | 1778 ScopedExtensionPrefUpdate update(prefs_, *ext_id); |
| 1820 // This creates an empty dictionary if none is stored. | 1779 // This creates an empty dictionary if none is stored. |
| 1821 update.Get(); | 1780 update.Get(); |
| 1822 } | 1781 } |
| 1823 | 1782 |
| 1824 FixMissingPrefs(extension_ids); | 1783 FixMissingPrefs(extension_ids); |
| 1825 MigratePermissions(extension_ids); | 1784 MigratePermissions(extension_ids); |
| 1826 MigrateDisableReasons(extension_ids); | 1785 MigrateDisableReasons(extension_ids); |
| 1827 app_sorting_->Initialize(extension_ids); | 1786 app_sorting_->Initialize(extension_ids); |
| 1828 | 1787 |
| 1829 InitExtensionControlledPrefs(this, extension_pref_value_map_); | 1788 InitExtensionControlledPrefs(extension_pref_value_map_); |
| 1830 | 1789 |
| 1831 extension_pref_value_map_->NotifyInitializationCompleted(); | 1790 extension_pref_value_map_->NotifyInitializationCompleted(); |
| 1832 } | 1791 } |
| 1833 | 1792 |
| 1834 bool ExtensionPrefs::HasIncognitoPrefValue(const std::string& pref_key) { | 1793 bool ExtensionPrefs::HasIncognitoPrefValue(const std::string& pref_key) { |
| 1835 bool has_incognito_pref_value = false; | 1794 bool has_incognito_pref_value = false; |
| 1836 extension_pref_value_map_->GetEffectivePrefValue(pref_key, | 1795 extension_pref_value_map_->GetEffectivePrefValue(pref_key, |
| 1837 true, | 1796 true, |
| 1838 &has_incognito_pref_value); | 1797 &has_incognito_pref_value); |
| 1839 return has_incognito_pref_value; | 1798 return has_incognito_pref_value; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1907 return install_parameter; | 1866 return install_parameter; |
| 1908 } | 1867 } |
| 1909 | 1868 |
| 1910 void ExtensionPrefs::SetInstallParam(const std::string& extension_id, | 1869 void ExtensionPrefs::SetInstallParam(const std::string& extension_id, |
| 1911 const std::string& install_parameter) { | 1870 const std::string& install_parameter) { |
| 1912 UpdateExtensionPref(extension_id, | 1871 UpdateExtensionPref(extension_id, |
| 1913 kPrefInstallParam, | 1872 kPrefInstallParam, |
| 1914 new base::StringValue(install_parameter)); | 1873 new base::StringValue(install_parameter)); |
| 1915 } | 1874 } |
| 1916 | 1875 |
| 1917 ExtensionPrefs::ExtensionPrefs( | 1876 ExtensionPrefs::ExtensionPrefs(PrefService* prefs, |
| 1918 PrefService* prefs, | 1877 const base::FilePath& root_dir, |
| 1919 const base::FilePath& root_dir, | 1878 ExtensionPrefValueMap* extension_pref_value_map, |
| 1920 ExtensionPrefValueMap* extension_pref_value_map, | 1879 scoped_ptr<AppSorting> app_sorting, |
| 1921 scoped_ptr<AppSorting> app_sorting, | 1880 scoped_ptr<TimeProvider> time_provider, |
| 1922 scoped_ptr<TimeProvider> time_provider, | 1881 bool extensions_disabled, |
| 1923 bool extensions_disabled) | 1882 const std::vector<Observer*>& early_observers) |
| 1924 : prefs_(prefs), | 1883 : prefs_(prefs), |
| 1925 install_directory_(root_dir), | 1884 install_directory_(root_dir), |
| 1926 extension_pref_value_map_(extension_pref_value_map), | 1885 extension_pref_value_map_(extension_pref_value_map), |
| 1927 app_sorting_(app_sorting.Pass()), | 1886 app_sorting_(app_sorting.Pass()), |
| 1928 content_settings_store_(new ContentSettingsStore()), | |
| 1929 time_provider_(time_provider.Pass()), | 1887 time_provider_(time_provider.Pass()), |
| 1930 extensions_disabled_(extensions_disabled) { | 1888 extensions_disabled_(extensions_disabled) { |
| 1931 app_sorting_->SetExtensionScopedPrefs(this); | 1889 app_sorting_->SetExtensionScopedPrefs(this); |
| 1932 MakePathsRelative(); | 1890 MakePathsRelative(); |
| 1891 |
| 1892 // Ensure that any early observers are watching before prefs are initialized. |
| 1893 for (std::vector<Observer*>::const_iterator iter = early_observers.begin(); |
| 1894 iter != early_observers.end(); |
| 1895 ++iter) { |
| 1896 AddObserver(*iter); |
| 1897 } |
| 1898 |
| 1933 InitPrefStore(); | 1899 InitPrefStore(); |
| 1934 } | 1900 } |
| 1935 | 1901 |
| 1936 void ExtensionPrefs::SetNeedsStorageGarbageCollection(bool value) { | 1902 void ExtensionPrefs::SetNeedsStorageGarbageCollection(bool value) { |
| 1937 prefs_->SetBoolean(pref_names::kStorageGarbageCollect, value); | 1903 prefs_->SetBoolean(pref_names::kStorageGarbageCollect, value); |
| 1938 } | 1904 } |
| 1939 | 1905 |
| 1940 bool ExtensionPrefs::NeedsStorageGarbageCollection() { | 1906 bool ExtensionPrefs::NeedsStorageGarbageCollection() { |
| 1941 return prefs_->GetBoolean(pref_names::kStorageGarbageCollect); | 1907 return prefs_->GetBoolean(pref_names::kStorageGarbageCollect); |
| 1942 } | 1908 } |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2084 new base::StringValue(install_parameter)); | 2050 new base::StringValue(install_parameter)); |
| 2085 } | 2051 } |
| 2086 // We store prefs about LOAD extensions, but don't cache their manifest | 2052 // We store prefs about LOAD extensions, but don't cache their manifest |
| 2087 // since it may change on disk. | 2053 // since it may change on disk. |
| 2088 if (!Manifest::IsUnpackedLocation(extension->location())) { | 2054 if (!Manifest::IsUnpackedLocation(extension->location())) { |
| 2089 extension_dict->Set(kPrefManifest, | 2055 extension_dict->Set(kPrefManifest, |
| 2090 extension->manifest()->value()->DeepCopy()); | 2056 extension->manifest()->value()->DeepCopy()); |
| 2091 } | 2057 } |
| 2092 } | 2058 } |
| 2093 | 2059 |
| 2060 void ExtensionPrefs::InitExtensionControlledPrefs( |
| 2061 ExtensionPrefValueMap* value_map) { |
| 2062 ExtensionIdList extension_ids; |
| 2063 GetExtensions(&extension_ids); |
| 2064 |
| 2065 for (ExtensionIdList::iterator extension_id = extension_ids.begin(); |
| 2066 extension_id != extension_ids.end(); |
| 2067 ++extension_id) { |
| 2068 base::Time install_time = GetInstallTime(*extension_id); |
| 2069 bool is_enabled = !IsExtensionDisabled(*extension_id); |
| 2070 bool is_incognito_enabled = IsIncognitoEnabled(*extension_id); |
| 2071 value_map->RegisterExtension( |
| 2072 *extension_id, install_time, is_enabled, is_incognito_enabled); |
| 2073 |
| 2074 FOR_EACH_OBSERVER( |
| 2075 Observer, |
| 2076 observer_list_, |
| 2077 OnExtensionRegistered(*extension_id, install_time, is_enabled)); |
| 2078 |
| 2079 // Set regular extension controlled prefs. |
| 2080 LoadExtensionControlledPrefs( |
| 2081 this, value_map, *extension_id, kExtensionPrefsScopeRegular); |
| 2082 // Set incognito extension controlled prefs. |
| 2083 LoadExtensionControlledPrefs(this, |
| 2084 value_map, |
| 2085 *extension_id, |
| 2086 kExtensionPrefsScopeIncognitoPersistent); |
| 2087 // Set regular-only extension controlled prefs. |
| 2088 LoadExtensionControlledPrefs( |
| 2089 this, value_map, *extension_id, kExtensionPrefsScopeRegularOnly); |
| 2090 |
| 2091 FOR_EACH_OBSERVER( |
| 2092 Observer, observer_list_, OnExtensionPrefsLoaded(*extension_id)); |
| 2093 } |
| 2094 } |
| 2095 |
| 2094 void ExtensionPrefs::FinishExtensionInfoPrefs( | 2096 void ExtensionPrefs::FinishExtensionInfoPrefs( |
| 2095 const std::string& extension_id, | 2097 const std::string& extension_id, |
| 2096 const base::Time install_time, | 2098 const base::Time install_time, |
| 2097 bool needs_sort_ordinal, | 2099 bool needs_sort_ordinal, |
| 2098 const syncer::StringOrdinal& suggested_page_ordinal, | 2100 const syncer::StringOrdinal& suggested_page_ordinal, |
| 2099 base::DictionaryValue* extension_dict) { | 2101 base::DictionaryValue* extension_dict) { |
| 2100 // Reinitializes various preferences with empty dictionaries. | 2102 // Reinitializes various preferences with empty dictionaries. |
| 2101 if (!extension_dict->HasKey(pref_names::kPrefPreferences)) { | 2103 if (!extension_dict->HasKey(pref_names::kPrefPreferences)) { |
| 2102 extension_dict->Set(pref_names::kPrefPreferences, | 2104 extension_dict->Set(pref_names::kPrefPreferences, |
| 2103 new base::DictionaryValue); | 2105 new base::DictionaryValue); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2125 // out of date. | 2127 // out of date. |
| 2126 extension_dict->Remove(kDelayedInstallInfo, NULL); | 2128 extension_dict->Remove(kDelayedInstallInfo, NULL); |
| 2127 | 2129 |
| 2128 // Clear state that may be registered from a previous install. | 2130 // Clear state that may be registered from a previous install. |
| 2129 extension_dict->Remove(EventRouter::kRegisteredEvents, NULL); | 2131 extension_dict->Remove(EventRouter::kRegisteredEvents, NULL); |
| 2130 | 2132 |
| 2131 // When evicted ephemeral apps are re-installed, this flag must be reset. | 2133 // When evicted ephemeral apps are re-installed, this flag must be reset. |
| 2132 extension_dict->Remove(kPrefEvictedEphemeralApp, NULL); | 2134 extension_dict->Remove(kPrefEvictedEphemeralApp, NULL); |
| 2133 | 2135 |
| 2134 // FYI, all code below here races on sudden shutdown because |extension_dict|, | 2136 // FYI, all code below here races on sudden shutdown because |extension_dict|, |
| 2135 // |app_sorting_|, |extension_pref_value_map_|, and |content_settings_store_| | 2137 // |app_sorting_|, |extension_pref_value_map_|, and (potentially) observers |
| 2136 // are updated non-transactionally. This is probably not fixable without | 2138 // are updated non-transactionally. This is probably not fixable without |
| 2137 // nested transactional updates to pref dictionaries. | 2139 // nested transactional updates to pref dictionaries. |
| 2138 if (needs_sort_ordinal) | 2140 if (needs_sort_ordinal) |
| 2139 app_sorting_->EnsureValidOrdinals(extension_id, suggested_page_ordinal); | 2141 app_sorting_->EnsureValidOrdinals(extension_id, suggested_page_ordinal); |
| 2140 | 2142 |
| 2141 bool is_enabled = false; | 2143 bool is_enabled = false; |
| 2142 int initial_state; | 2144 int initial_state; |
| 2143 if (extension_dict->GetInteger(kPrefState, &initial_state)) { | 2145 if (extension_dict->GetInteger(kPrefState, &initial_state)) { |
| 2144 is_enabled = initial_state == Extension::ENABLED; | 2146 is_enabled = initial_state == Extension::ENABLED; |
| 2145 } | 2147 } |
| 2146 bool is_incognito_enabled = IsIncognitoEnabled(extension_id); | 2148 bool is_incognito_enabled = IsIncognitoEnabled(extension_id); |
| 2147 | 2149 |
| 2148 extension_pref_value_map_->RegisterExtension( | 2150 extension_pref_value_map_->RegisterExtension( |
| 2149 extension_id, install_time, is_enabled, is_incognito_enabled); | 2151 extension_id, install_time, is_enabled, is_incognito_enabled); |
| 2150 content_settings_store_->RegisterExtension(extension_id, install_time, | 2152 |
| 2151 is_enabled); | 2153 FOR_EACH_OBSERVER( |
| 2154 Observer, |
| 2155 observer_list_, |
| 2156 OnExtensionRegistered(extension_id, install_time, is_enabled)); |
| 2152 } | 2157 } |
| 2153 | 2158 |
| 2154 } // namespace extensions | 2159 } // namespace extensions |
| OLD | NEW |