Commit c48098df authored by Makoto Shimazu's avatar Makoto Shimazu Committed by Chromium LUCI CQ

Remove RunOrPostTaskOnCoreThread() from ServiceWorkerContextWatcher

As a part of clean up code related to ServiceWorkerOnUI, this CL removes
RunOrPostTaskOnCoreThread() in ServiceWorkerContextWatcher.

Bug: 1138155
Change-Id: Icce0ab49209026e6323d79d0541840e023a30b66
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2600756
Auto-Submit: Makoto Shimazu <shimazu@chromium.org>
Commit-Queue: Asami Doi <asamidoi@chromium.org>
Reviewed-by: default avatarAsami Doi <asamidoi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839023}
parent 385197d4
...@@ -43,33 +43,23 @@ ServiceWorkerContextWatcher::ServiceWorkerContextWatcher( ...@@ -43,33 +43,23 @@ ServiceWorkerContextWatcher::ServiceWorkerContextWatcher(
void ServiceWorkerContextWatcher::Start() { void ServiceWorkerContextWatcher::Start() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
ServiceWorkerContextWrapper::RunOrPostTaskOnCoreThread( if (is_stopped_)
FROM_HERE, return;
base::BindOnce( context_->GetAllRegistrations(base::BindOnce(
&ServiceWorkerContextWatcher::GetStoredRegistrationsOnCoreThread, &ServiceWorkerContextWatcher::OnStoredRegistrations, this));
this));
} }
void ServiceWorkerContextWatcher::Stop() { void ServiceWorkerContextWatcher::Stop() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
stop_called_ = true; stop_called_ = true;
ServiceWorkerContextWrapper::RunOrPostTaskOnCoreThread( context_->RemoveObserver(this);
FROM_HERE, is_stopped_ = true;
base::BindOnce(&ServiceWorkerContextWatcher::StopOnCoreThread, this));
}
void ServiceWorkerContextWatcher::GetStoredRegistrationsOnCoreThread() {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
if (is_stopped_)
return;
context_->GetAllRegistrations(base::BindOnce(
&ServiceWorkerContextWatcher::OnStoredRegistrationsOnCoreThread, this));
} }
void ServiceWorkerContextWatcher::OnStoredRegistrationsOnCoreThread( void ServiceWorkerContextWatcher::OnStoredRegistrations(
blink::ServiceWorkerStatusCode status, blink::ServiceWorkerStatusCode status,
const std::vector<ServiceWorkerRegistrationInfo>& stored_registrations) { const std::vector<ServiceWorkerRegistrationInfo>& stored_registrations) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (is_stopped_) if (is_stopped_)
return; return;
context_->AddObserver(this); context_->AddObserver(this);
...@@ -114,20 +104,13 @@ void ServiceWorkerContextWatcher::OnStoredRegistrationsOnCoreThread( ...@@ -114,20 +104,13 @@ void ServiceWorkerContextWatcher::OnStoredRegistrationsOnCoreThread(
std::move(versions))); std::move(versions)));
} }
void ServiceWorkerContextWatcher::StopOnCoreThread() { ServiceWorkerContextWatcher::~ServiceWorkerContextWatcher() = default;
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
context_->RemoveObserver(this);
is_stopped_ = true;
}
ServiceWorkerContextWatcher::~ServiceWorkerContextWatcher() {
}
void ServiceWorkerContextWatcher::StoreRegistrationInfo( void ServiceWorkerContextWatcher::StoreRegistrationInfo(
const ServiceWorkerRegistrationInfo& registration_info, const ServiceWorkerRegistrationInfo& registration_info,
std::unordered_map<int64_t, std::unique_ptr<ServiceWorkerRegistrationInfo>>* std::unordered_map<int64_t, std::unique_ptr<ServiceWorkerRegistrationInfo>>*
info_map) { info_map) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (registration_info.registration_id == if (registration_info.registration_id ==
blink::mojom::kInvalidServiceWorkerRegistrationId) blink::mojom::kInvalidServiceWorkerRegistrationId)
return; return;
...@@ -140,7 +123,7 @@ void ServiceWorkerContextWatcher::StoreRegistrationInfo( ...@@ -140,7 +123,7 @@ void ServiceWorkerContextWatcher::StoreRegistrationInfo(
void ServiceWorkerContextWatcher::StoreVersionInfo( void ServiceWorkerContextWatcher::StoreVersionInfo(
const ServiceWorkerVersionInfo& version_info) { const ServiceWorkerVersionInfo& version_info) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (version_info.version_id == blink::mojom::kInvalidServiceWorkerVersionId) if (version_info.version_id == blink::mojom::kInvalidServiceWorkerVersionId)
return; return;
version_info_map_[version_info.version_id] = version_info_map_[version_info.version_id] =
...@@ -151,7 +134,7 @@ void ServiceWorkerContextWatcher::SendRegistrationInfo( ...@@ -151,7 +134,7 @@ void ServiceWorkerContextWatcher::SendRegistrationInfo(
int64_t registration_id, int64_t registration_id,
const GURL& scope, const GURL& scope,
ServiceWorkerRegistrationInfo::DeleteFlag delete_flag) { ServiceWorkerRegistrationInfo::DeleteFlag delete_flag) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); DCHECK_CURRENTLY_ON(BrowserThread::UI);
std::unique_ptr<std::vector<ServiceWorkerRegistrationInfo>> registrations = std::unique_ptr<std::vector<ServiceWorkerRegistrationInfo>> registrations =
std::make_unique<std::vector<ServiceWorkerRegistrationInfo>>(); std::make_unique<std::vector<ServiceWorkerRegistrationInfo>>();
ServiceWorkerRegistration* registration = ServiceWorkerRegistration* registration =
...@@ -171,7 +154,7 @@ void ServiceWorkerContextWatcher::SendRegistrationInfo( ...@@ -171,7 +154,7 @@ void ServiceWorkerContextWatcher::SendRegistrationInfo(
void ServiceWorkerContextWatcher::SendVersionInfo( void ServiceWorkerContextWatcher::SendVersionInfo(
const ServiceWorkerVersionInfo& version_info) { const ServiceWorkerVersionInfo& version_info) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); DCHECK_CURRENTLY_ON(BrowserThread::UI);
std::unique_ptr<std::vector<ServiceWorkerVersionInfo>> versions = std::unique_ptr<std::vector<ServiceWorkerVersionInfo>> versions =
std::make_unique<std::vector<ServiceWorkerVersionInfo>>(); std::make_unique<std::vector<ServiceWorkerVersionInfo>>();
versions->push_back(version_info); versions->push_back(version_info);
...@@ -210,14 +193,14 @@ void ServiceWorkerContextWatcher::RunWorkerErrorReportedCallback( ...@@ -210,14 +193,14 @@ void ServiceWorkerContextWatcher::RunWorkerErrorReportedCallback(
void ServiceWorkerContextWatcher::OnNewLiveRegistration(int64_t registration_id, void ServiceWorkerContextWatcher::OnNewLiveRegistration(int64_t registration_id,
const GURL& scope) { const GURL& scope) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); DCHECK_CURRENTLY_ON(BrowserThread::UI);
SendRegistrationInfo(registration_id, scope, SendRegistrationInfo(registration_id, scope,
ServiceWorkerRegistrationInfo::IS_NOT_DELETED); ServiceWorkerRegistrationInfo::IS_NOT_DELETED);
} }
void ServiceWorkerContextWatcher::OnNewLiveVersion( void ServiceWorkerContextWatcher::OnNewLiveVersion(
const ServiceWorkerVersionInfo& version_info) { const ServiceWorkerVersionInfo& version_info) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); DCHECK_CURRENTLY_ON(BrowserThread::UI);
int64_t version_id = version_info.version_id; int64_t version_id = version_info.version_id;
auto it = version_info_map_.find(version_id); auto it = version_info_map_.find(version_id);
if (it != version_info_map_.end()) { if (it != version_info_map_.end()) {
...@@ -258,7 +241,7 @@ void ServiceWorkerContextWatcher::OnVersionStateChanged( ...@@ -258,7 +241,7 @@ void ServiceWorkerContextWatcher::OnVersionStateChanged(
int64_t version_id, int64_t version_id,
const GURL& scope, const GURL& scope,
content::ServiceWorkerVersion::Status status) { content::ServiceWorkerVersion::Status status) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); DCHECK_CURRENTLY_ON(BrowserThread::UI);
auto it = version_info_map_.find(version_id); auto it = version_info_map_.find(version_id);
if (it == version_info_map_.end()) if (it == version_info_map_.end())
return; return;
...@@ -275,7 +258,7 @@ void ServiceWorkerContextWatcher::OnVersionDevToolsRoutingIdChanged( ...@@ -275,7 +258,7 @@ void ServiceWorkerContextWatcher::OnVersionDevToolsRoutingIdChanged(
int64_t version_id, int64_t version_id,
int process_id, int process_id,
int devtools_agent_route_id) { int devtools_agent_route_id) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); DCHECK_CURRENTLY_ON(BrowserThread::UI);
auto it = version_info_map_.find(version_id); auto it = version_info_map_.find(version_id);
if (it == version_info_map_.end()) if (it == version_info_map_.end())
return; return;
...@@ -295,7 +278,7 @@ void ServiceWorkerContextWatcher::OnMainScriptResponseSet( ...@@ -295,7 +278,7 @@ void ServiceWorkerContextWatcher::OnMainScriptResponseSet(
int64_t version_id, int64_t version_id,
base::Time script_response_time, base::Time script_response_time,
base::Time script_last_modified) { base::Time script_last_modified) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); DCHECK_CURRENTLY_ON(BrowserThread::UI);
auto it = version_info_map_.find(version_id); auto it = version_info_map_.find(version_id);
if (it == version_info_map_.end()) if (it == version_info_map_.end())
return; return;
...@@ -309,7 +292,7 @@ void ServiceWorkerContextWatcher::OnErrorReported( ...@@ -309,7 +292,7 @@ void ServiceWorkerContextWatcher::OnErrorReported(
int64_t version_id, int64_t version_id,
const GURL& scope, const GURL& scope,
const ServiceWorkerContextObserver::ErrorInfo& info) { const ServiceWorkerContextObserver::ErrorInfo& info) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); DCHECK_CURRENTLY_ON(BrowserThread::UI);
int64_t registration_id = blink::mojom::kInvalidServiceWorkerRegistrationId; int64_t registration_id = blink::mojom::kInvalidServiceWorkerRegistrationId;
auto it = version_info_map_.find(version_id); auto it = version_info_map_.find(version_id);
if (it != version_info_map_.end()) if (it != version_info_map_.end())
...@@ -326,7 +309,7 @@ void ServiceWorkerContextWatcher::OnReportConsoleMessage( ...@@ -326,7 +309,7 @@ void ServiceWorkerContextWatcher::OnReportConsoleMessage(
int64_t version_id, int64_t version_id,
const GURL& scope, const GURL& scope,
const ConsoleMessage& message) { const ConsoleMessage& message) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (message.message_level != blink::mojom::ConsoleMessageLevel::kError) if (message.message_level != blink::mojom::ConsoleMessageLevel::kError)
return; return;
int64_t registration_id = blink::mojom::kInvalidServiceWorkerRegistrationId; int64_t registration_id = blink::mojom::kInvalidServiceWorkerRegistrationId;
...@@ -347,7 +330,7 @@ void ServiceWorkerContextWatcher::OnControlleeAdded( ...@@ -347,7 +330,7 @@ void ServiceWorkerContextWatcher::OnControlleeAdded(
int64_t version_id, int64_t version_id,
const std::string& uuid, const std::string& uuid,
const ServiceWorkerClientInfo& info) { const ServiceWorkerClientInfo& info) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); DCHECK_CURRENTLY_ON(BrowserThread::UI);
auto it = version_info_map_.find(version_id); auto it = version_info_map_.find(version_id);
if (it == version_info_map_.end()) if (it == version_info_map_.end())
return; return;
...@@ -360,7 +343,7 @@ void ServiceWorkerContextWatcher::OnControlleeAdded( ...@@ -360,7 +343,7 @@ void ServiceWorkerContextWatcher::OnControlleeAdded(
void ServiceWorkerContextWatcher::OnControlleeRemoved(int64_t version_id, void ServiceWorkerContextWatcher::OnControlleeRemoved(int64_t version_id,
const std::string& uuid) { const std::string& uuid) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); DCHECK_CURRENTLY_ON(BrowserThread::UI);
auto it = version_info_map_.find(version_id); auto it = version_info_map_.find(version_id);
if (it == version_info_map_.end()) if (it == version_info_map_.end())
return; return;
...@@ -372,14 +355,14 @@ void ServiceWorkerContextWatcher::OnControlleeRemoved(int64_t version_id, ...@@ -372,14 +355,14 @@ void ServiceWorkerContextWatcher::OnControlleeRemoved(int64_t version_id,
void ServiceWorkerContextWatcher::OnRegistrationCompleted( void ServiceWorkerContextWatcher::OnRegistrationCompleted(
int64_t registration_id, int64_t registration_id,
const GURL& scope) { const GURL& scope) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); DCHECK_CURRENTLY_ON(BrowserThread::UI);
SendRegistrationInfo(registration_id, scope, SendRegistrationInfo(registration_id, scope,
ServiceWorkerRegistrationInfo::IS_NOT_DELETED); ServiceWorkerRegistrationInfo::IS_NOT_DELETED);
} }
void ServiceWorkerContextWatcher::OnRegistrationDeleted(int64_t registration_id, void ServiceWorkerContextWatcher::OnRegistrationDeleted(int64_t registration_id,
const GURL& scope) { const GURL& scope) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); DCHECK_CURRENTLY_ON(BrowserThread::UI);
SendRegistrationInfo(registration_id, scope, SendRegistrationInfo(registration_id, scope,
ServiceWorkerRegistrationInfo::IS_DELETED); ServiceWorkerRegistrationInfo::IS_DELETED);
} }
...@@ -387,7 +370,7 @@ void ServiceWorkerContextWatcher::OnRegistrationDeleted(int64_t registration_id, ...@@ -387,7 +370,7 @@ void ServiceWorkerContextWatcher::OnRegistrationDeleted(int64_t registration_id,
void ServiceWorkerContextWatcher::OnRunningStateChanged( void ServiceWorkerContextWatcher::OnRunningStateChanged(
int64_t version_id, int64_t version_id,
EmbeddedWorkerStatus running_status) { EmbeddedWorkerStatus running_status) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); DCHECK_CURRENTLY_ON(BrowserThread::UI);
auto it = version_info_map_.find(version_id); auto it = version_info_map_.find(version_id);
if (it == version_info_map_.end()) if (it == version_info_map_.end())
return; return;
......
...@@ -52,11 +52,9 @@ class CONTENT_EXPORT ServiceWorkerContextWatcher ...@@ -52,11 +52,9 @@ class CONTENT_EXPORT ServiceWorkerContextWatcher
~ServiceWorkerContextWatcher() override; ~ServiceWorkerContextWatcher() override;
void GetStoredRegistrationsOnCoreThread(); void OnStoredRegistrations(
void OnStoredRegistrationsOnCoreThread(
blink::ServiceWorkerStatusCode status, blink::ServiceWorkerStatusCode status,
const std::vector<ServiceWorkerRegistrationInfo>& stored_registrations); const std::vector<ServiceWorkerRegistrationInfo>& stored_registrations);
void StopOnCoreThread();
void StoreRegistrationInfo( void StoreRegistrationInfo(
const ServiceWorkerRegistrationInfo& registration, const ServiceWorkerRegistrationInfo& registration,
......
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