Commit 81635fcd authored by Matt Falkenhagen's avatar Matt Falkenhagen Committed by Commit Bot

background sync: Prepare for service worker UI thread core (pt 2).

This is a follow-up to r689906. It converts code added since then.

Also, this fixes a flaky DCHECK hit when trying to use the
KeepAliveRegistry after shutdown, when running the
VerifyShutdownBehavior test locally. I think this happens when the core
thread is the UI thread because we immediately try to make keep alive
object instead of posting a task to the UI thread to do so.

[ RUN      ] BackgroundSyncBrowserTest.VerifyShutdownBehavior
[FATAL:keep_alive_registry.cc(107)] Check failed: !is_shutting_down_.
...
3 KeepAliveRegistry::Register()
4 BackgroundSyncControllerImpl::BackgroundSyncEventKeepAliveImpl::BackgroundSyncEventKeepAliveImpl()
5 BackgroundSyncControllerImpl::CreateBackgroundSyncEventKeepAlive()
6 content::(anonymous namespace)::CreateBackgroundSyncEventKeepAliveOnUIThread()
7 content::BackgroundSyncManager::DidResolveRegistrationImpl()

Bug: 824858
Change-Id: I5d2ad7878cbd35203fe81fda013f1a839ee89c7f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1772415Reviewed-by: default avatarMugdha Lakhani <nator@chromium.org>
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691621}
parent 88e73b0d
......@@ -12,6 +12,7 @@
#include "chrome/browser/metrics/ukm_background_recorder_service.h"
#include "chrome/browser/profiles/profile.h"
#include "components/history/core/browser/history_service.h"
#include "components/keep_alive_registry/keep_alive_registry.h"
#include "components/variations/variations_associated_data.h"
#include "content/public/browser/background_sync_context.h"
#include "content/public/browser/background_sync_controller.h"
......@@ -331,7 +332,8 @@ base::TimeDelta BackgroundSyncControllerImpl::GetNextEventDelay(
std::unique_ptr<content::BackgroundSyncController::BackgroundSyncEventKeepAlive>
BackgroundSyncControllerImpl::CreateBackgroundSyncEventKeepAlive() {
#if !defined(OS_ANDROID)
return std::make_unique<BackgroundSyncEventKeepAliveImpl>();
if (!KeepAliveRegistry::GetInstance()->IsShuttingDown())
return std::make_unique<BackgroundSyncEventKeepAliveImpl>();
#endif
return nullptr;
}
......
......@@ -1548,7 +1548,7 @@ bool& BackgroundSyncManager::delayed_processing_scheduled(
void BackgroundSyncManager::ScheduleOrCancelDelayedProcessing(
BackgroundSyncType sync_type) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
bool can_fire_with_connectivity =
CanFireAnyRegistrationUponConnectivity(sync_type);
......@@ -1568,7 +1568,7 @@ void BackgroundSyncManager::ScheduleOrCancelDelayedProcessing(
bool BackgroundSyncManager::IsRegistrationReadyToFire(
const BackgroundSyncRegistration& registration,
int64_t service_worker_id) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
if (clock_->Now() < registration.delay_until())
return false;
......
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