Commit d66c5323 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Get rid of some new keywords in service_worker code.

Also remove checks for |ServiceWorkerContextCore::observer_list_| being
NULL. That cannot happen.

BUG=558179

Change-Id: I33685dd6d113aab2e6d2fbe85c62365131fc07d3
Reviewed-on: https://chromium-review.googlesource.com/1014659Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551243}
parent cd79b4e1
......@@ -286,13 +286,14 @@ ServiceWorkerContextCore::ServiceWorkerContextCore(
was_service_worker_registered_(false),
observer_list_(observer_list),
weak_factory_(this) {
// These get a WeakPtr from weak_factory_, so must be set after weak_factory_
// is initialized.
DCHECK(observer_list_);
// These get a WeakPtr from |weak_factory_|, so must be set after
// |weak_factory_| is initialized.
storage_ = ServiceWorkerStorage::Create(
path, AsWeakPtr(), std::move(database_task_runner), quota_manager_proxy,
special_storage_policy);
embedded_worker_registry_ = EmbeddedWorkerRegistry::Create(AsWeakPtr());
job_coordinator_.reset(new ServiceWorkerJobCoordinator(AsWeakPtr()));
job_coordinator_ = std::make_unique<ServiceWorkerJobCoordinator>(AsWeakPtr());
}
ServiceWorkerContextCore::ServiceWorkerContextCore(
......@@ -308,22 +309,21 @@ ServiceWorkerContextCore::ServiceWorkerContextCore(
old_context->was_service_worker_registered_),
observer_list_(old_context->observer_list_),
weak_factory_(this) {
// These get a WeakPtr from weak_factory_, so must be set after weak_factory_
// is initialized.
DCHECK(observer_list_);
// These get a WeakPtr from |weak_factory_|, so must be set after
// |weak_factory_| is initialized.
storage_ = ServiceWorkerStorage::Create(AsWeakPtr(), old_context->storage());
embedded_worker_registry_ = EmbeddedWorkerRegistry::Create(
AsWeakPtr(),
old_context->embedded_worker_registry());
job_coordinator_.reset(new ServiceWorkerJobCoordinator(AsWeakPtr()));
job_coordinator_ = std::make_unique<ServiceWorkerJobCoordinator>(AsWeakPtr());
}
ServiceWorkerContextCore::~ServiceWorkerContextCore() {
DCHECK(storage_);
for (VersionMap::iterator it = live_versions_.begin();
it != live_versions_.end();
++it) {
it->second->RemoveListener(this);
}
for (const auto& it : live_versions_)
it.second->RemoveListener(this);
weak_factory_.InvalidateWeakPtrs();
}
......@@ -553,11 +553,9 @@ void ServiceWorkerContextCore::RegistrationComplete(
// TODO(falken): At this point the registration promise is resolved, but we
// haven't persisted anything to storage yet. So we should either call
// OnRegistrationStored somewhere else or change its name.
if (observer_list_.get()) {
observer_list_->Notify(
FROM_HERE, &ServiceWorkerContextCoreObserver::OnRegistrationStored,
registration->id(), pattern);
}
observer_list_->Notify(
FROM_HERE, &ServiceWorkerContextCoreObserver::OnRegistrationStored,
registration->id(), pattern);
}
void ServiceWorkerContextCore::UpdateComplete(
......@@ -582,7 +580,7 @@ void ServiceWorkerContextCore::UnregistrationComplete(
int64_t registration_id,
ServiceWorkerStatusCode status) {
std::move(callback).Run(status);
if (status == SERVICE_WORKER_OK && observer_list_.get()) {
if (status == SERVICE_WORKER_OK) {
observer_list_->Notify(
FROM_HERE, &ServiceWorkerContextCoreObserver::OnRegistrationDeleted,
registration_id, pattern);
......@@ -599,11 +597,9 @@ void ServiceWorkerContextCore::AddLiveRegistration(
ServiceWorkerRegistration* registration) {
DCHECK(!GetLiveRegistration(registration->id()));
live_registrations_[registration->id()] = registration;
if (observer_list_.get()) {
observer_list_->Notify(
FROM_HERE, &ServiceWorkerContextCoreObserver::OnNewLiveRegistration,
registration->id(), registration->pattern());
}
observer_list_->Notify(
FROM_HERE, &ServiceWorkerContextCoreObserver::OnNewLiveRegistration,
registration->id(), registration->pattern());
}
void ServiceWorkerContextCore::RemoveLiveRegistration(int64_t id) {
......@@ -648,12 +644,10 @@ void ServiceWorkerContextCore::AddLiveVersion(ServiceWorkerVersion* version) {
CHECK(!GetLiveVersion(version->version_id()));
live_versions_[version->version_id()] = version;
version->AddListener(this);
if (observer_list_.get()) {
ServiceWorkerVersionInfo version_info = version->GetInfo();
observer_list_->Notify(FROM_HERE,
&ServiceWorkerContextCoreObserver::OnNewLiveVersion,
version_info);
}
ServiceWorkerVersionInfo version_info = version->GetInfo();
observer_list_->Notify(FROM_HERE,
&ServiceWorkerContextCoreObserver::OnNewLiveVersion,
version_info);
}
void ServiceWorkerContextCore::RemoveLiveVersion(int64_t id) {
......@@ -777,16 +771,12 @@ int ServiceWorkerContextCore::GetVersionFailureCount(int64_t version_id) {
}
void ServiceWorkerContextCore::OnStorageWiped() {
if (!observer_list_)
return;
observer_list_->Notify(FROM_HERE,
&ServiceWorkerContextCoreObserver::OnStorageWiped);
}
void ServiceWorkerContextCore::OnRunningStateChanged(
ServiceWorkerVersion* version) {
if (!observer_list_)
return;
observer_list_->Notify(
FROM_HERE, &ServiceWorkerContextCoreObserver::OnRunningStateChanged,
version->version_id(), version->running_status());
......@@ -794,8 +784,6 @@ void ServiceWorkerContextCore::OnRunningStateChanged(
void ServiceWorkerContextCore::OnVersionStateChanged(
ServiceWorkerVersion* version) {
if (!observer_list_)
return;
observer_list_->Notify(
FROM_HERE, &ServiceWorkerContextCoreObserver::OnVersionStateChanged,
version->version_id(), version->status());
......@@ -803,7 +791,7 @@ void ServiceWorkerContextCore::OnVersionStateChanged(
void ServiceWorkerContextCore::OnDevToolsRoutingIdChanged(
ServiceWorkerVersion* version) {
if (!observer_list_ || !version->embedded_worker())
if (!version->embedded_worker())
return;
observer_list_->Notify(
FROM_HERE,
......@@ -814,8 +802,6 @@ void ServiceWorkerContextCore::OnDevToolsRoutingIdChanged(
void ServiceWorkerContextCore::OnMainScriptHttpResponseInfoSet(
ServiceWorkerVersion* version) {
if (!observer_list_)
return;
const net::HttpResponseInfo* info = version->GetMainScriptHttpResponseInfo();
DCHECK(info);
base::Time lastModified;
......@@ -833,8 +819,6 @@ void ServiceWorkerContextCore::OnErrorReported(
int line_number,
int column_number,
const GURL& source_url) {
if (!observer_list_)
return;
observer_list_->Notify(
FROM_HERE, &ServiceWorkerContextCoreObserver::OnErrorReported,
version->version_id(), version->embedded_worker()->process_id(),
......@@ -850,8 +834,6 @@ void ServiceWorkerContextCore::OnReportConsoleMessage(
const base::string16& message,
int line_number,
const GURL& source_url) {
if (!observer_list_)
return;
observer_list_->Notify(
FROM_HERE, &ServiceWorkerContextCoreObserver::OnReportConsoleMessage,
version->version_id(), version->embedded_worker()->process_id(),
......@@ -863,8 +845,6 @@ void ServiceWorkerContextCore::OnReportConsoleMessage(
void ServiceWorkerContextCore::OnControlleeAdded(
ServiceWorkerVersion* version,
ServiceWorkerProviderHost* provider_host) {
if (!observer_list_)
return;
observer_list_->Notify(
FROM_HERE, &ServiceWorkerContextCoreObserver::OnControlleeAdded,
version->version_id(), provider_host->client_uuid(),
......@@ -875,8 +855,6 @@ void ServiceWorkerContextCore::OnControlleeAdded(
void ServiceWorkerContextCore::OnControlleeRemoved(
ServiceWorkerVersion* version,
ServiceWorkerProviderHost* provider_host) {
if (!observer_list_)
return;
observer_list_->Notify(FROM_HERE,
&ServiceWorkerContextCoreObserver::OnControlleeRemoved,
version->version_id(), provider_host->client_uuid());
......
......@@ -371,8 +371,10 @@ class CONTENT_EXPORT ServiceWorkerContextCore
// This is used to avoid unnecessary disk read operation in tests. This value
// is false if Chrome was relaunched after service workers were registered.
bool was_service_worker_registered_;
scoped_refptr<base::ObserverListThreadSafe<ServiceWorkerContextCoreObserver>>
observer_list_;
using ServiceWorkerContextObserverList =
base::ObserverListThreadSafe<ServiceWorkerContextCoreObserver>;
const scoped_refptr<ServiceWorkerContextObserverList> observer_list_;
base::WeakPtrFactory<ServiceWorkerContextCore> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContextCore);
......
......@@ -165,12 +165,9 @@ bool ServiceWorkerContext::ScopeMatches(const GURL& scope, const GURL& url) {
ServiceWorkerContextWrapper::ServiceWorkerContextWrapper(
BrowserContext* browser_context)
: core_observer_list_(
new base::ObserverListThreadSafe<ServiceWorkerContextCoreObserver>()),
base::MakeRefCounted<ServiceWorkerContextObserverList>()),
process_manager_(
std::make_unique<ServiceWorkerProcessManager>(browser_context)),
is_incognito_(false),
storage_partition_(nullptr),
resource_context_(nullptr) {
std::make_unique<ServiceWorkerProcessManager>(browser_context)) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
// Add this object as an observer of the wrapped |context_core_|. This lets us
......@@ -858,10 +855,10 @@ void ServiceWorkerContextWrapper::InitInternal(
quota_manager_proxy->RegisterClient(new ServiceWorkerQuotaClient(this));
}
context_core_.reset(new ServiceWorkerContextCore(
context_core_ = std::make_unique<ServiceWorkerContextCore>(
user_data_directory, std::move(database_task_runner), quota_manager_proxy,
special_storage_policy, loader_factory_getter, core_observer_list_.get(),
this));
this);
}
void ServiceWorkerContextWrapper::ShutdownOnIO() {
......
......@@ -343,9 +343,9 @@ class CONTENT_EXPORT ServiceWorkerContextWrapper
// Observers of |context_core_| which live within content's implementation
// boundary. Shared with |context_core_|.
const scoped_refptr<
base::ObserverListThreadSafe<ServiceWorkerContextCoreObserver>>
core_observer_list_;
using ServiceWorkerContextObserverList =
base::ObserverListThreadSafe<ServiceWorkerContextCoreObserver>;
const scoped_refptr<ServiceWorkerContextObserverList> core_observer_list_;
// Observers which live outside content's implementation boundary. Observer
// methods will always be dispatched on the UI thread.
......@@ -356,13 +356,13 @@ class CONTENT_EXPORT ServiceWorkerContextWrapper
std::unique_ptr<ServiceWorkerContextCore> context_core_;
// Initialized in Init(); true if the user data directory is empty.
bool is_incognito_;
bool is_incognito_ = false;
// Raw pointer to the StoragePartitionImpl owning |this|.
StoragePartitionImpl* storage_partition_;
StoragePartitionImpl* storage_partition_ = nullptr;
// The ResourceContext associated with this context.
ResourceContext* resource_context_;
ResourceContext* resource_context_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContextWrapper);
};
......
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