Commit a863086a authored by Zhuoyu Qian's avatar Zhuoyu Qian Committed by Commit Bot

Change SpecialStoragePolicy functions to use url::Origin.

This CL update the functions {Notify|On}{Granted|Revoked} of
SpecialStoragePolicy to use dedicated Origin type instead of GURL.

Bug: 598424
Change-Id: Ifd2ba2c513e866ff3b1f5857b95fa67a42a77d1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2086354Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Commit-Queue: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747070}
parent 2a6a2627
......@@ -287,7 +287,8 @@ void ExtensionSpecialStoragePolicy::NotifyGranted(
this, origin, change_flags));
return;
}
SpecialStoragePolicy::NotifyGranted(origin, change_flags);
SpecialStoragePolicy::NotifyGranted(url::Origin::Create(origin),
change_flags);
}
void ExtensionSpecialStoragePolicy::NotifyRevoked(
......@@ -299,7 +300,8 @@ void ExtensionSpecialStoragePolicy::NotifyRevoked(
this, origin, change_flags));
return;
}
SpecialStoragePolicy::NotifyRevoked(origin, change_flags);
SpecialStoragePolicy::NotifyRevoked(url::Origin::Create(origin),
change_flags);
}
void ExtensionSpecialStoragePolicy::NotifyCleared() {
......
......@@ -43,16 +43,16 @@ class ExtensionSpecialStoragePolicyTest : public testing::Test {
expected_change_flags_(0) {
}
void OnGranted(const GURL& origin, int change_flags) override {
void OnGranted(const url::Origin& origin, int change_flags) override {
EXPECT_EQ(expected_type_, NOTIFICATION_TYPE_GRANT);
EXPECT_EQ(expected_origin_, origin);
EXPECT_EQ(expected_origin_, origin.GetURL());
EXPECT_EQ(expected_change_flags_, change_flags);
expected_type_ = NOTIFICATION_TYPE_NONE;
}
void OnRevoked(const GURL& origin, int change_flags) override {
void OnRevoked(const url::Origin& origin, int change_flags) override {
EXPECT_EQ(expected_type_, NOTIFICATION_TYPE_REVOKE);
EXPECT_EQ(expected_origin_, origin);
EXPECT_EQ(expected_origin_, origin.GetURL());
EXPECT_EQ(expected_change_flags_, change_flags);
expected_type_ = NOTIFICATION_TYPE_NONE;
}
......
......@@ -454,34 +454,34 @@ bool ClientUsageTracker::IsUsageCacheEnabledForOrigin(
host, origin);
}
void ClientUsageTracker::OnGranted(const GURL& origin_url, int change_flags) {
void ClientUsageTracker::OnGranted(const url::Origin& origin,
int change_flags) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (change_flags & SpecialStoragePolicy::STORAGE_UNLIMITED) {
url::Origin origin = url::Origin::Create(origin_url);
int64_t usage = 0;
if (GetCachedOriginUsage(origin, &usage)) {
global_unlimited_usage_ += usage;
global_limited_usage_ -= usage;
}
std::string host = net::GetHostOrSpecFromURL(origin_url);
std::string host = net::GetHostOrSpecFromURL(origin.GetURL());
if (EraseOriginFromOriginSet(&non_cached_limited_origins_by_host_,
host, origin))
non_cached_unlimited_origins_by_host_[host].insert(origin);
}
}
void ClientUsageTracker::OnRevoked(const GURL& origin_url, int change_flags) {
void ClientUsageTracker::OnRevoked(const url::Origin& origin,
int change_flags) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (change_flags & SpecialStoragePolicy::STORAGE_UNLIMITED) {
url::Origin origin = url::Origin::Create(origin_url);
int64_t usage = 0;
if (GetCachedOriginUsage(origin, &usage)) {
global_unlimited_usage_ -= usage;
global_limited_usage_ += usage;
}
std::string host = net::GetHostOrSpecFromURL(origin_url);
std::string host = net::GetHostOrSpecFromURL(origin.GetURL());
if (EraseOriginFromOriginSet(&non_cached_unlimited_origins_by_host_,
host, origin))
non_cached_limited_origins_by_host_[host].insert(origin);
......
......@@ -99,8 +99,8 @@ class ClientUsageTracker : public SpecialStoragePolicy::Observer,
bool GetCachedOriginUsage(const url::Origin& origin, int64_t* usage) const;
// SpecialStoragePolicy::Observer overrides
void OnGranted(const GURL& origin_url, int change_flags) override;
void OnRevoked(const GURL& origin_url, int change_flags) override;
void OnGranted(const url::Origin& origin_url, int change_flags) override;
void OnRevoked(const url::Origin& origin_url, int change_flags) override;
void OnCleared() override;
void UpdateGlobalUsageValue(int64_t* usage_value, int64_t delta);
......
......@@ -20,14 +20,16 @@ void SpecialStoragePolicy::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
void SpecialStoragePolicy::NotifyGranted(const GURL& origin, int change_flags) {
void SpecialStoragePolicy::NotifyGranted(const url::Origin& origin,
int change_flags) {
scoped_refptr<SpecialStoragePolicy> protect(this);
for (auto& observer : observers_)
observer.OnGranted(origin, change_flags);
NotifyPolicyChanged();
}
void SpecialStoragePolicy::NotifyRevoked(const GURL& origin, int change_flags) {
void SpecialStoragePolicy::NotifyRevoked(const url::Origin& origin,
int change_flags) {
scoped_refptr<SpecialStoragePolicy> protect(this);
for (auto& observer : observers_)
observer.OnRevoked(origin, change_flags);
......
......@@ -15,6 +15,10 @@
class GURL;
namespace url {
class Origin;
}
namespace storage {
// Special rights are granted to 'extensions' and 'applications'. The
......@@ -36,11 +40,11 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) SpecialStoragePolicy
public:
// Called when one or more features corresponding to |change_flags| have
// been granted for |origin| storage.
virtual void OnGranted(const GURL& origin, int change_flags) {}
virtual void OnGranted(const url::Origin& origin, int change_flags) {}
// Called when one or more features corresponding to |change_flags| have
// been revoked for |origin| storage.
virtual void OnRevoked(const GURL& origin, int change_flags) {}
virtual void OnRevoked(const url::Origin& origin, int change_flags) {}
// Called when all features corresponding to ChangeFlags have been revoked
// for all origins.
......@@ -97,8 +101,8 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) SpecialStoragePolicy
// Notify observes of specific policy changes. Note that all of these also
// implicitly invoke |NotifyPolicyChanged()|.
void NotifyGranted(const GURL& origin, int change_flags);
void NotifyRevoked(const GURL& origin, int change_flags);
void NotifyGranted(const url::Origin& origin, int change_flags);
void NotifyRevoked(const url::Origin& origin, int change_flags);
void NotifyCleared();
// Subclasses can call this for any policy changes which don't fit any of the
......
......@@ -208,7 +208,7 @@ class UsageTrackerTest : public testing::Test {
void GrantUnlimitedStoragePolicy(const url::Origin& origin) {
if (!storage_policy_->IsStorageUnlimited(origin.GetURL())) {
storage_policy_->AddUnlimited(origin.GetURL());
storage_policy_->NotifyGranted(origin.GetURL(),
storage_policy_->NotifyGranted(origin,
SpecialStoragePolicy::STORAGE_UNLIMITED);
}
}
......@@ -216,7 +216,7 @@ class UsageTrackerTest : public testing::Test {
void RevokeUnlimitedStoragePolicy(const url::Origin& origin) {
if (storage_policy_->IsStorageUnlimited(origin.GetURL())) {
storage_policy_->RemoveUnlimited(origin.GetURL());
storage_policy_->NotifyRevoked(origin.GetURL(),
storage_policy_->NotifyRevoked(origin,
SpecialStoragePolicy::STORAGE_UNLIMITED);
}
}
......
......@@ -52,11 +52,11 @@ class MockSpecialStoragePolicy : public SpecialStoragePolicy {
all_unlimited_ = false;
}
void NotifyGranted(const GURL& origin, int change_flags) {
void NotifyGranted(const url::Origin& origin, int change_flags) {
SpecialStoragePolicy::NotifyGranted(origin, change_flags);
}
void NotifyRevoked(const GURL& origin, int change_flags) {
void NotifyRevoked(const url::Origin& origin, int change_flags) {
SpecialStoragePolicy::NotifyRevoked(origin, change_flags);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment