Bug 1434206 - Add const to functions and members that can take it. r?gcp draft
authorFrancois Marier <francois@mozilla.com>
Wed, 16 May 2018 15:39:33 -0700
changeset 467869 a1a382f2e773
parent 467868 976e25b49758
child 467870 b1565f3aacdb
push id180
push userfmarier@mozilla.com
push dateTue, 29 May 2018 01:16:16 +0000
reviewersgcp
bugs1434206
milestone62.0a1
Bug 1434206 - Add const to functions and members that can take it. r?gcp MozReview-Commit-ID: D8IQoLZkFaA
toolkit/components/url-classifier/LookupCache.h
toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
toolkit/components/url-classifier/nsUrlClassifierDBService.h
--- a/toolkit/components/url-classifier/LookupCache.h
+++ b/toolkit/components/url-classifier/LookupCache.h
@@ -92,19 +92,19 @@ public:
   enum { V2, V4 };
 
   virtual int Ver() const = 0;
   virtual bool findCompletion(const Completion& aCompletion) const = 0;
 
   virtual ~CacheResult() {}
 
   template<typename T>
-  static T* Cast(CacheResult* aThat) {
+  static const T* Cast(const CacheResult* aThat) {
     return ((aThat && T::VER == aThat->Ver()) ?
-      reinterpret_cast<T*>(aThat) : nullptr);
+      reinterpret_cast<const T*>(aThat) : nullptr);
   }
 
   nsCString table;
   Prefix prefix;
 };
 
 class CacheResultV2 final : public CacheResult
 {
--- a/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
@@ -908,22 +908,22 @@ nsUrlClassifierDBServiceWorker::CacheCom
 
   rv = mClassifier->ApplyFullHashes(updates);
   NS_ENSURE_SUCCESS(rv, rv);
   mLastResults = Move(resultsPtr);
   return NS_OK;
 }
 
 nsresult
-nsUrlClassifierDBServiceWorker::CacheResultToTableUpdate(CacheResult* aCacheResult,
+nsUrlClassifierDBServiceWorker::CacheResultToTableUpdate(const CacheResult* aCacheResult,
                                                          RefPtr<TableUpdate> aUpdate)
 {
   RefPtr<TableUpdateV2> tuV2 = TableUpdate::Cast<TableUpdateV2>(aUpdate);
   if (tuV2) {
-    const CacheResultV2* result = CacheResult::Cast<CacheResultV2>(aCacheResult);
+    const CacheResultV2* result = CacheResult::Cast<const CacheResultV2>(aCacheResult);
     MOZ_ASSERT(result);
 
     if (result->miss) {
       return tuV2->NewMissPrefix(result->prefix);
     } else {
       LOG(("CacheCompletion hash %X, Addchunk %d", result->completion.ToUint32(),
            result->addChunk));
 
@@ -932,17 +932,17 @@ nsUrlClassifierDBServiceWorker::CacheRes
         return rv;
       }
       return tuV2->NewAddChunk(result->addChunk);
     }
   }
 
   RefPtr<TableUpdateV4> tuV4 = TableUpdate::Cast<TableUpdateV4>(aUpdate);
   if (tuV4) {
-    const CacheResultV4* result = CacheResult::Cast<CacheResultV4>(aCacheResult);
+    const CacheResultV4* result = CacheResult::Cast<const CacheResultV4>(aCacheResult);
     MOZ_ASSERT(result);
 
     if (LOG_ENABLED()) {
       const FullHashExpiryCache& fullHashes = result->response.fullHashes;
       for (auto iter = fullHashes.ConstIter(); !iter.Done(); iter.Next()) {
         Completion completion;
         completion.Assign(iter.Key());
         LOG(("CacheCompletion(v4) hash %X, CacheExpireTime %" PRId64,
@@ -1020,21 +1020,21 @@ nsUrlClassifierDBServiceWorker::IsSameAs
     CacheResult* lhs = mLastResults->ElementAt(i).get();
     CacheResult* rhs = aResult[i].get();
 
     if (lhs->Ver() != rhs->Ver()) {
       return false;
     }
 
     if (lhs->Ver() == CacheResult::V2) {
-      equal = *(CacheResult::Cast<CacheResultV2>(lhs)) ==
-              *(CacheResult::Cast<CacheResultV2>(rhs));
+      equal = *(CacheResult::Cast<const CacheResultV2>(lhs)) ==
+              *(CacheResult::Cast<const CacheResultV2>(rhs));
     } else if (lhs->Ver() == CacheResult::V4) {
-      equal = *(CacheResult::Cast<CacheResultV4>(lhs)) ==
-              *(CacheResult::Cast<CacheResultV4>(rhs));
+      equal = *(CacheResult::Cast<const CacheResultV4>(lhs)) ==
+              *(CacheResult::Cast<const CacheResultV4>(rhs));
     }
   }
 
   return equal;
 }
 
 // -------------------------------------------------------------------------
 // nsUrlClassifierLookupCallback
--- a/toolkit/components/url-classifier/nsUrlClassifierDBService.h
+++ b/toolkit/components/url-classifier/nsUrlClassifierDBService.h
@@ -261,17 +261,17 @@ private:
                     const nsACString& tables,
                     nsIUrlClassifierLookupCallback* c);
 
   nsresult AddNoise(const Prefix aPrefix,
                     const nsCString tableName,
                     uint32_t aCount,
                     LookupResultArray& results);
 
-  nsresult CacheResultToTableUpdate(CacheResult* aCacheResult,
+  nsresult CacheResultToTableUpdate(const CacheResult* aCacheResult,
                                     RefPtr<TableUpdate> aUpdate);
 
   bool IsSameAsLastResults(const CacheResultArray& aResult) const;
 
   nsAutoPtr<mozilla::safebrowsing::Classifier> mClassifier;
   // The class that actually parses the update chunks.
   nsAutoPtr<ProtocolParser> mProtocolParser;