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

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

Issue 14973007: Auto-install/uninstall shared module dependencies for extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 7 years, 6 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/extensions/extension_prefs.h" 5 #include "chrome/browser/extensions/extension_prefs.h"
6 6
7 #include "base/prefs/pref_notifier.h" 7 #include "base/prefs/pref_notifier.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 const char kActiveBit[] = "active_bit"; 114 const char kActiveBit[] = "active_bit";
115 115
116 // Path for settings specific to blacklist update. 116 // Path for settings specific to blacklist update.
117 const char kExtensionsBlacklistUpdate[] = "extensions.blacklistupdate"; 117 const char kExtensionsBlacklistUpdate[] = "extensions.blacklistupdate";
118 118
119 // Path for the delayed install info dictionary preference. The actual string 119 // Path for the delayed install info dictionary preference. The actual string
120 // value is a legacy artifact for when delayed installs only pertained to 120 // value is a legacy artifact for when delayed installs only pertained to
121 // updates that were waiting for idle. 121 // updates that were waiting for idle.
122 const char kDelayedInstallInfo[] = "idle_install_info"; 122 const char kDelayedInstallInfo[] = "idle_install_info";
123 123
124 // Reason why the extension's install was delayed.
125 const char kDelayedInstallReason[] = "delay_install_reason";
126
124 // Path for the suggested page ordinal of a delayed extension install. 127 // Path for the suggested page ordinal of a delayed extension install.
125 const char kPrefSuggestedPageOrdinal[] = "suggested_page_ordinal"; 128 const char kPrefSuggestedPageOrdinal[] = "suggested_page_ordinal";
126 129
127 // A preference that, if true, will allow this extension to run in incognito 130 // A preference that, if true, will allow this extension to run in incognito
128 // mode. 131 // mode.
129 const char kPrefIncognitoEnabled[] = "incognito"; 132 const char kPrefIncognitoEnabled[] = "incognito";
130 133
131 // A preference to control whether an extension is allowed to inject script in 134 // A preference to control whether an extension is allowed to inject script in
132 // pages with file URLs. 135 // pages with file URLs.
133 const char kPrefAllowFileAccess[] = "newAllowFileAccess"; 136 const char kPrefAllowFileAccess[] = "newAllowFileAccess";
(...skipping 1187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 if (info) 1324 if (info)
1322 extensions_info->push_back(linked_ptr<ExtensionInfo>(info.release())); 1325 extensions_info->push_back(linked_ptr<ExtensionInfo>(info.release()));
1323 } 1326 }
1324 1327
1325 return extensions_info.Pass(); 1328 return extensions_info.Pass();
1326 } 1329 }
1327 1330
1328 void ExtensionPrefs::SetDelayedInstallInfo( 1331 void ExtensionPrefs::SetDelayedInstallInfo(
1329 const Extension* extension, 1332 const Extension* extension,
1330 Extension::State initial_state, 1333 Extension::State initial_state,
1334 DelayReason delay_reason,
1331 const syncer::StringOrdinal& page_ordinal) { 1335 const syncer::StringOrdinal& page_ordinal) {
1332 DictionaryValue* extension_dict = new DictionaryValue(); 1336 DictionaryValue* extension_dict = new DictionaryValue();
1333 PopulateExtensionInfoPrefs(extension, time_provider_->GetCurrentTime(), 1337 PopulateExtensionInfoPrefs(extension, time_provider_->GetCurrentTime(),
1334 initial_state, extension_dict); 1338 initial_state, extension_dict);
1335 1339
1336 // Add transient data that is needed by FinishDelayedInstallInfo(), but 1340 // Add transient data that is needed by FinishDelayedInstallInfo(), but
1337 // should not be in the final extension prefs. All entries here should have 1341 // should not be in the final extension prefs. All entries here should have
1338 // a corresponding Remove() call in FinishDelayedInstallInfo(). 1342 // a corresponding Remove() call in FinishDelayedInstallInfo().
1339 if (extension->RequiresSortOrdinal()) { 1343 if (extension->RequiresSortOrdinal()) {
1340 extension_dict->SetString( 1344 extension_dict->SetString(
1341 kPrefSuggestedPageOrdinal, 1345 kPrefSuggestedPageOrdinal,
1342 page_ordinal.IsValid() ? page_ordinal.ToInternalValue() 1346 page_ordinal.IsValid() ? page_ordinal.ToInternalValue()
1343 : std::string()); 1347 : std::string());
1344 } 1348 }
1349 extension_dict->SetInteger(kDelayedInstallReason,
1350 static_cast<int>(delay_reason));
1345 1351
1346 UpdateExtensionPref(extension->id(), kDelayedInstallInfo, extension_dict); 1352 UpdateExtensionPref(extension->id(), kDelayedInstallInfo, extension_dict);
1347 } 1353 }
1348 1354
1349 bool ExtensionPrefs::RemoveDelayedInstallInfo( 1355 bool ExtensionPrefs::RemoveDelayedInstallInfo(
1350 const std::string& extension_id) { 1356 const std::string& extension_id) {
1351 if (!GetExtensionPref(extension_id)) 1357 if (!GetExtensionPref(extension_id))
1352 return false; 1358 return false;
1353 ScopedExtensionPrefUpdate update(prefs_, extension_id); 1359 ScopedExtensionPrefUpdate update(prefs_, extension_id);
1354 bool result = update->Remove(kDelayedInstallInfo, NULL); 1360 bool result = update->Remove(kDelayedInstallInfo, NULL);
(...skipping 15 matching lines...) Expand all
1370 // Also do any other data cleanup that makes sense. 1376 // Also do any other data cleanup that makes sense.
1371 std::string serialized_ordinal; 1377 std::string serialized_ordinal;
1372 syncer::StringOrdinal suggested_page_ordinal; 1378 syncer::StringOrdinal suggested_page_ordinal;
1373 bool needs_sort_ordinal = false; 1379 bool needs_sort_ordinal = false;
1374 if (pending_install_dict->GetString(kPrefSuggestedPageOrdinal, 1380 if (pending_install_dict->GetString(kPrefSuggestedPageOrdinal,
1375 &serialized_ordinal)) { 1381 &serialized_ordinal)) {
1376 suggested_page_ordinal = syncer::StringOrdinal(serialized_ordinal); 1382 suggested_page_ordinal = syncer::StringOrdinal(serialized_ordinal);
1377 needs_sort_ordinal = true; 1383 needs_sort_ordinal = true;
1378 pending_install_dict->Remove(kPrefSuggestedPageOrdinal, NULL); 1384 pending_install_dict->Remove(kPrefSuggestedPageOrdinal, NULL);
1379 } 1385 }
1386 pending_install_dict->Remove(kDelayedInstallReason, NULL);
1380 1387
1381 const base::Time install_time = time_provider_->GetCurrentTime(); 1388 const base::Time install_time = time_provider_->GetCurrentTime();
1382 pending_install_dict->Set( 1389 pending_install_dict->Set(
1383 kPrefInstallTime, 1390 kPrefInstallTime,
1384 Value::CreateStringValue( 1391 Value::CreateStringValue(
1385 base::Int64ToString(install_time.ToInternalValue()))); 1392 base::Int64ToString(install_time.ToInternalValue())));
1386 1393
1387 // Commit the delayed install data. 1394 // Commit the delayed install data.
1388 extension_dict->MergeDictionary(pending_install_dict); 1395 extension_dict->MergeDictionary(pending_install_dict);
1389 FinishExtensionInfoPrefs(extension_id, install_time, needs_sort_ordinal, 1396 FinishExtensionInfoPrefs(extension_id, install_time, needs_sort_ordinal,
1390 suggested_page_ordinal, extension_dict); 1397 suggested_page_ordinal, extension_dict);
1391 return true; 1398 return true;
1392 } 1399 }
1393 1400
1394 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetDelayedInstallInfo( 1401 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetDelayedInstallInfo(
1395 const std::string& extension_id) const { 1402 const std::string& extension_id) const {
1396 const DictionaryValue* extension_prefs = 1403 const DictionaryValue* extension_prefs =
1397 GetExtensionPref(extension_id); 1404 GetExtensionPref(extension_id);
1398 if (!extension_prefs) 1405 if (!extension_prefs)
1399 return scoped_ptr<ExtensionInfo>(); 1406 return scoped_ptr<ExtensionInfo>();
1400 1407
1401 const DictionaryValue* ext = NULL; 1408 const DictionaryValue* ext = NULL;
1402 if (!extension_prefs->GetDictionary(kDelayedInstallInfo, &ext)) 1409 if (!extension_prefs->GetDictionary(kDelayedInstallInfo, &ext))
1403 return scoped_ptr<ExtensionInfo>(); 1410 return scoped_ptr<ExtensionInfo>();
1404 1411
1405 return GetInstalledInfoHelper(extension_id, ext); 1412 return GetInstalledInfoHelper(extension_id, ext);
1406 } 1413 }
1407 1414
1415 ExtensionPrefs::DelayReason ExtensionPrefs::GetDelayedInstallReason(
1416 const std::string& extension_id) const {
1417 const DictionaryValue* extension_prefs =
1418 GetExtensionPref(extension_id);
1419 if (!extension_prefs)
1420 return DELAY_REASON_NONE;
1421
1422 const DictionaryValue* ext = NULL;
1423 if (!extension_prefs->GetDictionary(kDelayedInstallInfo, &ext))
1424 return DELAY_REASON_NONE;
1425
1426 int delay_reason;
1427 if (!ext->GetInteger(kDelayedInstallReason, &delay_reason))
1428 return DELAY_REASON_NONE;
1429
1430 return static_cast<DelayReason>(delay_reason);
1431 }
1432
1408 scoped_ptr<ExtensionPrefs::ExtensionsInfo> ExtensionPrefs:: 1433 scoped_ptr<ExtensionPrefs::ExtensionsInfo> ExtensionPrefs::
1409 GetAllDelayedInstallInfo() const { 1434 GetAllDelayedInstallInfo() const {
1410 scoped_ptr<ExtensionsInfo> extensions_info(new ExtensionsInfo); 1435 scoped_ptr<ExtensionsInfo> extensions_info(new ExtensionsInfo);
1411 1436
1412 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); 1437 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
1413 for (DictionaryValue::Iterator extension_id(*extensions); 1438 for (DictionaryValue::Iterator extension_id(*extensions);
1414 !extension_id.IsAtEnd(); extension_id.Advance()) { 1439 !extension_id.IsAtEnd(); extension_id.Advance()) {
1415 if (!Extension::IdIsValid(extension_id.key())) 1440 if (!Extension::IdIsValid(extension_id.key()))
1416 continue; 1441 continue;
1417 1442
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1458 if (IsFromBookmark(extension_id)) 1483 if (IsFromBookmark(extension_id))
1459 creation_flags |= Extension::FROM_BOOKMARK; 1484 creation_flags |= Extension::FROM_BOOKMARK;
1460 if (IsFromWebStore(extension_id)) 1485 if (IsFromWebStore(extension_id))
1461 creation_flags |= Extension::FROM_WEBSTORE; 1486 creation_flags |= Extension::FROM_WEBSTORE;
1462 if (WasInstalledByDefault(extension_id)) 1487 if (WasInstalledByDefault(extension_id))
1463 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT; 1488 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT;
1464 } 1489 }
1465 return creation_flags; 1490 return creation_flags;
1466 } 1491 }
1467 1492
1493 int ExtensionPrefs::GetDelayedInstallCreationFlags(
1494 const std::string& extension_id) const {
1495 int creation_flags = Extension::NO_FLAGS;
1496 const DictionaryValue* delayed_info = NULL;
1497 if (ReadPrefAsDictionary(extension_id, kDelayedInstallInfo, &delayed_info)) {
1498 delayed_info->GetInteger(kPrefCreationFlags, &creation_flags);
1499 }
1500 return creation_flags;
1501 }
1502
1468 bool ExtensionPrefs::WasInstalledByDefault( 1503 bool ExtensionPrefs::WasInstalledByDefault(
1469 const std::string& extension_id) const { 1504 const std::string& extension_id) const {
1470 const DictionaryValue* dictionary = GetExtensionPref(extension_id); 1505 const DictionaryValue* dictionary = GetExtensionPref(extension_id);
1471 bool result = false; 1506 bool result = false;
1472 if (dictionary && 1507 if (dictionary &&
1473 dictionary->GetBoolean(kPrefWasInstalledByDefault, &result)) 1508 dictionary->GetBoolean(kPrefWasInstalledByDefault, &result))
1474 return result; 1509 return result;
1475 return false; 1510 return false;
1476 } 1511 }
1477 1512
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1823 is_enabled = initial_state == Extension::ENABLED; 1858 is_enabled = initial_state == Extension::ENABLED;
1824 } 1859 }
1825 1860
1826 extension_pref_value_map_->RegisterExtension(extension_id, install_time, 1861 extension_pref_value_map_->RegisterExtension(extension_id, install_time,
1827 is_enabled); 1862 is_enabled);
1828 content_settings_store_->RegisterExtension(extension_id, install_time, 1863 content_settings_store_->RegisterExtension(extension_id, install_time,
1829 is_enabled); 1864 is_enabled);
1830 } 1865 }
1831 1866
1832 } // namespace extensions 1867 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_prefs.h ('k') | chrome/browser/extensions/extension_prefs_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698