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

Start using ServiceWorkerStorageControl

This CL starts using ServiceWorkerStorageControl in
ServiceWorkerRegistry. For now, an instance of
ServiceWorkerStorageControl is owned by ServiceWorkerRegistry as a
drop-in replacement of ServiceWorkerStorage. Eventually the instance
will live in the Storage Service once all ServiceWorkerStorage method
calls are migrated into mojo methods.

This CL only replaces UpdateLastUpdateCheckTime() call. Subsequent
CLs will replace more ServiceWorkerStorage method calls.

According to android-binary-size trybot, this increases the binary
sizes by ~37kb. Most of the increase (~29kb) comes from mojo generated
code and there isn't much we can do to reduce them. Introducing this
mojo interface is necessary for migrating ServiceWorkerStroage to
the storage service. See the design doc [1] for the motivation and
plans.

[1] https://docs.google.com/document/d/1hO0WEuoEOgEBlf5nDE3fDjuQY2bV_d5hLtk25iBo0LM/edit?usp=sharing

Bug: 1055677
Binary-Size: Size increase is unavoidable (see above)
Change-Id: Ic843e25f3556249b67252f52e9e16428ec488dfb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2214582
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771488}
parent badb83e8
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "content/browser/service_worker/service_worker_context_wrapper.h" #include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_info.h" #include "content/browser/service_worker/service_worker_info.h"
#include "content/browser/service_worker/service_worker_registration.h" #include "content/browser/service_worker/service_worker_registration.h"
#include "content/browser/service_worker/service_worker_storage_control_impl.h"
#include "content/browser/service_worker/service_worker_version.h" #include "content/browser/service_worker/service_worker_version.h"
#include "content/common/service_worker/service_worker_utils.h" #include "content/common/service_worker/service_worker_utils.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
...@@ -121,9 +122,10 @@ ServiceWorkerRegistry::ServiceWorkerRegistry( ...@@ -121,9 +122,10 @@ ServiceWorkerRegistry::ServiceWorkerRegistry(
storage::QuotaManagerProxy* quota_manager_proxy, storage::QuotaManagerProxy* quota_manager_proxy,
storage::SpecialStoragePolicy* special_storage_policy) storage::SpecialStoragePolicy* special_storage_policy)
: context_(context), : context_(context),
storage_(ServiceWorkerStorage::Create(user_data_directory, storage_control_(std::make_unique<ServiceWorkerStorageControlImpl>(
std::move(database_task_runner), ServiceWorkerStorage::Create(user_data_directory,
quota_manager_proxy)), std::move(database_task_runner),
quota_manager_proxy))),
special_storage_policy_(special_storage_policy) { special_storage_policy_(special_storage_policy) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
DCHECK(context_); DCHECK(context_);
...@@ -134,7 +136,8 @@ ServiceWorkerRegistry::ServiceWorkerRegistry( ...@@ -134,7 +136,8 @@ ServiceWorkerRegistry::ServiceWorkerRegistry(
ServiceWorkerContextCore* context, ServiceWorkerContextCore* context,
ServiceWorkerRegistry* old_registry) ServiceWorkerRegistry* old_registry)
: context_(context), : context_(context),
storage_(ServiceWorkerStorage::Create(old_registry->storage())), storage_control_(std::make_unique<ServiceWorkerStorageControlImpl>(
ServiceWorkerStorage::Create(old_registry->storage()))),
special_storage_policy_(old_registry->special_storage_policy_) { special_storage_policy_(old_registry->special_storage_policy_) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
DCHECK(context_); DCHECK(context_);
...@@ -143,6 +146,10 @@ ServiceWorkerRegistry::ServiceWorkerRegistry( ...@@ -143,6 +146,10 @@ ServiceWorkerRegistry::ServiceWorkerRegistry(
ServiceWorkerRegistry::~ServiceWorkerRegistry() = default; ServiceWorkerRegistry::~ServiceWorkerRegistry() = default;
ServiceWorkerStorage* ServiceWorkerRegistry::storage() const {
return storage_control_->storage();
}
void ServiceWorkerRegistry::CreateNewRegistration( void ServiceWorkerRegistry::CreateNewRegistration(
blink::mojom::ServiceWorkerRegistrationOptions options, blink::mojom::ServiceWorkerRegistrationOptions options,
NewRegistrationCallback callback) { NewRegistrationCallback callback) {
...@@ -461,7 +468,8 @@ void ServiceWorkerRegistry::UpdateLastUpdateCheckTime( ...@@ -461,7 +468,8 @@ void ServiceWorkerRegistry::UpdateLastUpdateCheckTime(
base::Time last_update_check_time, base::Time last_update_check_time,
StatusCallback callback) { StatusCallback callback) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
storage()->UpdateLastUpdateCheckTime( BindRemoteStorageControlIfNeeded();
remote_storage_control_->UpdateLastUpdateCheckTime(
registration_id, origin, last_update_check_time, registration_id, origin, last_update_check_time,
CreateDatabaseStatusCallback(std::move(callback))); CreateDatabaseStatusCallback(std::move(callback)));
} }
...@@ -1375,4 +1383,15 @@ bool ServiceWorkerRegistry::ShouldPurgeOnShutdown(const url::Origin& origin) { ...@@ -1375,4 +1383,15 @@ bool ServiceWorkerRegistry::ShouldPurgeOnShutdown(const url::Origin& origin) {
!special_storage_policy_->IsStorageProtected(origin.GetURL()); !special_storage_policy_->IsStorageProtected(origin.GetURL());
} }
void ServiceWorkerRegistry::BindRemoteStorageControlIfNeeded() {
DCHECK(!(remote_storage_control_.is_bound() &&
!remote_storage_control_.is_connected()))
<< "Rebinding is not supported yet.";
if (remote_storage_control_.is_bound())
return;
storage_control_->Bind(remote_storage_control_.BindNewPipeAndPassReceiver());
}
} // namespace content } // namespace content
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "content/browser/service_worker/service_worker_registration.h" #include "content/browser/service_worker/service_worker_registration.h"
#include "content/browser/service_worker/service_worker_storage.h" #include "content/browser/service_worker/service_worker_storage.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace base { namespace base {
class SequencedTaskRunner; class SequencedTaskRunner;
...@@ -27,6 +28,7 @@ namespace content { ...@@ -27,6 +28,7 @@ namespace content {
class ServiceWorkerContextCore; class ServiceWorkerContextCore;
class ServiceWorkerVersion; class ServiceWorkerVersion;
class ServiceWorkerStorageControlImpl;
class ServiceWorkerRegistryTest; class ServiceWorkerRegistryTest;
FORWARD_DECLARE_TEST(ServiceWorkerRegistryTest, StoragePolicyChange); FORWARD_DECLARE_TEST(ServiceWorkerRegistryTest, StoragePolicyChange);
...@@ -78,7 +80,7 @@ class CONTENT_EXPORT ServiceWorkerRegistry { ...@@ -78,7 +80,7 @@ class CONTENT_EXPORT ServiceWorkerRegistry {
~ServiceWorkerRegistry(); ~ServiceWorkerRegistry();
ServiceWorkerStorage* storage() const { return storage_.get(); } ServiceWorkerStorage* storage() const;
// Creates a new in-memory representation of registration. Can be null when // Creates a new in-memory representation of registration. Can be null when
// storage is disabled. This method must be called after storage is // storage is disabled. This method must be called after storage is
...@@ -345,10 +347,18 @@ class CONTENT_EXPORT ServiceWorkerRegistry { ...@@ -345,10 +347,18 @@ class CONTENT_EXPORT ServiceWorkerRegistry {
void OnStoragePolicyChanged(); void OnStoragePolicyChanged();
bool ShouldPurgeOnShutdown(const url::Origin& origin); bool ShouldPurgeOnShutdown(const url::Origin& origin);
void BindRemoteStorageControlIfNeeded();
// The ServiceWorkerContextCore object must outlive this. // The ServiceWorkerContextCore object must outlive this.
ServiceWorkerContextCore* const context_; ServiceWorkerContextCore* const context_;
std::unique_ptr<ServiceWorkerStorage> storage_; mojo::Remote<storage::mojom::ServiceWorkerStorageControl>
remote_storage_control_;
// TODO(crbug.com/1055677): Remove this field after all storage operations are
// called via |remote_storage_control_|. An instance of this impl should live
// in the storage service.
std::unique_ptr<ServiceWorkerStorageControlImpl> storage_control_;
bool is_storage_disabled_ = false; bool is_storage_disabled_ = false;
const scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_; const scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_;
......
...@@ -92,6 +92,17 @@ ServiceWorkerStorageControlImpl::ServiceWorkerStorageControlImpl( ...@@ -92,6 +92,17 @@ ServiceWorkerStorageControlImpl::ServiceWorkerStorageControlImpl(
ServiceWorkerStorageControlImpl::~ServiceWorkerStorageControlImpl() = default; ServiceWorkerStorageControlImpl::~ServiceWorkerStorageControlImpl() = default;
void ServiceWorkerStorageControlImpl::Bind(
mojo::PendingReceiver<storage::mojom::ServiceWorkerStorageControl>
receiver) {
// There should be one connection at most for now because this class hasn't
// moved to the storage service yet.
DCHECK(receivers_.empty())
<< "ServiceWorkerStorageControl doesn't support multiple connections yet";
receivers_.Add(this, std::move(receiver));
}
void ServiceWorkerStorageControlImpl::LazyInitializeForTest() { void ServiceWorkerStorageControlImpl::LazyInitializeForTest() {
storage_->LazyInitializeForTest(); storage_->LazyInitializeForTest();
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "components/services/storage/public/mojom/service_worker_storage_control.mojom.h" #include "components/services/storage/public/mojom/service_worker_storage_control.mojom.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
namespace content { namespace content {
...@@ -32,6 +33,13 @@ class CONTENT_EXPORT ServiceWorkerStorageControlImpl ...@@ -32,6 +33,13 @@ class CONTENT_EXPORT ServiceWorkerStorageControlImpl
~ServiceWorkerStorageControlImpl() override; ~ServiceWorkerStorageControlImpl() override;
// TODO(crbug.com/1055677): Remove this accessor after all
// ServiceWorkerStorage method calls are replaced with mojo methods.
ServiceWorkerStorage* storage() const { return storage_.get(); }
void Bind(mojo::PendingReceiver<storage::mojom::ServiceWorkerStorageControl>
receiver);
void LazyInitializeForTest(); void LazyInitializeForTest();
private: private:
...@@ -124,6 +132,8 @@ class CONTENT_EXPORT ServiceWorkerStorageControlImpl ...@@ -124,6 +132,8 @@ class CONTENT_EXPORT ServiceWorkerStorageControlImpl
policy_updates) override; policy_updates) override;
const std::unique_ptr<ServiceWorkerStorage> storage_; const std::unique_ptr<ServiceWorkerStorage> storage_;
mojo::ReceiverSet<storage::mojom::ServiceWorkerStorageControl> receivers_;
}; };
} // namespace content } // namespace content
......
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