summaryrefslogtreecommitdiffstats
path: root/extensions/common/permissions
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/common/permissions
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/common/permissions')
-rw-r--r--extensions/common/permissions/permission_set.cc66
-rw-r--r--extensions/common/permissions/permission_set.h21
-rw-r--r--extensions/common/permissions/permissions_data.cc3
3 files changed, 39 insertions, 51 deletions
diff --git a/extensions/common/permissions/permission_set.cc b/extensions/common/permissions/permission_set.cc
index 4687102..5cd8d05 100644
--- a/extensions/common/permissions/permission_set.cc
+++ b/extensions/common/permissions/permission_set.cc
@@ -44,77 +44,65 @@ PermissionSet::PermissionSet(
}
// static
-PermissionSet* PermissionSet::CreateDifference(
- const PermissionSet* set1,
- const PermissionSet* set2) {
- scoped_refptr<PermissionSet> empty = new PermissionSet();
- const PermissionSet* set1_safe = (set1 == NULL) ? empty.get() : set1;
- const PermissionSet* set2_safe = (set2 == NULL) ? empty.get() : set2;
-
+scoped_refptr<const PermissionSet> PermissionSet::CreateDifference(
+ const PermissionSet& set1,
+ const PermissionSet& set2) {
APIPermissionSet apis;
- APIPermissionSet::Difference(set1_safe->apis(), set2_safe->apis(), &apis);
+ APIPermissionSet::Difference(set1.apis(), set2.apis(), &apis);
ManifestPermissionSet manifest_permissions;
- ManifestPermissionSet::Difference(set1_safe->manifest_permissions(),
- set2_safe->manifest_permissions(),
+ ManifestPermissionSet::Difference(set1.manifest_permissions(),
+ set2.manifest_permissions(),
&manifest_permissions);
URLPatternSet explicit_hosts = URLPatternSet::CreateDifference(
- set1_safe->explicit_hosts(), set2_safe->explicit_hosts());
+ set1.explicit_hosts(), set2.explicit_hosts());
URLPatternSet scriptable_hosts = URLPatternSet::CreateDifference(
- set1_safe->scriptable_hosts(), set2_safe->scriptable_hosts());
+ set1.scriptable_hosts(), set2.scriptable_hosts());
- return new PermissionSet(apis, manifest_permissions,
- explicit_hosts, scriptable_hosts);
+ return make_scoped_refptr(new PermissionSet(
+ apis, manifest_permissions, explicit_hosts, scriptable_hosts));
}
// static
-PermissionSet* PermissionSet::CreateIntersection(
- const PermissionSet* set1,
- const PermissionSet* set2) {
- scoped_refptr<PermissionSet> empty = new PermissionSet();
- const PermissionSet* set1_safe = (set1 == NULL) ? empty.get() : set1;
- const PermissionSet* set2_safe = (set2 == NULL) ? empty.get() : set2;
-
+scoped_refptr<const PermissionSet> PermissionSet::CreateIntersection(
+ const PermissionSet& set1,
+ const PermissionSet& set2) {
APIPermissionSet apis;
- APIPermissionSet::Intersection(set1_safe->apis(), set2_safe->apis(), &apis);
+ APIPermissionSet::Intersection(set1.apis(), set2.apis(), &apis);
ManifestPermissionSet manifest_permissions;
- ManifestPermissionSet::Intersection(set1_safe->manifest_permissions(),
- set2_safe->manifest_permissions(),
+ ManifestPermissionSet::Intersection(set1.manifest_permissions(),
+ set2.manifest_permissions(),
&manifest_permissions);
URLPatternSet explicit_hosts = URLPatternSet::CreateSemanticIntersection(
- set1_safe->explicit_hosts(), set2_safe->explicit_hosts());
+ set1.explicit_hosts(), set2.explicit_hosts());
URLPatternSet scriptable_hosts = URLPatternSet::CreateSemanticIntersection(
- set1_safe->scriptable_hosts(), set2_safe->scriptable_hosts());
+ set1.scriptable_hosts(), set2.scriptable_hosts());
return new PermissionSet(apis, manifest_permissions,
explicit_hosts, scriptable_hosts);
}
// static
-PermissionSet* PermissionSet::CreateUnion(
- const PermissionSet* set1,
- const PermissionSet* set2) {
- scoped_refptr<PermissionSet> empty = new PermissionSet();
- const PermissionSet* set1_safe = (set1 == NULL) ? empty.get() : set1;
- const PermissionSet* set2_safe = (set2 == NULL) ? empty.get() : set2;
-
+scoped_refptr<const PermissionSet> PermissionSet::CreateUnion(
+ const PermissionSet& set1,
+ const PermissionSet& set2) {
APIPermissionSet apis;
- APIPermissionSet::Union(set1_safe->apis(), set2_safe->apis(), &apis);
+ APIPermissionSet::Union(set1.apis(), set2.apis(), &apis);
ManifestPermissionSet manifest_permissions;
- ManifestPermissionSet::Union(set1_safe->manifest_permissions(),
- set2_safe->manifest_permissions(),
+ ManifestPermissionSet::Union(set1.manifest_permissions(),
+ set2.manifest_permissions(),
&manifest_permissions);
- URLPatternSet explicit_hosts = URLPatternSet::CreateUnion(
- set1_safe->explicit_hosts(), set2_safe->explicit_hosts());
+ URLPatternSet explicit_hosts =
+ URLPatternSet::CreateUnion(set1.explicit_hosts(), set2.explicit_hosts());
URLPatternSet scriptable_hosts = URLPatternSet::CreateUnion(
- set1_safe->scriptable_hosts(), set2_safe->scriptable_hosts());
+ set1.scriptable_hosts(), set2.scriptable_hosts());
return new PermissionSet(apis, manifest_permissions,
explicit_hosts, scriptable_hosts);
diff --git a/extensions/common/permissions/permission_set.h b/extensions/common/permissions/permission_set.h
index e7b5311..a6c62be 100644
--- a/extensions/common/permissions/permission_set.h
+++ b/extensions/common/permissions/permission_set.h
@@ -40,20 +40,21 @@ class PermissionSet
const URLPatternSet& explicit_hosts,
const URLPatternSet& scriptable_hosts);
- // Creates a new permission set equal to |set1| - |set2|, passing ownership of
- // the new set to the caller.
- static PermissionSet* CreateDifference(
- const PermissionSet* set1, const PermissionSet* set2);
+ // Creates a new permission set equal to |set1| - |set2|.
+ static scoped_refptr<const PermissionSet> CreateDifference(
+ const PermissionSet& set1,
+ const PermissionSet& set2);
// Creates a new permission set equal to the intersection of |set1| and
- // |set2|, passing ownership of the new set to the caller.
- static PermissionSet* CreateIntersection(
- const PermissionSet* set1, const PermissionSet* set2);
+ // |set2|.
+ static scoped_refptr<const PermissionSet> CreateIntersection(
+ const PermissionSet& set1,
+ const PermissionSet& set2);
// Creates a new permission set equal to the union of |set1| and |set2|.
- // Passes ownership of the new set to the caller.
- static PermissionSet* CreateUnion(
- const PermissionSet* set1, const PermissionSet* set2);
+ static scoped_refptr<const PermissionSet> CreateUnion(
+ const PermissionSet& set1,
+ const PermissionSet& set2);
bool operator==(const PermissionSet& rhs) const;
bool operator!=(const PermissionSet& rhs) const;
diff --git a/extensions/common/permissions/permissions_data.cc b/extensions/common/permissions/permissions_data.cc
index ad45cd5..7fdbd2c 100644
--- a/extensions/common/permissions/permissions_data.cc
+++ b/extensions/common/permissions/permissions_data.cc
@@ -138,8 +138,7 @@ void PermissionsData::UpdateTabSpecificPermissions(
if (iter == tab_specific_permissions_.end())
tab_specific_permissions_[tab_id] = permissions;
else
- iter->second =
- PermissionSet::CreateUnion(iter->second.get(), permissions.get());
+ iter->second = PermissionSet::CreateUnion(*(iter->second), *permissions);
}
void PermissionsData::ClearTabSpecificPermissions(int tab_id) const {