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



commit 6cfd4359319661a534b267a879c9b467e0550f03
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 8843944..e88516e 100644
--- a/lib/safe-browsing/ephy-gsb-service.c
+++ b/lib/safe-browsing/ephy-gsb-service.c
@@ -172,7 +172,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
@@ -422,6 +422,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);
@@ -445,6 +452,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",
@@ -454,6 +469,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 27d1789..9be0798 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]