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/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 // A preference that indicates whether the extension was installed as an | 162 // A preference that indicates whether the extension was installed as an |
163 // OEM app. | 163 // OEM app. |
164 const char kPrefWasInstalledByOem[] = "was_installed_by_oem"; | 164 const char kPrefWasInstalledByOem[] = "was_installed_by_oem"; |
165 | 165 |
166 // Key for Geometry Cache preference. | 166 // Key for Geometry Cache preference. |
167 const char kPrefGeometryCache[] = "geometry_cache"; | 167 const char kPrefGeometryCache[] = "geometry_cache"; |
168 | 168 |
169 // A preference that indicates when an extension is last launched. | 169 // A preference that indicates when an extension is last launched. |
170 const char kPrefLastLaunchTime[] = "last_launch_time"; | 170 const char kPrefLastLaunchTime[] = "last_launch_time"; |
171 | 171 |
172 // A preference indicating whether the extension is an ephemeral app. | |
173 const char kPrefEphemeralApp[] = "ephemeral_app"; | |
174 | |
175 // Am installation parameter bundled with an extension. | 172 // Am installation parameter bundled with an extension. |
176 const char kPrefInstallParam[] = "install_parameter"; | 173 const char kPrefInstallParam[] = "install_parameter"; |
177 | 174 |
178 // A list of installed ids and a signature. | 175 // A list of installed ids and a signature. |
179 const char kInstallSignature[] = "extensions.install_signature"; | 176 const char kInstallSignature[] = "extensions.install_signature"; |
180 | 177 |
181 // A boolean preference that indicates whether the extension should not be | 178 // A boolean preference that indicates whether the extension should not be |
182 // synced. Default value is false. | 179 // synced. Default value is false. |
183 const char kPrefDoNotSync[] = "do_not_sync"; | 180 const char kPrefDoNotSync[] = "do_not_sync"; |
184 | 181 |
(...skipping 981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1166 ScopedExtensionPrefUpdate update(prefs_, extension->id()); | 1163 ScopedExtensionPrefUpdate update(prefs_, extension->id()); |
1167 base::DictionaryValue* extension_dict = update.Get(); | 1164 base::DictionaryValue* extension_dict = update.Get(); |
1168 const base::Time install_time = time_provider_->GetCurrentTime(); | 1165 const base::Time install_time = time_provider_->GetCurrentTime(); |
1169 PopulateExtensionInfoPrefs(extension, | 1166 PopulateExtensionInfoPrefs(extension, |
1170 install_time, | 1167 install_time, |
1171 initial_state, | 1168 initial_state, |
1172 install_flags, | 1169 install_flags, |
1173 install_parameter, | 1170 install_parameter, |
1174 extension_dict); | 1171 extension_dict); |
1175 | 1172 |
1176 bool requires_sort_ordinal = extension->RequiresSortOrdinal() && | 1173 FinishExtensionInfoPrefs(extension->id(), install_time, |
1177 (install_flags & kInstallFlagIsEphemeral) == 0; | 1174 extension->RequiresSortOrdinal(), page_ordinal, |
1178 FinishExtensionInfoPrefs(extension->id(), | |
1179 install_time, | |
1180 requires_sort_ordinal, | |
1181 page_ordinal, | |
1182 extension_dict); | 1175 extension_dict); |
1183 } | 1176 } |
1184 | 1177 |
1185 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, | 1178 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, |
1186 const Manifest::Location& location, | 1179 const Manifest::Location& location, |
1187 bool external_uninstall) { | 1180 bool external_uninstall) { |
1188 app_sorting()->ClearOrdinals(extension_id); | 1181 app_sorting()->ClearOrdinals(extension_id); |
1189 | 1182 |
1190 // For external extensions, we save a preference reminding ourself not to try | 1183 // For external extensions, we save a preference reminding ourself not to try |
1191 // and install the extension anymore (except when |external_uninstall| is | 1184 // and install the extension anymore (except when |external_uninstall| is |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1391 PopulateExtensionInfoPrefs(extension, | 1384 PopulateExtensionInfoPrefs(extension, |
1392 time_provider_->GetCurrentTime(), | 1385 time_provider_->GetCurrentTime(), |
1393 initial_state, | 1386 initial_state, |
1394 install_flags, | 1387 install_flags, |
1395 install_parameter, | 1388 install_parameter, |
1396 extension_dict); | 1389 extension_dict); |
1397 | 1390 |
1398 // Add transient data that is needed by FinishDelayedInstallInfo(), but | 1391 // Add transient data that is needed by FinishDelayedInstallInfo(), but |
1399 // should not be in the final extension prefs. All entries here should have | 1392 // should not be in the final extension prefs. All entries here should have |
1400 // a corresponding Remove() call in FinishDelayedInstallInfo(). | 1393 // a corresponding Remove() call in FinishDelayedInstallInfo(). |
1401 if (extension->RequiresSortOrdinal() && | 1394 if (extension->RequiresSortOrdinal()) { |
1402 (install_flags & kInstallFlagIsEphemeral) == 0) { | |
1403 extension_dict->SetString( | 1395 extension_dict->SetString( |
1404 kPrefSuggestedPageOrdinal, | 1396 kPrefSuggestedPageOrdinal, |
1405 page_ordinal.IsValid() ? page_ordinal.ToInternalValue() | 1397 page_ordinal.IsValid() ? page_ordinal.ToInternalValue() |
1406 : std::string()); | 1398 : std::string()); |
1407 } | 1399 } |
1408 extension_dict->SetInteger(kDelayedInstallReason, | 1400 extension_dict->SetInteger(kDelayedInstallReason, |
1409 static_cast<int>(delay_reason)); | 1401 static_cast<int>(delay_reason)); |
1410 | 1402 |
1411 UpdateExtensionPref(extension->id(), kDelayedInstallInfo, extension_dict); | 1403 UpdateExtensionPref(extension->id(), kDelayedInstallInfo, extension_dict); |
1412 } | 1404 } |
(...skipping 30 matching lines...) Expand all Loading... |
1443 pending_install_dict->Remove(kPrefSuggestedPageOrdinal, NULL); | 1435 pending_install_dict->Remove(kPrefSuggestedPageOrdinal, NULL); |
1444 } | 1436 } |
1445 pending_install_dict->Remove(kDelayedInstallReason, NULL); | 1437 pending_install_dict->Remove(kDelayedInstallReason, NULL); |
1446 | 1438 |
1447 const base::Time install_time = time_provider_->GetCurrentTime(); | 1439 const base::Time install_time = time_provider_->GetCurrentTime(); |
1448 pending_install_dict->Set( | 1440 pending_install_dict->Set( |
1449 kPrefInstallTime, | 1441 kPrefInstallTime, |
1450 new base::StringValue( | 1442 new base::StringValue( |
1451 base::Int64ToString(install_time.ToInternalValue()))); | 1443 base::Int64ToString(install_time.ToInternalValue()))); |
1452 | 1444 |
1453 // Some extension pref values are written conditionally. If they are not | |
1454 // present in the delayed install data, they should be removed when the | |
1455 // delayed install is committed. | |
1456 extension_dict->Remove(kPrefEphemeralApp, NULL); | |
1457 | |
1458 // Commit the delayed install data. | 1445 // Commit the delayed install data. |
1459 for (base::DictionaryValue::Iterator it(*pending_install_dict); !it.IsAtEnd(); | 1446 for (base::DictionaryValue::Iterator it(*pending_install_dict); !it.IsAtEnd(); |
1460 it.Advance()) { | 1447 it.Advance()) { |
1461 extension_dict->Set(it.key(), it.value().DeepCopy()); | 1448 extension_dict->Set(it.key(), it.value().DeepCopy()); |
1462 } | 1449 } |
1463 FinishExtensionInfoPrefs(extension_id, install_time, needs_sort_ordinal, | 1450 FinishExtensionInfoPrefs(extension_id, install_time, needs_sort_ordinal, |
1464 suggested_page_ordinal, extension_dict); | 1451 suggested_page_ordinal, extension_dict); |
1465 return true; | 1452 return true; |
1466 } | 1453 } |
1467 | 1454 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1509 continue; | 1496 continue; |
1510 | 1497 |
1511 scoped_ptr<ExtensionInfo> info = GetDelayedInstallInfo(extension_id.key()); | 1498 scoped_ptr<ExtensionInfo> info = GetDelayedInstallInfo(extension_id.key()); |
1512 if (info) | 1499 if (info) |
1513 extensions_info->push_back(linked_ptr<ExtensionInfo>(info.release())); | 1500 extensions_info->push_back(linked_ptr<ExtensionInfo>(info.release())); |
1514 } | 1501 } |
1515 | 1502 |
1516 return extensions_info.Pass(); | 1503 return extensions_info.Pass(); |
1517 } | 1504 } |
1518 | 1505 |
1519 bool ExtensionPrefs::IsEphemeralApp(const std::string& extension_id) const { | |
1520 if (ReadPrefAsBooleanAndReturn(extension_id, kPrefEphemeralApp)) | |
1521 return true; | |
1522 | |
1523 // Ephemerality was previously stored in the creation flags, so we must also | |
1524 // check it for backcompatibility. | |
1525 return (GetCreationFlags(extension_id) & Extension::IS_EPHEMERAL) != 0; | |
1526 } | |
1527 | |
1528 void ExtensionPrefs::OnEphemeralAppPromoted(const std::string& extension_id) { | |
1529 DCHECK(IsEphemeralApp(extension_id)); | |
1530 | |
1531 UpdateExtensionPref(extension_id, kPrefEphemeralApp, NULL); | |
1532 | |
1533 // Ephemerality was previously stored in the creation flags, so ensure the bit | |
1534 // is cleared. | |
1535 int creation_flags = Extension::NO_FLAGS; | |
1536 if (ReadPrefAsInteger(extension_id, kPrefCreationFlags, &creation_flags)) { | |
1537 if (creation_flags & Extension::IS_EPHEMERAL) { | |
1538 creation_flags &= ~static_cast<int>(Extension::IS_EPHEMERAL); | |
1539 UpdateExtensionPref(extension_id, | |
1540 kPrefCreationFlags, | |
1541 new base::FundamentalValue(creation_flags)); | |
1542 } | |
1543 } | |
1544 } | |
1545 | |
1546 bool ExtensionPrefs::WasAppDraggedByUser( | 1506 bool ExtensionPrefs::WasAppDraggedByUser( |
1547 const std::string& extension_id) const { | 1507 const std::string& extension_id) const { |
1548 return ReadPrefAsBooleanAndReturn(extension_id, kPrefUserDraggedApp); | 1508 return ReadPrefAsBooleanAndReturn(extension_id, kPrefUserDraggedApp); |
1549 } | 1509 } |
1550 | 1510 |
1551 void ExtensionPrefs::SetAppDraggedByUser(const std::string& extension_id) { | 1511 void ExtensionPrefs::SetAppDraggedByUser(const std::string& extension_id) { |
1552 UpdateExtensionPref(extension_id, kPrefUserDraggedApp, | 1512 UpdateExtensionPref(extension_id, kPrefUserDraggedApp, |
1553 new base::FundamentalValue(true)); | 1513 new base::FundamentalValue(true)); |
1554 } | 1514 } |
1555 | 1515 |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1987 new base::FundamentalValue(extension->was_installed_by_default())); | 1947 new base::FundamentalValue(extension->was_installed_by_default())); |
1988 extension_dict->Set( | 1948 extension_dict->Set( |
1989 kPrefWasInstalledByOem, | 1949 kPrefWasInstalledByOem, |
1990 new base::FundamentalValue(extension->was_installed_by_oem())); | 1950 new base::FundamentalValue(extension->was_installed_by_oem())); |
1991 extension_dict->Set(kPrefInstallTime, | 1951 extension_dict->Set(kPrefInstallTime, |
1992 new base::StringValue( | 1952 new base::StringValue( |
1993 base::Int64ToString(install_time.ToInternalValue()))); | 1953 base::Int64ToString(install_time.ToInternalValue()))); |
1994 if (install_flags & kInstallFlagIsBlacklistedForMalware) | 1954 if (install_flags & kInstallFlagIsBlacklistedForMalware) |
1995 extension_dict->Set(kPrefBlacklist, new base::FundamentalValue(true)); | 1955 extension_dict->Set(kPrefBlacklist, new base::FundamentalValue(true)); |
1996 | 1956 |
1997 if (install_flags & kInstallFlagIsEphemeral) | |
1998 extension_dict->Set(kPrefEphemeralApp, new base::FundamentalValue(true)); | |
1999 else | |
2000 extension_dict->Remove(kPrefEphemeralApp, NULL); | |
2001 | |
2002 base::FilePath::StringType path = MakePathRelative(install_directory_, | 1957 base::FilePath::StringType path = MakePathRelative(install_directory_, |
2003 extension->path()); | 1958 extension->path()); |
2004 extension_dict->Set(kPrefPath, new base::StringValue(path)); | 1959 extension_dict->Set(kPrefPath, new base::StringValue(path)); |
2005 if (!install_parameter.empty()) { | 1960 if (!install_parameter.empty()) { |
2006 extension_dict->Set(kPrefInstallParam, | 1961 extension_dict->Set(kPrefInstallParam, |
2007 new base::StringValue(install_parameter)); | 1962 new base::StringValue(install_parameter)); |
2008 } | 1963 } |
2009 // We store prefs about LOAD extensions, but don't cache their manifest | 1964 // We store prefs about LOAD extensions, but don't cache their manifest |
2010 // since it may change on disk. | 1965 // since it may change on disk. |
2011 if (!Manifest::IsUnpackedLocation(extension->location())) { | 1966 if (!Manifest::IsUnpackedLocation(extension->location())) { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2115 extension_pref_value_map_->RegisterExtension( | 2070 extension_pref_value_map_->RegisterExtension( |
2116 extension_id, install_time, is_enabled, is_incognito_enabled); | 2071 extension_id, install_time, is_enabled, is_incognito_enabled); |
2117 | 2072 |
2118 FOR_EACH_OBSERVER( | 2073 FOR_EACH_OBSERVER( |
2119 ExtensionPrefsObserver, | 2074 ExtensionPrefsObserver, |
2120 observer_list_, | 2075 observer_list_, |
2121 OnExtensionRegistered(extension_id, install_time, is_enabled)); | 2076 OnExtensionRegistered(extension_id, install_time, is_enabled)); |
2122 } | 2077 } |
2123 | 2078 |
2124 } // namespace extensions | 2079 } // namespace extensions |
OLD | NEW |