[epiphany/wip/google-safe-browsing: 31/35] gsb-service: Make next_full_hashes_time persistent



commit ed026cd34dd330a3a8298943f1e475c51cee65a8
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 ea916fa..556e727 100644
--- a/lib/safe-browsing/ephy-gsb-service.c
+++ b/lib/safe-browsing/ephy-gsb-service.c
@@ -411,6 +411,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);
@@ -434,6 +438,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",
@@ -606,7 +615,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]