Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Unified Diff: content/browser/background_sync/background_sync_manager.cc

Issue 1614063002: [BackgroundSync Cleanup] Remove periodic sync code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@purge_power
Patch Set: Address comments from PS3 Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/background_sync/background_sync_manager.cc
diff --git a/content/browser/background_sync/background_sync_manager.cc b/content/browser/background_sync/background_sync_manager.cc
index b10978dde30e5412951fab805c921d8af67b644d..d596760706d62bf58d5f68afa65d7768c5f18e3f 100644
--- a/content/browser/background_sync/background_sync_manager.cc
+++ b/content/browser/background_sync/background_sync_manager.cc
@@ -163,19 +163,17 @@ BackgroundSyncManager::~BackgroundSyncManager() {
BackgroundSyncManager::RegistrationKey::RegistrationKey(
const BackgroundSyncRegistration& registration)
- : RegistrationKey(registration.options()->tag,
- registration.options()->periodicity) {
-}
+ : RegistrationKey(registration.options()->tag) {}
BackgroundSyncManager::RegistrationKey::RegistrationKey(
const BackgroundSyncRegistrationOptions& options)
- : RegistrationKey(options.tag, options.periodicity) {
-}
+ : RegistrationKey(options.tag) {}
-BackgroundSyncManager::RegistrationKey::RegistrationKey(
- const std::string& tag,
- SyncPeriodicity periodicity)
- : value_(periodicity == SYNC_ONE_SHOT ? "o_" + tag : "p_" + tag) {
+BackgroundSyncManager::RegistrationKey::RegistrationKey(const std::string& tag)
+ : value_("o_" + tag) {
+ // Note that the "o_" prefix on the key is because at one time one-shots were
+ // prefixed with an "o_" and periodic with a "p_". Removing the "o_" requires
+ // migration.
}
void BackgroundSyncManager::Register(
@@ -187,7 +185,7 @@ void BackgroundSyncManager::Register(
if (disabled_) {
BackgroundSyncMetrics::CountRegisterFailure(
- options.periodicity, BACKGROUND_SYNC_STATUS_STORAGE_ERROR);
+ BACKGROUND_SYNC_STATUS_STORAGE_ERROR);
PostErrorResponse(BACKGROUND_SYNC_STATUS_STORAGE_ERROR, callback);
return;
}
@@ -209,7 +207,6 @@ void BackgroundSyncManager::Register(
void BackgroundSyncManager::GetRegistration(
int64_t sw_registration_id,
const std::string& sync_registration_tag,
- SyncPeriodicity periodicity,
const StatusAndRegistrationCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -218,7 +215,7 @@ void BackgroundSyncManager::GetRegistration(
return;
}
- RegistrationKey registration_key(sync_registration_tag, periodicity);
+ RegistrationKey registration_key(sync_registration_tag);
op_scheduler_.ScheduleOperation(base::Bind(
&BackgroundSyncManager::GetRegistrationImpl,
@@ -228,7 +225,6 @@ void BackgroundSyncManager::GetRegistration(
void BackgroundSyncManager::GetRegistrations(
int64_t sw_registration_id,
- SyncPeriodicity periodicity,
const StatusAndRegistrationsCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -246,7 +242,7 @@ void BackgroundSyncManager::GetRegistrations(
op_scheduler_.ScheduleOperation(
base::Bind(&BackgroundSyncManager::GetRegistrationsImpl,
weak_ptr_factory_.GetWeakPtr(), sw_registration_id,
- periodicity, MakeStatusAndRegistrationsCompletion(callback)));
+ MakeStatusAndRegistrationsCompletion(callback)));
}
// Given a HandleId |handle_id|, return a new handle for the same
@@ -397,8 +393,7 @@ void BackgroundSyncManager::InitDidGetDataFromBackend(
break;
}
- RegistrationKey registration_key(registration_proto.tag(),
- registration_proto.periodicity());
+ RegistrationKey registration_key(registration_proto.tag());
scoped_refptr<RefCountedRegistration> ref_registration(
new RefCountedRegistration());
@@ -407,8 +402,6 @@ void BackgroundSyncManager::InitDidGetDataFromBackend(
BackgroundSyncRegistrationOptions* options = registration->options();
options->tag = registration_proto.tag();
- options->periodicity = registration_proto.periodicity();
- options->min_period = registration_proto.min_period();
options->network_state = registration_proto.network_state();
registration->set_id(registration_proto.id());
@@ -444,7 +437,7 @@ void BackgroundSyncManager::RegisterCheckIfHasMainFrame(
service_worker_context_->GetLiveRegistration(sw_registration_id);
if (!sw_registration || !sw_registration->active_version()) {
BackgroundSyncMetrics::CountRegisterFailure(
- options.periodicity, BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER);
+ BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER);
PostErrorResponse(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback);
return;
}
@@ -465,7 +458,7 @@ void BackgroundSyncManager::RegisterDidCheckIfMainFrame(
if (!has_main_frame_client) {
BackgroundSyncMetrics::CountRegisterFailure(
- options.periodicity, BACKGROUND_SYNC_STATUS_NOT_ALLOWED);
+ BACKGROUND_SYNC_STATUS_NOT_ALLOWED);
PostErrorResponse(BACKGROUND_SYNC_STATUS_NOT_ALLOWED, callback);
return;
}
@@ -480,14 +473,14 @@ void BackgroundSyncManager::RegisterImpl(
if (disabled_) {
BackgroundSyncMetrics::CountRegisterFailure(
- options.periodicity, BACKGROUND_SYNC_STATUS_STORAGE_ERROR);
+ BACKGROUND_SYNC_STATUS_STORAGE_ERROR);
PostErrorResponse(BACKGROUND_SYNC_STATUS_STORAGE_ERROR, callback);
return;
}
if (options.tag.length() > kMaxTagLength) {
BackgroundSyncMetrics::CountRegisterFailure(
- options.periodicity, BACKGROUND_SYNC_STATUS_NOT_ALLOWED);
+ BACKGROUND_SYNC_STATUS_NOT_ALLOWED);
PostErrorResponse(BACKGROUND_SYNC_STATUS_NOT_ALLOWED, callback);
return;
}
@@ -496,7 +489,7 @@ void BackgroundSyncManager::RegisterImpl(
service_worker_context_->GetLiveRegistration(sw_registration_id);
if (!sw_registration || !sw_registration->active_version()) {
BackgroundSyncMetrics::CountRegisterFailure(
- options.periodicity, BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER);
+ BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER);
PostErrorResponse(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback);
return;
}
@@ -518,7 +511,6 @@ void BackgroundSyncManager::RegisterImpl(
? BackgroundSyncMetrics::REGISTRATION_COULD_FIRE
: BackgroundSyncMetrics::REGISTRATION_COULD_NOT_FIRE;
BackgroundSyncMetrics::CountRegisterSuccess(
- existing_registration->options()->periodicity,
registration_could_fire,
BackgroundSyncMetrics::REGISTRATION_IS_DUPLICATE);
@@ -666,8 +658,6 @@ void BackgroundSyncManager::StoreRegistrations(
registrations_proto.add_registration();
registration_proto->set_id(registration.id());
registration_proto->set_tag(registration.options()->tag);
- registration_proto->set_periodicity(registration.options()->periodicity);
- registration_proto->set_min_period(registration.options()->min_period);
registration_proto->set_network_state(
registration.options()->network_state);
registration_proto->set_num_attempts(registration.num_attempts());
@@ -695,7 +685,6 @@ void BackgroundSyncManager::RegisterDidStore(
if (status == SERVICE_WORKER_ERROR_NOT_FOUND) {
// The service worker registration is gone.
BackgroundSyncMetrics::CountRegisterFailure(
- new_registration->options()->periodicity,
BACKGROUND_SYNC_STATUS_STORAGE_ERROR);
active_registrations_.erase(sw_registration_id);
PostErrorResponse(BACKGROUND_SYNC_STATUS_STORAGE_ERROR, callback);
@@ -706,7 +695,6 @@ void BackgroundSyncManager::RegisterDidStore(
LOG(ERROR) << "BackgroundSync failed to store registration due to backend "
"failure.";
BackgroundSyncMetrics::CountRegisterFailure(
- new_registration->options()->periodicity,
BACKGROUND_SYNC_STATUS_STORAGE_ERROR);
DisableAndClearManager(base::Bind(
callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR,
@@ -719,7 +707,7 @@ void BackgroundSyncManager::RegisterDidStore(
? BackgroundSyncMetrics::REGISTRATION_COULD_FIRE
: BackgroundSyncMetrics::REGISTRATION_COULD_NOT_FIRE;
BackgroundSyncMetrics::CountRegisterSuccess(
- new_registration->options()->periodicity, registration_could_fire,
+ registration_could_fire,
BackgroundSyncMetrics::REGISTRATION_IS_NOT_DUPLICATE);
FireReadyEvents();
@@ -870,7 +858,6 @@ void BackgroundSyncManager::Unregister(
if (disabled_) {
BackgroundSyncMetrics::CountUnregister(
- registration->options()->periodicity,
BACKGROUND_SYNC_STATUS_STORAGE_ERROR);
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR));
@@ -880,20 +867,19 @@ void BackgroundSyncManager::Unregister(
op_scheduler_.ScheduleOperation(base::Bind(
&BackgroundSyncManager::UnregisterImpl, weak_ptr_factory_.GetWeakPtr(),
sw_registration_id, RegistrationKey(*registration), registration->id(),
- registration->options()->periodicity, MakeStatusCompletion(callback)));
+ MakeStatusCompletion(callback)));
}
void BackgroundSyncManager::UnregisterImpl(
int64_t sw_registration_id,
const RegistrationKey& registration_key,
BackgroundSyncRegistration::RegistrationId sync_registration_id,
- SyncPeriodicity periodicity,
const StatusCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (disabled_) {
BackgroundSyncMetrics::CountUnregister(
- periodicity, BACKGROUND_SYNC_STATUS_STORAGE_ERROR);
+ BACKGROUND_SYNC_STATUS_STORAGE_ERROR);
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR));
return;
@@ -904,8 +890,7 @@ void BackgroundSyncManager::UnregisterImpl(
if (!existing_registration ||
existing_registration->value()->id() != sync_registration_id) {
- BackgroundSyncMetrics::CountUnregister(periodicity,
- BACKGROUND_SYNC_STATUS_NOT_FOUND);
+ BackgroundSyncMetrics::CountUnregister(BACKGROUND_SYNC_STATUS_NOT_FOUND);
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_NOT_FOUND));
return;
@@ -915,14 +900,13 @@ void BackgroundSyncManager::UnregisterImpl(
RemoveActiveRegistration(sw_registration_id, registration_key);
- StoreRegistrations(sw_registration_id,
- base::Bind(&BackgroundSyncManager::UnregisterDidStore,
- weak_ptr_factory_.GetWeakPtr(),
- sw_registration_id, periodicity, callback));
+ StoreRegistrations(
+ sw_registration_id,
+ base::Bind(&BackgroundSyncManager::UnregisterDidStore,
+ weak_ptr_factory_.GetWeakPtr(), sw_registration_id, callback));
}
void BackgroundSyncManager::UnregisterDidStore(int64_t sw_registration_id,
- SyncPeriodicity periodicity,
const StatusCallback& callback,
ServiceWorkerStatusCode status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -930,7 +914,7 @@ void BackgroundSyncManager::UnregisterDidStore(int64_t sw_registration_id,
if (status == SERVICE_WORKER_ERROR_NOT_FOUND) {
// ServiceWorker was unregistered.
BackgroundSyncMetrics::CountUnregister(
- periodicity, BACKGROUND_SYNC_STATUS_STORAGE_ERROR);
+ BACKGROUND_SYNC_STATUS_STORAGE_ERROR);
active_registrations_.erase(sw_registration_id);
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR));
@@ -940,14 +924,13 @@ void BackgroundSyncManager::UnregisterDidStore(int64_t sw_registration_id,
if (status != SERVICE_WORKER_OK) {
LOG(ERROR) << "BackgroundSync failed to unregister due to backend failure.";
BackgroundSyncMetrics::CountUnregister(
- periodicity, BACKGROUND_SYNC_STATUS_STORAGE_ERROR);
+ BACKGROUND_SYNC_STATUS_STORAGE_ERROR);
DisableAndClearManager(
base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR));
return;
}
- BackgroundSyncMetrics::CountUnregister(periodicity,
- BACKGROUND_SYNC_STATUS_OK);
+ BackgroundSyncMetrics::CountUnregister(BACKGROUND_SYNC_STATUS_OK);
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_OK));
}
@@ -977,7 +960,6 @@ void BackgroundSyncManager::NotifyWhenFinishedImpl(
scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle,
const StatusAndStateCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- DCHECK_EQ(SYNC_ONE_SHOT, registration_handle->options()->periodicity);
if (disabled_) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
@@ -1034,7 +1016,6 @@ void BackgroundSyncManager::GetRegistrationImpl(
void BackgroundSyncManager::GetRegistrationsImpl(
int64_t sw_registration_id,
- SyncPeriodicity periodicity,
const StatusAndRegistrationsCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -1055,10 +1036,8 @@ void BackgroundSyncManager::GetRegistrationsImpl(
const BackgroundSyncRegistrations& registrations = it->second;
for (const auto& tag_and_registration : registrations.registration_map) {
RefCountedRegistration* registration = tag_and_registration.second.get();
- if (registration->value()->options()->periodicity == periodicity) {
- out_registrations->push_back(
- CreateRegistrationHandle(registration).release());
- }
+ out_registrations->push_back(
+ CreateRegistrationHandle(registration).release());
}
}
@@ -1077,18 +1056,12 @@ bool BackgroundSyncManager::IsRegistrationReadyToFire(
const BackgroundSyncRegistration& registration) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- // TODO(jkarlin): Add support for firing periodic registrations.
- if (registration.options()->periodicity == SYNC_PERIODIC)
- return false;
-
if (registration.sync_state() != BackgroundSyncState::PENDING)
return false;
if (clock_->Now() < registration.delay_until())
return false;
- DCHECK_EQ(SYNC_ONE_SHOT, registration.options()->periodicity);
-
return AreOptionConditionsMet(*registration.options());
}
@@ -1102,18 +1075,13 @@ void BackgroundSyncManager::RunInBackgroundIfNecessary() {
const BackgroundSyncRegistration& registration =
*key_and_registration.second->value();
if (registration.sync_state() == BackgroundSyncState::PENDING) {
- if (registration.options()->periodicity == SYNC_ONE_SHOT) {
- if (clock_->Now() >= registration.delay_until()) {
- soonest_wakeup_delta = base::TimeDelta();
- } else {
- base::TimeDelta delay_delta =
- registration.delay_until() - clock_->Now();
- if (delay_delta < soonest_wakeup_delta)
- soonest_wakeup_delta = delay_delta;
- }
+ if (clock_->Now() >= registration.delay_until()) {
+ soonest_wakeup_delta = base::TimeDelta();
} else {
- // TODO(jkarlin): Support keeping the browser alive for periodic
- // syncs.
+ base::TimeDelta delay_delta =
+ registration.delay_until() - clock_->Now();
+ if (delay_delta < soonest_wakeup_delta)
+ soonest_wakeup_delta = delay_delta;
}
}
}
@@ -1260,8 +1228,7 @@ void BackgroundSyncManager::FireReadyEventsDidFindRegistration(
HasMainFrameProviderHost(
service_worker_registration->pattern().GetOrigin(),
- base::Bind(&BackgroundSyncMetrics::RecordEventStarted,
- registration->value()->options()->periodicity));
+ base::Bind(&BackgroundSyncMetrics::RecordEventStarted));
FireOneShotSync(
handle_id, service_worker_registration->active_version(), last_chance,
@@ -1326,52 +1293,44 @@ void BackgroundSyncManager::EventCompleteImpl(
HasMainFrameProviderHost(
sw_registration->pattern().GetOrigin(),
base::Bind(&BackgroundSyncMetrics::RecordEventResult,
- registration->options()->periodicity,
status_code == SERVICE_WORKER_OK));
}
- if (registration->options()->periodicity == SYNC_ONE_SHOT) {
+ if (registration->sync_state() ==
+ BackgroundSyncState::REREGISTERED_WHILE_FIRING) {
+ registration->set_sync_state(BackgroundSyncState::PENDING);
+ registration->set_num_attempts(0);
+ } else if (status_code != SERVICE_WORKER_OK) { // Sync failed
+ bool can_retry =
+ registration->num_attempts() < parameters_->max_sync_attempts;
if (registration->sync_state() ==
- BackgroundSyncState::REREGISTERED_WHILE_FIRING) {
+ BackgroundSyncState::UNREGISTERED_WHILE_FIRING) {
+ registration->set_sync_state(can_retry ? BackgroundSyncState::UNREGISTERED
+ : BackgroundSyncState::FAILED);
+ registration->RunFinishedCallbacks();
+ } else if (can_retry) {
registration->set_sync_state(BackgroundSyncState::PENDING);
- registration->set_num_attempts(0);
- } else if (status_code != SERVICE_WORKER_OK) { // Sync failed
- bool can_retry =
- registration->num_attempts() < parameters_->max_sync_attempts;
- if (registration->sync_state() ==
- BackgroundSyncState::UNREGISTERED_WHILE_FIRING) {
- registration->set_sync_state(can_retry
- ? BackgroundSyncState::UNREGISTERED
- : BackgroundSyncState::FAILED);
- registration->RunFinishedCallbacks();
- } else if (can_retry) {
- registration->set_sync_state(BackgroundSyncState::PENDING);
- registration->set_delay_until(
- clock_->Now() +
- parameters_->initial_retry_delay *
- pow(parameters_->retry_delay_factor,
- registration->num_attempts() - 1));
- } else {
- registration->set_sync_state(BackgroundSyncState::FAILED);
- registration->RunFinishedCallbacks();
- }
- } else { // Sync succeeded
- registration->set_sync_state(BackgroundSyncState::SUCCESS);
+ registration->set_delay_until(clock_->Now() +
+ parameters_->initial_retry_delay *
+ pow(parameters_->retry_delay_factor,
+ registration->num_attempts() - 1));
+ } else {
+ registration->set_sync_state(BackgroundSyncState::FAILED);
registration->RunFinishedCallbacks();
}
+ } else { // Sync succeeded
+ registration->set_sync_state(BackgroundSyncState::SUCCESS);
+ registration->RunFinishedCallbacks();
+ }
- if (registration->HasCompleted()) {
- RegistrationKey key(*registration);
- RefCountedRegistration* active_registration =
- LookupActiveRegistration(service_worker_id, key);
- if (active_registration &&
- active_registration->value()->id() == registration->id()) {
- RemoveActiveRegistration(service_worker_id, key);
- }
+ if (registration->HasCompleted()) {
+ RegistrationKey key(*registration);
+ RefCountedRegistration* active_registration =
+ LookupActiveRegistration(service_worker_id, key);
+ if (active_registration &&
+ active_registration->value()->id() == registration->id()) {
+ RemoveActiveRegistration(service_worker_id, key);
}
- } else { // !SYNC_ONE_SHOT
- // TODO(jkarlin): Add support for running periodic syncs. (crbug.com/479674)
- NOTREACHED();
}
if (disabled_) {

Powered by Google App Engine
This is Rietveld 408576698