[epiphany/wip/google-safe-browsing: 27/30] gsb-service: Make next_full_hashes_time persistent



commit 180cbd7edce90f9c8c799ff5760ca2043de3b625
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 8ef607c..8843944 100644
--- a/lib/safe-browsing/ephy-gsb-service.c
+++ b/lib/safe-browsing/ephy-gsb-service.c
@@ -418,6 +418,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);
@@ -441,6 +445,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",
@@ -615,7 +624,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 726cd92..27d1789 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]