Bug 1515286 - Get rid of nsIURIClassifier.asyncClassifyLocalWithTables, r=dimi
authorAndrea Marchesini <amarchesini@mozilla.com>
Sat, 05 Jan 2019 09:10:56 +0100
changeset 509736 4e04d5fd29aa51a57662ff65fa64c9ed6e504b11
parent 509735 cf02de018ec52940d002efde37c539dec74a7469
child 509737 dfd83fc53601bd3966fa28628b501f59c43d0821
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdimi
bugs1515286
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1515286 - Get rid of nsIURIClassifier.asyncClassifyLocalWithTables, r=dimi
netwerk/url-classifier/nsIURIClassifier.idl
toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
--- a/netwerk/url-classifier/nsIURIClassifier.idl
+++ b/netwerk/url-classifier/nsIURIClassifier.idl
@@ -77,30 +77,16 @@ interface nsIURIClassifier : nsISupports
    *         callback will be called.
    */
   boolean classify(in nsIPrincipal aPrincipal,
                    in nsIEventTarget aEventTarget,
                    in boolean aTrackingProtectionEnabled,
                    in nsIURIClassifierCallback aCallback);
 
   /**
-   * Asynchronously classify a URI with a comma-separated string
-   * containing the given tables. This does not make network requests.
-   * The callback does NOT totally follow nsIURIClassifierCallback's
-   * semantics described above. Only |aList| will be meaningful, which
-   * is a comma separated list of table names. (same as what classifyLocal
-   * returns.)
-   */
-  void asyncClassifyLocalWithTables(in nsIURI aURI,
-                                    in ACString aTables,
-                                    in Array<ACString> aExtraTablesByPrefs,
-                                    in Array<ACString> aExtraEntriesByPrefs,
-                                    in nsIURIClassifierCallback aCallback);
-
-  /**
    * Asynchronously classify a URI with list of features. This does not make
    * network requests.
    */
   void asyncClassifyLocalWithFeatures(in nsIURI aURI,
                                       in Array<nsIUrlClassifierFeature> aFeatures,
                                       in nsIUrlClassifierFeature_listType aListType,
                                       in nsIUrlClassifierFeatureCallback aCallback);
 
--- a/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
@@ -236,141 +236,16 @@ class FeatureHolder final {
     return tableData;
   }
 
   nsCOMPtr<nsIURI> mURI;
   nsTArray<FeatureData> mFeatureData;
   nsTArray<RefPtr<TableData>> mTableData;
 };
 
-// Simple feature which wraps preferences and tables received by
-// AsyncClassifyLocalWithTables() as arguments.
-class DummyFeature final : public nsIUrlClassifierFeature {
- public:
-  NS_DECL_ISUPPORTS
-
-  enum Type { ePreference, eTable };
-
-  explicit DummyFeature(const nsACString& aName)
-      : mType(eTable), mName(aName) {}
-
-  explicit DummyFeature(const nsACString& aPreference,
-                        nsTArray<nsCString>& aHostsFromPreference)
-      : mType(ePreference),
-        mName(aPreference),
-        mHostsFromPreference(aHostsFromPreference) {}
-
-  NS_IMETHOD
-  GetName(nsACString& aName) override {
-    aName = mName;
-    return NS_OK;
-  }
-
-  NS_IMETHOD
-  GetTables(nsIUrlClassifierFeature::listType,
-            nsTArray<nsCString>& aTables) override {
-    if (mType == eTable) {
-      aTables.AppendElement(mName);
-    }
-    return NS_OK;
-  }
-
-  NS_IMETHOD
-  HasTable(const nsACString& aTable, nsIUrlClassifierFeature::listType,
-           bool* aResult) override {
-    NS_ENSURE_ARG_POINTER(aResult);
-    *aResult = mType == eTable && aTable == mName;
-    return NS_OK;
-  }
-
-  NS_IMETHOD
-  HasHostInPreferences(const nsACString& aHost,
-                       nsIUrlClassifierFeature::listType,
-                       nsACString& aPrefTableName, bool* aResult) override {
-    NS_ENSURE_ARG_POINTER(aResult);
-    *aResult = mHostsFromPreference.Contains(aHost);
-    aPrefTableName = mName;
-    return NS_OK;
-  }
-
-  NS_IMETHOD
-  GetSkipHostList(nsACString& aList) override {
-    // Nothing to do here.
-    return NS_OK;
-  }
-
-  NS_IMETHOD
-  ProcessChannel(nsIChannel* aChannel, const nsACString& aList,
-                 bool* aShouldContinue) override {
-    NS_ENSURE_ARG_POINTER(aShouldContinue);
-    *aShouldContinue = true;
-
-    // Nothing to do here.
-    return NS_OK;
-  }
-
-  NS_IMETHODIMP
-  GetURIByListType(nsIChannel* aChannel,
-                   nsIUrlClassifierFeature::listType aListType,
-                   nsIURI** aURI) override {
-    return NS_ERROR_NOT_IMPLEMENTED;
-  }
-
- private:
-  ~DummyFeature() = default;
-
-  Type mType;
-  nsCString mName;
-  nsTArray<nsCString> mHostsFromPreference;
-};
-
-NS_IMPL_ISUPPORTS(DummyFeature, nsIUrlClassifierFeature)
-
-// This class is a proxy from nsIUrlClassifierFeatureCallback to
-// nsIUrlClassifierCallback.
-class CallbackWrapper final : public nsIUrlClassifierFeatureCallback {
- public:
-  NS_DECL_ISUPPORTS
-
-  explicit CallbackWrapper(nsIURIClassifierCallback* aCallback)
-      : mCallback(aCallback) {
-    MOZ_ASSERT(aCallback);
-  }
-
-  NS_IMETHOD
-  OnClassifyComplete(const nsTArray<RefPtr<nsIUrlClassifierFeatureResult>>&
-                         aResults) override {
-    nsAutoCString finalList;
-
-    for (nsIUrlClassifierFeatureResult* result : aResults) {
-      const nsCString& list =
-          static_cast<mozilla::net::UrlClassifierFeatureResult*>(result)
-              ->List();
-      MOZ_ASSERT(!list.IsEmpty());
-
-      if (!finalList.IsEmpty()) {
-        finalList.AppendLiteral(",");
-      }
-
-      finalList.Append(list);
-    }
-
-    mCallback->OnClassifyComplete(NS_OK, finalList, EmptyCString(),
-                                  EmptyCString());
-    return NS_OK;
-  }
-
- private:
-  ~CallbackWrapper() = default;
-
-  nsCOMPtr<nsIURIClassifierCallback> mCallback;
-};
-
-NS_IMPL_ISUPPORTS(CallbackWrapper, nsIUrlClassifierFeatureCallback)
-
 }  // namespace
 
 using namespace mozilla;
 using namespace mozilla::safebrowsing;
 
 // MOZ_LOG=UrlClassifierDbService:5
 LazyLogModule gUrlClassifierDbServiceLog("UrlClassifierDbService");
 #define LOG(args) \
