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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <iterator> | 10 #include <iterator> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" |
14 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
17 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
19 #include "components/crx_file/id_util.h" | 20 #include "components/crx_file/id_util.h" |
20 #include "components/pref_registry/pref_registry_syncable.h" | 21 #include "components/pref_registry/pref_registry_syncable.h" |
21 #include "components/prefs/pref_service.h" | 22 #include "components/prefs/pref_service.h" |
22 #include "extensions/browser/app_sorting.h" | 23 #include "extensions/browser/app_sorting.h" |
23 #include "extensions/browser/event_router.h" | 24 #include "extensions/browser/event_router.h" |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 ExtensionPrefs* ExtensionPrefs::Create( | 327 ExtensionPrefs* ExtensionPrefs::Create( |
327 content::BrowserContext* browser_context, | 328 content::BrowserContext* browser_context, |
328 PrefService* prefs, | 329 PrefService* prefs, |
329 const base::FilePath& root_dir, | 330 const base::FilePath& root_dir, |
330 ExtensionPrefValueMap* extension_pref_value_map, | 331 ExtensionPrefValueMap* extension_pref_value_map, |
331 bool extensions_disabled, | 332 bool extensions_disabled, |
332 const std::vector<ExtensionPrefsObserver*>& early_observers) { | 333 const std::vector<ExtensionPrefsObserver*>& early_observers) { |
333 return ExtensionPrefs::Create(browser_context, prefs, root_dir, | 334 return ExtensionPrefs::Create(browser_context, prefs, root_dir, |
334 extension_pref_value_map, extensions_disabled, | 335 extension_pref_value_map, extensions_disabled, |
335 early_observers, | 336 early_observers, |
336 make_scoped_ptr(new TimeProvider())); | 337 base::WrapUnique(new TimeProvider())); |
337 } | 338 } |
338 | 339 |
339 // static | 340 // static |
340 ExtensionPrefs* ExtensionPrefs::Create( | 341 ExtensionPrefs* ExtensionPrefs::Create( |
341 content::BrowserContext* browser_context, | 342 content::BrowserContext* browser_context, |
342 PrefService* pref_service, | 343 PrefService* pref_service, |
343 const base::FilePath& root_dir, | 344 const base::FilePath& root_dir, |
344 ExtensionPrefValueMap* extension_pref_value_map, | 345 ExtensionPrefValueMap* extension_pref_value_map, |
345 bool extensions_disabled, | 346 bool extensions_disabled, |
346 const std::vector<ExtensionPrefsObserver*>& early_observers, | 347 const std::vector<ExtensionPrefsObserver*>& early_observers, |
347 scoped_ptr<TimeProvider> time_provider) { | 348 std::unique_ptr<TimeProvider> time_provider) { |
348 return new ExtensionPrefs(browser_context, pref_service, root_dir, | 349 return new ExtensionPrefs(browser_context, pref_service, root_dir, |
349 extension_pref_value_map, std::move(time_provider), | 350 extension_pref_value_map, std::move(time_provider), |
350 extensions_disabled, early_observers); | 351 extensions_disabled, early_observers); |
351 } | 352 } |
352 | 353 |
353 ExtensionPrefs::~ExtensionPrefs() { | 354 ExtensionPrefs::~ExtensionPrefs() { |
354 } | 355 } |
355 | 356 |
356 // static | 357 // static |
357 ExtensionPrefs* ExtensionPrefs::Get(content::BrowserContext* context) { | 358 ExtensionPrefs* ExtensionPrefs::Get(content::BrowserContext* context) { |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 UpdateExtensionPref(extension_id, pref_key, new_value.ToValue().release()); | 544 UpdateExtensionPref(extension_id, pref_key, new_value.ToValue().release()); |
544 } | 545 } |
545 | 546 |
546 bool ExtensionPrefs::ReadPrefAsBooleanAndReturn( | 547 bool ExtensionPrefs::ReadPrefAsBooleanAndReturn( |
547 const std::string& extension_id, | 548 const std::string& extension_id, |
548 const std::string& pref_key) const { | 549 const std::string& pref_key) const { |
549 bool out_value = false; | 550 bool out_value = false; |
550 return ReadPrefAsBoolean(extension_id, pref_key, &out_value) && out_value; | 551 return ReadPrefAsBoolean(extension_id, pref_key, &out_value) && out_value; |
551 } | 552 } |
552 | 553 |
553 scoped_ptr<const PermissionSet> ExtensionPrefs::ReadPrefAsPermissionSet( | 554 std::unique_ptr<const PermissionSet> ExtensionPrefs::ReadPrefAsPermissionSet( |
554 const std::string& extension_id, | 555 const std::string& extension_id, |
555 const std::string& pref_key) const { | 556 const std::string& pref_key) const { |
556 if (!GetExtensionPref(extension_id)) | 557 if (!GetExtensionPref(extension_id)) |
557 return nullptr; | 558 return nullptr; |
558 | 559 |
559 // Retrieve the API permissions. Please refer SetExtensionPrefPermissionSet() | 560 // Retrieve the API permissions. Please refer SetExtensionPrefPermissionSet() |
560 // for api_values format. | 561 // for api_values format. |
561 APIPermissionSet apis; | 562 APIPermissionSet apis; |
562 const base::ListValue* api_values = NULL; | 563 const base::ListValue* api_values = NULL; |
563 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); | 564 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); |
(...skipping 20 matching lines...) Expand all Loading... |
584 ReadPrefAsURLPatternSet( | 585 ReadPrefAsURLPatternSet( |
585 extension_id, JoinPrefs(pref_key, kPrefExplicitHosts), | 586 extension_id, JoinPrefs(pref_key, kPrefExplicitHosts), |
586 &explicit_hosts, Extension::kValidHostPermissionSchemes); | 587 &explicit_hosts, Extension::kValidHostPermissionSchemes); |
587 | 588 |
588 // Retrieve the scriptable host permissions. | 589 // Retrieve the scriptable host permissions. |
589 URLPatternSet scriptable_hosts; | 590 URLPatternSet scriptable_hosts; |
590 ReadPrefAsURLPatternSet( | 591 ReadPrefAsURLPatternSet( |
591 extension_id, JoinPrefs(pref_key, kPrefScriptableHosts), | 592 extension_id, JoinPrefs(pref_key, kPrefScriptableHosts), |
592 &scriptable_hosts, UserScript::ValidUserScriptSchemes()); | 593 &scriptable_hosts, UserScript::ValidUserScriptSchemes()); |
593 | 594 |
594 return make_scoped_ptr(new PermissionSet(apis, manifest_permissions, | 595 return base::WrapUnique(new PermissionSet(apis, manifest_permissions, |
595 explicit_hosts, scriptable_hosts)); | 596 explicit_hosts, scriptable_hosts)); |
596 } | 597 } |
597 | 598 |
598 // Set the API or Manifest permissions. | 599 // Set the API or Manifest permissions. |
599 // The format of api_values is: | 600 // The format of api_values is: |
600 // [ "permission_name1", // permissions do not support detail. | 601 // [ "permission_name1", // permissions do not support detail. |
601 // "permission_name2", | 602 // "permission_name2", |
602 // {"permission_name3": value }, | 603 // {"permission_name3": value }, |
603 // // permission supports detail, permission detail will be stored in value. | 604 // // permission supports detail, permission detail will be stored in value. |
604 // ... | 605 // ... |
605 // ] | 606 // ] |
606 template<typename T> | 607 template<typename T> |
607 static base::ListValue* CreatePermissionList(const T& permissions) { | 608 static base::ListValue* CreatePermissionList(const T& permissions) { |
608 base::ListValue* values = new base::ListValue(); | 609 base::ListValue* values = new base::ListValue(); |
609 for (typename T::const_iterator i = permissions.begin(); | 610 for (typename T::const_iterator i = permissions.begin(); |
610 i != permissions.end(); ++i) { | 611 i != permissions.end(); ++i) { |
611 scoped_ptr<base::Value> detail(i->ToValue()); | 612 std::unique_ptr<base::Value> detail(i->ToValue()); |
612 if (detail) { | 613 if (detail) { |
613 base::DictionaryValue* tmp = new base::DictionaryValue(); | 614 base::DictionaryValue* tmp = new base::DictionaryValue(); |
614 tmp->Set(i->name(), detail.release()); | 615 tmp->Set(i->name(), detail.release()); |
615 values->Append(tmp); | 616 values->Append(tmp); |
616 } else { | 617 } else { |
617 values->Append(new base::StringValue(i->name())); | 618 values->Append(new base::StringValue(i->name())); |
618 } | 619 } |
619 } | 620 } |
620 return values; | 621 return values; |
621 } | 622 } |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 return result; | 932 return result; |
932 return false; | 933 return false; |
933 } | 934 } |
934 | 935 |
935 void ExtensionPrefs::SetActiveBit(const std::string& extension_id, | 936 void ExtensionPrefs::SetActiveBit(const std::string& extension_id, |
936 bool active) { | 937 bool active) { |
937 UpdateExtensionPref(extension_id, kActiveBit, | 938 UpdateExtensionPref(extension_id, kActiveBit, |
938 new base::FundamentalValue(active)); | 939 new base::FundamentalValue(active)); |
939 } | 940 } |
940 | 941 |
941 scoped_ptr<const PermissionSet> ExtensionPrefs::GetGrantedPermissions( | 942 std::unique_ptr<const PermissionSet> ExtensionPrefs::GetGrantedPermissions( |
942 const std::string& extension_id) const { | 943 const std::string& extension_id) const { |
943 CHECK(crx_file::id_util::IdIsValid(extension_id)); | 944 CHECK(crx_file::id_util::IdIsValid(extension_id)); |
944 return ReadPrefAsPermissionSet(extension_id, kPrefGrantedPermissions); | 945 return ReadPrefAsPermissionSet(extension_id, kPrefGrantedPermissions); |
945 } | 946 } |
946 | 947 |
947 void ExtensionPrefs::AddGrantedPermissions(const std::string& extension_id, | 948 void ExtensionPrefs::AddGrantedPermissions(const std::string& extension_id, |
948 const PermissionSet& permissions) { | 949 const PermissionSet& permissions) { |
949 CHECK(crx_file::id_util::IdIsValid(extension_id)); | 950 CHECK(crx_file::id_util::IdIsValid(extension_id)); |
950 scoped_ptr<const PermissionSet> granted = GetGrantedPermissions(extension_id); | 951 std::unique_ptr<const PermissionSet> granted = |
951 scoped_ptr<const PermissionSet> union_set; | 952 GetGrantedPermissions(extension_id); |
| 953 std::unique_ptr<const PermissionSet> union_set; |
952 if (granted) | 954 if (granted) |
953 union_set = PermissionSet::CreateUnion(permissions, *granted); | 955 union_set = PermissionSet::CreateUnion(permissions, *granted); |
954 // The new granted permissions are the union of the already granted | 956 // The new granted permissions are the union of the already granted |
955 // permissions and the newly granted permissions. | 957 // permissions and the newly granted permissions. |
956 SetExtensionPrefPermissionSet(extension_id, kPrefGrantedPermissions, | 958 SetExtensionPrefPermissionSet(extension_id, kPrefGrantedPermissions, |
957 union_set ? *union_set : permissions); | 959 union_set ? *union_set : permissions); |
958 } | 960 } |
959 | 961 |
960 void ExtensionPrefs::RemoveGrantedPermissions( | 962 void ExtensionPrefs::RemoveGrantedPermissions( |
961 const std::string& extension_id, | 963 const std::string& extension_id, |
962 const PermissionSet& permissions) { | 964 const PermissionSet& permissions) { |
963 CHECK(crx_file::id_util::IdIsValid(extension_id)); | 965 CHECK(crx_file::id_util::IdIsValid(extension_id)); |
964 | 966 |
965 // The new granted permissions are the difference of the already granted | 967 // The new granted permissions are the difference of the already granted |
966 // permissions and the newly ungranted permissions. | 968 // permissions and the newly ungranted permissions. |
967 SetExtensionPrefPermissionSet( | 969 SetExtensionPrefPermissionSet( |
968 extension_id, kPrefGrantedPermissions, | 970 extension_id, kPrefGrantedPermissions, |
969 *PermissionSet::CreateDifference(*GetGrantedPermissions(extension_id), | 971 *PermissionSet::CreateDifference(*GetGrantedPermissions(extension_id), |
970 permissions)); | 972 permissions)); |
971 } | 973 } |
972 | 974 |
973 scoped_ptr<const PermissionSet> ExtensionPrefs::GetActivePermissions( | 975 std::unique_ptr<const PermissionSet> ExtensionPrefs::GetActivePermissions( |
974 const std::string& extension_id) const { | 976 const std::string& extension_id) const { |
975 CHECK(crx_file::id_util::IdIsValid(extension_id)); | 977 CHECK(crx_file::id_util::IdIsValid(extension_id)); |
976 return ReadPrefAsPermissionSet(extension_id, kPrefActivePermissions); | 978 return ReadPrefAsPermissionSet(extension_id, kPrefActivePermissions); |
977 } | 979 } |
978 | 980 |
979 void ExtensionPrefs::SetActivePermissions(const std::string& extension_id, | 981 void ExtensionPrefs::SetActivePermissions(const std::string& extension_id, |
980 const PermissionSet& permissions) { | 982 const PermissionSet& permissions) { |
981 SetExtensionPrefPermissionSet( | 983 SetExtensionPrefPermissionSet( |
982 extension_id, kPrefActivePermissions, permissions); | 984 extension_id, kPrefActivePermissions, permissions); |
983 } | 985 } |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1179 bool update_required = | 1181 bool update_required = |
1180 !extension_dict->GetDictionary(kPrefManifest, &old_manifest) || | 1182 !extension_dict->GetDictionary(kPrefManifest, &old_manifest) || |
1181 !extension->manifest()->value()->Equals(old_manifest); | 1183 !extension->manifest()->value()->Equals(old_manifest); |
1182 if (update_required) { | 1184 if (update_required) { |
1183 UpdateExtensionPref(extension->id(), kPrefManifest, | 1185 UpdateExtensionPref(extension->id(), kPrefManifest, |
1184 extension->manifest()->value()->DeepCopy()); | 1186 extension->manifest()->value()->DeepCopy()); |
1185 } | 1187 } |
1186 } | 1188 } |
1187 } | 1189 } |
1188 | 1190 |
1189 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledInfoHelper( | 1191 std::unique_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledInfoHelper( |
1190 const std::string& extension_id, | 1192 const std::string& extension_id, |
1191 const base::DictionaryValue* extension) const { | 1193 const base::DictionaryValue* extension) const { |
1192 int location_value; | 1194 int location_value; |
1193 if (!extension->GetInteger(kPrefLocation, &location_value)) | 1195 if (!extension->GetInteger(kPrefLocation, &location_value)) |
1194 return scoped_ptr<ExtensionInfo>(); | 1196 return std::unique_ptr<ExtensionInfo>(); |
1195 | 1197 |
1196 Manifest::Location location = static_cast<Manifest::Location>(location_value); | 1198 Manifest::Location location = static_cast<Manifest::Location>(location_value); |
1197 if (location == Manifest::COMPONENT) { | 1199 if (location == Manifest::COMPONENT) { |
1198 // Component extensions are ignored. Component extensions may have data | 1200 // Component extensions are ignored. Component extensions may have data |
1199 // saved in preferences, but they are already loaded at this point (by | 1201 // saved in preferences, but they are already loaded at this point (by |
1200 // ComponentLoader) and shouldn't be populated into the result of | 1202 // ComponentLoader) and shouldn't be populated into the result of |
1201 // GetInstalledExtensionsInfo, otherwise InstalledLoader would also want to | 1203 // GetInstalledExtensionsInfo, otherwise InstalledLoader would also want to |
1202 // load them. | 1204 // load them. |
1203 return scoped_ptr<ExtensionInfo>(); | 1205 return std::unique_ptr<ExtensionInfo>(); |
1204 } | 1206 } |
1205 | 1207 |
1206 // Only the following extension types have data saved in the preferences. | 1208 // Only the following extension types have data saved in the preferences. |
1207 if (location != Manifest::INTERNAL && | 1209 if (location != Manifest::INTERNAL && |
1208 !Manifest::IsUnpackedLocation(location) && | 1210 !Manifest::IsUnpackedLocation(location) && |
1209 !Manifest::IsExternalLocation(location)) { | 1211 !Manifest::IsExternalLocation(location)) { |
1210 NOTREACHED(); | 1212 NOTREACHED(); |
1211 return scoped_ptr<ExtensionInfo>(); | 1213 return std::unique_ptr<ExtensionInfo>(); |
1212 } | 1214 } |
1213 | 1215 |
1214 const base::DictionaryValue* manifest = NULL; | 1216 const base::DictionaryValue* manifest = NULL; |
1215 if (!Manifest::IsUnpackedLocation(location) && | 1217 if (!Manifest::IsUnpackedLocation(location) && |
1216 !extension->GetDictionary(kPrefManifest, &manifest)) { | 1218 !extension->GetDictionary(kPrefManifest, &manifest)) { |
1217 LOG(WARNING) << "Missing manifest for extension " << extension_id; | 1219 LOG(WARNING) << "Missing manifest for extension " << extension_id; |
1218 // Just a warning for now. | 1220 // Just a warning for now. |
1219 } | 1221 } |
1220 | 1222 |
1221 base::FilePath::StringType path; | 1223 base::FilePath::StringType path; |
1222 if (!extension->GetString(kPrefPath, &path)) | 1224 if (!extension->GetString(kPrefPath, &path)) |
1223 return scoped_ptr<ExtensionInfo>(); | 1225 return std::unique_ptr<ExtensionInfo>(); |
1224 | 1226 |
1225 // Make path absolute. Most (but not all) extension types have relative paths. | 1227 // Make path absolute. Most (but not all) extension types have relative paths. |
1226 if (!base::FilePath(path).IsAbsolute()) | 1228 if (!base::FilePath(path).IsAbsolute()) |
1227 path = install_directory_.Append(path).value(); | 1229 path = install_directory_.Append(path).value(); |
1228 | 1230 |
1229 return scoped_ptr<ExtensionInfo>(new ExtensionInfo( | 1231 return std::unique_ptr<ExtensionInfo>(new ExtensionInfo( |
1230 manifest, extension_id, base::FilePath(path), location)); | 1232 manifest, extension_id, base::FilePath(path), location)); |
1231 } | 1233 } |
1232 | 1234 |
1233 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledExtensionInfo( | 1235 std::unique_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledExtensionInfo( |
1234 const std::string& extension_id) const { | 1236 const std::string& extension_id) const { |
1235 const base::DictionaryValue* ext = NULL; | 1237 const base::DictionaryValue* ext = NULL; |
1236 const base::DictionaryValue* extensions = | 1238 const base::DictionaryValue* extensions = |
1237 prefs_->GetDictionary(pref_names::kExtensions); | 1239 prefs_->GetDictionary(pref_names::kExtensions); |
1238 if (!extensions || | 1240 if (!extensions || |
1239 !extensions->GetDictionaryWithoutPathExpansion(extension_id, &ext)) | 1241 !extensions->GetDictionaryWithoutPathExpansion(extension_id, &ext)) |
1240 return scoped_ptr<ExtensionInfo>(); | 1242 return std::unique_ptr<ExtensionInfo>(); |
1241 int state_value; | 1243 int state_value; |
1242 if (ext->GetInteger(kPrefState, &state_value) && | 1244 if (ext->GetInteger(kPrefState, &state_value) && |
1243 state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) { | 1245 state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) { |
1244 LOG(WARNING) << "External extension with id " << extension_id | 1246 LOG(WARNING) << "External extension with id " << extension_id |
1245 << " has been uninstalled by the user"; | 1247 << " has been uninstalled by the user"; |
1246 return scoped_ptr<ExtensionInfo>(); | 1248 return std::unique_ptr<ExtensionInfo>(); |
1247 } | 1249 } |
1248 | 1250 |
1249 return GetInstalledInfoHelper(extension_id, ext); | 1251 return GetInstalledInfoHelper(extension_id, ext); |
1250 } | 1252 } |
1251 | 1253 |
1252 scoped_ptr<ExtensionPrefs::ExtensionsInfo> | 1254 std::unique_ptr<ExtensionPrefs::ExtensionsInfo> |
1253 ExtensionPrefs::GetInstalledExtensionsInfo() const { | 1255 ExtensionPrefs::GetInstalledExtensionsInfo() const { |
1254 scoped_ptr<ExtensionsInfo> extensions_info(new ExtensionsInfo); | 1256 std::unique_ptr<ExtensionsInfo> extensions_info(new ExtensionsInfo); |
1255 | 1257 |
1256 const base::DictionaryValue* extensions = | 1258 const base::DictionaryValue* extensions = |
1257 prefs_->GetDictionary(pref_names::kExtensions); | 1259 prefs_->GetDictionary(pref_names::kExtensions); |
1258 for (base::DictionaryValue::Iterator extension_id(*extensions); | 1260 for (base::DictionaryValue::Iterator extension_id(*extensions); |
1259 !extension_id.IsAtEnd(); extension_id.Advance()) { | 1261 !extension_id.IsAtEnd(); extension_id.Advance()) { |
1260 if (!crx_file::id_util::IdIsValid(extension_id.key())) | 1262 if (!crx_file::id_util::IdIsValid(extension_id.key())) |
1261 continue; | 1263 continue; |
1262 | 1264 |
1263 scoped_ptr<ExtensionInfo> info = | 1265 std::unique_ptr<ExtensionInfo> info = |
1264 GetInstalledExtensionInfo(extension_id.key()); | 1266 GetInstalledExtensionInfo(extension_id.key()); |
1265 if (info) | 1267 if (info) |
1266 extensions_info->push_back(linked_ptr<ExtensionInfo>(info.release())); | 1268 extensions_info->push_back(linked_ptr<ExtensionInfo>(info.release())); |
1267 } | 1269 } |
1268 | 1270 |
1269 return extensions_info; | 1271 return extensions_info; |
1270 } | 1272 } |
1271 | 1273 |
1272 scoped_ptr<ExtensionPrefs::ExtensionsInfo> | 1274 std::unique_ptr<ExtensionPrefs::ExtensionsInfo> |
1273 ExtensionPrefs::GetUninstalledExtensionsInfo() const { | 1275 ExtensionPrefs::GetUninstalledExtensionsInfo() const { |
1274 scoped_ptr<ExtensionsInfo> extensions_info(new ExtensionsInfo); | 1276 std::unique_ptr<ExtensionsInfo> extensions_info(new ExtensionsInfo); |
1275 | 1277 |
1276 const base::DictionaryValue* extensions = | 1278 const base::DictionaryValue* extensions = |
1277 prefs_->GetDictionary(pref_names::kExtensions); | 1279 prefs_->GetDictionary(pref_names::kExtensions); |
1278 for (base::DictionaryValue::Iterator extension_id(*extensions); | 1280 for (base::DictionaryValue::Iterator extension_id(*extensions); |
1279 !extension_id.IsAtEnd(); extension_id.Advance()) { | 1281 !extension_id.IsAtEnd(); extension_id.Advance()) { |
1280 const base::DictionaryValue* ext = NULL; | 1282 const base::DictionaryValue* ext = NULL; |
1281 if (!crx_file::id_util::IdIsValid(extension_id.key()) || | 1283 if (!crx_file::id_util::IdIsValid(extension_id.key()) || |
1282 !IsExternalExtensionUninstalled(extension_id.key()) || | 1284 !IsExternalExtensionUninstalled(extension_id.key()) || |
1283 !extension_id.value().GetAsDictionary(&ext)) | 1285 !extension_id.value().GetAsDictionary(&ext)) |
1284 continue; | 1286 continue; |
1285 | 1287 |
1286 scoped_ptr<ExtensionInfo> info = | 1288 std::unique_ptr<ExtensionInfo> info = |
1287 GetInstalledInfoHelper(extension_id.key(), ext); | 1289 GetInstalledInfoHelper(extension_id.key(), ext); |
1288 if (info) | 1290 if (info) |
1289 extensions_info->push_back(linked_ptr<ExtensionInfo>(info.release())); | 1291 extensions_info->push_back(linked_ptr<ExtensionInfo>(info.release())); |
1290 } | 1292 } |
1291 | 1293 |
1292 return extensions_info; | 1294 return extensions_info; |
1293 } | 1295 } |
1294 | 1296 |
1295 void ExtensionPrefs::SetDelayedInstallInfo( | 1297 void ExtensionPrefs::SetDelayedInstallInfo( |
1296 const Extension* extension, | 1298 const Extension* extension, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 // Commit the delayed install data. | 1366 // Commit the delayed install data. |
1365 for (base::DictionaryValue::Iterator it(*pending_install_dict); !it.IsAtEnd(); | 1367 for (base::DictionaryValue::Iterator it(*pending_install_dict); !it.IsAtEnd(); |
1366 it.Advance()) { | 1368 it.Advance()) { |
1367 extension_dict->Set(it.key(), it.value().DeepCopy()); | 1369 extension_dict->Set(it.key(), it.value().DeepCopy()); |
1368 } | 1370 } |
1369 FinishExtensionInfoPrefs(extension_id, install_time, needs_sort_ordinal, | 1371 FinishExtensionInfoPrefs(extension_id, install_time, needs_sort_ordinal, |
1370 suggested_page_ordinal, extension_dict); | 1372 suggested_page_ordinal, extension_dict); |
1371 return true; | 1373 return true; |
1372 } | 1374 } |
1373 | 1375 |
1374 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetDelayedInstallInfo( | 1376 std::unique_ptr<ExtensionInfo> ExtensionPrefs::GetDelayedInstallInfo( |
1375 const std::string& extension_id) const { | 1377 const std::string& extension_id) const { |
1376 const base::DictionaryValue* extension_prefs = | 1378 const base::DictionaryValue* extension_prefs = |
1377 GetExtensionPref(extension_id); | 1379 GetExtensionPref(extension_id); |
1378 if (!extension_prefs) | 1380 if (!extension_prefs) |
1379 return scoped_ptr<ExtensionInfo>(); | 1381 return std::unique_ptr<ExtensionInfo>(); |
1380 | 1382 |
1381 const base::DictionaryValue* ext = NULL; | 1383 const base::DictionaryValue* ext = NULL; |
1382 if (!extension_prefs->GetDictionary(kDelayedInstallInfo, &ext)) | 1384 if (!extension_prefs->GetDictionary(kDelayedInstallInfo, &ext)) |
1383 return scoped_ptr<ExtensionInfo>(); | 1385 return std::unique_ptr<ExtensionInfo>(); |
1384 | 1386 |
1385 return GetInstalledInfoHelper(extension_id, ext); | 1387 return GetInstalledInfoHelper(extension_id, ext); |
1386 } | 1388 } |
1387 | 1389 |
1388 ExtensionPrefs::DelayReason ExtensionPrefs::GetDelayedInstallReason( | 1390 ExtensionPrefs::DelayReason ExtensionPrefs::GetDelayedInstallReason( |
1389 const std::string& extension_id) const { | 1391 const std::string& extension_id) const { |
1390 const base::DictionaryValue* extension_prefs = | 1392 const base::DictionaryValue* extension_prefs = |
1391 GetExtensionPref(extension_id); | 1393 GetExtensionPref(extension_id); |
1392 if (!extension_prefs) | 1394 if (!extension_prefs) |
1393 return DELAY_REASON_NONE; | 1395 return DELAY_REASON_NONE; |
1394 | 1396 |
1395 const base::DictionaryValue* ext = NULL; | 1397 const base::DictionaryValue* ext = NULL; |
1396 if (!extension_prefs->GetDictionary(kDelayedInstallInfo, &ext)) | 1398 if (!extension_prefs->GetDictionary(kDelayedInstallInfo, &ext)) |
1397 return DELAY_REASON_NONE; | 1399 return DELAY_REASON_NONE; |
1398 | 1400 |
1399 int delay_reason; | 1401 int delay_reason; |
1400 if (!ext->GetInteger(kDelayedInstallReason, &delay_reason)) | 1402 if (!ext->GetInteger(kDelayedInstallReason, &delay_reason)) |
1401 return DELAY_REASON_NONE; | 1403 return DELAY_REASON_NONE; |
1402 | 1404 |
1403 return static_cast<DelayReason>(delay_reason); | 1405 return static_cast<DelayReason>(delay_reason); |
1404 } | 1406 } |
1405 | 1407 |
1406 scoped_ptr<ExtensionPrefs::ExtensionsInfo> ExtensionPrefs:: | 1408 std::unique_ptr<ExtensionPrefs::ExtensionsInfo> |
1407 GetAllDelayedInstallInfo() const { | 1409 ExtensionPrefs::GetAllDelayedInstallInfo() const { |
1408 scoped_ptr<ExtensionsInfo> extensions_info(new ExtensionsInfo); | 1410 std::unique_ptr<ExtensionsInfo> extensions_info(new ExtensionsInfo); |
1409 | 1411 |
1410 const base::DictionaryValue* extensions = | 1412 const base::DictionaryValue* extensions = |
1411 prefs_->GetDictionary(pref_names::kExtensions); | 1413 prefs_->GetDictionary(pref_names::kExtensions); |
1412 for (base::DictionaryValue::Iterator extension_id(*extensions); | 1414 for (base::DictionaryValue::Iterator extension_id(*extensions); |
1413 !extension_id.IsAtEnd(); extension_id.Advance()) { | 1415 !extension_id.IsAtEnd(); extension_id.Advance()) { |
1414 if (!crx_file::id_util::IdIsValid(extension_id.key())) | 1416 if (!crx_file::id_util::IdIsValid(extension_id.key())) |
1415 continue; | 1417 continue; |
1416 | 1418 |
1417 scoped_ptr<ExtensionInfo> info = GetDelayedInstallInfo(extension_id.key()); | 1419 std::unique_ptr<ExtensionInfo> info = |
| 1420 GetDelayedInstallInfo(extension_id.key()); |
1418 if (info) | 1421 if (info) |
1419 extensions_info->push_back(linked_ptr<ExtensionInfo>(info.release())); | 1422 extensions_info->push_back(linked_ptr<ExtensionInfo>(info.release())); |
1420 } | 1423 } |
1421 | 1424 |
1422 return extensions_info; | 1425 return extensions_info; |
1423 } | 1426 } |
1424 | 1427 |
1425 bool ExtensionPrefs::WasAppDraggedByUser( | 1428 bool ExtensionPrefs::WasAppDraggedByUser( |
1426 const std::string& extension_id) const { | 1429 const std::string& extension_id) const { |
1427 return ReadPrefAsBooleanAndReturn(extension_id, kPrefUserDraggedApp); | 1430 return ReadPrefAsBooleanAndReturn(extension_id, kPrefUserDraggedApp); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1557 continue; | 1560 continue; |
1558 | 1561 |
1559 if (extension_dict->HasKey(kPrefLastLaunchTime)) | 1562 if (extension_dict->HasKey(kPrefLastLaunchTime)) |
1560 extension_dict->Remove(kPrefLastLaunchTime, NULL); | 1563 extension_dict->Remove(kPrefLastLaunchTime, NULL); |
1561 } | 1564 } |
1562 } | 1565 } |
1563 | 1566 |
1564 void ExtensionPrefs::GetExtensions(ExtensionIdList* out) const { | 1567 void ExtensionPrefs::GetExtensions(ExtensionIdList* out) const { |
1565 CHECK(out); | 1568 CHECK(out); |
1566 | 1569 |
1567 scoped_ptr<ExtensionsInfo> extensions_info(GetInstalledExtensionsInfo()); | 1570 std::unique_ptr<ExtensionsInfo> extensions_info(GetInstalledExtensionsInfo()); |
1568 | 1571 |
1569 for (size_t i = 0; i < extensions_info->size(); ++i) { | 1572 for (size_t i = 0; i < extensions_info->size(); ++i) { |
1570 ExtensionInfo* info = extensions_info->at(i).get(); | 1573 ExtensionInfo* info = extensions_info->at(i).get(); |
1571 out->push_back(info->extension_id); | 1574 out->push_back(info->extension_id); |
1572 } | 1575 } |
1573 } | 1576 } |
1574 | 1577 |
1575 // static | 1578 // static |
1576 ExtensionIdList ExtensionPrefs::GetExtensionsFrom( | 1579 ExtensionIdList ExtensionPrefs::GetExtensionsFrom( |
1577 const PrefService* pref_service) { | 1580 const PrefService* pref_service) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1652 | 1655 |
1653 const base::DictionaryValue* ext = NULL; | 1656 const base::DictionaryValue* ext = NULL; |
1654 if (!extension_prefs->GetDictionary(kPrefGeometryCache, &ext)) | 1657 if (!extension_prefs->GetDictionary(kPrefGeometryCache, &ext)) |
1655 return NULL; | 1658 return NULL; |
1656 | 1659 |
1657 return ext; | 1660 return ext; |
1658 } | 1661 } |
1659 | 1662 |
1660 void ExtensionPrefs::SetGeometryCache( | 1663 void ExtensionPrefs::SetGeometryCache( |
1661 const std::string& extension_id, | 1664 const std::string& extension_id, |
1662 scoped_ptr<base::DictionaryValue> cache) { | 1665 std::unique_ptr<base::DictionaryValue> cache) { |
1663 UpdateExtensionPref(extension_id, kPrefGeometryCache, cache.release()); | 1666 UpdateExtensionPref(extension_id, kPrefGeometryCache, cache.release()); |
1664 } | 1667 } |
1665 | 1668 |
1666 const base::DictionaryValue* ExtensionPrefs::GetInstallSignature() const { | 1669 const base::DictionaryValue* ExtensionPrefs::GetInstallSignature() const { |
1667 return prefs_->GetDictionary(kInstallSignature); | 1670 return prefs_->GetDictionary(kInstallSignature); |
1668 } | 1671 } |
1669 | 1672 |
1670 void ExtensionPrefs::SetInstallSignature( | 1673 void ExtensionPrefs::SetInstallSignature( |
1671 const base::DictionaryValue* signature) { | 1674 const base::DictionaryValue* signature) { |
1672 if (signature) { | 1675 if (signature) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1713 bool needs_sync) { | 1716 bool needs_sync) { |
1714 UpdateExtensionPref(extension_id, kPrefNeedsSync, | 1717 UpdateExtensionPref(extension_id, kPrefNeedsSync, |
1715 needs_sync ? new base::FundamentalValue(true) : nullptr); | 1718 needs_sync ? new base::FundamentalValue(true) : nullptr); |
1716 } | 1719 } |
1717 | 1720 |
1718 ExtensionPrefs::ExtensionPrefs( | 1721 ExtensionPrefs::ExtensionPrefs( |
1719 content::BrowserContext* browser_context, | 1722 content::BrowserContext* browser_context, |
1720 PrefService* prefs, | 1723 PrefService* prefs, |
1721 const base::FilePath& root_dir, | 1724 const base::FilePath& root_dir, |
1722 ExtensionPrefValueMap* extension_pref_value_map, | 1725 ExtensionPrefValueMap* extension_pref_value_map, |
1723 scoped_ptr<TimeProvider> time_provider, | 1726 std::unique_ptr<TimeProvider> time_provider, |
1724 bool extensions_disabled, | 1727 bool extensions_disabled, |
1725 const std::vector<ExtensionPrefsObserver*>& early_observers) | 1728 const std::vector<ExtensionPrefsObserver*>& early_observers) |
1726 : browser_context_(browser_context), | 1729 : browser_context_(browser_context), |
1727 prefs_(prefs), | 1730 prefs_(prefs), |
1728 install_directory_(root_dir), | 1731 install_directory_(root_dir), |
1729 extension_pref_value_map_(extension_pref_value_map), | 1732 extension_pref_value_map_(extension_pref_value_map), |
1730 time_provider_(std::move(time_provider)), | 1733 time_provider_(std::move(time_provider)), |
1731 extensions_disabled_(extensions_disabled) { | 1734 extensions_disabled_(extensions_disabled) { |
1732 MakePathsRelative(); | 1735 MakePathsRelative(); |
1733 | 1736 |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1966 extension_pref_value_map_->RegisterExtension( | 1969 extension_pref_value_map_->RegisterExtension( |
1967 extension_id, install_time, is_enabled, is_incognito_enabled); | 1970 extension_id, install_time, is_enabled, is_incognito_enabled); |
1968 | 1971 |
1969 FOR_EACH_OBSERVER( | 1972 FOR_EACH_OBSERVER( |
1970 ExtensionPrefsObserver, | 1973 ExtensionPrefsObserver, |
1971 observer_list_, | 1974 observer_list_, |
1972 OnExtensionRegistered(extension_id, install_time, is_enabled)); | 1975 OnExtensionRegistered(extension_id, install_time, is_enabled)); |
1973 } | 1976 } |
1974 | 1977 |
1975 } // namespace extensions | 1978 } // namespace extensions |
OLD | NEW |