Commit f6033c7d authored by Josh Karlin's avatar Josh Karlin Committed by Commit Bot

[BackgroundSync] Remove the requested network state from registration

We used to support sync registrations having various types of network
conditions under which they would fire. That's not specced and it's
unused, so removing it.

Bug: 901034
Change-Id: I38fb1cf2779aebe8814f7bb1bf5564f467397149
Reviewed-on: https://chromium-review.googlesource.com/c/1313191
Commit-Queue: Josh Karlin <jkarlin@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605448}
parent c584481a
...@@ -19,7 +19,7 @@ message BackgroundSyncRegistrationProto { ...@@ -19,7 +19,7 @@ message BackgroundSyncRegistrationProto {
required string tag = 2; required string tag = 2;
// required SyncPeriodicity periodicity = 3; // required SyncPeriodicity periodicity = 3;
// required int64 min_period = 4; // required int64 min_period = 4;
required SyncNetworkState network_state = 5; // required SyncNetworkState network_state = 5;
// required SyncPowerState power_state = 6; // required SyncPowerState power_state = 6;
required int32 num_attempts = 7; required int32 num_attempts = 7;
required int64 delay_until = 8; required int64 delay_until = 8;
......
...@@ -400,7 +400,6 @@ void BackgroundSyncManager::InitDidGetDataFromBackend( ...@@ -400,7 +400,6 @@ void BackgroundSyncManager::InitDidGetDataFromBackend(
BackgroundSyncRegistrationOptions* options = registration->options(); BackgroundSyncRegistrationOptions* options = registration->options();
options->tag = registration_proto.tag(); options->tag = registration_proto.tag();
options->network_state = registration_proto.network_state();
registration->set_num_attempts(registration_proto.num_attempts()); registration->set_num_attempts(registration_proto.num_attempts());
registration->set_delay_until( registration->set_delay_until(
...@@ -655,8 +654,6 @@ void BackgroundSyncManager::StoreRegistrations( ...@@ -655,8 +654,6 @@ void BackgroundSyncManager::StoreRegistrations(
BackgroundSyncRegistrationProto* registration_proto = BackgroundSyncRegistrationProto* registration_proto =
registrations_proto.add_registration(); registrations_proto.add_registration();
registration_proto->set_tag(registration.options()->tag); registration_proto->set_tag(registration.options()->tag);
registration_proto->set_network_state(
registration.options()->network_state);
registration_proto->set_num_attempts(registration.num_attempts()); registration_proto->set_num_attempts(registration.num_attempts());
registration_proto->set_delay_until( registration_proto->set_delay_until(
registration.delay_until().ToInternalValue()); registration.delay_until().ToInternalValue());
...@@ -837,7 +834,7 @@ void BackgroundSyncManager::GetRegistrationsImpl( ...@@ -837,7 +834,7 @@ void BackgroundSyncManager::GetRegistrationsImpl(
bool BackgroundSyncManager::AreOptionConditionsMet( bool BackgroundSyncManager::AreOptionConditionsMet(
const BackgroundSyncRegistrationOptions& options) { const BackgroundSyncRegistrationOptions& options) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
return network_observer_->NetworkSufficient(options.network_state); return network_observer_->NetworkSufficient();
} }
bool BackgroundSyncManager::IsRegistrationReadyToFire( bool BackgroundSyncManager::IsRegistrationReadyToFire(
...@@ -1204,7 +1201,7 @@ blink::ServiceWorkerStatusCode BackgroundSyncManager::CanEmulateSyncEvent( ...@@ -1204,7 +1201,7 @@ blink::ServiceWorkerStatusCode BackgroundSyncManager::CanEmulateSyncEvent(
scoped_refptr<ServiceWorkerVersion> active_version) { scoped_refptr<ServiceWorkerVersion> active_version) {
if (!active_version) if (!active_version)
return blink::ServiceWorkerStatusCode::kErrorFailed; return blink::ServiceWorkerStatusCode::kErrorFailed;
if (!network_observer_->NetworkSufficient(NETWORK_STATE_ONLINE)) if (!network_observer_->NetworkSufficient())
return blink::ServiceWorkerStatusCode::kErrorNetwork; return blink::ServiceWorkerStatusCode::kErrorNetwork;
int64_t registration_id = active_version->registration_id(); int64_t registration_id = active_version->registration_id();
if (base::ContainsKey(emulated_offline_sw_, registration_id)) if (base::ContainsKey(emulated_offline_sw_, registration_id))
......
...@@ -88,10 +88,7 @@ class BackgroundSyncManagerTest : public testing::Test { ...@@ -88,10 +88,7 @@ class BackgroundSyncManagerTest : public testing::Test {
BackgroundSyncManagerTest() BackgroundSyncManagerTest()
: browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) { : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {
sync_options_1_.tag = "foo"; sync_options_1_.tag = "foo";
sync_options_1_.network_state = NETWORK_STATE_ONLINE;
sync_options_2_.tag = "bar"; sync_options_2_.tag = "bar";
sync_options_2_.network_state = NETWORK_STATE_ONLINE;
} }
void SetUp() override { void SetUp() override {
...@@ -744,23 +741,12 @@ TEST_F(BackgroundSyncManagerTest, RegistrationEqualsTag) { ...@@ -744,23 +741,12 @@ TEST_F(BackgroundSyncManagerTest, RegistrationEqualsTag) {
EXPECT_FALSE(reg_1.Equals(reg_2)); EXPECT_FALSE(reg_1.Equals(reg_2));
} }
TEST_F(BackgroundSyncManagerTest, RegistrationEqualsNetworkState) {
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;
EXPECT_FALSE(reg_1.Equals(reg_2));
}
TEST_F(BackgroundSyncManagerTest, StoreAndRetrievePreservesValues) { TEST_F(BackgroundSyncManagerTest, StoreAndRetrievePreservesValues) {
InitDelayedSyncEventTest(); InitDelayedSyncEventTest();
BackgroundSyncRegistrationOptions options; BackgroundSyncRegistrationOptions options;
// Set non-default values for each field. // Set non-default values for each field.
options.tag = "foo"; options.tag = "foo";
EXPECT_NE(NETWORK_STATE_AVOID_CELLULAR, options.network_state);
options.network_state = NETWORK_STATE_AVOID_CELLULAR;
// Store the registration. // Store the registration.
EXPECT_TRUE(Register(options)); EXPECT_TRUE(Register(options));
......
...@@ -67,26 +67,10 @@ void BackgroundSyncNetworkObserver::UpdateConnectionType() { ...@@ -67,26 +67,10 @@ void BackgroundSyncNetworkObserver::UpdateConnectionType() {
OnConnectionChanged(connection_type); OnConnectionChanged(connection_type);
} }
bool BackgroundSyncNetworkObserver::NetworkSufficient( bool BackgroundSyncNetworkObserver::NetworkSufficient() {
SyncNetworkState network_state) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
switch (network_state) { return connection_type_ != network::mojom::ConnectionType::CONNECTION_NONE;
case NETWORK_STATE_ANY:
return true;
case NETWORK_STATE_AVOID_CELLULAR:
// Note that this returns true for CONNECTION_UNKNOWN to avoid never
// firing.
return connection_type_ !=
network::mojom::ConnectionType::CONNECTION_NONE &&
!network::NetworkConnectionTracker::IsConnectionCellular(
connection_type_);
case NETWORK_STATE_ONLINE:
return connection_type_ !=
network::mojom::ConnectionType::CONNECTION_NONE;
}
NOTREACHED();
return false; return false;
} }
......
...@@ -28,9 +28,8 @@ class CONTENT_EXPORT BackgroundSyncNetworkObserver ...@@ -28,9 +28,8 @@ class CONTENT_EXPORT BackgroundSyncNetworkObserver
// (For preventing flakes in tests) // (For preventing flakes in tests)
static void SetIgnoreNetworkChangesForTests(bool ignore); static void SetIgnoreNetworkChangesForTests(bool ignore);
// Returns true if the state of the network meets the needs of // Returns true if the network is online.
// |network_state|. bool NetworkSufficient();
bool NetworkSufficient(SyncNetworkState network_state);
// NetworkConnectionObserver overrides // NetworkConnectionObserver overrides
void OnConnectionChanged( void OnConnectionChanged(
......
...@@ -51,58 +51,18 @@ TEST_F(BackgroundSyncNetworkObserverTest, NetworkChangeInvokesCallback) { ...@@ -51,58 +51,18 @@ TEST_F(BackgroundSyncNetworkObserverTest, NetworkChangeInvokesCallback) {
EXPECT_EQ(4, network_changed_count_); EXPECT_EQ(4, network_changed_count_);
} }
TEST_F(BackgroundSyncNetworkObserverTest, NetworkSufficientAnyNetwork) {
SetNetwork(network::mojom::ConnectionType::CONNECTION_WIFI);
EXPECT_TRUE(network_observer_->NetworkSufficient(NETWORK_STATE_ANY));
SetNetwork(network::mojom::ConnectionType::CONNECTION_3G);
EXPECT_TRUE(network_observer_->NetworkSufficient(NETWORK_STATE_ANY));
SetNetwork(network::mojom::ConnectionType::CONNECTION_UNKNOWN);
EXPECT_TRUE(network_observer_->NetworkSufficient(NETWORK_STATE_ANY));
SetNetwork(network::mojom::ConnectionType::CONNECTION_NONE);
EXPECT_TRUE(network_observer_->NetworkSufficient(NETWORK_STATE_ANY));
}
TEST_F(BackgroundSyncNetworkObserverTest, NetworkSufficientAvoidCellular) {
SetNetwork(network::mojom::ConnectionType::CONNECTION_WIFI);
EXPECT_TRUE(
network_observer_->NetworkSufficient(NETWORK_STATE_AVOID_CELLULAR));
SetNetwork(network::mojom::ConnectionType::CONNECTION_UNKNOWN);
EXPECT_TRUE(
network_observer_->NetworkSufficient(NETWORK_STATE_AVOID_CELLULAR));
SetNetwork(network::mojom::ConnectionType::CONNECTION_2G);
EXPECT_FALSE(
network_observer_->NetworkSufficient(NETWORK_STATE_AVOID_CELLULAR));
SetNetwork(network::mojom::ConnectionType::CONNECTION_3G);
EXPECT_FALSE(
network_observer_->NetworkSufficient(NETWORK_STATE_AVOID_CELLULAR));
SetNetwork(network::mojom::ConnectionType::CONNECTION_4G);
EXPECT_FALSE(
network_observer_->NetworkSufficient(NETWORK_STATE_AVOID_CELLULAR));
SetNetwork(network::mojom::ConnectionType::CONNECTION_NONE);
EXPECT_FALSE(
network_observer_->NetworkSufficient(NETWORK_STATE_AVOID_CELLULAR));
}
TEST_F(BackgroundSyncNetworkObserverTest, ConditionsMetOnline) { TEST_F(BackgroundSyncNetworkObserverTest, ConditionsMetOnline) {
SetNetwork(network::mojom::ConnectionType::CONNECTION_WIFI); SetNetwork(network::mojom::ConnectionType::CONNECTION_WIFI);
EXPECT_TRUE(network_observer_->NetworkSufficient(NETWORK_STATE_ONLINE)); EXPECT_TRUE(network_observer_->NetworkSufficient());
SetNetwork(network::mojom::ConnectionType::CONNECTION_3G); SetNetwork(network::mojom::ConnectionType::CONNECTION_3G);
EXPECT_TRUE(network_observer_->NetworkSufficient(NETWORK_STATE_ONLINE)); EXPECT_TRUE(network_observer_->NetworkSufficient());
SetNetwork(network::mojom::ConnectionType::CONNECTION_UNKNOWN); SetNetwork(network::mojom::ConnectionType::CONNECTION_UNKNOWN);
EXPECT_TRUE(network_observer_->NetworkSufficient(NETWORK_STATE_ONLINE)); EXPECT_TRUE(network_observer_->NetworkSufficient());
SetNetwork(network::mojom::ConnectionType::CONNECTION_NONE); SetNetwork(network::mojom::ConnectionType::CONNECTION_NONE);
EXPECT_FALSE(network_observer_->NetworkSufficient(NETWORK_STATE_ONLINE)); EXPECT_FALSE(network_observer_->NetworkSufficient());
} }
TEST_F(BackgroundSyncNetworkObserverTest, GetNetworkOnConstruction) { TEST_F(BackgroundSyncNetworkObserverTest, GetNetworkOnConstruction) {
...@@ -120,7 +80,7 @@ TEST_F(BackgroundSyncNetworkObserverTest, GetNetworkOnConstruction) { ...@@ -120,7 +80,7 @@ TEST_F(BackgroundSyncNetworkObserverTest, GetNetworkOnConstruction) {
// The network observer should have learned that the current network is not // The network observer should have learned that the current network is not
// the default (UNKNOWN) but is in fact NONE. // the default (UNKNOWN) but is in fact NONE.
EXPECT_EQ(1, network_changed_count_); EXPECT_EQ(1, network_changed_count_);
EXPECT_FALSE(observer->NetworkSufficient(NETWORK_STATE_ONLINE)); EXPECT_FALSE(observer->NetworkSufficient());
} }
} // namespace content } // namespace content
...@@ -8,7 +8,7 @@ namespace content { ...@@ -8,7 +8,7 @@ namespace content {
bool BackgroundSyncRegistrationOptions::Equals( bool BackgroundSyncRegistrationOptions::Equals(
const BackgroundSyncRegistrationOptions& other) const { const BackgroundSyncRegistrationOptions& other) const {
return tag == other.tag && network_state == other.network_state; return tag == other.tag;
} }
} // namespace content } // namespace content
...@@ -19,7 +19,6 @@ struct CONTENT_EXPORT BackgroundSyncRegistrationOptions { ...@@ -19,7 +19,6 @@ struct CONTENT_EXPORT BackgroundSyncRegistrationOptions {
bool Equals(const BackgroundSyncRegistrationOptions& other) const; bool Equals(const BackgroundSyncRegistrationOptions& other) const;
std::string tag; std::string tag;
SyncNetworkState network_state = NETWORK_STATE_ONLINE;
}; };
} // namespace content } // namespace content
......
...@@ -23,7 +23,6 @@ BackgroundSyncRegistrationOptions ToBackgroundSyncRegistrationOptions( ...@@ -23,7 +23,6 @@ BackgroundSyncRegistrationOptions ToBackgroundSyncRegistrationOptions(
BackgroundSyncRegistrationOptions out; BackgroundSyncRegistrationOptions out;
out.tag = in->tag; out.tag = in->tag;
out.network_state = static_cast<SyncNetworkState>(in->network_state);
return out; return out;
} }
...@@ -31,8 +30,6 @@ blink::mojom::SyncRegistrationPtr ToMojoRegistration( ...@@ -31,8 +30,6 @@ blink::mojom::SyncRegistrationPtr ToMojoRegistration(
const BackgroundSyncRegistration& in) { const BackgroundSyncRegistration& in) {
blink::mojom::SyncRegistrationPtr out(blink::mojom::SyncRegistration::New()); blink::mojom::SyncRegistrationPtr out(blink::mojom::SyncRegistration::New());
out->tag = in.options()->tag; out->tag = in.options()->tag;
out->network_state = static_cast<blink::mojom::BackgroundSyncNetworkState>(
in.options()->network_state);
return out; return out;
} }
...@@ -59,15 +56,6 @@ COMPILE_ASSERT_MATCHING_ENUM(mojom::BackgroundSyncError::PERMISSION_DENIED, ...@@ -59,15 +56,6 @@ COMPILE_ASSERT_MATCHING_ENUM(mojom::BackgroundSyncError::PERMISSION_DENIED,
COMPILE_ASSERT_MATCHING_ENUM(mojom::BackgroundSyncError::MAX, COMPILE_ASSERT_MATCHING_ENUM(mojom::BackgroundSyncError::MAX,
BACKGROUND_SYNC_STATUS_PERMISSION_DENIED); BACKGROUND_SYNC_STATUS_PERMISSION_DENIED);
COMPILE_ASSERT_MATCHING_ENUM(mojom::BackgroundSyncNetworkState::ANY,
SyncNetworkState::NETWORK_STATE_ANY);
COMPILE_ASSERT_MATCHING_ENUM(mojom::BackgroundSyncNetworkState::AVOID_CELLULAR,
SyncNetworkState::NETWORK_STATE_AVOID_CELLULAR);
COMPILE_ASSERT_MATCHING_ENUM(mojom::BackgroundSyncNetworkState::ONLINE,
SyncNetworkState::NETWORK_STATE_ONLINE);
COMPILE_ASSERT_MATCHING_ENUM(mojom::BackgroundSyncNetworkState::MAX,
SyncNetworkState::NETWORK_STATE_ONLINE);
BackgroundSyncServiceImpl::~BackgroundSyncServiceImpl() { BackgroundSyncServiceImpl::~BackgroundSyncServiceImpl() {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(background_sync_context_->background_sync_manager()); DCHECK(background_sync_context_->background_sync_manager());
......
...@@ -4,16 +4,8 @@ ...@@ -4,16 +4,8 @@
module blink.mojom; module blink.mojom;
enum BackgroundSyncNetworkState {
ANY,
AVOID_CELLULAR,
ONLINE,
MAX=ONLINE
};
struct SyncRegistration { struct SyncRegistration {
string tag = ""; string tag = "";
BackgroundSyncNetworkState network_state = ONLINE;
}; };
enum BackgroundSyncError { enum BackgroundSyncError {
......
...@@ -40,8 +40,6 @@ ScriptPromise SyncManager::registerFunction(ScriptState* script_state, ...@@ -40,8 +40,6 @@ ScriptPromise SyncManager::registerFunction(ScriptState* script_state,
mojom::blink::SyncRegistrationPtr sync_registration = mojom::blink::SyncRegistrationPtr sync_registration =
mojom::blink::SyncRegistration::New(); mojom::blink::SyncRegistration::New();
sync_registration->tag = tag; sync_registration->tag = tag;
sync_registration->network_state =
blink::mojom::BackgroundSyncNetworkState::ONLINE;
GetBackgroundSyncServicePtr()->Register( GetBackgroundSyncServicePtr()->Register(
std::move(sync_registration), registration_->RegistrationId(), std::move(sync_registration), registration_->RegistrationId(),
......
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