Commit fdef2414 authored by Kenichi Ishibashi's avatar Kenichi Ishibashi Committed by Commit Bot

Reland: "Add ServiceWorkerStorageControl::UpdateLastUpdateCheckTime()"

This is a reland of 6d769734.
Difference from the original CL is to rebase after
85a40bf3.

Original change's description:
> Add ServiceWorkerStorageControl::UpdateLastUpdateCheckTime()
>
> This is a wrapper of ServiceWorkerStorage::UpdateLastUpdateCheckTime().
>
> Bug: 1055677
> Change-Id: I3bf89d2c227d5b6f0a1c41e108843ae1d51a778b
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2147435
> Reviewed-by: Makoto Shimazu <shimazu@chromium.org>
> Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
> Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#759541}

Tbr: shimazu@chromium.org, kinuko@chromium.org
Change-Id: Id03cd5f3afa0c7338f924e8569f7d01cb50acb1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2152327Reviewed-by: default avatarKenichi Ishibashi <bashi@chromium.org>
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759582}
parent 99732fac
......@@ -6,6 +6,7 @@ module storage.mojom;
import "components/services/storage/public/mojom/service_worker_database.mojom";
import "mojo/public/mojom/base/big_buffer.mojom";
import "mojo/public/mojom/base/time.mojom";
import "services/network/public/mojom/url_response_head.mojom";
import "url/mojom/url.mojom";
......@@ -115,6 +116,11 @@ interface ServiceWorkerStorageControl {
// Updates the state of the registration's stored version to active.
UpdateToActiveState(int64 registration_id, url.mojom.Url origin) =>
(ServiceWorkerDatabaseStatus status);
// Updates the last update check time on the storage.
UpdateLastUpdateCheckTime(int64 registration_id,
url.mojom.Url origin,
mojo_base.mojom.Time last_update_check_time) =>
(ServiceWorkerDatabaseStatus status);
// Returns a new registration id which is guaranteed to be unique in the
// storage. Returns blink::mojom::kInvalidServiceWorkerRegistrationId if the
......
......@@ -176,6 +176,15 @@ void ServiceWorkerStorageControlImpl::UpdateToActiveState(
storage_->UpdateToActiveState(registration_id, origin, std::move(callback));
}
void ServiceWorkerStorageControlImpl::UpdateLastUpdateCheckTime(
int64_t registration_id,
const GURL& origin,
base::Time last_update_check_time,
UpdateLastUpdateCheckTimeCallback callback) {
storage_->UpdateLastUpdateCheckTime(
registration_id, origin, last_update_check_time, std::move(callback));
}
void ServiceWorkerStorageControlImpl::GetNewRegistrationId(
GetNewRegistrationIdCallback callback) {
storage_->GetNewRegistrationId(std::move(callback));
......
......@@ -58,6 +58,11 @@ class CONTENT_EXPORT ServiceWorkerStorageControlImpl
void UpdateToActiveState(int64_t registration_id,
const GURL& origin,
UpdateToActiveStateCallback callback) override;
void UpdateLastUpdateCheckTime(
int64_t registration_id,
const GURL& origin,
base::Time last_update_check_time,
UpdateLastUpdateCheckTimeCallback callback) override;
void GetNewRegistrationId(GetNewRegistrationIdCallback callback) override;
void GetNewVersionId(GetNewVersionIdCallback callback) override;
void GetNewResourceId(GetNewResourceIdCallback callback) override;
......
......@@ -13,6 +13,7 @@
#include "base/files/scoped_temp_dir.h"
#include "base/test/bind_test_util.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "content/browser/service_worker/service_worker_storage.h"
#include "content/browser/service_worker/service_worker_test_utils.h"
#include "content/public/test/browser_task_environment.h"
......@@ -276,6 +277,21 @@ class ServiceWorkerStorageControlImplTest : public testing::Test {
return out_status;
}
DatabaseStatus UpdateLastUpdateCheckTime(int64_t registration_id,
const GURL& origin,
base::Time last_update_check_time) {
DatabaseStatus out_status;
base::RunLoop loop;
storage()->UpdateLastUpdateCheckTime(
registration_id, origin, last_update_check_time,
base::BindLambdaForTesting([&](DatabaseStatus status) {
out_status = status;
loop.Quit();
}));
loop.Run();
return out_status;
}
int64_t GetNewRegistrationId() {
int64_t return_value;
base::RunLoop loop;
......@@ -650,6 +666,42 @@ TEST_F(ServiceWorkerStorageControlImplTest, UpdateToActiveState) {
}
}
TEST_F(ServiceWorkerStorageControlImplTest, UpdateLastUpdateCheckTime) {
const GURL kScope("https://www.example.com/");
const GURL kScriptUrl("https://www.example.com/sw.js");
const int64_t kScriptSize = 10;
LazyInitializeForTest();
// Preparation: Store a registration.
const int64_t registration_id = GetNewRegistrationId();
const int64_t version_id = GetNewVersionId();
DatabaseStatus status = CreateAndStoreRegistration(
registration_id, version_id, kScope, kScriptUrl, kScriptSize);
ASSERT_EQ(status, DatabaseStatus::kOk);
// The stored registration shouldn't have the last update check time yet.
{
FindRegistrationResult result =
FindRegistrationForId(registration_id, kScope.GetOrigin());
ASSERT_EQ(result->status, DatabaseStatus::kOk);
EXPECT_EQ(result->registration->last_update_check, base::Time());
}
// Set the last update check time.
const base::Time now = base::Time::Now();
status = UpdateLastUpdateCheckTime(registration_id, kScope.GetOrigin(), now);
ASSERT_EQ(status, DatabaseStatus::kOk);
// Now the stored registration should be active.
{
FindRegistrationResult result =
FindRegistrationForId(registration_id, kScope.GetOrigin());
ASSERT_EQ(result->status, DatabaseStatus::kOk);
EXPECT_EQ(result->registration->last_update_check, now);
}
}
// Tests that getting registrations works.
TEST_F(ServiceWorkerStorageControlImplTest, GetRegistrationsForOrigin) {
const GURL kScope1("https://www.example.com/foo/");
......
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