[epiphany/wip/google-safe-browsing: 26/37] gsb-service: Make next_full_hashes_time persistent



commit ddeef8ee516945af3372796a0459dc2608f17897
Author: Gabriel Ivascu <gabrielivascu gnome org>
Date:   Fri Sep 22 18:30:50 2017 +0300

    gsb-service: Make next_full_hashes_time persistent

 lib/safe-browsing/ephy-gsb-service.c |   11 ++++++++++-
 lib/safe-browsing/ephy-gsb-storage.c |    3 ++-
 2 files changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/lib/safe-browsing/ephy-gsb-service.c b/lib/safe-browsing/ephy-gsb-service.c
index d732fcf..b77b484 100644
--- a/lib/safe-browsing/ephy-gsb-service.c
+++ b/lib/safe-browsing/ephy-gsb-service.c
@@ -413,6 +413,10 @@ ephy_gsb_service_dispose (GObject *object)
     ephy_gsb_storage_set_metadata (self->storage,
                                    "next_list_updates_time",
                                    self->next_list_updates_time);
+    /* Store next fullHashes:find request time. */
+    ephy_gsb_storage_set_metadata (self->storage,
+                                   "next_full_hashes_time",
+                                   self->next_full_hashes_time);
   }
 
   g_clear_object (&self->storage);
@@ -436,6 +440,11 @@ ephy_gsb_service_constructed (GObject *object)
   if (!ephy_gsb_storage_is_operable (self->storage))
     return;
 
+  /* Restore next fullHashes:find request time. */
+  self->next_full_hashes_time = ephy_gsb_storage_get_metadata (self->storage,
+                                                               "next_full_hashes_time",
+                                                               CURRENT_TIME);
+
   /* Restore next threatListUpdates:fetch request time. */
   self->next_list_updates_time = ephy_gsb_storage_get_metadata (self->storage,
                                                                 "next_list_updates_time",
@@ -608,7 +617,7 @@ ephy_gsb_service_find_full_hashes (EphyGSBService                  *self,
   g_assert (matching_hashes);
   g_assert (callback);
 
-  if (CURRENT_TIME < self->next_full_hashes_time) {
+  if (self->next_full_hashes_time > CURRENT_TIME) {
     LOG ("Cannot send fullHashes:find request. Requests are restricted for %ld seconds",
          self->next_full_hashes_time - CURRENT_TIME);
     callback (threats, user_data);
diff --git a/lib/safe-browsing/ephy-gsb-storage.c b/lib/safe-browsing/ephy-gsb-storage.c
index 071d818..6029d1a 100644
--- a/lib/safe-browsing/ephy-gsb-storage.c
+++ b/lib/safe-browsing/ephy-gsb-storage.c
@@ -176,7 +176,8 @@ 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_list_updates_time', (CAST(strftime('%s', 'now') AS INT))),"
+        "('next_full_hashes_time', (CAST(strftime('%s', 'now') AS INT)))";
   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]