From 3f3edff3184c67a26c0c64c4aa71494b00dff5a5 Mon Sep 17 00:00:00 2001 From: serge-sans-paille Date: Tue, 15 Oct 2024 08:37:06 +0000 Subject: [PATCH] Bug 1924513 - Remove code guarded by MOZ_SAFEBROWSING_DUMP_FAILED_UPDATES r=dimi Differential Revision: https://phabricator.services.mozilla.com/D225508 --- .../components/url-classifier/Classifier.cpp | 74 ------------------- .../components/url-classifier/Classifier.h | 9 --- .../url-classifier/ProtocolParser.cpp | 3 - .../url-classifier/ProtocolParser.h | 14 ---- .../nsUrlClassifierDBService.cpp | 19 +---- .../url-classifier/nsUrlClassifierDBService.h | 5 -- toolkit/moz.configure | 7 -- 7 files changed, 2 insertions(+), 129 deletions(-) diff --git a/toolkit/components/url-classifier/Classifier.cpp b/toolkit/components/url-classifier/Classifier.cpp index 3b0f532bce04..d40359243108 100644 --- a/toolkit/components/url-classifier/Classifier.cpp +++ b/toolkit/components/url-classifier/Classifier.cpp @@ -1081,80 +1081,6 @@ nsresult Classifier::CleanToDelete() { return NS_OK; } -#ifdef MOZ_SAFEBROWSING_DUMP_FAILED_UPDATES - -already_AddRefed Classifier::GetFailedUpdateDirectroy() { - nsCString failedUpdatekDirName = STORE_DIRECTORY + nsCString("-failedupdate"); - - nsCOMPtr failedUpdatekDirectory; - if (NS_FAILED( - mCacheDirectory->Clone(getter_AddRefs(failedUpdatekDirectory))) || - NS_FAILED(failedUpdatekDirectory->AppendNative(failedUpdatekDirName))) { - LOG(("Failed to init failedUpdatekDirectory.")); - return nullptr; - } - - return failedUpdatekDirectory.forget(); -} - -nsresult Classifier::DumpRawTableUpdates(const nsACString& aRawUpdates) { - LOG(("Dumping raw table updates...")); - - DumpFailedUpdate(); - - nsCOMPtr failedUpdatekDirectory = GetFailedUpdateDirectroy(); - - // Create tableupdate.bin and dump raw table update data. - nsCOMPtr rawTableUpdatesFile; - nsCOMPtr outputStream; - if (NS_FAILED( - failedUpdatekDirectory->Clone(getter_AddRefs(rawTableUpdatesFile))) || - NS_FAILED( - rawTableUpdatesFile->AppendNative(nsCString("tableupdates.bin"))) || - NS_FAILED(NS_NewLocalFileOutputStream( - getter_AddRefs(outputStream), rawTableUpdatesFile, - PR_WRONLY | PR_TRUNCATE | PR_CREATE_FILE))) { - LOG(("Failed to create file to dump raw table updates.")); - return NS_ERROR_FAILURE; - } - - // Write out the data. - uint32_t written; - nsresult rv = outputStream->Write(aRawUpdates.BeginReading(), - aRawUpdates.Length(), &written); - NS_ENSURE_SUCCESS(rv, rv); - NS_ENSURE_TRUE(written == aRawUpdates.Length(), NS_ERROR_FAILURE); - - return rv; -} - -nsresult Classifier::DumpFailedUpdate() { - LOG(("Dumping failed update...")); - - nsCOMPtr failedUpdatekDirectory = GetFailedUpdateDirectroy(); - - // Remove the "failed update" directory no matter it exists or not. - // Failure is fine because the directory may not exist. - failedUpdatekDirectory->Remove(true); - - nsCString failedUpdatekDirName; - nsresult rv = failedUpdatekDirectory->GetNativeLeafName(failedUpdatekDirName); - NS_ENSURE_SUCCESS(rv, rv); - - // Copy the in-use directory to a clean "failed update" directory. - nsCOMPtr inUseDirectory; - if (NS_FAILED(mRootStoreDirectory->Clone(getter_AddRefs(inUseDirectory))) || - NS_FAILED(inUseDirectory->CopyToNative(nullptr, failedUpdatekDirName))) { - LOG(("Failed to move in-use to the \"failed update\" directory %s", - failedUpdatekDirName.get())); - return NS_ERROR_FAILURE; - } - - return rv; -} - -#endif // MOZ_SAFEBROWSING_DUMP_FAILED_UPDATES - /** * This function copies the files one by one to the destination folder. * Before copying a file, it checks ::ShouldAbort and returns diff --git a/toolkit/components/url-classifier/Classifier.h b/toolkit/components/url-classifier/Classifier.h index 8995a2ff604b..8b8f29755a53 100644 --- a/toolkit/components/url-classifier/Classifier.h +++ b/toolkit/components/url-classifier/Classifier.h @@ -93,10 +93,6 @@ class Classifier { nsresult ReadNoiseEntries(const Prefix& aPrefix, const nsACString& aTableName, uint32_t aCount, PrefixArray& aNoiseEntries); -#ifdef MOZ_SAFEBROWSING_DUMP_FAILED_UPDATES - nsresult DumpRawTableUpdates(const nsACString& aRawUpdates); -#endif - static void SplitTables(const nsACString& str, nsTArray& tables); // Given a root store directory, return a private store directory @@ -149,11 +145,6 @@ class Classifier { // and on-disk data. void RemoveUpdateIntermediaries(); -#ifdef MOZ_SAFEBROWSING_DUMP_FAILED_UPDATES - already_AddRefed GetFailedUpdateDirectroy(); - nsresult DumpFailedUpdate(); -#endif - nsresult ScanStoreDir(nsIFile* aDirectory, const nsTArray& aExtensions, nsTArray& aTables); diff --git a/toolkit/components/url-classifier/ProtocolParser.cpp b/toolkit/components/url-classifier/ProtocolParser.cpp index 2c9c919c58a3..e6d71bbc6858 100644 --- a/toolkit/components/url-classifier/ProtocolParser.cpp +++ b/toolkit/components/url-classifier/ProtocolParser.cpp @@ -124,9 +124,6 @@ nsresult ProtocolParserV2::AppendStream(const nsACString& aData) { if (!mPending.Append(aData, mozilla::fallible)) { return NS_ERROR_OUT_OF_MEMORY; } -#ifdef MOZ_SAFEBROWSING_DUMP_FAILED_UPDATES - mRawUpdate.Append(aData); -#endif bool done = false; while (!done) { diff --git a/toolkit/components/url-classifier/ProtocolParser.h b/toolkit/components/url-classifier/ProtocolParser.h index 125255f10cb7..89b3f4f0e99e 100644 --- a/toolkit/components/url-classifier/ProtocolParser.h +++ b/toolkit/components/url-classifier/ProtocolParser.h @@ -27,10 +27,6 @@ class ProtocolParser { nsresult Status() const { return mUpdateStatus; } -#ifdef MOZ_SAFEBROWSING_DUMP_FAILED_UPDATES - virtual nsCString GetRawTableUpdates() const { return mPending; } -#endif - virtual void SetCurrentTable(const nsACString& aTable) = 0; void SetRequestedTables(const nsTArray& aRequestTables) { @@ -100,12 +96,6 @@ class ProtocolParserV2 final : public ProtocolParser { return mForwards; } -#ifdef MOZ_SAFEBROWSING_DUMP_FAILED_UPDATES - // Unfortunately we have to override to return mRawUpdate which - // will not be modified during the parsing, unlike mPending. - virtual nsCString GetRawTableUpdates() const override { return mRawUpdate; } -#endif - private: virtual RefPtr CreateTableUpdate( const nsACString& aTableName) const override; @@ -163,10 +153,6 @@ class ProtocolParserV2 final : public ProtocolParser { // Updates to apply to the current table being parsed. RefPtr mTableUpdate; - -#ifdef MOZ_SAFEBROWSING_DUMP_FAILED_UPDATES - nsCString mRawUpdate; // Keep a copy of mPending before it's processed. -#endif }; // Helpers to parse the "proto" list format. diff --git a/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp b/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp index b8b06279f078..14e553bd1f60 100644 --- a/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp +++ b/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp @@ -734,11 +734,6 @@ nsUrlClassifierDBServiceWorker::FinishStream() { mTableUpdates.AppendElements(mProtocolParser->GetTableUpdates()); mProtocolParser->ForgetTableUpdates(); -#ifdef MOZ_SAFEBROWSING_DUMP_FAILED_UPDATES - // The assignment involves no string copy since the source string is - // sharable. - mRawTableUpdates = mProtocolParser->GetRawTableUpdates(); -#endif } else { LOG( ("nsUrlClassifierDBService::FinishStream Failed to parse the stream " @@ -795,18 +790,8 @@ nsUrlClassifierDBServiceWorker::FinishUpdate() { RefPtr self = this; nsresult rv = mClassifier->AsyncApplyUpdates( - mTableUpdates, [self](nsresult aRv) -> void { -#ifdef MOZ_SAFEBROWSING_DUMP_FAILED_UPDATES - if (NS_FAILED(aRv) && NS_ERROR_OUT_OF_MEMORY != aRv && - NS_ERROR_UC_UPDATE_SHUTDOWNING != aRv) { - self->mClassifier->DumpRawTableUpdates(self->mRawTableUpdates); - } - // Invalidate the raw table updates. - self->mRawTableUpdates.Truncate(); -#endif - - self->NotifyUpdateObserver(aRv); - }); + mTableUpdates, + [self](nsresult aRv) -> void { self->NotifyUpdateObserver(aRv); }); mTableUpdates.Clear(); // Classifier is working on its copy. if (NS_FAILED(rv)) { diff --git a/toolkit/components/url-classifier/nsUrlClassifierDBService.h b/toolkit/components/url-classifier/nsUrlClassifierDBService.h index 462d9a7b9df9..dae363982c93 100644 --- a/toolkit/components/url-classifier/nsUrlClassifierDBService.h +++ b/toolkit/components/url-classifier/nsUrlClassifierDBService.h @@ -271,11 +271,6 @@ class nsUrlClassifierDBServiceWorker final : public nsIUrlClassifierDBService { // list of pending lookups nsTArray mPendingLookups; - -#ifdef MOZ_SAFEBROWSING_DUMP_FAILED_UPDATES - // The raw update response for debugging. - nsCString mRawTableUpdates; -#endif }; NS_DEFINE_STATIC_IID_ACCESSOR(nsUrlClassifierDBService, diff --git a/toolkit/moz.configure b/toolkit/moz.configure index 88521821b235..b72d08acd463 100644 --- a/toolkit/moz.configure +++ b/toolkit/moz.configure @@ -1140,13 +1140,6 @@ def telemetry_on_by_default(reporting, is_nightly): set_define("MOZ_TELEMETRY_ON_BY_DEFAULT", True, when=telemetry_on_by_default) -# Safe browing -# ============================================================== -set_define( - "MOZ_SAFEBROWSING_DUMP_FAILED_UPDATES", True, when=milestone.is_nightly | moz_debug -) - - # Miscellaneous programs # ==============================================================