Commit 8428d739 authored by Matt Falkenhagen's avatar Matt Falkenhagen Committed by Commit Bot

notifications: Prepare for service worker UI thread core.

The thread ServiceWorkerContextCore lives on (the "core thread") will
move from the IO thread to the UI thread when the ServiceWorkerOnUI
feature is enabled.

This CL makes code in content/browser/notifications aware of the core
thread instead of assuming the IO thread. This makes the remaining
"Push*" browser_tests pass when the feature is enabled.

Bug: 824858
Change-Id: Ice834d2d4a69505b977cb469b516e0705c36202c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1768602Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690276}
parent 9727a4fa
......@@ -80,29 +80,29 @@ PersistentNotificationStatus ConvertServiceWorkerStatus(
}
// To be called when a notification event has finished with a
// blink::ServiceWorkerStatusCode result. Will post a task to call
// blink::ServiceWorkerStatusCode result. Will run or post a task to call
// |dispatch_complete_callback| on the UI thread with a
// PersistentNotificationStatus derived from the service worker status.
void ServiceWorkerNotificationEventFinished(
NotificationDispatchCompleteCallback dispatch_complete_callback,
blink::ServiceWorkerStatusCode service_worker_status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
base::PostTask(
FROM_HERE, {BrowserThread::UI},
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
RunOrPostTaskOnThread(
FROM_HERE, BrowserThread::UI,
base::BindOnce(std::move(dispatch_complete_callback),
ConvertServiceWorkerStatus(service_worker_status)));
}
// Dispatches the given notification action event on
// |service_worker_registration| if the registration was available. Must be
// called on the IO thread.
// called on the service worker core thread.
void DispatchNotificationEventOnRegistration(
const NotificationDatabaseData& notification_database_data,
NotificationOperationCallback dispatch_event_action,
NotificationDispatchCompleteCallback dispatch_complete_callback,
blink::ServiceWorkerStatusCode service_worker_status,
scoped_refptr<ServiceWorkerRegistration> service_worker_registration) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
#if defined(OS_ANDROID)
// This LOG(INFO) deliberately exists to help track down the cause of
// https://crbug.com/534537, where notifications sometimes do not react to
......@@ -175,8 +175,8 @@ void FindServiceWorkerRegistration(
return;
}
base::PostTask(
FROM_HERE, {BrowserThread::IO},
RunOrPostTaskOnThread(
FROM_HERE, ServiceWorkerContext::GetCoreThreadId(),
base::BindOnce(&ServiceWorkerContextWrapper::FindReadyRegistrationForId,
service_worker_context,
notification_database_data.service_worker_registration_id,
......@@ -209,7 +209,7 @@ void ReadNotificationDatabaseData(
// -----------------------------------------------------------------------------
// Dispatches the notificationclick event on |service_worker|.
// Must be called on the IO thread.
// Must be called on the service worker core thread.
void DispatchNotificationClickEventOnWorker(
const scoped_refptr<ServiceWorkerVersion>& service_worker,
const NotificationDatabaseData& notification_database_data,
......@@ -217,7 +217,7 @@ void DispatchNotificationClickEventOnWorker(
const base::Optional<base::string16>& reply,
ServiceWorkerVersion::StatusCallback callback,
blink::ServiceWorkerStatusCode start_worker_status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
if (start_worker_status != blink::ServiceWorkerStatusCode::kOk) {
std::move(callback).Run(start_worker_status);
return;
......@@ -245,10 +245,10 @@ void DoDispatchNotificationClickEvent(
const ServiceWorkerRegistration* service_worker_registration,
const NotificationDatabaseData& notification_database_data,
NotificationDispatchCompleteCallback dispatch_complete_callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
base::PostTask(
FROM_HERE, {BrowserThread::UI},
RunOrPostTaskOnThread(
FROM_HERE, BrowserThread::UI,
base::BindOnce(&notifications::LogNotificationClickedEventToDevTools,
browser_context, notification_database_data, action_index,
reply));
......@@ -288,9 +288,9 @@ void DeleteNotificationDataFromDatabase(
const scoped_refptr<PlatformNotificationContext>& notification_context,
NotificationDispatchCompleteCallback dispatch_complete_callback,
blink::ServiceWorkerStatusCode status_code) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
base::PostTask(
FROM_HERE, {BrowserThread::UI},
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
RunOrPostTaskOnThread(
FROM_HERE, BrowserThread::UI,
base::BindOnce(
&PlatformNotificationContext::DeleteNotificationData,
notification_context, notification_id, origin,
......@@ -300,13 +300,13 @@ void DeleteNotificationDataFromDatabase(
}
// Dispatches the notificationclose event on |service_worker|.
// Must be called on the IO thread.
// Must be called on the service worker core thread.
void DispatchNotificationCloseEventOnWorker(
const scoped_refptr<ServiceWorkerVersion>& service_worker,
const NotificationDatabaseData& notification_database_data,
ServiceWorkerVersion::StatusCallback callback,
blink::ServiceWorkerStatusCode start_worker_status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
if (start_worker_status != blink::ServiceWorkerStatusCode::kOk) {
std::move(callback).Run(start_worker_status);
return;
......@@ -330,7 +330,7 @@ void DoDispatchNotificationCloseEvent(
const ServiceWorkerRegistration* service_worker_registration,
const NotificationDatabaseData& notification_database_data,
NotificationDispatchCompleteCallback dispatch_complete_callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
if (by_user) {
service_worker_registration->active_version()->RunAfterStartWorker(
ServiceWorkerMetrics::EventType::NOTIFICATION_CLOSE,
......
......@@ -47,7 +47,7 @@ NotificationStorage::~NotificationStorage() = default;
void NotificationStorage::WriteNotificationData(
const NotificationDatabaseData& data,
PlatformNotificationContext::WriteResultCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
std::string serialized_data;
if (!SerializeNotificationDatabaseData(data, &serialized_data)) {
DLOG(ERROR) << "Unable to serialize data for a notification belonging "
......@@ -81,7 +81,7 @@ void NotificationStorage::ReadNotificationDataAndRecordInteraction(
const std::string& notification_id,
PlatformNotificationContext::Interaction interaction,
PlatformNotificationContext::ReadResultCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
service_worker_context_->GetRegistrationUserData(
service_worker_registration_id, {CreateDataKey(notification_id)},
base::BindOnce(&NotificationStorage::OnReadCompleteUpdateInteraction,
......
......@@ -60,19 +60,25 @@ void PlatformNotificationServiceProxy::VerifyServiceWorkerScope(
DisplayResultCallback callback,
blink::ServiceWorkerStatusCode status,
scoped_refptr<ServiceWorkerRegistration> registration) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
base::OnceClosure task;
if (status == blink::ServiceWorkerStatusCode::kOk &&
registration->scope().GetOrigin() == data.origin) {
base::PostTask(
FROM_HERE, {BrowserThread::UI, base::TaskPriority::USER_VISIBLE},
base::BindOnce(&PlatformNotificationServiceProxy::DoDisplayNotification,
AsWeakPtr(), data, registration->scope(),
std::move(callback)));
task = base::BindOnce(
&PlatformNotificationServiceProxy::DoDisplayNotification, AsWeakPtr(),
data, registration->scope(), std::move(callback));
} else {
task = base::BindOnce(std::move(callback), /* success= */ false,
/* notification_id= */ "");
}
if (ServiceWorkerContextWrapper::IsServiceWorkerOnUIEnabled()) {
std::move(task).Run();
} else {
base::PostTask(FROM_HERE,
{BrowserThread::UI, base::TaskPriority::USER_VISIBLE},
base::BindOnce(std::move(callback), /* success= */ false,
/* notification_id= */ ""));
std::move(task));
}
}
......@@ -88,7 +94,9 @@ void PlatformNotificationServiceProxy::DisplayNotification(
}
base::PostTask(
FROM_HERE, {BrowserThread::IO, base::TaskPriority::USER_VISIBLE},
FROM_HERE,
{ServiceWorkerContext::GetCoreThreadId(),
base::TaskPriority::USER_VISIBLE},
base::BindOnce(
&ServiceWorkerContextWrapper::FindReadyRegistrationForId,
service_worker_context_, data.service_worker_registration_id,
......
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