@@ -1999,60 +1874,16 @@ nsUrlClassifierDBService::Classify(nsIPr
     // The URI had no hostname, don't try to classify it.
     return NS_OK;
   }
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsUrlClassifierDBService::AsyncClassifyLocalWithTables(
-    nsIURI* aURI, const nsACString& aTables,
-    const nsTArray<nsCString>& aExtraTablesByPrefs,
-    const nsTArray<nsCString>& aExtraEntriesByPrefs,
-    nsIURIClassifierCallback* aCallback) {
-  MOZ_ASSERT(NS_IsMainThread(),
-             "AsyncClassifyLocalWithTables must be called "
-             "on main thread");
-
-  if (aExtraTablesByPrefs.Length() != aExtraEntriesByPrefs.Length()) {
-    return NS_ERROR_FAILURE;
-  }
-
-  if (gShuttingDownThread) {
-    return NS_ERROR_ABORT;
-  }
-
-  // Let's convert the current params in a list of features.
-  nsTArray<RefPtr<nsIUrlClassifierFeature>> features;
-
-  for (uint32_t i = 0; i < aExtraTablesByPrefs.Length(); ++i) {
-    nsTArray<nsCString> hosts;
-    Classifier::SplitTables(aExtraEntriesByPrefs[i], hosts);
-    RefPtr<DummyFeature> feature =
-        new DummyFeature(aExtraTablesByPrefs[i], hosts);
-    features.AppendElement(feature);
-  }
-
-  nsTArray<nsCString> tables;
-  Classifier::SplitTables(aTables, tables);
-  for (uint32_t i = 0; i < tables.Length(); ++i) {
-    RefPtr<DummyFeature> feature = new DummyFeature(tables[i]);
-    features.AppendElement(feature);
-  }
-
-  RefPtr<CallbackWrapper> callback = new CallbackWrapper(aCallback);
-
-  // Doesn't really matter if we pass blacklist, whitelist or any other list
-  // here because the DummyFeature returns always the same values.
-  return AsyncClassifyLocalWithFeatures(
-      aURI, features, nsIUrlClassifierFeature::blacklist, callback);
-}
-
 class ThreatHitReportListener final : public nsIStreamListener {
  public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIREQUESTOBSERVER
   NS_DECL_NSISTREAMLISTENER
 
   ThreatHitReportListener() = default;
 
@@ -2313,17 +2144,17 @@ nsresult nsUrlClassifierDBService::Looku
       nsTArray<nsCString> entries;
       Classifier::SplitTables(aExtraEntriesByPrefs[i], entries);
       if (entries.Contains(host)) {
         *didLookup = true;
 
         nsCString table = aExtraTablesByPrefs[i];
         nsCOMPtr<nsIUrlClassifierCallback> callback(c);
         nsCOMPtr<nsIRunnable> cbRunnable = NS_NewRunnableFunction(
-            "nsUrlClassifierDBService::AsyncClassifyLocalWithTables",
+            "nsUrlClassifierDBService::LookupURI",
             [callback, table]() -> void { callback->HandleEvent(table); });
 
         NS_DispatchToMainThread(cbRunnable);
         return NS_OK;
       }
     }
   }