[epiphany/wip/google-safe-browsing: 43/57] gsb-service: Make back-off parameters persistent



commit ab88ce2a49aa39543e9cadb5ccd0c2aa5f8c1679
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 3eb4a4f..d7fd9ef 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
@@ -418,6 +418,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);
@@ -441,6 +448,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",
@@ -450,6 +465,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 bc1670e..86864b6 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]