From 4f731551c1685f17a103999f9be25292de838179 Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 19 Jan 2017 17:16:13 +0800 Subject: [PATCH] Bug 1332213 - Store the update stream duplicately in v2 protocol parser. r=francois. MozReview-Commit-ID: dPbvro5xIa --HG-- extra : rebase_source : 911291a89531bbe55490f38b094015fcd6664562 --- toolkit/components/url-classifier/ProtocolParser.cpp | 3 +++ toolkit/components/url-classifier/ProtocolParser.h | 12 +++++++++++- .../components/url-classifier/tests/gtest/moz.build | 5 +++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/toolkit/components/url-classifier/ProtocolParser.cpp b/toolkit/components/url-classifier/ProtocolParser.cpp index 5da7787be88b..e0f5fbfaf040 100644 --- a/toolkit/components/url-classifier/ProtocolParser.cpp +++ b/toolkit/components/url-classifier/ProtocolParser.cpp @@ -142,6 +142,9 @@ ProtocolParserV2::AppendStream(const nsACString& aData) nsresult rv; mPending.Append(aData); +#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 ec1a695f44a3..329911621f18 100644 --- a/toolkit/components/url-classifier/ProtocolParser.h +++ b/toolkit/components/url-classifier/ProtocolParser.h @@ -31,7 +31,7 @@ public: nsresult Init(nsICryptoHash* aHasher); #ifdef MOZ_SAFEBROWSING_DUMP_FAILED_UPDATES - nsCString GetRawTableUpdates() const { return mPending; } + virtual nsCString GetRawTableUpdates() const { return mPending; } #endif virtual void SetCurrentTable(const nsACString& aTable) = 0; @@ -101,6 +101,12 @@ public: virtual const nsTArray &Forwards() const override { return mForwards; } virtual bool ResetRequested() override { return mResetRequested; } +#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 TableUpdate* CreateTableUpdate(const nsACString& aTableName) const override; @@ -158,6 +164,10 @@ private: // Updates to apply to the current table being parsed. TableUpdateV2 *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/tests/gtest/moz.build b/toolkit/components/url-classifier/tests/gtest/moz.build index 8c28889c8dd1..2af5cf874bac 100644 --- a/toolkit/components/url-classifier/tests/gtest/moz.build +++ b/toolkit/components/url-classifier/tests/gtest/moz.build @@ -25,4 +25,9 @@ UNIFIED_SOURCES += [ 'TestVariableLengthPrefixSet.cpp', ] +# Required to have the same MOZ_SAFEBROWSING_DUMP_FAILED_UPDATES +# as non-testing code. +if CONFIG['NIGHTLY_BUILD'] or CONFIG['MOZ_DEBUG']: + DEFINES['MOZ_SAFEBROWSING_DUMP_FAILED_UPDATES'] = True + FINAL_LIBRARY = 'xul-gtest'