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