WebBrowser/SafeBrowsing/SafeBrowsingManager.py

branch
safe_browsing
changeset 5821
6c7766cde4c1
parent 5820
b610cb5b501a
child 5829
d3448873ced3
--- a/WebBrowser/SafeBrowsing/SafeBrowsingManager.py	Sat Jul 29 19:41:16 2017 +0200
+++ b/WebBrowser/SafeBrowsing/SafeBrowsingManager.py	Sun Jul 30 19:56:04 2017 +0200
@@ -19,7 +19,7 @@
 import os
 import base64
 
-from PyQt5.QtCore import QObject
+from PyQt5.QtCore import pyqtSignal, QObject, QCoreApplication
 
 import Preferences
 import Utilities
@@ -31,7 +31,14 @@
 class SafeBrowsingManager(QObject):
     """
     Class implementing the interface for Google Safe Browsing.
+    
+    @signal progressMessage(message,maximum) emitted to give a message for the
+        action about to be performed and the maximum value
+    @signal progress(current) emitted to signal the current progress
     """
+    progressMessage = pyqtSignal(str, int)
+    progress = pyqtSignal(int)
+    
     def __init__(self):
         """
         Constructor
@@ -128,7 +135,13 @@
         for threatList, clientState in self.__cache.getThreatLists():
             threatListsForRemove[repr(threatList)] = threatList
         threatLists = self.__apiClient.getThreatLists()
+        maximum = len(threatLists)
+        current = 0
+        self.progressMessage.emit(self.tr("Updating threat lists"), maximum)
         for entry in threatLists:
+            current += 1
+            self.progress.emit(current)
+            QCoreApplication.processEvents()
             threatList = ThreatList.fromApiEntry(entry)
             if self.__platforms is None or \
                     threatList.platformType in self.__platforms:
@@ -136,7 +149,14 @@
                 key = repr(threatList)
                 if key in threatListsForRemove:
                     del threatListsForRemove[key]
+        maximum = len(threatListsForRemove.values())
+        current = 0
+        self.progressMessage.emit(self.tr("Deleting obsolete threat lists"),
+                                  maximum)
         for threatList in threatListsForRemove.values():
+            current += 1
+            self.progress.emit(current)
+            QCoreApplication.processEvents()
             self.__cache.deleteHashPrefixList(threatList)
             self.__cache.deleteThreatList(threatList)
         del threatListsForRemove
@@ -148,19 +168,27 @@
             clientStates[threatList.asTuple()] = clientState
         threatsUpdateResponses = \
             self.__apiClient.getThreatsUpdate(clientStates)
+        maximum = len(threatsUpdateResponses)
+        current = 0
+        self.progressMessage.emit(self.tr("Updating hash prefixes"), maximum)
         for response in threatsUpdateResponses:
+            current += 1
+            self.progress.emit(current)
+            QCoreApplication.processEvents()
             responseThreatList = ThreatList.fromApiEntry(response)
             if response["responseType"] == "FULL_UPDATE":
                 self.__cache.deleteHashPrefixList(responseThreatList)
             for removal in response.get("removals", []):
                 self.__cache.removeHashPrefixIndices(
                     responseThreatList, removal["rawIndices"]["indices"])
+                QCoreApplication.processEvents()
             for addition in response.get("additions", []):
                 hashPrefixList = HashPrefixList(
                     addition["rawHashes"]["prefixSize"],
                     base64.b64decode(addition["rawHashes"]["rawHashes"]))
                 self.__cache.populateHashPrefixList(responseThreatList,
                                                     hashPrefixList)
+                QCoreApplication.processEvents()
             expectedChecksum = base64.b64decode(response["checksum"]["sha256"])
             if self.__verifyThreatListChecksum(responseThreatList,
                                                expectedChecksum):

eric ide

mercurial