[epiphany/wip/google-safe-browsing: 27/37] gsb-service: Make back-off parameters persistent
- From: Gabriel Ivașcu <gabrielivascu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/google-safe-browsing: 27/37] gsb-service: Make back-off parameters persistent
- Date: Mon, 2 Oct 2017 18:54:17 +0000 (UTC)
commit d108418f7d763f5401c260e9bf84527643a80323
Author: Gabriel Ivascu <gabrielivascu gnome org>
Date: Fri Sep 22 19:01:56 2017 +0300
gsb-service: Make back-off parameters persistent
lib/safe-browsing/ephy-gsb-service.c | 23 ++++++++++++++++++++++-
lib/safe-browsing/ephy-gsb-storage.c | 4 +++-
2 files changed, 25 insertions(+), 2 deletions(-)
---
diff --git a/lib/safe-browsing/ephy-gsb-service.c b/lib/safe-browsing/ephy-gsb-service.c
index b77b484..1486e1c 100644
--- a/lib/safe-browsing/ephy-gsb-service.c
+++ b/lib/safe-browsing/ephy-gsb-service.c
@@ -174,7 +174,7 @@ ephy_gsb_service_is_back_off_mode (EphyGSBService *self)
{
g_assert (EPHY_IS_GSB_SERVICE (self));
- return self->back_off_num_fails > 0 && CURRENT_TIME < self->back_off_exit_time;
+ return self->back_off_num_fails > 0 && self->back_off_exit_time > CURRENT_TIME;
}
static void
@@ -417,6 +417,13 @@ ephy_gsb_service_dispose (GObject *object)
ephy_gsb_storage_set_metadata (self->storage,
"next_full_hashes_time",
self->next_full_hashes_time);
+ /* Store back-off parameters. */
+ ephy_gsb_storage_set_metadata (self->storage,
+ "back_off_exit_time",
+ self->back_off_exit_time);
+ ephy_gsb_storage_set_metadata (self->storage,
+ "back_off_num_fails",
+ self->back_off_num_fails);
}
g_clear_object (&self->storage);
@@ -440,6 +447,14 @@ ephy_gsb_service_constructed (GObject *object)
if (!ephy_gsb_storage_is_operable (self->storage))
return;
+ /* Restore back-off parameters. */
+ self->back_off_exit_time = ephy_gsb_storage_get_metadata (self->storage,
+ "back_off_exit_time",
+ CURRENT_TIME);
+ self->back_off_num_fails = ephy_gsb_storage_get_metadata (self->storage,
+ "back_off_num_fails",
+ 0);
+
/* Restore next fullHashes:find request time. */
self->next_full_hashes_time = ephy_gsb_storage_get_metadata (self->storage,
"next_full_hashes_time",
@@ -449,6 +464,12 @@ ephy_gsb_service_constructed (GObject *object)
self->next_list_updates_time = ephy_gsb_storage_get_metadata (self->storage,
"next_list_updates_time",
CURRENT_TIME);
+
+ if (ephy_gsb_service_is_back_off_mode (self))
+ self->next_list_updates_time = self->back_off_exit_time;
+ else
+ ephy_gsb_service_reset_back_off_mode (self);
+
if (self->next_list_updates_time > CURRENT_TIME)
ephy_gsb_service_schedule_update (self);
else
diff --git a/lib/safe-browsing/ephy-gsb-storage.c b/lib/safe-browsing/ephy-gsb-storage.c
index 6029d1a..f38fcde 100644
--- a/lib/safe-browsing/ephy-gsb-storage.c
+++ b/lib/safe-browsing/ephy-gsb-storage.c
@@ -177,7 +177,9 @@ ephy_gsb_storage_init_metadata_table (EphyGSBStorage *self)
sql = "INSERT INTO metadata (key, value) VALUES"
"('schema_version', ?),"
"('next_list_updates_time', (CAST(strftime('%s', 'now') AS INT))),"
- "('next_full_hashes_time', (CAST(strftime('%s', 'now') AS INT)))";
+ "('next_full_hashes_time', (CAST(strftime('%s', 'now') AS INT))),"
+ "('back_off_exit_time', 0),"
+ "('back_off_num_fails', 0)";
statement = ephy_sqlite_connection_create_statement (self->db, sql, &error);
if (error) {
g_warning ("Failed to create metadata insert statement: %s", error->message);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]