toolkit/components/url-classifier/nsUrlClassifierDBService.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/url-classifier/nsUrlClassifierDBService.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,119 @@
     1.4 +//* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-/
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsUrlClassifierDBService_h_
    1.10 +#define nsUrlClassifierDBService_h_
    1.11 +
    1.12 +#include <nsISupportsUtils.h>
    1.13 +
    1.14 +#include "nsID.h"
    1.15 +#include "nsInterfaceHashtable.h"
    1.16 +#include "nsIObserver.h"
    1.17 +#include "nsUrlClassifierPrefixSet.h"
    1.18 +#include "nsIUrlClassifierHashCompleter.h"
    1.19 +#include "nsIUrlClassifierDBService.h"
    1.20 +#include "nsIURIClassifier.h"
    1.21 +#include "nsToolkitCompsCID.h"
    1.22 +#include "nsICryptoHash.h"
    1.23 +#include "nsICryptoHMAC.h"
    1.24 +#include "mozilla/Attributes.h"
    1.25 +
    1.26 +#include "LookupCache.h"
    1.27 +
    1.28 +// The hash length for a domain key.
    1.29 +#define DOMAIN_LENGTH 4
    1.30 +
    1.31 +// The hash length of a partial hash entry.
    1.32 +#define PARTIAL_LENGTH 4
    1.33 +
    1.34 +// The hash length of a complete hash entry.
    1.35 +#define COMPLETE_LENGTH 32
    1.36 +
    1.37 +class nsUrlClassifierDBServiceWorker;
    1.38 +class nsIThread;
    1.39 +class nsIURI;
    1.40 +
    1.41 +// This is a proxy class that just creates a background thread and delagates
    1.42 +// calls to the background thread.
    1.43 +class nsUrlClassifierDBService MOZ_FINAL : public nsIUrlClassifierDBService,
    1.44 +                                           public nsIURIClassifier,
    1.45 +                                           public nsIObserver
    1.46 +{
    1.47 +public:
    1.48 +  // This is thread safe. It throws an exception if the thread is busy.
    1.49 +  nsUrlClassifierDBService();
    1.50 +
    1.51 +  nsresult Init();
    1.52 +
    1.53 +  static nsUrlClassifierDBService* GetInstance(nsresult *result);
    1.54 +
    1.55 +  NS_DECLARE_STATIC_IID_ACCESSOR(NS_URLCLASSIFIERDBSERVICE_CID)
    1.56 +
    1.57 +  NS_DECL_THREADSAFE_ISUPPORTS
    1.58 +  NS_DECL_NSIURLCLASSIFIERDBSERVICE
    1.59 +  NS_DECL_NSIURICLASSIFIER
    1.60 +  NS_DECL_NSIOBSERVER
    1.61 +
    1.62 +  bool GetCompleter(const nsACString& tableName,
    1.63 +                      nsIUrlClassifierHashCompleter** completer);
    1.64 +  nsresult CacheCompletions(mozilla::safebrowsing::CacheResultArray *results);
    1.65 +  nsresult CacheMisses(mozilla::safebrowsing::PrefixArray *results);
    1.66 +
    1.67 +  static nsIThread* BackgroundThread();
    1.68 +
    1.69 +private:
    1.70 +  // No subclassing
    1.71 +  ~nsUrlClassifierDBService();
    1.72 +
    1.73 +  // Disallow copy constructor
    1.74 +  nsUrlClassifierDBService(nsUrlClassifierDBService&);
    1.75 +
    1.76 +  nsresult LookupURI(nsIPrincipal* aPrincipal,
    1.77 +                     const nsACString& tables,
    1.78 +                     nsIUrlClassifierCallback* c,
    1.79 +                     bool forceCheck, bool *didCheck);
    1.80 +
    1.81 +  // Close db connection and join the background thread if it exists.
    1.82 +  nsresult Shutdown();
    1.83 +
    1.84 +  // Check if the key is on a known-clean host.
    1.85 +  nsresult CheckClean(const nsACString &lookupKey,
    1.86 +                      bool *clean);
    1.87 +
    1.88 +  // Read everything into mGethashTables and mDisallowCompletionTables
    1.89 +  nsresult ReadTablesFromPrefs();
    1.90 +
    1.91 +  nsRefPtr<nsUrlClassifierDBServiceWorker> mWorker;
    1.92 +  nsCOMPtr<nsIUrlClassifierDBServiceWorker> mWorkerProxy;
    1.93 +
    1.94 +  nsInterfaceHashtable<nsCStringHashKey, nsIUrlClassifierHashCompleter> mCompleters;
    1.95 +
    1.96 +  // TRUE if the nsURIClassifier implementation should check for malware
    1.97 +  // uris on document loads.
    1.98 +  bool mCheckMalware;
    1.99 +
   1.100 +  // TRUE if the nsURIClassifier implementation should check for phishing
   1.101 +  // uris on document loads.
   1.102 +  bool mCheckPhishing;
   1.103 +
   1.104 +  // TRUE if a BeginUpdate() has been called without an accompanying
   1.105 +  // CancelUpdate()/FinishUpdate().  This is used to prevent competing
   1.106 +  // updates, not to determine whether an update is still being
   1.107 +  // processed.
   1.108 +  bool mInUpdate;
   1.109 +
   1.110 +  // The list of tables that can use the default hash completer object.
   1.111 +  nsTArray<nsCString> mGethashTables;
   1.112 +
   1.113 +  // The list of tables that should never be hash completed.
   1.114 +  nsTArray<nsCString> mDisallowCompletionsTables;
   1.115 +
   1.116 +  // Thread that we do the updates on.
   1.117 +  static nsIThread* gDbBackgroundThread;
   1.118 +};
   1.119 +
   1.120 +NS_DEFINE_STATIC_IID_ACCESSOR(nsUrlClassifierDBService, NS_URLCLASSIFIERDBSERVICE_CID)
   1.121 +
   1.122 +#endif // nsUrlClassifierDBService_h_

mercurial