Commit 037854c8 authored by Victor Costan's avatar Victor Costan Committed by Commit Bot

AppCache: Rename AppCacheQuotaClient methods to clarify lifecycle.

This CL renames two AppCacheQuotaClient methods, NotifyAppCacheReady ->
NotifyStorageReady, and NotifyAppCacheDestroyed ->
NotifyServiceDestroyed, to clarify when the methods will get called.

This CL does not introduce any functional changes.

Bug: 1016065
Change-Id: I52238c731bcf805212d24bf744519adaf7a78374
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2514666
Auto-Submit: Victor Costan <pwnall@chromium.org>
Commit-Queue: enne <enne@chromium.org>
Reviewed-by: default avatarenne <enne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823328}
parent a1067992
......@@ -251,7 +251,7 @@ AppCacheQuotaClient::GetServiceDeleteCallback() {
return service_delete_callback_.get();
}
void AppCacheQuotaClient::NotifyAppCacheReady() {
void AppCacheQuotaClient::NotifyStorageReady() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Can reoccur during reinitialization.
......@@ -261,7 +261,7 @@ void AppCacheQuotaClient::NotifyAppCacheReady() {
}
}
void AppCacheQuotaClient::NotifyAppCacheDestroyed() {
void AppCacheQuotaClient::NotifyServiceDestroyed() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
service_ = nullptr;
......
......@@ -57,8 +57,8 @@ class AppCacheQuotaClient : public storage::QuotaClient {
private:
friend class content::AppCacheQuotaClientTest;
friend class AppCacheServiceImpl; // for NotifyAppCacheIsDestroyed
friend class AppCacheStorageImpl; // for NotifyAppCacheIsReady
friend class AppCacheServiceImpl; // for NotifyServiceDestroyed
friend class AppCacheStorageImpl; // for NotifyStorageReady
~AppCacheQuotaClient() override;
......@@ -70,8 +70,15 @@ class AppCacheQuotaClient : public storage::QuotaClient {
net::CancelableCompletionRepeatingCallback* GetServiceDeleteCallback();
// For use by appcache internals during initialization and shutdown.
CONTENT_EXPORT void NotifyAppCacheReady();
CONTENT_EXPORT void NotifyAppCacheDestroyed();
// Called when the AppCacheStorageImpl's storage is fully initialized.
//
// After this point, calling AppCacheServiceImpl::storage() is guaranteed to
// return a non-null value.
CONTENT_EXPORT void NotifyStorageReady();
// Called when the AppCacheServiceImpl passed to the constructor is destroyed.
CONTENT_EXPORT void NotifyServiceDestroyed();
// Prior to appcache service being ready, we have to queue
// up requests and defer acting on them until we're ready.
......
......@@ -126,12 +126,12 @@ class AppCacheQuotaClientTest : public testing::Test {
return base::MakeRefCounted<AppCacheQuotaClient>(mock_service_.AsWeakPtr());
}
void Call_NotifyAppCacheReady(AppCacheQuotaClient& client) {
client.NotifyAppCacheReady();
void Call_NotifyStorageReady(AppCacheQuotaClient& client) {
client.NotifyStorageReady();
}
void Call_NotifyAppCacheDestroyed(AppCacheQuotaClient& client) {
client.NotifyAppCacheDestroyed();
void Call_NotifyServiceDestroyed(AppCacheQuotaClient& client) {
client.NotifyServiceDestroyed();
}
void Call_OnQuotaManagerDestroyed(AppCacheQuotaClient& client) {
......@@ -167,14 +167,14 @@ class AppCacheQuotaClientTest : public testing::Test {
TEST_F(AppCacheQuotaClientTest, BasicCreateDestroy) {
auto client = CreateClient();
Call_NotifyAppCacheReady(*client);
Call_NotifyStorageReady(*client);
Call_OnQuotaManagerDestroyed(*client);
Call_NotifyAppCacheDestroyed(*client);
Call_NotifyServiceDestroyed(*client);
}
TEST_F(AppCacheQuotaClientTest, QuotaManagerDestroyedInCallback) {
auto client = CreateClient();
Call_NotifyAppCacheReady(*client);
Call_NotifyStorageReady(*client);
client->DeleteOriginData(kOriginA, kTemp,
base::BindOnce(
[](AppCacheQuotaClientTest* test,
......@@ -183,12 +183,12 @@ TEST_F(AppCacheQuotaClientTest, QuotaManagerDestroyedInCallback) {
test->Call_OnQuotaManagerDestroyed(*client);
},
this, client));
Call_NotifyAppCacheDestroyed(*client);
Call_NotifyServiceDestroyed(*client);
}
TEST_F(AppCacheQuotaClientTest, EmptyService) {
auto client = CreateClient();
Call_NotifyAppCacheReady(*client);
Call_NotifyStorageReady(*client);
EXPECT_EQ(0, GetOriginUsage(*client, kOriginA, kTemp));
EXPECT_TRUE(GetOriginsForType(*client, kTemp).empty());
......@@ -196,14 +196,14 @@ TEST_F(AppCacheQuotaClientTest, EmptyService) {
EXPECT_EQ(blink::mojom::QuotaStatusCode::kOk,
DeleteOriginData(*client, kTemp, kOriginA));
Call_NotifyAppCacheDestroyed(*client);
Call_NotifyServiceDestroyed(*client);
Call_OnQuotaManagerDestroyed(*client);
}
TEST_F(AppCacheQuotaClientTest, NoService) {
auto client = CreateClient();
Call_NotifyAppCacheReady(*client);
Call_NotifyAppCacheDestroyed(*client);
Call_NotifyStorageReady(*client);
Call_NotifyServiceDestroyed(*client);
EXPECT_EQ(0, GetOriginUsage(*client, kOriginA, kTemp));
EXPECT_TRUE(GetOriginsForType(*client, kTemp).empty());
......@@ -216,19 +216,19 @@ TEST_F(AppCacheQuotaClientTest, NoService) {
TEST_F(AppCacheQuotaClientTest, GetOriginUsage) {
auto client = CreateClient();
Call_NotifyAppCacheReady(*client);
Call_NotifyStorageReady(*client);
SetUsageMapEntry(kOriginA, 1000);
EXPECT_EQ(1000, GetOriginUsage(*client, kOriginA, kTemp));
EXPECT_EQ(0, GetOriginUsage(*client, kOriginB, kTemp));
Call_NotifyAppCacheDestroyed(*client);
Call_NotifyServiceDestroyed(*client);
Call_OnQuotaManagerDestroyed(*client);
}
TEST_F(AppCacheQuotaClientTest, GetOriginsForHost) {
auto client = CreateClient();
Call_NotifyAppCacheReady(*client);
Call_NotifyStorageReady(*client);
EXPECT_EQ(kOriginA.host(), kOriginB.host());
EXPECT_NE(kOriginA.host(), kOriginOther.host());
......@@ -250,13 +250,13 @@ TEST_F(AppCacheQuotaClientTest, GetOriginsForHost) {
EXPECT_EQ(1ul, origins.size());
EXPECT_THAT(origins, testing::Contains(kOriginOther));
Call_NotifyAppCacheDestroyed(*client);
Call_NotifyServiceDestroyed(*client);
Call_OnQuotaManagerDestroyed(*client);
}
TEST_F(AppCacheQuotaClientTest, GetOriginsForType) {
auto client = CreateClient();
Call_NotifyAppCacheReady(*client);
Call_NotifyStorageReady(*client);
EXPECT_TRUE(GetOriginsForType(*client, kTemp).empty());
......@@ -268,13 +268,13 @@ TEST_F(AppCacheQuotaClientTest, GetOriginsForType) {
EXPECT_THAT(origins, testing::Contains(kOriginA));
EXPECT_THAT(origins, testing::Contains(kOriginB));
Call_NotifyAppCacheDestroyed(*client);
Call_NotifyServiceDestroyed(*client);
Call_OnQuotaManagerDestroyed(*client);
}
TEST_F(AppCacheQuotaClientTest, DeleteOriginData) {
auto client = CreateClient();
Call_NotifyAppCacheReady(*client);
Call_NotifyStorageReady(*client);
EXPECT_EQ(blink::mojom::QuotaStatusCode::kOk,
DeleteOriginData(*client, kTemp, kOriginA));
......@@ -287,7 +287,7 @@ TEST_F(AppCacheQuotaClientTest, DeleteOriginData) {
EXPECT_EQ(2, mock_service_.delete_called_count());
Call_OnQuotaManagerDestroyed(*client);
Call_NotifyAppCacheDestroyed(*client);
Call_NotifyServiceDestroyed(*client);
}
TEST_F(AppCacheQuotaClientTest, PendingRequests) {
......@@ -316,7 +316,7 @@ TEST_F(AppCacheQuotaClientTest, PendingRequests) {
EXPECT_EQ(0, num_delete_origins_completions_);
// Pending requests should get serviced when the appcache is ready.
Call_NotifyAppCacheReady(*client);
Call_NotifyStorageReady(*client);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(2, num_get_origin_usage_completions_);
EXPECT_EQ(4, num_get_origins_completions_);
......@@ -327,7 +327,7 @@ TEST_F(AppCacheQuotaClientTest, PendingRequests) {
EXPECT_EQ(1ul, origins_.size());
EXPECT_THAT(origins_, testing::Contains(kOriginOther));
Call_NotifyAppCacheDestroyed(*client);
Call_NotifyServiceDestroyed(*client);
Call_OnQuotaManagerDestroyed(*client);
}
......@@ -353,7 +353,7 @@ TEST_F(AppCacheQuotaClientTest, DestroyServiceWithPending) {
EXPECT_EQ(0, num_delete_origins_completions_);
// Kill the service.
Call_NotifyAppCacheDestroyed(*client);
Call_NotifyServiceDestroyed(*client);
// All should have been aborted and called completion.
EXPECT_EQ(2, num_get_origin_usage_completions_);
......@@ -389,7 +389,7 @@ TEST_F(AppCacheQuotaClientTest, DestroyQuotaManagerWithPending) {
// Kill the quota manager.
Call_OnQuotaManagerDestroyed(*client);
Call_NotifyAppCacheReady(*client);
Call_NotifyStorageReady(*client);
// Callbacks should be deleted and not called.
base::RunLoop().RunUntilIdle();
......@@ -397,26 +397,26 @@ TEST_F(AppCacheQuotaClientTest, DestroyQuotaManagerWithPending) {
EXPECT_EQ(0, num_get_origins_completions_);
EXPECT_EQ(0, num_delete_origins_completions_);
Call_NotifyAppCacheDestroyed(*client);
Call_NotifyServiceDestroyed(*client);
}
TEST_F(AppCacheQuotaClientTest, DestroyWithDeleteInProgress) {
auto client = CreateClient();
Call_NotifyAppCacheReady(*client);
Call_NotifyStorageReady(*client);
// Start an async delete.
AsyncDeleteOriginData(*client, kTemp, kOriginB);
EXPECT_EQ(0, num_delete_origins_completions_);
// Kill the service.
Call_NotifyAppCacheDestroyed(*client);
Call_NotifyServiceDestroyed(*client);
// Should have been aborted.
EXPECT_EQ(1, num_delete_origins_completions_);
EXPECT_EQ(blink::mojom::QuotaStatusCode::kErrorAbort, delete_status_);
// A real completion callback from the service should
// be dropped if it comes in after NotifyAppCacheDestroyed.
// be dropped if it comes in after NotifyServiceDestroyed.
base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, num_delete_origins_completions_);
EXPECT_EQ(blink::mojom::QuotaStatusCode::kErrorAbort, delete_status_);
......
......@@ -403,7 +403,7 @@ AppCacheServiceImpl::~AppCacheServiceImpl() {
pending_helpers_.clear();
if (quota_client_) {
GetIOThreadTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce(&AppCacheQuotaClient::NotifyAppCacheDestroyed,
FROM_HERE, base::BindOnce(&AppCacheQuotaClient::NotifyServiceDestroyed,
std::move(quota_client_)));
}
......
......@@ -310,7 +310,7 @@ void AppCacheStorageImpl::InitTask::RunCompleted() {
if (storage_->service()->quota_client()) {
GetIOThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(&AppCacheQuotaClient::NotifyAppCacheReady,
base::BindOnce(&AppCacheQuotaClient::NotifyStorageReady,
base::RetainedRef(storage_->service()->quota_client())));
}
}
......
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