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 { ...@@ -21,7 +21,7 @@ enum SyncPowerState {
message BackgroundSyncRegistrationProto { message BackgroundSyncRegistrationProto {
required int64 id = 1; required int64 id = 1;
required string name = 2; required string tag = 2;
required bool fire_once = 3; required bool fire_once = 3;
required int64 min_period = 4; required int64 min_period = 4;
required SyncNetworkState network_state = 5; required SyncNetworkState network_state = 5;
......
...@@ -73,7 +73,7 @@ void BackgroundSyncManager::Register( ...@@ -73,7 +73,7 @@ void BackgroundSyncManager::Register(
void BackgroundSyncManager::Unregister( void BackgroundSyncManager::Unregister(
const GURL& origin, const GURL& origin,
int64 sw_registration_id, int64 sw_registration_id,
const std::string& sync_registration_name, const std::string& sync_registration_tag,
BackgroundSyncRegistration::RegistrationId sync_registration_id, BackgroundSyncRegistration::RegistrationId sync_registration_id,
const StatusCallback& callback) { const StatusCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
...@@ -86,14 +86,14 @@ void BackgroundSyncManager::Unregister( ...@@ -86,14 +86,14 @@ void BackgroundSyncManager::Unregister(
op_scheduler_.ScheduleOperation(base::Bind( op_scheduler_.ScheduleOperation(base::Bind(
&BackgroundSyncManager::UnregisterImpl, weak_ptr_factory_.GetWeakPtr(), &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))); MakeStatusCompletion(callback)));
} }
void BackgroundSyncManager::GetRegistration( void BackgroundSyncManager::GetRegistration(
const GURL& origin, const GURL& origin,
int64 sw_registration_id, int64 sw_registration_id,
const std::string sync_registration_name, const std::string sync_registration_tag,
const StatusAndRegistrationCallback& callback) { const StatusAndRegistrationCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
...@@ -107,7 +107,7 @@ void BackgroundSyncManager::GetRegistration( ...@@ -107,7 +107,7 @@ void BackgroundSyncManager::GetRegistration(
op_scheduler_.ScheduleOperation(base::Bind( op_scheduler_.ScheduleOperation(base::Bind(
&BackgroundSyncManager::GetRegistrationImpl, &BackgroundSyncManager::GetRegistrationImpl,
weak_ptr_factory_.GetWeakPtr(), origin, sw_registration_id, weak_ptr_factory_.GetWeakPtr(), origin, sw_registration_id,
sync_registration_name, MakeStatusAndRegistrationCompletion(callback))); sync_registration_tag, MakeStatusAndRegistrationCompletion(callback)));
} }
void BackgroundSyncManager::OnRegistrationDeleted(int64 registration_id, void BackgroundSyncManager::OnRegistrationDeleted(int64 registration_id,
...@@ -194,10 +194,10 @@ void BackgroundSyncManager::InitDidGetDataFromBackend( ...@@ -194,10 +194,10 @@ void BackgroundSyncManager::InitDidGetDataFromBackend(
} }
BackgroundSyncRegistration* registration = BackgroundSyncRegistration* registration =
&registrations->name_to_registration_map[registration_proto.name()]; &registrations->tag_to_registration_map[registration_proto.tag()];
registration->id = registration_proto.id(); registration->id = registration_proto.id();
registration->name = registration_proto.name(); registration->tag = registration_proto.tag();
registration->fire_once = registration_proto.fire_once(); registration->fire_once = registration_proto.fire_once();
registration->min_period = registration_proto.min_period(); registration->min_period = registration_proto.min_period();
registration->network_state = registration_proto.network_state(); registration->network_state = registration_proto.network_state();
...@@ -233,7 +233,7 @@ void BackgroundSyncManager::RegisterImpl( ...@@ -233,7 +233,7 @@ void BackgroundSyncManager::RegisterImpl(
} }
BackgroundSyncRegistration existing_registration; BackgroundSyncRegistration existing_registration;
if (LookupRegistration(sw_registration_id, sync_registration.name, if (LookupRegistration(sw_registration_id, sync_registration.tag,
&existing_registration)) { &existing_registration)) {
if (existing_registration.Equals(sync_registration)) { if (existing_registration.Equals(sync_registration)) {
base::MessageLoop::current()->PostTask( base::MessageLoop::current()->PostTask(
...@@ -306,7 +306,7 @@ void BackgroundSyncManager::DisableAndClearManagerClearedOne( ...@@ -306,7 +306,7 @@ void BackgroundSyncManager::DisableAndClearManagerClearedOne(
bool BackgroundSyncManager::LookupRegistration( bool BackgroundSyncManager::LookupRegistration(
int64 sw_registration_id, int64 sw_registration_id,
const std::string& sync_registration_name, const std::string& sync_registration_tag,
BackgroundSyncRegistration* existing_registration) { BackgroundSyncRegistration* existing_registration) {
SWIdToRegistrationsMap::iterator it = SWIdToRegistrationsMap::iterator it =
sw_to_registrations_map_.find(sw_registration_id); sw_to_registrations_map_.find(sw_registration_id);
...@@ -314,14 +314,13 @@ bool BackgroundSyncManager::LookupRegistration( ...@@ -314,14 +314,13 @@ bool BackgroundSyncManager::LookupRegistration(
return false; return false;
const BackgroundSyncRegistrations& registrations = it->second; const BackgroundSyncRegistrations& registrations = it->second;
const auto name_and_registration_iter = const auto tag_and_registration_iter =
registrations.name_to_registration_map.find(sync_registration_name); registrations.tag_to_registration_map.find(sync_registration_tag);
if (name_and_registration_iter == if (tag_and_registration_iter == registrations.tag_to_registration_map.end())
registrations.name_to_registration_map.end())
return false; return false;
if (existing_registration) if (existing_registration)
*existing_registration = name_and_registration_iter->second; *existing_registration = tag_and_registration_iter->second;
return true; return true;
} }
...@@ -336,14 +335,14 @@ void BackgroundSyncManager::StoreRegistrations( ...@@ -336,14 +335,14 @@ void BackgroundSyncManager::StoreRegistrations(
BackgroundSyncRegistrationsProto registrations_proto; BackgroundSyncRegistrationsProto registrations_proto;
registrations_proto.set_next_registration_id(registrations.next_id); registrations_proto.set_next_registration_id(registrations.next_id);
for (const auto& name_and_registration : for (const auto& tag_and_registration :
registrations.name_to_registration_map) { registrations.tag_to_registration_map) {
const BackgroundSyncRegistration& registration = const BackgroundSyncRegistration& registration =
name_and_registration.second; tag_and_registration.second;
BackgroundSyncRegistrationProto* registration_proto = BackgroundSyncRegistrationProto* registration_proto =
registrations_proto.add_registration(); registrations_proto.add_registration();
registration_proto->set_id(registration.id); 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_fire_once(registration.fire_once);
registration_proto->set_min_period(registration.min_period); registration_proto->set_min_period(registration.min_period);
registration_proto->set_network_state(registration.network_state); registration_proto->set_network_state(registration.network_state);
...@@ -386,14 +385,14 @@ void BackgroundSyncManager::RegisterDidStore( ...@@ -386,14 +385,14 @@ void BackgroundSyncManager::RegisterDidStore(
void BackgroundSyncManager::RemoveRegistrationFromMap( void BackgroundSyncManager::RemoveRegistrationFromMap(
int64 sw_registration_id, int64 sw_registration_id,
const std::string& sync_registration_name) { const std::string& sync_registration_tag) {
DCHECK( DCHECK(
LookupRegistration(sw_registration_id, sync_registration_name, nullptr)); LookupRegistration(sw_registration_id, sync_registration_tag, nullptr));
BackgroundSyncRegistrations* registrations = BackgroundSyncRegistrations* registrations =
&sw_to_registrations_map_[sw_registration_id]; &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( void BackgroundSyncManager::AddRegistrationToMap(
...@@ -404,7 +403,7 @@ void BackgroundSyncManager::AddRegistrationToMap( ...@@ -404,7 +403,7 @@ void BackgroundSyncManager::AddRegistrationToMap(
BackgroundSyncRegistrations* registrations = BackgroundSyncRegistrations* registrations =
&sw_to_registrations_map_[sw_registration_id]; &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; sync_registration;
} }
...@@ -431,7 +430,7 @@ void BackgroundSyncManager::GetDataFromBackend( ...@@ -431,7 +430,7 @@ void BackgroundSyncManager::GetDataFromBackend(
void BackgroundSyncManager::UnregisterImpl( void BackgroundSyncManager::UnregisterImpl(
const GURL& origin, const GURL& origin,
int64 sw_registration_id, int64 sw_registration_id,
const std::string& sync_registration_name, const std::string& sync_registration_tag,
BackgroundSyncRegistration::RegistrationId sync_registration_id, BackgroundSyncRegistration::RegistrationId sync_registration_id,
const StatusCallback& callback) { const StatusCallback& callback) {
if (disabled_) { if (disabled_) {
...@@ -441,7 +440,7 @@ void BackgroundSyncManager::UnregisterImpl( ...@@ -441,7 +440,7 @@ void BackgroundSyncManager::UnregisterImpl(
} }
BackgroundSyncRegistration existing_registration; BackgroundSyncRegistration existing_registration;
if (!LookupRegistration(sw_registration_id, sync_registration_name, if (!LookupRegistration(sw_registration_id, sync_registration_tag,
&existing_registration) || &existing_registration) ||
existing_registration.id != sync_registration_id) { existing_registration.id != sync_registration_id) {
base::MessageLoop::current()->PostTask( base::MessageLoop::current()->PostTask(
...@@ -449,7 +448,7 @@ void BackgroundSyncManager::UnregisterImpl( ...@@ -449,7 +448,7 @@ void BackgroundSyncManager::UnregisterImpl(
return; return;
} }
RemoveRegistrationFromMap(sw_registration_id, sync_registration_name); RemoveRegistrationFromMap(sw_registration_id, sync_registration_tag);
StoreRegistrations( StoreRegistrations(
origin, sw_registration_id, origin, sw_registration_id,
...@@ -483,7 +482,7 @@ void BackgroundSyncManager::UnregisterDidStore( ...@@ -483,7 +482,7 @@ void BackgroundSyncManager::UnregisterDidStore(
void BackgroundSyncManager::GetRegistrationImpl( void BackgroundSyncManager::GetRegistrationImpl(
const GURL& origin, const GURL& origin,
int64 sw_registration_id, int64 sw_registration_id,
const std::string sync_registration_name, const std::string sync_registration_tag,
const StatusAndRegistrationCallback& callback) { const StatusAndRegistrationCallback& callback) {
if (disabled_) { if (disabled_) {
base::MessageLoop::current()->PostTask( base::MessageLoop::current()->PostTask(
...@@ -493,7 +492,7 @@ void BackgroundSyncManager::GetRegistrationImpl( ...@@ -493,7 +492,7 @@ void BackgroundSyncManager::GetRegistrationImpl(
} }
BackgroundSyncRegistration out_registration; BackgroundSyncRegistration out_registration;
if (!LookupRegistration(sw_registration_id, sync_registration_name, if (!LookupRegistration(sw_registration_id, sync_registration_tag,
&out_registration)) { &out_registration)) {
base::MessageLoop::current()->PostTask( base::MessageLoop::current()->PostTask(
FROM_HERE, base::Bind(callback, ERROR_TYPE_NOT_FOUND, FROM_HERE, base::Bind(callback, ERROR_TYPE_NOT_FOUND,
......
...@@ -55,14 +55,14 @@ class CONTENT_EXPORT BackgroundSyncManager ...@@ -55,14 +55,14 @@ class CONTENT_EXPORT BackgroundSyncManager
BackgroundSyncRegistration() {} BackgroundSyncRegistration() {}
bool Equals(const BackgroundSyncRegistration& other) { 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 && this->min_period == other.min_period &&
network_state == other.network_state && network_state == other.network_state &&
power_state == other.power_state; power_state == other.power_state;
} }
RegistrationId id = kInvalidRegistrationId; RegistrationId id = kInvalidRegistrationId;
std::string name; std::string tag;
bool fire_once = true; bool fire_once = true;
int64 min_period = 0; int64 min_period = 0;
SyncNetworkState network_state = NETWORK_STATE_ONLINE; SyncNetworkState network_state = NETWORK_STATE_ONLINE;
...@@ -70,7 +70,7 @@ class CONTENT_EXPORT BackgroundSyncManager ...@@ -70,7 +70,7 @@ class CONTENT_EXPORT BackgroundSyncManager
}; };
struct CONTENT_EXPORT BackgroundSyncRegistrations { struct CONTENT_EXPORT BackgroundSyncRegistrations {
using NameToRegistrationMap = using TagToRegistrationMap =
std::map<std::string, BackgroundSyncRegistration>; std::map<std::string, BackgroundSyncRegistration>;
static const BackgroundSyncRegistration::RegistrationId kInitialId; static const BackgroundSyncRegistration::RegistrationId kInitialId;
...@@ -79,7 +79,7 @@ class CONTENT_EXPORT BackgroundSyncManager ...@@ -79,7 +79,7 @@ class CONTENT_EXPORT BackgroundSyncManager
BackgroundSyncRegistration::RegistrationId next_id); BackgroundSyncRegistration::RegistrationId next_id);
~BackgroundSyncRegistrations(); ~BackgroundSyncRegistrations();
NameToRegistrationMap name_to_registration_map; TagToRegistrationMap tag_to_registration_map;
BackgroundSyncRegistration::RegistrationId next_id; BackgroundSyncRegistration::RegistrationId next_id;
}; };
...@@ -92,7 +92,7 @@ class CONTENT_EXPORT BackgroundSyncManager ...@@ -92,7 +92,7 @@ class CONTENT_EXPORT BackgroundSyncManager
~BackgroundSyncManager() override; ~BackgroundSyncManager() override;
// Stores the given background sync registration and adds it to the scheduling // 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 // different parameters (other than the id). Calls |callback| with ErrorTypeOK
// and the accepted registration on success. The accepted registration will // 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 // have a unique id. It may also have altered parameters if the user or UA
...@@ -102,15 +102,15 @@ class CONTENT_EXPORT BackgroundSyncManager ...@@ -102,15 +102,15 @@ class CONTENT_EXPORT BackgroundSyncManager
const BackgroundSyncRegistration& sync_registration, const BackgroundSyncRegistration& sync_registration,
const StatusAndRegistrationCallback& callback); 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 // 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 // Calls |callback| with ErrorTypeNotFound if no match is found. Calls
// |callback| with ErrorTypeOK on success. // |callback| with ErrorTypeOK on success.
void Unregister( void Unregister(
const GURL& origin, const GURL& origin,
int64 sw_registration_id, int64 sw_registration_id,
const std::string& sync_registration_name, const std::string& sync_registration_tag,
BackgroundSyncRegistration::RegistrationId sync_registration_id, BackgroundSyncRegistration::RegistrationId sync_registration_id,
const StatusCallback& callback); const StatusCallback& callback);
...@@ -119,7 +119,7 @@ class CONTENT_EXPORT BackgroundSyncManager ...@@ -119,7 +119,7 @@ class CONTENT_EXPORT BackgroundSyncManager
// exist. Calls |callback| with ErrorTypeOK on success. // exist. Calls |callback| with ErrorTypeOK on success.
void GetRegistration(const GURL& origin, void GetRegistration(const GURL& origin,
int64 sw_registration_id, int64 sw_registration_id,
const std::string sync_registration_name, const std::string sync_registration_tag,
const StatusAndRegistrationCallback& callback); const StatusAndRegistrationCallback& callback);
// ServiceWorkerContextObserver overrides. // ServiceWorkerContextObserver overrides.
...@@ -166,7 +166,7 @@ class CONTENT_EXPORT BackgroundSyncManager ...@@ -166,7 +166,7 @@ class CONTENT_EXPORT BackgroundSyncManager
// Returns the existing registration in |existing_registration| if it is not // Returns the existing registration in |existing_registration| if it is not
// null. // null.
bool LookupRegistration(int64 sw_registration_id, bool LookupRegistration(int64 sw_registration_id,
const std::string& sync_registration_name, const std::string& sync_registration_tag,
BackgroundSyncRegistration* existing_registration); BackgroundSyncRegistration* existing_registration);
// Store all registrations for a given |sw_registration_id|. // Store all registrations for a given |sw_registration_id|.
...@@ -176,7 +176,7 @@ class CONTENT_EXPORT BackgroundSyncManager ...@@ -176,7 +176,7 @@ class CONTENT_EXPORT BackgroundSyncManager
// Removes the registration if it is in the map. // Removes the registration if it is in the map.
void RemoveRegistrationFromMap(int64 sw_registration_id, void RemoveRegistrationFromMap(int64 sw_registration_id,
const std::string& sync_registration_name); const std::string& sync_registration_tag);
void AddRegistrationToMap( void AddRegistrationToMap(
int64 sw_registration_id, int64 sw_registration_id,
...@@ -202,7 +202,7 @@ class CONTENT_EXPORT BackgroundSyncManager ...@@ -202,7 +202,7 @@ class CONTENT_EXPORT BackgroundSyncManager
void UnregisterImpl( void UnregisterImpl(
const GURL& origin, const GURL& origin,
int64 sw_registration_id, int64 sw_registration_id,
const std::string& sync_registration_name, const std::string& sync_registration_tag,
BackgroundSyncRegistration::RegistrationId sync_registration_id, BackgroundSyncRegistration::RegistrationId sync_registration_id,
const StatusCallback& callback); const StatusCallback& callback);
void UnregisterDidStore( void UnregisterDidStore(
...@@ -213,7 +213,7 @@ class CONTENT_EXPORT BackgroundSyncManager ...@@ -213,7 +213,7 @@ class CONTENT_EXPORT BackgroundSyncManager
// GetRegistration callbacks // GetRegistration callbacks
void GetRegistrationImpl(const GURL& origin, void GetRegistrationImpl(const GURL& origin,
int64 sw_registration_id, int64 sw_registration_id,
const std::string sync_registration_name, const std::string sync_registration_tag,
const StatusAndRegistrationCallback& callback); const StatusAndRegistrationCallback& callback);
// OnRegistrationDeleted callbacks // OnRegistrationDeleted callbacks
......
...@@ -141,8 +141,8 @@ class BackgroundSyncManagerTest : public testing::Test { ...@@ -141,8 +141,8 @@ class BackgroundSyncManagerTest : public testing::Test {
sync_reg_2_(BackgroundSyncManager::BackgroundSyncRegistration()), sync_reg_2_(BackgroundSyncManager::BackgroundSyncRegistration()),
callback_error_(BackgroundSyncManager::ERROR_TYPE_OK), callback_error_(BackgroundSyncManager::ERROR_TYPE_OK),
callback_sw_status_code_(SERVICE_WORKER_OK) { callback_sw_status_code_(SERVICE_WORKER_OK) {
sync_reg_1_.name = "foo"; sync_reg_1_.tag = "foo";
sync_reg_2_.name = "bar"; sync_reg_2_.tag = "bar";
} }
void SetUp() override { void SetUp() override {
...@@ -228,7 +228,7 @@ class BackgroundSyncManagerTest : public testing::Test { ...@@ -228,7 +228,7 @@ class BackgroundSyncManagerTest : public testing::Test {
sync_registration) { sync_registration) {
bool was_called = false; bool was_called = false;
background_sync_manager_->Unregister( background_sync_manager_->Unregister(
GURL(kOrigin), sw_registration_id, sync_registration.name, GURL(kOrigin), sw_registration_id, sync_registration.tag,
sync_registration.id, sync_registration.id,
base::Bind(&BackgroundSyncManagerTest::StatusCallback, base::Bind(&BackgroundSyncManagerTest::StatusCallback,
base::Unretained(this), &was_called)); base::Unretained(this), &was_called));
...@@ -237,24 +237,24 @@ class BackgroundSyncManagerTest : public testing::Test { ...@@ -237,24 +237,24 @@ class BackgroundSyncManagerTest : public testing::Test {
return callback_error_ == BackgroundSyncManager::ERROR_TYPE_OK; return callback_error_ == BackgroundSyncManager::ERROR_TYPE_OK;
} }
bool GetRegistration(const std::string& sync_registration_name) { bool GetRegistration(const std::string& sync_registration_tag) {
return GetRegistrationWithServiceWorkerId(sw_registration_id_1_, return GetRegistrationWithServiceWorkerId(sw_registration_id_1_,
sync_registration_name); sync_registration_tag);
} }
bool GetRegistrationWithServiceWorkerId( bool GetRegistrationWithServiceWorkerId(
int64 sw_registration_id, int64 sw_registration_id,
const std::string& sync_registration_name) { const std::string& sync_registration_tag) {
bool was_called = false; bool was_called = false;
background_sync_manager_->GetRegistration( background_sync_manager_->GetRegistration(
GURL(kOrigin), sw_registration_id, sync_registration_name, GURL(kOrigin), sw_registration_id, sync_registration_tag,
base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback,
base::Unretained(this), &was_called)); base::Unretained(this), &was_called));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(was_called); EXPECT_TRUE(was_called);
if (callback_error_ == BackgroundSyncManager::ERROR_TYPE_OK) if (callback_error_ == BackgroundSyncManager::ERROR_TYPE_OK)
EXPECT_TRUE(sync_registration_name == callback_registration_.name); EXPECT_TRUE(sync_registration_tag == callback_registration_.tag);
return callback_error_ == BackgroundSyncManager::ERROR_TYPE_OK; return callback_error_ == BackgroundSyncManager::ERROR_TYPE_OK;
} }
...@@ -300,7 +300,7 @@ TEST_F(BackgroundSyncManagerTest, Register) { ...@@ -300,7 +300,7 @@ TEST_F(BackgroundSyncManagerTest, Register) {
TEST_F(BackgroundSyncManagerTest, RegistractionIntact) { TEST_F(BackgroundSyncManagerTest, RegistractionIntact) {
EXPECT_TRUE(Register(sync_reg_1_)); EXPECT_TRUE(Register(sync_reg_1_));
EXPECT_STREQ(sync_reg_1_.name.c_str(), callback_registration_.name.c_str()); EXPECT_STREQ(sync_reg_1_.tag.c_str(), callback_registration_.tag.c_str());
EXPECT_NE( EXPECT_NE(
BackgroundSyncManager::BackgroundSyncRegistration::kInvalidRegistrationId, BackgroundSyncManager::BackgroundSyncRegistration::kInvalidRegistrationId,
callback_registration_.id); callback_registration_.id);
...@@ -332,7 +332,7 @@ TEST_F(BackgroundSyncManagerTest, RegisterBadBackend) { ...@@ -332,7 +332,7 @@ TEST_F(BackgroundSyncManagerTest, RegisterBadBackend) {
EXPECT_FALSE(Register(sync_reg_1_)); EXPECT_FALSE(Register(sync_reg_1_));
manager->set_corrupt_backend(false); manager->set_corrupt_backend(false);
EXPECT_FALSE(Register(sync_reg_1_)); EXPECT_FALSE(Register(sync_reg_1_));
EXPECT_FALSE(GetRegistration(sync_reg_1_.name)); EXPECT_FALSE(GetRegistration(sync_reg_1_.tag));
} }
TEST_F(BackgroundSyncManagerTest, TwoRegistrations) { TEST_F(BackgroundSyncManagerTest, TwoRegistrations) {
...@@ -341,32 +341,32 @@ TEST_F(BackgroundSyncManagerTest, TwoRegistrations) { ...@@ -341,32 +341,32 @@ TEST_F(BackgroundSyncManagerTest, TwoRegistrations) {
} }
TEST_F(BackgroundSyncManagerTest, GetRegistrationNonExisting) { TEST_F(BackgroundSyncManagerTest, GetRegistrationNonExisting) {
EXPECT_FALSE(GetRegistration(sync_reg_1_.name)); EXPECT_FALSE(GetRegistration(sync_reg_1_.tag));
} }
TEST_F(BackgroundSyncManagerTest, GetRegistrationExisting) { TEST_F(BackgroundSyncManagerTest, GetRegistrationExisting) {
EXPECT_TRUE(Register(sync_reg_1_)); EXPECT_TRUE(Register(sync_reg_1_));
EXPECT_TRUE(GetRegistration(sync_reg_1_.name)); EXPECT_TRUE(GetRegistration(sync_reg_1_.tag));
EXPECT_FALSE(GetRegistration(sync_reg_2_.name)); EXPECT_FALSE(GetRegistration(sync_reg_2_.tag));
} }
TEST_F(BackgroundSyncManagerTest, GetRegistrationBadBackend) { TEST_F(BackgroundSyncManagerTest, GetRegistrationBadBackend) {
TestBackgroundSyncManager* manager = UseTestBackgroundSyncManager(); TestBackgroundSyncManager* manager = UseTestBackgroundSyncManager();
EXPECT_TRUE(Register(sync_reg_1_)); EXPECT_TRUE(Register(sync_reg_1_));
manager->set_corrupt_backend(true); manager->set_corrupt_backend(true);
EXPECT_TRUE(GetRegistration(sync_reg_1_.name)); EXPECT_TRUE(GetRegistration(sync_reg_1_.tag));
EXPECT_FALSE(Register(sync_reg_2_)); EXPECT_FALSE(Register(sync_reg_2_));
// Registration should have discovered the bad backend and disabled the // Registration should have discovered the bad backend and disabled the
// BackgroundSyncManager. // BackgroundSyncManager.
EXPECT_FALSE(GetRegistration(sync_reg_1_.name)); EXPECT_FALSE(GetRegistration(sync_reg_1_.tag));
manager->set_corrupt_backend(false); manager->set_corrupt_backend(false);
EXPECT_FALSE(GetRegistration(sync_reg_1_.name)); EXPECT_FALSE(GetRegistration(sync_reg_1_.tag));
} }
TEST_F(BackgroundSyncManagerTest, Unregister) { TEST_F(BackgroundSyncManagerTest, Unregister) {
EXPECT_TRUE(Register(sync_reg_1_)); EXPECT_TRUE(Register(sync_reg_1_));
EXPECT_TRUE(Unregister(callback_registration_)); EXPECT_TRUE(Unregister(callback_registration_));
EXPECT_FALSE(GetRegistration(sync_reg_1_.name)); EXPECT_FALSE(GetRegistration(sync_reg_1_.tag));
} }
TEST_F(BackgroundSyncManagerTest, UnregisterWrongId) { TEST_F(BackgroundSyncManagerTest, UnregisterWrongId) {
...@@ -390,7 +390,7 @@ TEST_F(BackgroundSyncManagerTest, UnregisterSecond) { ...@@ -390,7 +390,7 @@ TEST_F(BackgroundSyncManagerTest, UnregisterSecond) {
EXPECT_TRUE(Register(sync_reg_1_)); EXPECT_TRUE(Register(sync_reg_1_));
EXPECT_TRUE(Register(sync_reg_2_)); EXPECT_TRUE(Register(sync_reg_2_));
EXPECT_TRUE(Unregister(callback_registration_)); EXPECT_TRUE(Unregister(callback_registration_));
EXPECT_TRUE(GetRegistration(sync_reg_1_.name)); EXPECT_TRUE(GetRegistration(sync_reg_1_.tag));
EXPECT_TRUE(Register(sync_reg_2_)); EXPECT_TRUE(Register(sync_reg_2_));
} }
...@@ -404,8 +404,8 @@ TEST_F(BackgroundSyncManagerTest, UnregisterBadBackend) { ...@@ -404,8 +404,8 @@ TEST_F(BackgroundSyncManagerTest, UnregisterBadBackend) {
// Unregister should have discovered the bad backend and disabled the // Unregister should have discovered the bad backend and disabled the
// BackgroundSyncManager. // BackgroundSyncManager.
manager->set_corrupt_backend(false); manager->set_corrupt_backend(false);
EXPECT_FALSE(GetRegistration(sync_reg_1_.name)); EXPECT_FALSE(GetRegistration(sync_reg_1_.tag));
EXPECT_FALSE(GetRegistration(sync_reg_2_.name)); EXPECT_FALSE(GetRegistration(sync_reg_2_.tag));
} }
TEST_F(BackgroundSyncManagerTest, RegistrationIncreasesId) { TEST_F(BackgroundSyncManagerTest, RegistrationIncreasesId) {
...@@ -415,7 +415,7 @@ TEST_F(BackgroundSyncManagerTest, RegistrationIncreasesId) { ...@@ -415,7 +415,7 @@ TEST_F(BackgroundSyncManagerTest, RegistrationIncreasesId) {
BackgroundSyncManager::BackgroundSyncRegistration::RegistrationId cur_id = BackgroundSyncManager::BackgroundSyncRegistration::RegistrationId cur_id =
callback_registration_.id; callback_registration_.id;
EXPECT_TRUE(GetRegistration(sync_reg_1_.name)); EXPECT_TRUE(GetRegistration(sync_reg_1_.tag));
EXPECT_TRUE(Register(sync_reg_2_)); EXPECT_TRUE(Register(sync_reg_2_));
EXPECT_LT(cur_id, callback_registration_.id); EXPECT_LT(cur_id, callback_registration_.id);
cur_id = callback_registration_.id; cur_id = callback_registration_.id;
...@@ -431,8 +431,8 @@ TEST_F(BackgroundSyncManagerTest, RebootRecovery) { ...@@ -431,8 +431,8 @@ TEST_F(BackgroundSyncManagerTest, RebootRecovery) {
background_sync_manager_ = background_sync_manager_ =
BackgroundSyncManager::Create(helper_->context_wrapper()); BackgroundSyncManager::Create(helper_->context_wrapper());
EXPECT_TRUE(GetRegistration(sync_reg_1_.name)); EXPECT_TRUE(GetRegistration(sync_reg_1_.tag));
EXPECT_FALSE(GetRegistration(sync_reg_2_.name)); EXPECT_FALSE(GetRegistration(sync_reg_2_.tag));
} }
TEST_F(BackgroundSyncManagerTest, RebootRecoveryTwoServiceWorkers) { TEST_F(BackgroundSyncManagerTest, RebootRecoveryTwoServiceWorkers) {
...@@ -443,18 +443,18 @@ TEST_F(BackgroundSyncManagerTest, RebootRecoveryTwoServiceWorkers) { ...@@ -443,18 +443,18 @@ TEST_F(BackgroundSyncManagerTest, RebootRecoveryTwoServiceWorkers) {
BackgroundSyncManager::Create(helper_->context_wrapper()); BackgroundSyncManager::Create(helper_->context_wrapper());
EXPECT_TRUE(GetRegistrationWithServiceWorkerId(sw_registration_id_1_, EXPECT_TRUE(GetRegistrationWithServiceWorkerId(sw_registration_id_1_,
sync_reg_1_.name)); sync_reg_1_.tag));
EXPECT_FALSE(GetRegistrationWithServiceWorkerId(sw_registration_id_1_, EXPECT_FALSE(GetRegistrationWithServiceWorkerId(sw_registration_id_1_,
sync_reg_2_.name)); sync_reg_2_.tag));
EXPECT_FALSE(GetRegistrationWithServiceWorkerId(sw_registration_id_2_, EXPECT_FALSE(GetRegistrationWithServiceWorkerId(sw_registration_id_2_,
sync_reg_1_.name)); sync_reg_1_.tag));
EXPECT_TRUE(GetRegistrationWithServiceWorkerId(sw_registration_id_2_, EXPECT_TRUE(GetRegistrationWithServiceWorkerId(sw_registration_id_2_,
sync_reg_2_.name)); sync_reg_2_.tag));
EXPECT_TRUE(GetRegistrationWithServiceWorkerId(sw_registration_id_1_, EXPECT_TRUE(GetRegistrationWithServiceWorkerId(sw_registration_id_1_,
sync_reg_1_.name)); sync_reg_1_.tag));
EXPECT_TRUE(GetRegistrationWithServiceWorkerId(sw_registration_id_2_, EXPECT_TRUE(GetRegistrationWithServiceWorkerId(sw_registration_id_2_,
sync_reg_2_.name)); sync_reg_2_.tag));
EXPECT_TRUE(RegisterWithServiceWorkerId(sw_registration_id_1_, sync_reg_2_)); EXPECT_TRUE(RegisterWithServiceWorkerId(sw_registration_id_1_, sync_reg_2_));
EXPECT_TRUE(RegisterWithServiceWorkerId(sw_registration_id_2_, sync_reg_1_)); EXPECT_TRUE(RegisterWithServiceWorkerId(sw_registration_id_2_, sync_reg_1_));
...@@ -468,7 +468,7 @@ TEST_F(BackgroundSyncManagerTest, InitWithBadBackend) { ...@@ -468,7 +468,7 @@ TEST_F(BackgroundSyncManagerTest, InitWithBadBackend) {
manager->DoInit(); manager->DoInit();
EXPECT_FALSE(Register(sync_reg_1_)); EXPECT_FALSE(Register(sync_reg_1_));
EXPECT_FALSE(GetRegistration(sync_reg_1_.name)); EXPECT_FALSE(GetRegistration(sync_reg_1_.tag));
} }
TEST_F(BackgroundSyncManagerTest, SequentialOperations) { TEST_F(BackgroundSyncManagerTest, SequentialOperations) {
...@@ -490,12 +490,12 @@ TEST_F(BackgroundSyncManagerTest, SequentialOperations) { ...@@ -490,12 +490,12 @@ TEST_F(BackgroundSyncManagerTest, SequentialOperations) {
GURL(kOrigin), sw_registration_id_1_, sync_reg_1_, GURL(kOrigin), sw_registration_id_1_, sync_reg_1_,
base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback,
base::Unretained(this), &register_called)); base::Unretained(this), &register_called));
manager->Unregister(GURL(kOrigin), sw_registration_id_1_, sync_reg_1_.name, manager->Unregister(GURL(kOrigin), sw_registration_id_1_, sync_reg_1_.tag,
kExpectedInitialId, kExpectedInitialId,
base::Bind(&BackgroundSyncManagerTest::StatusCallback, base::Bind(&BackgroundSyncManagerTest::StatusCallback,
base::Unretained(this), &unregister_called)); base::Unretained(this), &unregister_called));
manager->GetRegistration( manager->GetRegistration(
GURL(kOrigin), sw_registration_id_1_, sync_reg_1_.name, GURL(kOrigin), sw_registration_id_1_, sync_reg_1_.tag,
base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback,
base::Unretained(this), &get_registration_called)); base::Unretained(this), &get_registration_called));
...@@ -533,7 +533,7 @@ TEST_F(BackgroundSyncManagerTest, SequentialOperations) { ...@@ -533,7 +533,7 @@ TEST_F(BackgroundSyncManagerTest, SequentialOperations) {
TEST_F(BackgroundSyncManagerTest, UnregisterServiceWorker) { TEST_F(BackgroundSyncManagerTest, UnregisterServiceWorker) {
EXPECT_TRUE(Register(sync_reg_1_)); EXPECT_TRUE(Register(sync_reg_1_));
UnregisterServiceWorker(sw_registration_id_1_); UnregisterServiceWorker(sw_registration_id_1_);
EXPECT_FALSE(GetRegistration(sync_reg_1_.name)); EXPECT_FALSE(GetRegistration(sync_reg_1_.tag));
} }
TEST_F(BackgroundSyncManagerTest, TEST_F(BackgroundSyncManagerTest,
...@@ -562,14 +562,14 @@ TEST_F(BackgroundSyncManagerTest, ...@@ -562,14 +562,14 @@ TEST_F(BackgroundSyncManagerTest,
EXPECT_EQ(BackgroundSyncManager::ERROR_TYPE_STORAGE, callback_error_); EXPECT_EQ(BackgroundSyncManager::ERROR_TYPE_STORAGE, callback_error_);
manager->set_delay_backend(false); manager->set_delay_backend(false);
EXPECT_FALSE(GetRegistration(sync_reg_1_.name)); EXPECT_FALSE(GetRegistration(sync_reg_1_.tag));
} }
TEST_F(BackgroundSyncManagerTest, DeleteAndStartOverServiceWorkerContext) { TEST_F(BackgroundSyncManagerTest, DeleteAndStartOverServiceWorkerContext) {
EXPECT_TRUE(Register(sync_reg_1_)); EXPECT_TRUE(Register(sync_reg_1_));
helper_->context()->ScheduleDeleteAndStartOver(); helper_->context()->ScheduleDeleteAndStartOver();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_FALSE(GetRegistration(sync_reg_1_.name)); EXPECT_FALSE(GetRegistration(sync_reg_1_.tag));
} }
TEST_F(BackgroundSyncManagerTest, DisabledManagerWorksAfterBrowserRestart) { TEST_F(BackgroundSyncManagerTest, DisabledManagerWorksAfterBrowserRestart) {
...@@ -584,13 +584,13 @@ TEST_F(BackgroundSyncManagerTest, DisabledManagerWorksAfterBrowserRestart) { ...@@ -584,13 +584,13 @@ TEST_F(BackgroundSyncManagerTest, DisabledManagerWorksAfterBrowserRestart) {
// The manager is now disabled and not accepting new requests until browser // The manager is now disabled and not accepting new requests until browser
// restart or notification that the storage has been wiped. // restart or notification that the storage has been wiped.
manager->set_corrupt_backend(false); manager->set_corrupt_backend(false);
EXPECT_FALSE(GetRegistration(sync_reg_1_.name)); EXPECT_FALSE(GetRegistration(sync_reg_1_.tag));
EXPECT_FALSE(Register(sync_reg_2_)); EXPECT_FALSE(Register(sync_reg_2_));
// Simulate restarting the browser by creating a new BackgroundSyncManager. // Simulate restarting the browser by creating a new BackgroundSyncManager.
background_sync_manager_.reset( background_sync_manager_.reset(
new TestBackgroundSyncManager(helper_->context_wrapper())); new TestBackgroundSyncManager(helper_->context_wrapper()));
EXPECT_FALSE(GetRegistration(sync_reg_1_.name)); EXPECT_FALSE(GetRegistration(sync_reg_1_.tag));
EXPECT_TRUE(Register(sync_reg_1_)); EXPECT_TRUE(Register(sync_reg_1_));
} }
...@@ -618,8 +618,8 @@ TEST_F(BackgroundSyncManagerTest, DisabledManagerWorksAfterDeleteAndStartOver) { ...@@ -618,8 +618,8 @@ TEST_F(BackgroundSyncManagerTest, DisabledManagerWorksAfterDeleteAndStartOver) {
EXPECT_TRUE(called); EXPECT_TRUE(called);
EXPECT_TRUE(Register(sync_reg_2_)); EXPECT_TRUE(Register(sync_reg_2_));
EXPECT_FALSE(GetRegistration(sync_reg_1_.name)); EXPECT_FALSE(GetRegistration(sync_reg_1_.tag));
EXPECT_TRUE(GetRegistration(sync_reg_2_.name)); EXPECT_TRUE(GetRegistration(sync_reg_2_.tag));
} }
TEST_F(BackgroundSyncManagerTest, RegistrationEqualsId) { TEST_F(BackgroundSyncManagerTest, RegistrationEqualsId) {
...@@ -631,11 +631,11 @@ TEST_F(BackgroundSyncManagerTest, RegistrationEqualsId) { ...@@ -631,11 +631,11 @@ TEST_F(BackgroundSyncManagerTest, RegistrationEqualsId) {
EXPECT_TRUE(reg_1.Equals(reg_2)); EXPECT_TRUE(reg_1.Equals(reg_2));
} }
TEST_F(BackgroundSyncManagerTest, RegistrationEqualsName) { TEST_F(BackgroundSyncManagerTest, RegistrationEqualsTag) {
BackgroundSyncManager::BackgroundSyncRegistration reg_1; BackgroundSyncManager::BackgroundSyncRegistration reg_1;
BackgroundSyncManager::BackgroundSyncRegistration reg_2; BackgroundSyncManager::BackgroundSyncRegistration reg_2;
EXPECT_TRUE(reg_1.Equals(reg_2)); EXPECT_TRUE(reg_1.Equals(reg_2));
reg_2.name = "bar"; reg_2.tag = "bar";
EXPECT_FALSE(reg_1.Equals(reg_2)); EXPECT_FALSE(reg_1.Equals(reg_2));
} }
...@@ -676,7 +676,7 @@ TEST_F(BackgroundSyncManagerTest, RegistrationEqualsPowerState) { ...@@ -676,7 +676,7 @@ TEST_F(BackgroundSyncManagerTest, RegistrationEqualsPowerState) {
TEST_F(BackgroundSyncManagerTest, StoreAndRetrievePreservesValues) { TEST_F(BackgroundSyncManagerTest, StoreAndRetrievePreservesValues) {
BackgroundSyncManager::BackgroundSyncRegistration reg_1; BackgroundSyncManager::BackgroundSyncRegistration reg_1;
// Set non-default values for each field. // Set non-default values for each field.
reg_1.name = "foo"; reg_1.tag = "foo";
reg_1.fire_once = !reg_1.fire_once; reg_1.fire_once = !reg_1.fire_once;
reg_1.min_period += 1; reg_1.min_period += 1;
EXPECT_NE(NETWORK_STATE_ANY, reg_1.network_state); EXPECT_NE(NETWORK_STATE_ANY, reg_1.network_state);
...@@ -691,7 +691,7 @@ TEST_F(BackgroundSyncManagerTest, StoreAndRetrievePreservesValues) { ...@@ -691,7 +691,7 @@ TEST_F(BackgroundSyncManagerTest, StoreAndRetrievePreservesValues) {
// disk. // disk.
UseTestBackgroundSyncManager(); UseTestBackgroundSyncManager();
EXPECT_TRUE(GetRegistration(reg_1.name)); EXPECT_TRUE(GetRegistration(reg_1.tag));
EXPECT_TRUE(reg_1.Equals(callback_registration_)); EXPECT_TRUE(reg_1.Equals(callback_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