summaryrefslogtreecommitdiffstats
path: root/content/browser/background_sync
diff options
context:
space:
mode:
Diffstat (limited to 'content/browser/background_sync')
-rw-r--r--content/browser/background_sync/background_sync_manager.cc89
-rw-r--r--content/browser/background_sync/background_sync_manager.h19
-rw-r--r--content/browser/background_sync/background_sync_manager_unittest.cc128
-rw-r--r--content/browser/background_sync/background_sync_registration.cc24
-rw-r--r--content/browser/background_sync/background_sync_registration.h41
-rw-r--r--content/browser/background_sync/background_sync_service_impl.cc24
-rw-r--r--content/browser/background_sync/background_sync_service_impl.h10
7 files changed, 182 insertions, 153 deletions
diff --git a/content/browser/background_sync/background_sync_manager.cc b/content/browser/background_sync/background_sync_manager.cc
index 3843ead8..e056d23 100644
--- a/content/browser/background_sync/background_sync_manager.cc
+++ b/content/browser/background_sync/background_sync_manager.cc
@@ -26,13 +26,6 @@ const char kBackgroundSyncUserDataKey[] = "BackgroundSyncUserData";
namespace content {
-const BackgroundSyncManager::BackgroundSyncRegistration::RegistrationId
- BackgroundSyncManager::BackgroundSyncRegistration::kInvalidRegistrationId =
- -1;
-
-const BackgroundSyncManager::BackgroundSyncRegistration::RegistrationId
- BackgroundSyncManager::BackgroundSyncRegistration::kInitialId = 0;
-
BackgroundSyncManager::BackgroundSyncRegistrations::
BackgroundSyncRegistrations()
: next_id(BackgroundSyncRegistration::kInitialId) {
@@ -61,8 +54,8 @@ BackgroundSyncManager::~BackgroundSyncManager() {
BackgroundSyncManager::RegistrationKey::RegistrationKey(
const BackgroundSyncRegistration& registration)
- : RegistrationKey(registration.options.tag,
- registration.options.periodicity) {
+ : RegistrationKey(registration.options()->tag,
+ registration.options()->periodicity) {
}
BackgroundSyncManager::RegistrationKey::RegistrationKey(
@@ -258,18 +251,20 @@ void BackgroundSyncManager::InitDidGetDataFromBackend(
BackgroundSyncRegistration* registration =
&registrations->registration_map[registration_key];
- registration->id = registration_proto.id();
- registration->options.tag = registration_proto.tag();
- registration->options.periodicity = registration_proto.periodicity();
- registration->options.min_period = registration_proto.min_period();
- registration->options.network_state =
- registration_proto.network_state();
- registration->options.power_state = registration_proto.power_state();
- registration->sync_state = registration_proto.sync_state();
- if (registration->sync_state == SYNC_STATE_FIRING) {
+ 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();
+ options->power_state = registration_proto.power_state();
+
+ registration->set_id(registration_proto.id());
+ registration->set_sync_state(registration_proto.sync_state());
+
+ if (registration->sync_state() == SYNC_STATE_FIRING) {
// If the browser (or worker) closed while firing the event, consider
// it pending again>
- registration->sync_state = SYNC_STATE_PENDING;
+ registration->set_sync_state(SYNC_STATE_PENDING);
}
}
}
@@ -305,18 +300,19 @@ void BackgroundSyncManager::RegisterImpl(
const BackgroundSyncRegistration* existing_registration =
LookupRegistration(sw_registration_id, RegistrationKey(options));
- if (existing_registration && existing_registration->options.Equals(options)) {
+ if (existing_registration &&
+ existing_registration->options()->Equals(options)) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(callback, ERROR_TYPE_OK, *existing_registration));
return;
}
BackgroundSyncRegistration new_registration;
- new_registration.options = options;
+ *new_registration.options() = options;
BackgroundSyncRegistrations* registrations =
&sw_to_registrations_map_[sw_registration_id];
- new_registration.id = registrations->next_id++;
+ new_registration.set_id(registrations->next_id++);
ServiceWorkerRegistration* sw_registration =
service_worker_context_->GetLiveRegistration(sw_registration_id);
@@ -393,8 +389,7 @@ void BackgroundSyncManager::DisableAndClearManagerClearedOne(
base::Bind(barrier_closure));
}
-BackgroundSyncManager::BackgroundSyncRegistration*
-BackgroundSyncManager::LookupRegistration(
+BackgroundSyncRegistration* BackgroundSyncManager::LookupRegistration(
int64 sw_registration_id,
const RegistrationKey& registration_key) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -433,13 +428,14 @@ void BackgroundSyncManager::StoreRegistrations(
key_and_registration.second;
BackgroundSyncRegistrationProto* registration_proto =
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_power_state(registration.options.power_state);
- registration_proto->set_sync_state(registration.sync_state);
+ registration_proto->set_id(registration.id());
+ registration_proto->set_sync_state(registration.sync_state());
+ 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_power_state(registration.options()->power_state);
}
std::string serialized;
bool success = registrations_proto.SerializeToString(&serialized);
@@ -495,8 +491,7 @@ void BackgroundSyncManager::AddRegistrationToMap(
const GURL& origin,
const BackgroundSyncRegistration& sync_registration) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- DCHECK_NE(BackgroundSyncRegistration::kInvalidRegistrationId,
- sw_registration_id);
+ DCHECK(sync_registration.IsValid());
BackgroundSyncRegistrations* registrations =
&sw_to_registrations_map_[sw_registration_id];
@@ -552,7 +547,7 @@ void BackgroundSyncManager::UnregisterImpl(
const BackgroundSyncRegistration* existing_registration =
LookupRegistration(sw_registration_id, registration_key);
if (!existing_registration ||
- existing_registration->id != sync_registration_id) {
+ existing_registration->id() != sync_registration_id) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(callback, ERROR_TYPE_NOT_FOUND));
return;
@@ -638,7 +633,7 @@ void BackgroundSyncManager::GetRegistrationsImpl(
for (const auto& tag_and_registration : registrations.registration_map) {
const BackgroundSyncRegistration& registration =
tag_and_registration.second;
- if (registration.options.periodicity == periodicity)
+ if (registration.options()->periodicity == periodicity)
out_registrations.push_back(registration);
}
}
@@ -652,17 +647,17 @@ bool BackgroundSyncManager::IsRegistrationReadyToFire(
DCHECK_CURRENTLY_ON(BrowserThread::IO);
// TODO(jkarlin): Add support for firing periodic registrations.
- if (registration.options.periodicity == SYNC_PERIODIC)
+ if (registration.options()->periodicity == SYNC_PERIODIC)
return false;
- if (registration.sync_state != SYNC_STATE_PENDING)
+ if (registration.sync_state() != SYNC_STATE_PENDING)
return false;
- DCHECK_EQ(SYNC_ONE_SHOT, registration.options.periodicity);
+ DCHECK_EQ(SYNC_ONE_SHOT, registration.options()->periodicity);
return network_observer_->NetworkSufficient(
- registration.options.network_state) &&
- power_observer_->PowerSufficient(registration.options.power_state);
+ registration.options()->network_state) &&
+ power_observer_->PowerSufficient(registration.options()->power_state);
}
void BackgroundSyncManager::SchedulePendingRegistrations() {
@@ -674,8 +669,8 @@ void BackgroundSyncManager::SchedulePendingRegistrations() {
sw_id_and_registrations.second.registration_map) {
const BackgroundSyncRegistration& registration =
key_and_registration.second;
- if (registration.sync_state == SYNC_STATE_PENDING) {
- if (registration.options.periodicity == SYNC_ONE_SHOT) {
+ if (registration.sync_state() == SYNC_STATE_PENDING) {
+ if (registration.options()->periodicity == SYNC_ONE_SHOT) {
keep_browser_alive_for_one_shot = true;
} else {
// TODO(jkarlin): Support keeping the browser alive for periodic
@@ -730,7 +725,7 @@ void BackgroundSyncManager::FireReadyEventsImpl(const base::Closure& callback) {
// The state change is not saved to persistent storage because
// if the sync event is killed mid-sync then it should return to
// SYNC_STATE_PENDING.
- registration->sync_state = SYNC_STATE_FIRING;
+ registration->set_sync_state(SYNC_STATE_FIRING);
}
}
}
@@ -749,7 +744,7 @@ void BackgroundSyncManager::FireReadyEventsImpl(const base::Closure& callback) {
service_worker_id, sw_to_registrations_map_[service_worker_id].origin,
base::Bind(&BackgroundSyncManager::FireReadyEventsDidFindRegistration,
weak_ptr_factory_.GetWeakPtr(), sw_id_and_key.second,
- registration->id, barrier_closure));
+ registration->id(), barrier_closure));
}
SchedulePendingRegistrations();
@@ -816,17 +811,17 @@ void BackgroundSyncManager::EventCompleteImpl(
BackgroundSyncRegistration* registration =
LookupRegistration(service_worker_id, key);
- if (!registration || registration->id != sync_registration_id) {
+ if (!registration || registration->id() != sync_registration_id) {
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
base::Bind(callback));
return;
}
- if (registration->options.periodicity == SYNC_ONE_SHOT) {
+ if (registration->options()->periodicity == SYNC_ONE_SHOT) {
if (status_code != SERVICE_WORKER_OK) {
// TODO(jkarlin) Fire the sync event on the next page load controlled by
// this registration. (crbug.com/479665)
- registration->sync_state = SYNC_STATE_FAILED;
+ registration->set_sync_state(SYNC_STATE_FAILED);
} else {
registration = nullptr;
RemoveRegistrationFromMap(service_worker_id, key);
diff --git a/content/browser/background_sync/background_sync_manager.h b/content/browser/background_sync/background_sync_manager.h
index b198072..e49c815 100644
--- a/content/browser/background_sync/background_sync_manager.h
+++ b/content/browser/background_sync/background_sync_manager.h
@@ -12,7 +12,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "content/browser/background_sync/background_sync.pb.h"
-#include "content/browser/background_sync/background_sync_registration_options.h"
+#include "content/browser/background_sync/background_sync_registration.h"
#include "content/browser/cache_storage/cache_storage_scheduler.h"
#include "content/browser/service_worker/service_worker_context_observer.h"
#include "content/browser/service_worker/service_worker_storage.h"
@@ -51,23 +51,6 @@ class CONTENT_EXPORT BackgroundSyncManager
ERROR_TYPE_NO_SERVICE_WORKER
};
- // TODO(jkarlin): Remove this and use the struct from IPC messages once it
- // lands.
- struct CONTENT_EXPORT BackgroundSyncRegistration {
- using RegistrationId = int64;
- static const RegistrationId kInvalidRegistrationId;
- static const RegistrationId kInitialId;
- BackgroundSyncRegistration() {}
-
- bool Equals(const BackgroundSyncRegistration& other) const {
- return options.Equals(other.options);
- }
-
- BackgroundSyncRegistrationOptions options;
- RegistrationId id = kInvalidRegistrationId;
- SyncState sync_state = SYNC_STATE_PENDING;
- };
-
using StatusCallback = base::Callback<void(ErrorType)>;
using StatusAndRegistrationCallback =
base::Callback<void(ErrorType, const BackgroundSyncRegistration&)>;
diff --git a/content/browser/background_sync/background_sync_manager_unittest.cc b/content/browser/background_sync/background_sync_manager_unittest.cc
index 9063c8d..a118418 100644
--- a/content/browser/background_sync/background_sync_manager_unittest.cc
+++ b/content/browser/background_sync/background_sync_manager_unittest.cc
@@ -282,7 +282,7 @@ class BackgroundSyncManagerTest : public testing::Test {
void StatusAndRegistrationCallback(
bool* was_called,
BackgroundSyncManager::ErrorType error,
- const BackgroundSyncManager::BackgroundSyncRegistration& registration) {
+ const BackgroundSyncRegistration& registration) {
*was_called = true;
callback_error_ = error;
callback_registration_ = registration;
@@ -291,8 +291,7 @@ class BackgroundSyncManagerTest : public testing::Test {
void StatusAndRegistrationsCallback(
bool* was_called,
BackgroundSyncManager::ErrorType error,
- const std::vector<BackgroundSyncManager::BackgroundSyncRegistration>&
- registrations) {
+ const std::vector<BackgroundSyncRegistration>& registrations) {
*was_called = true;
callback_error_ = error;
callback_registrations_ = registrations;
@@ -361,20 +360,18 @@ class BackgroundSyncManagerTest : public testing::Test {
return callback_error_ == BackgroundSyncManager::ERROR_TYPE_OK;
}
- bool Unregister(const BackgroundSyncManager::BackgroundSyncRegistration&
- sync_registration) {
+ bool Unregister(const BackgroundSyncRegistration& sync_registration) {
return UnregisterWithServiceWorkerId(sw_registration_id_1_,
sync_registration);
}
bool UnregisterWithServiceWorkerId(
int64 sw_registration_id,
- const BackgroundSyncManager::BackgroundSyncRegistration&
- sync_registration) {
+ const BackgroundSyncRegistration& sync_registration) {
bool was_called = false;
background_sync_manager_->Unregister(
- sw_registration_id, sync_registration.options.tag,
- sync_registration.options.periodicity, sync_registration.id,
+ sw_registration_id, sync_registration.options()->tag,
+ sync_registration.options()->periodicity, sync_registration.id(),
base::Bind(&BackgroundSyncManagerTest::StatusCallback,
base::Unretained(this), &was_called));
base::RunLoop().RunUntilIdle();
@@ -400,7 +397,7 @@ class BackgroundSyncManagerTest : public testing::Test {
if (callback_error_ == BackgroundSyncManager::ERROR_TYPE_OK) {
EXPECT_STREQ(sync_options.tag.c_str(),
- callback_registration_.options.tag.c_str());
+ callback_registration_.options()->tag.c_str());
}
return callback_error_ == BackgroundSyncManager::ERROR_TYPE_OK;
@@ -493,9 +490,8 @@ class BackgroundSyncManagerTest : public testing::Test {
// Callback values.
BackgroundSyncManager::ErrorType callback_error_;
- BackgroundSyncManager::BackgroundSyncRegistration callback_registration_;
- std::vector<BackgroundSyncManager::BackgroundSyncRegistration>
- callback_registrations_;
+ BackgroundSyncRegistration callback_registration_;
+ std::vector<BackgroundSyncRegistration> callback_registrations_;
ServiceWorkerStatusCode callback_sw_status_code_;
int sync_events_called_;
ServiceWorkerVersion::StatusCallback sync_fired_callback_;
@@ -508,10 +504,8 @@ TEST_F(BackgroundSyncManagerTest, Register) {
TEST_F(BackgroundSyncManagerTest, RegistractionIntact) {
EXPECT_TRUE(Register(sync_options_1_));
EXPECT_STREQ(sync_options_1_.tag.c_str(),
- callback_registration_.options.tag.c_str());
- EXPECT_NE(
- BackgroundSyncManager::BackgroundSyncRegistration::kInvalidRegistrationId,
- callback_registration_.id);
+ callback_registration_.options()->tag.c_str());
+ EXPECT_TRUE(callback_registration_.IsValid());
}
TEST_F(BackgroundSyncManagerTest, RegisterWithoutLiveSWRegistration) {
@@ -530,21 +524,19 @@ TEST_F(BackgroundSyncManagerTest, RegisterWithoutActiveSWRegistration) {
TEST_F(BackgroundSyncManagerTest, RegisterExistingKeepsId) {
EXPECT_TRUE(Register(sync_options_1_));
- BackgroundSyncManager::BackgroundSyncRegistration first_registration =
- callback_registration_;
+ BackgroundSyncRegistration first_registration = callback_registration_;
EXPECT_TRUE(Register(sync_options_1_));
EXPECT_TRUE(callback_registration_.Equals(first_registration));
- EXPECT_EQ(first_registration.id, callback_registration_.id);
+ EXPECT_EQ(first_registration.id(), callback_registration_.id());
}
TEST_F(BackgroundSyncManagerTest, RegisterOverwrites) {
EXPECT_TRUE(Register(sync_options_1_));
- BackgroundSyncManager::BackgroundSyncRegistration first_registration =
- callback_registration_;
+ BackgroundSyncRegistration first_registration = callback_registration_;
sync_options_1_.min_period = 100;
EXPECT_TRUE(Register(sync_options_1_));
- EXPECT_LT(first_registration.id, callback_registration_.id);
+ EXPECT_LT(first_registration.id(), callback_registration_.id());
EXPECT_FALSE(callback_registration_.Equals(first_registration));
}
@@ -558,9 +550,9 @@ TEST_F(BackgroundSyncManagerTest, RegisterOverlappingPeriodicAndOneShotTags) {
EXPECT_TRUE(Register(sync_options_1_));
EXPECT_TRUE(Register(sync_options_2_));
EXPECT_TRUE(GetRegistration(sync_options_1_));
- EXPECT_EQ(SYNC_PERIODIC, callback_registration_.options.periodicity);
+ EXPECT_EQ(SYNC_PERIODIC, callback_registration_.options()->periodicity);
EXPECT_TRUE(GetRegistration(sync_options_2_));
- EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_.options.periodicity);
+ EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_.options()->periodicity);
}
TEST_F(BackgroundSyncManagerTest, RegisterBadBackend) {
@@ -608,7 +600,7 @@ TEST_F(BackgroundSyncManagerTest, GetRegistrationsOne) {
EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity));
EXPECT_EQ(1u, callback_registrations_.size());
- sync_options_1_.Equals(callback_registrations_[0].options);
+ sync_options_1_.Equals(*callback_registrations_[0].options());
}
TEST_F(BackgroundSyncManagerTest, GetRegistrationsTwo) {
@@ -619,8 +611,8 @@ TEST_F(BackgroundSyncManagerTest, GetRegistrationsTwo) {
EXPECT_TRUE(GetRegistrations(sync_options_1_.periodicity));
EXPECT_EQ(2u, callback_registrations_.size());
- sync_options_1_.Equals(callback_registrations_[0].options);
- sync_options_2_.Equals(callback_registrations_[1].options);
+ sync_options_1_.Equals(*callback_registrations_[0].options());
+ sync_options_2_.Equals(*callback_registrations_[1].options());
}
TEST_F(BackgroundSyncManagerTest, GetRegistrationsPeriodicity) {
@@ -631,11 +623,11 @@ TEST_F(BackgroundSyncManagerTest, GetRegistrationsPeriodicity) {
EXPECT_TRUE(GetRegistrations(SYNC_ONE_SHOT));
EXPECT_EQ(1u, callback_registrations_.size());
- sync_options_1_.Equals(callback_registrations_[0].options);
+ sync_options_1_.Equals(*callback_registrations_[0].options());
EXPECT_TRUE(GetRegistrations(SYNC_PERIODIC));
EXPECT_EQ(1u, callback_registrations_.size());
- sync_options_2_.Equals(callback_registrations_[0].options);
+ sync_options_2_.Equals(*callback_registrations_[0].options());
}
TEST_F(BackgroundSyncManagerTest, GetRegistrationsBadBackend) {
@@ -658,7 +650,7 @@ TEST_F(BackgroundSyncManagerTest, Unregister) {
TEST_F(BackgroundSyncManagerTest, UnregisterWrongId) {
EXPECT_TRUE(Register(sync_options_1_));
- callback_registration_.id += 1;
+ callback_registration_.set_id(callback_registration_.id() + 1);
EXPECT_FALSE(Unregister(callback_registration_));
}
@@ -669,8 +661,8 @@ TEST_F(BackgroundSyncManagerTest, Reregister) {
}
TEST_F(BackgroundSyncManagerTest, UnregisterNonExisting) {
- BackgroundSyncManager::BackgroundSyncRegistration nonexistant_registration;
- nonexistant_registration.id = 1;
+ BackgroundSyncRegistration nonexistant_registration;
+ nonexistant_registration.set_id(1);
EXPECT_FALSE(Unregister(nonexistant_registration));
EXPECT_EQ(BackgroundSyncManager::ERROR_TYPE_NOT_FOUND, callback_error_);
}
@@ -698,19 +690,18 @@ TEST_F(BackgroundSyncManagerTest, UnregisterBadBackend) {
TEST_F(BackgroundSyncManagerTest, RegistrationIncreasesId) {
EXPECT_TRUE(Register(sync_options_1_));
- BackgroundSyncManager::BackgroundSyncRegistration registered_sync =
- callback_registration_;
- BackgroundSyncManager::BackgroundSyncRegistration::RegistrationId cur_id =
- callback_registration_.id;
+ BackgroundSyncRegistration registered_sync = callback_registration_;
+ BackgroundSyncRegistration::RegistrationId cur_id =
+ callback_registration_.id();
EXPECT_TRUE(GetRegistration(sync_options_1_));
EXPECT_TRUE(Register(sync_options_2_));
- EXPECT_LT(cur_id, callback_registration_.id);
- cur_id = callback_registration_.id;
+ EXPECT_LT(cur_id, callback_registration_.id());
+ cur_id = callback_registration_.id();
EXPECT_TRUE(Unregister(registered_sync));
EXPECT_TRUE(Register(sync_options_1_));
- EXPECT_LT(cur_id, callback_registration_.id);
+ EXPECT_LT(cur_id, callback_registration_.id());
}
TEST_F(BackgroundSyncManagerTest, RebootRecovery) {
@@ -762,8 +753,7 @@ TEST_F(BackgroundSyncManagerTest, SequentialOperations) {
// the operations complete sequentially.
SetupDelayedBackgroundSyncManager();
- const int64 kExpectedInitialId =
- BackgroundSyncManager::BackgroundSyncRegistration::kInitialId;
+ const int64 kExpectedInitialId = BackgroundSyncRegistration::kInitialId;
bool register_called = false;
bool unregister_called = false;
@@ -798,7 +788,7 @@ TEST_F(BackgroundSyncManagerTest, SequentialOperations) {
test_background_sync_manager_->Continue();
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(register_called);
- EXPECT_EQ(kExpectedInitialId, callback_registration_.id);
+ EXPECT_EQ(kExpectedInitialId, callback_registration_.id());
EXPECT_EQ(BackgroundSyncManager::ERROR_TYPE_OK, callback_error_);
// Unregister should be blocked while storing to the backend.
EXPECT_FALSE(unregister_called);
@@ -886,54 +876,54 @@ TEST_F(BackgroundSyncManagerTest, DisabledManagerWorksAfterDeleteAndStartOver) {
}
TEST_F(BackgroundSyncManagerTest, RegistrationEqualsId) {
- BackgroundSyncManager::BackgroundSyncRegistration reg_1;
- BackgroundSyncManager::BackgroundSyncRegistration reg_2;
+ BackgroundSyncRegistration reg_1;
+ BackgroundSyncRegistration reg_2;
EXPECT_TRUE(reg_1.Equals(reg_2));
- reg_2.id = reg_1.id + 1;
+ reg_2.set_id(reg_1.id() + 1);
EXPECT_TRUE(reg_1.Equals(reg_2));
}
TEST_F(BackgroundSyncManagerTest, RegistrationEqualsTag) {
- BackgroundSyncManager::BackgroundSyncRegistration reg_1;
- BackgroundSyncManager::BackgroundSyncRegistration reg_2;
+ BackgroundSyncRegistration reg_1;
+ BackgroundSyncRegistration reg_2;
EXPECT_TRUE(reg_1.Equals(reg_2));
- reg_2.options.tag = "bar";
+ reg_2.options()->tag = "bar";
EXPECT_FALSE(reg_1.Equals(reg_2));
}
TEST_F(BackgroundSyncManagerTest, RegistrationEqualsPeriodicity) {
- BackgroundSyncManager::BackgroundSyncRegistration reg_1;
- BackgroundSyncManager::BackgroundSyncRegistration reg_2;
+ BackgroundSyncRegistration reg_1;
+ BackgroundSyncRegistration reg_2;
EXPECT_TRUE(reg_1.Equals(reg_2));
- reg_1.options.periodicity = SYNC_PERIODIC;
- reg_2.options.periodicity = SYNC_ONE_SHOT;
+ reg_1.options()->periodicity = SYNC_PERIODIC;
+ reg_2.options()->periodicity = SYNC_ONE_SHOT;
EXPECT_FALSE(reg_1.Equals(reg_2));
}
TEST_F(BackgroundSyncManagerTest, RegistrationEqualsMinPeriod) {
- BackgroundSyncManager::BackgroundSyncRegistration reg_1;
- BackgroundSyncManager::BackgroundSyncRegistration reg_2;
+ BackgroundSyncRegistration reg_1;
+ BackgroundSyncRegistration reg_2;
EXPECT_TRUE(reg_1.Equals(reg_2));
- reg_2.options.min_period = reg_1.options.min_period + 1;
+ reg_2.options()->min_period = reg_1.options()->min_period + 1;
EXPECT_FALSE(reg_1.Equals(reg_2));
}
TEST_F(BackgroundSyncManagerTest, RegistrationEqualsNetworkState) {
- BackgroundSyncManager::BackgroundSyncRegistration reg_1;
- BackgroundSyncManager::BackgroundSyncRegistration reg_2;
+ BackgroundSyncRegistration reg_1;
+ BackgroundSyncRegistration reg_2;
EXPECT_TRUE(reg_1.Equals(reg_2));
- reg_1.options.network_state = NETWORK_STATE_ANY;
- reg_2.options.network_state = NETWORK_STATE_ONLINE;
+ reg_1.options()->network_state = NETWORK_STATE_ANY;
+ reg_2.options()->network_state = NETWORK_STATE_ONLINE;
EXPECT_FALSE(reg_1.Equals(reg_2));
}
TEST_F(BackgroundSyncManagerTest, RegistrationEqualsPowerState) {
- BackgroundSyncManager::BackgroundSyncRegistration reg_1;
- BackgroundSyncManager::BackgroundSyncRegistration reg_2;
+ BackgroundSyncRegistration reg_1;
+ BackgroundSyncRegistration reg_2;
EXPECT_TRUE(reg_1.Equals(reg_2));
- reg_1.options.power_state = POWER_STATE_AUTO;
- reg_2.options.power_state = POWER_STATE_AVOID_DRAINING;
+ reg_1.options()->power_state = POWER_STATE_AUTO;
+ reg_2.options()->power_state = POWER_STATE_AVOID_DRAINING;
EXPECT_FALSE(reg_1.Equals(reg_2));
}
@@ -957,14 +947,14 @@ TEST_F(BackgroundSyncManagerTest, StoreAndRetrievePreservesValues) {
SetupBackgroundSyncManager();
EXPECT_TRUE(GetRegistration(options));
- EXPECT_TRUE(options.Equals(callback_registration_.options));
+ EXPECT_TRUE(options.Equals(*callback_registration_.options()));
}
TEST_F(BackgroundSyncManagerTest, EmptyTagSupported) {
sync_options_1_.tag = "a";
EXPECT_TRUE(Register(sync_options_1_));
EXPECT_TRUE(GetRegistration(sync_options_1_));
- EXPECT_TRUE(sync_options_1_.Equals(callback_registration_.options));
+ EXPECT_TRUE(sync_options_1_.Equals(*callback_registration_.options()));
EXPECT_TRUE(Unregister(callback_registration_));
EXPECT_FALSE(GetRegistration(sync_options_1_));
}
@@ -981,15 +971,15 @@ TEST_F(BackgroundSyncManagerTest, OverlappingPeriodicAndOneShotTags) {
EXPECT_TRUE(Register(sync_options_2_));
EXPECT_TRUE(GetRegistration(sync_options_1_));
- EXPECT_EQ(SYNC_PERIODIC, callback_registration_.options.periodicity);
+ EXPECT_EQ(SYNC_PERIODIC, callback_registration_.options()->periodicity);
EXPECT_TRUE(GetRegistration(sync_options_2_));
- EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_.options.periodicity);
+ EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_.options()->periodicity);
EXPECT_TRUE(GetRegistration(sync_options_1_));
EXPECT_TRUE(Unregister(callback_registration_));
EXPECT_FALSE(GetRegistration(sync_options_1_));
EXPECT_TRUE(GetRegistration(sync_options_2_));
- EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_.options.periodicity);
+ EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_.options()->periodicity);
EXPECT_TRUE(Unregister(callback_registration_));
EXPECT_FALSE(GetRegistration(sync_options_2_));
diff --git a/content/browser/background_sync/background_sync_registration.cc b/content/browser/background_sync/background_sync_registration.cc
new file mode 100644
index 0000000..d6a122c
--- /dev/null
+++ b/content/browser/background_sync/background_sync_registration.cc
@@ -0,0 +1,24 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/background_sync/background_sync_registration.h"
+
+namespace content {
+
+const BackgroundSyncRegistration::RegistrationId
+ BackgroundSyncRegistration::kInvalidRegistrationId = -1;
+
+const BackgroundSyncRegistration::RegistrationId
+ BackgroundSyncRegistration::kInitialId = 0;
+
+bool BackgroundSyncRegistration::Equals(
+ const BackgroundSyncRegistration& other) const {
+ return options_.Equals(other.options_);
+}
+
+bool BackgroundSyncRegistration::IsValid() const {
+ return id_ != kInvalidRegistrationId;
+}
+
+} // namespace content
diff --git a/content/browser/background_sync/background_sync_registration.h b/content/browser/background_sync/background_sync_registration.h
new file mode 100644
index 0000000..de7c271
--- /dev/null
+++ b/content/browser/background_sync/background_sync_registration.h
@@ -0,0 +1,41 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_H_
+#define CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_H_
+
+#include "content/browser/background_sync/background_sync.pb.h"
+#include "content/browser/background_sync/background_sync_registration_options.h"
+#include "content/common/content_export.h"
+
+namespace content {
+
+class CONTENT_EXPORT BackgroundSyncRegistration {
+ public:
+ using RegistrationId = int64_t;
+ static const RegistrationId kInitialId;
+
+ bool Equals(const BackgroundSyncRegistration& other) const;
+ bool IsValid() const;
+
+ const BackgroundSyncRegistrationOptions* options() const { return &options_; }
+ BackgroundSyncRegistrationOptions* options() { return &options_; }
+
+ RegistrationId id() const { return id_; }
+ void set_id(RegistrationId id) { id_ = id; }
+
+ SyncState sync_state() const { return sync_state_; }
+ void set_sync_state(SyncState state) { sync_state_ = state; }
+
+ private:
+ static const RegistrationId kInvalidRegistrationId;
+
+ BackgroundSyncRegistrationOptions options_;
+ RegistrationId id_ = kInvalidRegistrationId;
+ SyncState sync_state_ = SYNC_STATE_PENDING;
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_H_
diff --git a/content/browser/background_sync/background_sync_service_impl.cc b/content/browser/background_sync/background_sync_service_impl.cc
index a281921..0975c148 100644
--- a/content/browser/background_sync/background_sync_service_impl.cc
+++ b/content/browser/background_sync/background_sync_service_impl.cc
@@ -6,7 +6,7 @@
#include "base/memory/weak_ptr.h"
#include "content/browser/background_sync/background_sync_context_impl.h"
-#include "content/browser/background_sync/background_sync_registration_options.h"
+#include "content/browser/background_sync/background_sync_registration.h"
#include "content/public/browser/browser_thread.h"
namespace content {
@@ -28,18 +28,17 @@ BackgroundSyncRegistrationOptions ToBackgroundSyncRegistrationOptions(
return out;
}
-SyncRegistrationPtr ToMojoRegistration(
- const BackgroundSyncManager::BackgroundSyncRegistration& in) {
+SyncRegistrationPtr ToMojoRegistration(const BackgroundSyncRegistration& in) {
SyncRegistrationPtr out(content::SyncRegistration::New());
- out->id = in.id;
- out->tag = in.options.tag;
- out->min_period_ms = in.options.min_period;
- out->periodicity =
- static_cast<content::BackgroundSyncPeriodicity>(in.options.periodicity);
+ out->id = in.id();
+ out->tag = in.options()->tag;
+ out->min_period_ms = in.options()->min_period;
+ out->periodicity = static_cast<content::BackgroundSyncPeriodicity>(
+ in.options()->periodicity);
out->power_state =
- static_cast<content::BackgroundSyncPowerState>(in.options.power_state);
+ static_cast<content::BackgroundSyncPowerState>(in.options()->power_state);
out->network_state = static_cast<content::BackgroundSyncNetworkState>(
- in.options.network_state);
+ in.options()->network_state);
return out.Pass();
}
@@ -196,7 +195,7 @@ void BackgroundSyncServiceImpl::GetPermissionStatus(
void BackgroundSyncServiceImpl::OnRegisterResult(
const RegisterCallback& callback,
BackgroundSyncManager::ErrorType error,
- const BackgroundSyncManager::BackgroundSyncRegistration& result) {
+ const BackgroundSyncRegistration& result) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
SyncRegistrationPtr mojoResult = ToMojoRegistration(result);
callback.Run(static_cast<content::BackgroundSyncError>(error),
@@ -213,8 +212,7 @@ void BackgroundSyncServiceImpl::OnUnregisterResult(
void BackgroundSyncServiceImpl::OnGetRegistrationsResult(
const GetRegistrationsCallback& callback,
BackgroundSyncManager::ErrorType error,
- const std::vector<BackgroundSyncManager::BackgroundSyncRegistration>&
- result_registrations) {
+ const std::vector<BackgroundSyncRegistration>& result_registrations) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
mojo::Array<content::SyncRegistrationPtr> mojo_registrations(0);
for (const auto& registration : result_registrations)
diff --git a/content/browser/background_sync/background_sync_service_impl.h b/content/browser/background_sync/background_sync_service_impl.h
index a585517..8a28714 100644
--- a/content/browser/background_sync/background_sync_service_impl.h
+++ b/content/browser/background_sync/background_sync_service_impl.h
@@ -57,17 +57,15 @@ class CONTENT_EXPORT BackgroundSyncServiceImpl
int64_t sw_registration_id,
const GetPermissionStatusCallback& callback) override;
- void OnRegisterResult(
- const RegisterCallback& callback,
- BackgroundSyncManager::ErrorType error,
- const BackgroundSyncManager::BackgroundSyncRegistration& result);
+ void OnRegisterResult(const RegisterCallback& callback,
+ BackgroundSyncManager::ErrorType error,
+ const BackgroundSyncRegistration& result);
void OnUnregisterResult(const UnregisterCallback& callback,
BackgroundSyncManager::ErrorType error);
void OnGetRegistrationsResult(
const GetRegistrationsCallback& callback,
BackgroundSyncManager::ErrorType error,
- const std::vector<BackgroundSyncManager::BackgroundSyncRegistration>&
- result);
+ const std::vector<BackgroundSyncRegistration>& result);
scoped_refptr<BackgroundSyncContextImpl> background_sync_context_;
mojo::StrongBinding<BackgroundSyncService> binding_;