toolkit/components/url-classifier/nsUrlClassifierDBService.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     1 //* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-/
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef nsUrlClassifierDBService_h_
     7 #define nsUrlClassifierDBService_h_
     9 #include <nsISupportsUtils.h>
    11 #include "nsID.h"
    12 #include "nsInterfaceHashtable.h"
    13 #include "nsIObserver.h"
    14 #include "nsUrlClassifierPrefixSet.h"
    15 #include "nsIUrlClassifierHashCompleter.h"
    16 #include "nsIUrlClassifierDBService.h"
    17 #include "nsIURIClassifier.h"
    18 #include "nsToolkitCompsCID.h"
    19 #include "nsICryptoHash.h"
    20 #include "nsICryptoHMAC.h"
    21 #include "mozilla/Attributes.h"
    23 #include "LookupCache.h"
    25 // The hash length for a domain key.
    26 #define DOMAIN_LENGTH 4
    28 // The hash length of a partial hash entry.
    29 #define PARTIAL_LENGTH 4
    31 // The hash length of a complete hash entry.
    32 #define COMPLETE_LENGTH 32
    34 class nsUrlClassifierDBServiceWorker;
    35 class nsIThread;
    36 class nsIURI;
    38 // This is a proxy class that just creates a background thread and delagates
    39 // calls to the background thread.
    40 class nsUrlClassifierDBService MOZ_FINAL : public nsIUrlClassifierDBService,
    41                                            public nsIURIClassifier,
    42                                            public nsIObserver
    43 {
    44 public:
    45   // This is thread safe. It throws an exception if the thread is busy.
    46   nsUrlClassifierDBService();
    48   nsresult Init();
    50   static nsUrlClassifierDBService* GetInstance(nsresult *result);
    52   NS_DECLARE_STATIC_IID_ACCESSOR(NS_URLCLASSIFIERDBSERVICE_CID)
    54   NS_DECL_THREADSAFE_ISUPPORTS
    55   NS_DECL_NSIURLCLASSIFIERDBSERVICE
    56   NS_DECL_NSIURICLASSIFIER
    57   NS_DECL_NSIOBSERVER
    59   bool GetCompleter(const nsACString& tableName,
    60                       nsIUrlClassifierHashCompleter** completer);
    61   nsresult CacheCompletions(mozilla::safebrowsing::CacheResultArray *results);
    62   nsresult CacheMisses(mozilla::safebrowsing::PrefixArray *results);
    64   static nsIThread* BackgroundThread();
    66 private:
    67   // No subclassing
    68   ~nsUrlClassifierDBService();
    70   // Disallow copy constructor
    71   nsUrlClassifierDBService(nsUrlClassifierDBService&);
    73   nsresult LookupURI(nsIPrincipal* aPrincipal,
    74                      const nsACString& tables,
    75                      nsIUrlClassifierCallback* c,
    76                      bool forceCheck, bool *didCheck);
    78   // Close db connection and join the background thread if it exists.
    79   nsresult Shutdown();
    81   // Check if the key is on a known-clean host.
    82   nsresult CheckClean(const nsACString &lookupKey,
    83                       bool *clean);
    85   // Read everything into mGethashTables and mDisallowCompletionTables
    86   nsresult ReadTablesFromPrefs();
    88   nsRefPtr<nsUrlClassifierDBServiceWorker> mWorker;
    89   nsCOMPtr<nsIUrlClassifierDBServiceWorker> mWorkerProxy;
    91   nsInterfaceHashtable<nsCStringHashKey, nsIUrlClassifierHashCompleter> mCompleters;
    93   // TRUE if the nsURIClassifier implementation should check for malware
    94   // uris on document loads.
    95   bool mCheckMalware;
    97   // TRUE if the nsURIClassifier implementation should check for phishing
    98   // uris on document loads.
    99   bool mCheckPhishing;
   101   // TRUE if a BeginUpdate() has been called without an accompanying
   102   // CancelUpdate()/FinishUpdate().  This is used to prevent competing
   103   // updates, not to determine whether an update is still being
   104   // processed.
   105   bool mInUpdate;
   107   // The list of tables that can use the default hash completer object.
   108   nsTArray<nsCString> mGethashTables;
   110   // The list of tables that should never be hash completed.
   111   nsTArray<nsCString> mDisallowCompletionsTables;
   113   // Thread that we do the updates on.
   114   static nsIThread* gDbBackgroundThread;
   115 };
   117 NS_DEFINE_STATIC_IID_ACCESSOR(nsUrlClassifierDBService, NS_URLCLASSIFIERDBSERVICE_CID)
   119 #endif // nsUrlClassifierDBService_h_

mercurial