Bug 1434206 - Add const to functions and members that can take it. r?gcp
MozReview-Commit-ID: D8IQoLZkFaA
--- 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
@@ -910,22 +910,22 @@ nsUrlClassifierDBServiceWorker::CacheCom
rv = mClassifier->ApplyFullHashes(updates);
if (NS_SUCCEEDED(rv)) {
mLastResults = std::move(resultsPtr);
}
return rv;
}
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));
@@ -934,17 +934,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,
@@ -1022,21 +1022,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;