summaryrefslogtreecommitdiffstats
path: root/extensions/browser/extension_prefs.cc
diff options
context:
space:
mode:
authorrdevlin.cronin <rdevlin.cronin@chromium.org>2015-09-17 14:27:28 -0700
committerCommit bot <commit-bot@chromium.org>2015-09-17 21:29:05 +0000
commite01ec2c18b6206199b2d61ba1a4149f68f1be63f (patch)
treedd9097173fc7322fd0deb75381a6d6ea6359ab60 /extensions/browser/extension_prefs.cc
parent4dc350fb506b83d5ff62c0be8ac9a45ca20a1616 (diff)
downloadchromium_src-e01ec2c18b6206199b2d61ba1a4149f68f1be63f.zip
chromium_src-e01ec2c18b6206199b2d61ba1a4149f68f1be63f.tar.gz
chromium_src-e01ec2c18b6206199b2d61ba1a4149f68f1be63f.tar.bz2
[Extensions] Make methods return refptrs for PermissionSet
PermissionSet is refcounted (why is another issue), but multiple functions are returning raw pointers to constructed PermissionSets, which makes for ugly casts and potential leaks. Make all functions return refptrs. Review URL: https://codereview.chromium.org/1353543002 Cr-Commit-Position: refs/heads/master@{#349497}
Diffstat (limited to 'extensions/browser/extension_prefs.cc')
-rw-r--r--extensions/browser/extension_prefs.cc40
1 files changed, 17 insertions, 23 deletions
diff --git a/extensions/browser/extension_prefs.cc b/extensions/browser/extension_prefs.cc
index 57a4e05..c7a5aea 100644
--- a/extensions/browser/extension_prefs.cc
+++ b/extensions/browser/extension_prefs.cc
@@ -556,11 +556,11 @@ bool ExtensionPrefs::ReadPrefAsBooleanAndReturn(
return ReadPrefAsBoolean(extension_id, pref_key, &out_value) && out_value;
}
-PermissionSet* ExtensionPrefs::ReadPrefAsPermissionSet(
+scoped_refptr<const PermissionSet> ExtensionPrefs::ReadPrefAsPermissionSet(
const std::string& extension_id,
const std::string& pref_key) const {
if (!GetExtensionPref(extension_id))
- return NULL;
+ return nullptr;
// Retrieve the API permissions. Please refer SetExtensionPrefPermissionSet()
// for api_values format.
@@ -597,8 +597,8 @@ PermissionSet* ExtensionPrefs::ReadPrefAsPermissionSet(
extension_id, JoinPrefs(pref_key, kPrefScriptableHosts),
&scriptable_hosts, UserScript::ValidUserScriptSchemes());
- return new PermissionSet(
- apis, manifest_permissions, explicit_hosts, scriptable_hosts);
+ return make_scoped_refptr(new PermissionSet(
+ apis, manifest_permissions, explicit_hosts, scriptable_hosts));
}
// Set the API or Manifest permissions.
@@ -1014,7 +1014,7 @@ void ExtensionPrefs::MigrateDisableReasons(
}
}
-PermissionSet* ExtensionPrefs::GetGrantedPermissions(
+scoped_refptr<const PermissionSet> ExtensionPrefs::GetGrantedPermissions(
const std::string& extension_id) const {
CHECK(crx_file::id_util::IdIsValid(extension_id));
return ReadPrefAsPermissionSet(extension_id, kPrefGrantedPermissions);
@@ -1024,18 +1024,16 @@ void ExtensionPrefs::AddGrantedPermissions(
const std::string& extension_id,
const PermissionSet* permissions) {
CHECK(crx_file::id_util::IdIsValid(extension_id));
+ DCHECK(permissions);
- scoped_refptr<PermissionSet> granted_permissions(
- GetGrantedPermissions(extension_id));
-
+ scoped_refptr<const PermissionSet> granted =
+ GetGrantedPermissions(extension_id);
+ granted = granted.get() ? PermissionSet::CreateUnion(*permissions, *granted)
+ : permissions;
// The new granted permissions are the union of the already granted
// permissions and the newly granted permissions.
- scoped_refptr<PermissionSet> new_perms(
- PermissionSet::CreateUnion(
- permissions, granted_permissions.get()));
-
- SetExtensionPrefPermissionSet(
- extension_id, kPrefGrantedPermissions, new_perms.get());
+ SetExtensionPrefPermissionSet(extension_id, kPrefGrantedPermissions,
+ granted.get());
}
void ExtensionPrefs::RemoveGrantedPermissions(
@@ -1043,20 +1041,16 @@ void ExtensionPrefs::RemoveGrantedPermissions(
const PermissionSet* permissions) {
CHECK(crx_file::id_util::IdIsValid(extension_id));
- scoped_refptr<PermissionSet> granted_permissions(
- GetGrantedPermissions(extension_id));
-
// The new granted permissions are the difference of the already granted
// permissions and the newly ungranted permissions.
- scoped_refptr<PermissionSet> new_perms(
- PermissionSet::CreateDifference(
- granted_permissions.get(), permissions));
-
SetExtensionPrefPermissionSet(
- extension_id, kPrefGrantedPermissions, new_perms.get());
+ extension_id, kPrefGrantedPermissions,
+ PermissionSet::CreateDifference(*GetGrantedPermissions(extension_id),
+ *permissions)
+ .get());
}
-PermissionSet* ExtensionPrefs::GetActivePermissions(
+scoped_refptr<const PermissionSet> ExtensionPrefs::GetActivePermissions(
const std::string& extension_id) const {
CHECK(crx_file::id_util::IdIsValid(extension_id));
return ReadPrefAsPermissionSet(extension_id, kPrefActivePermissions);