Commit 1c8dbbf5 authored by jkarlin's avatar jkarlin Committed by Commit bot

[BackgroundSyncManager] Rename BackgroundSyncRegistration.name to tag

This refactoring of 'name' to 'tag' is part of tracking the latest spec changes found in https://github.com/slightlyoff/BackgroundSync/pull/74

BUG=474573

Review URL: https://codereview.chromium.org/1068863003

Cr-Commit-Position: refs/heads/master@{#324233}
parent 5eef409e
......@@ -21,7 +21,7 @@ enum SyncPowerState {
message BackgroundSyncRegistrationProto {
required int64 id = 1;
required string name = 2;
required string tag = 2;
required bool fire_once = 3;
required int64 min_period = 4;
required SyncNetworkState network_state = 5;
......
......@@ -73,7 +73,7 @@ void BackgroundSyncManager::Register(
void BackgroundSyncManager::Unregister(
const GURL& origin,
int64 sw_registration_id,
const std::string& sync_registration_name,
const std::string& sync_registration_tag,
BackgroundSyncRegistration::RegistrationId sync_registration_id,
const StatusCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
......@@ -86,14 +86,14 @@ void BackgroundSyncManager::Unregister(
op_scheduler_.ScheduleOperation(base::Bind(
&BackgroundSyncManager::UnregisterImpl, weak_ptr_factory_.GetWeakPtr(),
origin, sw_registration_id, sync_registration_name, sync_registration_id,
origin, sw_registration_id, sync_registration_tag, sync_registration_id,
MakeStatusCompletion(callback)));
}
void BackgroundSyncManager::GetRegistration(
const GURL& origin,
int64 sw_registration_id,
const std::string sync_registration_name,
const std::string sync_registration_tag,
const StatusAndRegistrationCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
......@@ -107,7 +107,7 @@ void BackgroundSyncManager::GetRegistration(
op_scheduler_.ScheduleOperation(base::Bind(
&BackgroundSyncManager::GetRegistrationImpl,
weak_ptr_factory_.GetWeakPtr(), origin, sw_registration_id,
sync_registration_name, MakeStatusAndRegistrationCompletion(callback)));
sync_registration_tag, MakeStatusAndRegistrationCompletion(callback)));
}
void BackgroundSyncManager::OnRegistrationDeleted(int64 registration_id,
......@@ -194,10 +194,10 @@ void BackgroundSyncManager::InitDidGetDataFromBackend(
}
BackgroundSyncRegistration* registration =
&registrations->name_to_registration_map[registration_proto.name()];
&registrations->tag_to_registration_map[registration_proto.tag()];
registration->id = registration_proto.id();
registration->name = registration_proto.name();
registration->tag = registration_proto.tag();
registration->fire_once = registration_proto.fire_once();
registration->min_period = registration_proto.min_period();
registration->network_state = registration_proto.network_state();
......@@ -233,7 +233,7 @@ void BackgroundSyncManager::RegisterImpl(
}
BackgroundSyncRegistration existing_registration;
if (LookupRegistration(sw_registration_id, sync_registration.name,
if (LookupRegistration(sw_registration_id, sync_registration.tag,
&existing_registration)) {
if (existing_registration.Equals(sync_registration)) {
base::MessageLoop::current()->PostTask(
......@@ -306,7 +306,7 @@ void BackgroundSyncManager::DisableAndClearManagerClearedOne(
bool BackgroundSyncManager::LookupRegistration(
int64 sw_registration_id,
const std::string& sync_registration_name,
const std::string& sync_registration_tag,
BackgroundSyncRegistration* existing_registration) {
SWIdToRegistrationsMap::iterator it =
sw_to_registrations_map_.find(sw_registration_id);
......@@ -314,14 +314,13 @@ bool BackgroundSyncManager::LookupRegistration(
return false;
const BackgroundSyncRegistrations& registrations = it->second;
const auto name_and_registration_iter =
registrations.name_to_registration_map.find(sync_registration_name);
if (name_and_registration_iter ==
registrations.name_to_registration_map.end())
const auto tag_and_registration_iter =
registrations.tag_to_registration_map.find(sync_registration_tag);
if (tag_and_registration_iter == registrations.tag_to_registration_map.end())
return false;
if (existing_registration)
*existing_registration = name_and_registration_iter->second;
*existing_registration = tag_and_registration_iter->second;
return true;
}
......@@ -336,14 +335,14 @@ void BackgroundSyncManager::StoreRegistrations(
BackgroundSyncRegistrationsProto registrations_proto;
registrations_proto.set_next_registration_id(registrations.next_id);
for (const auto& name_and_registration :
registrations.name_to_registration_map) {
for (const auto& tag_and_registration :
registrations.tag_to_registration_map) {
const BackgroundSyncRegistration& registration =
name_and_registration.second;
tag_and_registration.second;
BackgroundSyncRegistrationProto* registration_proto =
registrations_proto.add_registration();
registration_proto->set_id(registration.id);
registration_proto->set_name(registration.name);
registration_proto->set_tag(registration.tag);
registration_proto->set_fire_once(registration.fire_once);
registration_proto->set_min_period(registration.min_period);
registration_proto->set_network_state(registration.network_state);
......@@ -386,14 +385,14 @@ void BackgroundSyncManager::RegisterDidStore(
void BackgroundSyncManager::RemoveRegistrationFromMap(
int64 sw_registration_id,
const std::string& sync_registration_name) {
const std::string& sync_registration_tag) {
DCHECK(
LookupRegistration(sw_registration_id, sync_registration_name, nullptr));
LookupRegistration(sw_registration_id, sync_registration_tag, nullptr));
BackgroundSyncRegistrations* registrations =
&sw_to_registrations_map_[sw_registration_id];
registrations->name_to_registration_map.erase(sync_registration_name);
registrations->tag_to_registration_map.erase(sync_registration_tag);
}
void BackgroundSyncManager::AddRegistrationToMap(
......@@ -404,7 +403,7 @@ void BackgroundSyncManager::AddRegistrationToMap(
BackgroundSyncRegistrations* registrations =
&sw_to_registrations_map_[sw_registration_id];
registrations->name_to_registration_map[sync_registration.name] =
registrations->tag_to_registration_map[sync_registration.tag] =
sync_registration;
}
......@@ -431,7 +430,7 @@ void BackgroundSyncManager::GetDataFromBackend(
void BackgroundSyncManager::UnregisterImpl(
const GURL& origin,
int64 sw_registration_id,
const std::string& sync_registration_name,
const std::string& sync_registration_tag,
BackgroundSyncRegistration::RegistrationId sync_registration_id,
const StatusCallback& callback) {
if (disabled_) {
......@@ -441,7 +440,7 @@ void BackgroundSyncManager::UnregisterImpl(
}
BackgroundSyncRegistration existing_registration;
if (!LookupRegistration(sw_registration_id, sync_registration_name,
if (!LookupRegistration(sw_registration_id, sync_registration_tag,
&existing_registration) ||
existing_registration.id != sync_registration_id) {
base::MessageLoop::current()->PostTask(
......@@ -449,7 +448,7 @@ void BackgroundSyncManager::UnregisterImpl(
return;
}
RemoveRegistrationFromMap(sw_registration_id, sync_registration_name);
RemoveRegistrationFromMap(sw_registration_id, sync_registration_tag);
StoreRegistrations(
origin, sw_registration_id,
......@@ -483,7 +482,7 @@ void BackgroundSyncManager::UnregisterDidStore(
void BackgroundSyncManager::GetRegistrationImpl(
const GURL& origin,
int64 sw_registration_id,
const std::string sync_registration_name,
const std::string sync_registration_tag,
const StatusAndRegistrationCallback& callback) {
if (disabled_) {
base::MessageLoop::current()->PostTask(
......@@ -493,7 +492,7 @@ void BackgroundSyncManager::GetRegistrationImpl(
}
BackgroundSyncRegistration out_registration;
if (!LookupRegistration(sw_registration_id, sync_registration_name,
if (!LookupRegistration(sw_registration_id, sync_registration_tag,
&out_registration)) {
base::MessageLoop::current()->PostTask(
FROM_HERE, base::Bind(callback, ERROR_TYPE_NOT_FOUND,
......
......@@ -55,14 +55,14 @@ class CONTENT_EXPORT BackgroundSyncManager
BackgroundSyncRegistration() {}
bool Equals(const BackgroundSyncRegistration& other) {
return this->name == other.name && this->fire_once == other.fire_once &&
return this->tag == other.tag && this->fire_once == other.fire_once &&
this->min_period == other.min_period &&
network_state == other.network_state &&
power_state == other.power_state;
}
RegistrationId id = kInvalidRegistrationId;
std::string name;
std::string tag;
bool fire_once = true;
int64 min_period = 0;
SyncNetworkState network_state = NETWORK_STATE_ONLINE;
......@@ -70,7 +70,7 @@ class CONTENT_EXPORT BackgroundSyncManager
};
struct CONTENT_EXPORT BackgroundSyncRegistrations {
using NameToRegistrationMap =
using TagToRegistrationMap =
std::map<std::string, BackgroundSyncRegistration>;
static const BackgroundSyncRegistration::RegistrationId kInitialId;
......@@ -79,7 +79,7 @@ class CONTENT_EXPORT BackgroundSyncManager
BackgroundSyncRegistration::RegistrationId next_id);
~BackgroundSyncRegistrations();
NameToRegistrationMap name_to_registration_map;
TagToRegistrationMap tag_to_registration_map;
BackgroundSyncRegistration::RegistrationId next_id;
};
......@@ -92,7 +92,7 @@ class CONTENT_EXPORT BackgroundSyncManager
~BackgroundSyncManager() override;
// Stores the given background sync registration and adds it to the scheduling
// queue. Overwrites any existing registration with the same name but
// queue. Overwrites any existing registration with the same tag but
// different parameters (other than the id). Calls |callback| with ErrorTypeOK
// and the accepted registration on success. The accepted registration will
// have a unique id. It may also have altered parameters if the user or UA
......@@ -102,15 +102,15 @@ class CONTENT_EXPORT BackgroundSyncManager
const BackgroundSyncRegistration& sync_registration,
const StatusAndRegistrationCallback& callback);
// Removes the background sync registration with |sync_registration_name| if
// Removes the background sync registration with |sync_registration_tag| if
// the |sync_registration_id| matches. |sync_registration_id| will not match
// if, for instance, a new registration with the same name has replaced it.
// if, for instance, a new registration with the same tag has replaced it.
// Calls |callback| with ErrorTypeNotFound if no match is found. Calls
// |callback| with ErrorTypeOK on success.
void Unregister(
const GURL& origin,
int64 sw_registration_id,
const std::string& sync_registration_name,
const std::string& sync_registration_tag,
BackgroundSyncRegistration::RegistrationId sync_registration_id,
const StatusCallback& callback);
......@@ -119,7 +119,7 @@ class CONTENT_EXPORT BackgroundSyncManager
// exist. Calls |callback| with ErrorTypeOK on success.
void GetRegistration(const GURL& origin,
int64 sw_registration_id,
const std::string sync_registration_name,
const std::string sync_registration_tag,
const StatusAndRegistrationCallback& callback);
// ServiceWorkerContextObserver overrides.
......@@ -166,7 +166,7 @@ class CONTENT_EXPORT BackgroundSyncManager
// Returns the existing registration in |existing_registration| if it is not
// null.
bool LookupRegistration(int64 sw_registration_id,
const std::string& sync_registration_name,
const std::string& sync_registration_tag,
BackgroundSyncRegistration* existing_registration);
// Store all registrations for a given |sw_registration_id|.
......@@ -176,7 +176,7 @@ class CONTENT_EXPORT BackgroundSyncManager
// Removes the registration if it is in the map.
void RemoveRegistrationFromMap(int64 sw_registration_id,
const std::string& sync_registration_name);
const std::string& sync_registration_tag);
void AddRegistrationToMap(
int64 sw_registration_id,
......@@ -202,7 +202,7 @@ class CONTENT_EXPORT BackgroundSyncManager
void UnregisterImpl(
const GURL& origin,
int64 sw_registration_id,
const std::string& sync_registration_name,
const std::string& sync_registration_tag,
BackgroundSyncRegistration::RegistrationId sync_registration_id,
const StatusCallback& callback);
void UnregisterDidStore(
......@@ -213,7 +213,7 @@ class CONTENT_EXPORT BackgroundSyncManager
// GetRegistration callbacks
void GetRegistrationImpl(const GURL& origin,
int64 sw_registration_id,
const std::string sync_registration_name,
const std::string sync_registration_tag,
const StatusAndRegistrationCallback& callback);
// OnRegistrationDeleted callbacks
......
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