Bug 1434206 - Add const to members and functions that can take it. r=gcp

MozReview-Commit-ID: B2aaQTttPAV

--HG--
extra : rebase_source : bbd8d9c734660a4380922ed9b76f1af1de427f3f
This commit is contained in:
Francois Marier 2018-05-16 15:26:14 -07:00
Родитель deb19204a3
Коммит 30207d91aa
11 изменённых файлов: 53 добавлений и 54 удалений

Просмотреть файл

@ -998,7 +998,7 @@ Classifier::ScanStoreDir(nsIFile* aDirectory, nsTArray<nsCString>& aTables)
}
nsresult
Classifier::ActiveTables(nsTArray<nsCString>& aTables)
Classifier::ActiveTables(nsTArray<nsCString>& aTables) const
{
aTables = mActiveTablesCache;
return NS_OK;

Просмотреть файл

@ -52,7 +52,7 @@ public:
/*
* Get all tables that we know about.
*/
nsresult ActiveTables(nsTArray<nsCString>& aTables);
nsresult ActiveTables(nsTArray<nsCString>& aTables) const;
/**
* Check a URL against the specified tables.
@ -172,7 +172,7 @@ private:
nsresult LoadMetadata(nsIFile* aDirectory, nsACString& aResult);
nsCString GetProvider(const nsACString& aTableName);
static nsCString GetProvider(const nsACString& aTableName);
/**
* The "background" part of ApplyUpdates. Once the background update

Просмотреть файл

@ -220,7 +220,7 @@ TableUpdateV4::NewChecksum(const std::string& aChecksum)
nsresult
TableUpdateV4::NewFullHashResponse(const Prefix& aPrefix,
CachedFullHashResponse& aResponse)
const CachedFullHashResponse& aResponse)
{
CachedFullHashResponse* response =
mFullHashResponseMap.LookupOrAdd(aPrefix.ToUint32());
@ -374,7 +374,7 @@ HashStore::ReadHeader()
}
nsresult
HashStore::SanityCheck()
HashStore::SanityCheck() const
{
if (mHeader.magic != STORE_MAGIC || mHeader.version != CURRENT_VERSION) {
NS_WARNING("Unexpected header data in the store.");
@ -1245,7 +1245,7 @@ HashStore::SubCompletes()
}
bool
HashStore::AlreadyReadChunkNumbers()
HashStore::AlreadyReadChunkNumbers() const
{
// If there are chunks but chunk set not yet contains any data
// Then we haven't read chunk numbers.
@ -1257,7 +1257,7 @@ HashStore::AlreadyReadChunkNumbers()
}
bool
HashStore::AlreadyReadCompletions()
HashStore::AlreadyReadCompletions() const
{
// If there are completions but completion set not yet contains any data
// Then we haven't read completions.

Просмотреть файл

@ -46,7 +46,7 @@ public:
private:
virtual int Tag() const = 0;
nsCString mTable;
const nsCString mTable;
};
// A table update is built from a single update chunk from the server. As the
@ -173,7 +173,7 @@ public:
nsresult NewRemovalIndices(const uint32_t* aIndices, size_t aNumOfIndices);
nsresult NewFullHashResponse(const Prefix& aPrefix,
CachedFullHashResponse& aResponse);
const CachedFullHashResponse& aResponse);
private:
virtual int Tag() const override { return TAG; }
@ -240,7 +240,7 @@ private:
nsresult Reset();
nsresult ReadHeader();
nsresult SanityCheck();
nsresult SanityCheck() const;
nsresult CalculateChecksum(nsAutoCString& aChecksum, uint32_t aFileSize,
bool aChecksumPresent);
nsresult CheckChecksum(uint32_t aFileSize);
@ -260,8 +260,8 @@ private:
nsresult PrepareForUpdate();
bool AlreadyReadChunkNumbers();
bool AlreadyReadCompletions();
bool AlreadyReadChunkNumbers() const;
bool AlreadyReadCompletions() const;
// This is used for checking that the database is correct and for figuring out
// the number of chunks, etc. to read from disk on restart.
@ -280,7 +280,7 @@ private:
// The name of the table (must end in -shavar or -digest256, or evidently
// -simple for unittesting.
nsCString mTableName;
const nsCString mTableName;
nsCOMPtr<nsIFile> mStoreDirectory;
bool mInUpdate;

Просмотреть файл

@ -600,7 +600,7 @@ LookupCacheV2::Has(const Completion& aCompletion,
}
bool
LookupCacheV2::IsEmpty()
LookupCacheV2::IsEmpty() const
{
bool isEmpty;
mPrefixSet->IsEmpty(&isEmpty);
@ -716,7 +716,7 @@ LookupCacheV2::LoadFromFile(nsIFile* aFile)
}
size_t
LookupCacheV2::SizeOfPrefixSet()
LookupCacheV2::SizeOfPrefixSet() const
{
return mPrefixSet->SizeOfIncludingThis(moz_malloc_size_of);
}

Просмотреть файл

@ -37,23 +37,23 @@ public:
Completion complete;
} hash;
const Completion &CompleteHash() {
const Completion &CompleteHash() const {
MOZ_ASSERT(!mNoise);
return hash.complete;
}
nsCString PartialHash() {
nsCString PartialHash() const {
MOZ_ASSERT(mPartialHashLength <= COMPLETE_SIZE);
if (mNoise) {
return nsCString(reinterpret_cast<char*>(hash.fixedLengthPrefix.buf),
return nsCString(reinterpret_cast<const char*>(hash.fixedLengthPrefix.buf),
PREFIX_SIZE);
} else {
return nsCString(reinterpret_cast<char*>(hash.complete.buf),
return nsCString(reinterpret_cast<const char*>(hash.complete.buf),
mPartialHashLength);
}
}
nsCString PartialHashHex() {
nsCString PartialHashHex() const {
nsAutoCString hex;
for (size_t i = 0; i < mPartialHashLength; i++) {
hex.AppendPrintf("%.2X", hash.complete.buf[i]);
@ -208,7 +208,7 @@ public:
// Check if completions can be found in cache.
// Currently this is only used by testcase.
bool IsInCache(uint32_t key) { return mFullHashCache.Get(key); };
bool IsInCache(uint32_t key) const { return mFullHashCache.Get(key); };
#if DEBUG
void DumpCache();
@ -224,7 +224,7 @@ public:
uint32_t* aMatchLength,
bool* aConfirmed) = 0;
virtual bool IsEmpty() = 0;
virtual bool IsEmpty() const = 0;
virtual void ClearAll();
@ -238,7 +238,7 @@ private:
virtual nsresult StoreToFile(nsIFile* aFile) = 0;
virtual nsresult LoadFromFile(nsIFile* aFile) = 0;
virtual size_t SizeOfPrefixSet() = 0;
virtual size_t SizeOfPrefixSet() const = 0;
virtual int Ver() const = 0;
@ -250,8 +250,8 @@ protected:
bool* aConfirmed);
bool mPrimed; // true when the PrefixSet has been loaded (or constructed)
nsCString mTableName;
nsCString mProvider;
const nsCString mTableName;
const nsCString mProvider;
nsCOMPtr<nsIFile> mRootStoreDirectory;
nsCOMPtr<nsIFile> mStoreDirectory;
@ -279,7 +279,7 @@ public:
uint32_t* aMatchLength,
bool* aConfirmed) override;
virtual bool IsEmpty() override;
virtual bool IsEmpty() const override;
nsresult Build(AddPrefixArray& aAddPrefixes,
AddCompleteArray& aAddCompletes);
@ -304,7 +304,7 @@ protected:
virtual nsresult ClearPrefixes() override;
virtual nsresult StoreToFile(nsIFile* aFile) override;
virtual nsresult LoadFromFile(nsIFile* aFile) override;
virtual size_t SizeOfPrefixSet() override;
virtual size_t SizeOfPrefixSet() const override;
private:
virtual int Ver() const override { return VER; }

Просмотреть файл

@ -36,7 +36,7 @@ public:
void Merge(PrefixStringMap& aPrefixMap);
// Find the smallest string from the map in VLPrefixSet.
bool GetSmallestPrefix(nsACString& aOutString);
bool GetSmallestPrefix(nsACString& aOutString) const;
// Return the number of prefixes in the map
uint32_t Count() const { return mCount; }
@ -136,7 +136,7 @@ LookupCacheV4::Has(const Completion& aCompletion,
}
bool
LookupCacheV4::IsEmpty()
LookupCacheV4::IsEmpty() const
{
bool isEmpty;
mVLPrefixSet->IsEmpty(&isEmpty);
@ -210,7 +210,7 @@ LookupCacheV4::LoadFromFile(nsIFile* aFile)
}
size_t
LookupCacheV4::SizeOfPrefixSet()
LookupCacheV4::SizeOfPrefixSet() const
{
return mVLPrefixSet->SizeOfIncludingThis(moz_malloc_size_of);
}
@ -232,6 +232,21 @@ AppendPrefixToMap(PrefixStringMap& prefixes, const nsACString& prefix)
return NS_OK;
}
static nsresult
InitCrypto(nsCOMPtr<nsICryptoHash>& aCrypto)
{
nsresult rv;
aCrypto = do_CreateInstance(NS_CRYPTO_HASH_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = aCrypto->Init(nsICryptoHash::SHA256);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "InitCrypto failed");
return rv;
}
// Read prefix into a buffer and also update the hash which
// keeps track of the checksum
static void
@ -379,21 +394,6 @@ LookupCacheV4::AddFullHashResponseToCache(const FullHashResponseMap& aResponseMa
return NS_OK;
}
nsresult
LookupCacheV4::InitCrypto(nsCOMPtr<nsICryptoHash>& aCrypto)
{
nsresult rv;
aCrypto = do_CreateInstance(NS_CRYPTO_HASH_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = aCrypto->Init(nsICryptoHash::SHA256);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "InitCrypto failed");
return rv;
}
nsresult
LookupCacheV4::VerifyChecksum(const nsACString& aChecksum)
{
@ -618,7 +618,7 @@ VLPrefixSet::Merge(PrefixStringMap& aPrefixMap) {
}
bool
VLPrefixSet::GetSmallestPrefix(nsACString& aOutString) {
VLPrefixSet::GetSmallestPrefix(nsACString& aOutString) const {
PrefixString* pick = nullptr;
for (auto iter = mMap.ConstIter(); !iter.Done(); iter.Next()) {
PrefixString* str = iter.Data();

Просмотреть файл

@ -29,7 +29,7 @@ public:
uint32_t* aMatchLength,
bool* aConfirmed) override;
virtual bool IsEmpty() override;
virtual bool IsEmpty() const override;
nsresult Build(PrefixStringMap& aPrefixMap);
@ -53,12 +53,11 @@ protected:
virtual nsresult ClearPrefixes() override;
virtual nsresult StoreToFile(nsIFile* aFile) override;
virtual nsresult LoadFromFile(nsIFile* aFile) override;
virtual size_t SizeOfPrefixSet() override;
virtual size_t SizeOfPrefixSet() const override;
private:
virtual int Ver() const override { return VER; }
nsresult InitCrypto(nsCOMPtr<nsICryptoHash>& aCrypto);
nsresult VerifyChecksum(const nsACString& aChecksum);
RefPtr<VariableLengthPrefixSet> mVLPrefixSet;

Просмотреть файл

@ -52,7 +52,7 @@ public:
// becomes the caller's responsibility to free them. This is shitty.
TableUpdate *GetTableUpdate(const nsACString& aTable);
void ForgetTableUpdates() { mTableUpdates.Clear(); }
nsTArray<TableUpdate*> &GetTableUpdates() { return mTableUpdates; }
const nsTArray<TableUpdate*>& GetTableUpdates() { return mTableUpdates; }
// These are only meaningful to V2. Since they were originally public,
// moving them to ProtocolParserV2 requires a dymamic cast in the call

Просмотреть файл

@ -915,7 +915,7 @@ nsUrlClassifierDBServiceWorker::CacheResultToTableUpdate(CacheResult* aCacheResu
{
auto tuV2 = TableUpdate::Cast<TableUpdateV2>(aUpdate);
if (tuV2) {
auto result = CacheResult::Cast<CacheResultV2>(aCacheResult);
const CacheResultV2* result = CacheResult::Cast<CacheResultV2>(aCacheResult);
MOZ_ASSERT(result);
if (result->miss) {
@ -934,7 +934,7 @@ nsUrlClassifierDBServiceWorker::CacheResultToTableUpdate(CacheResult* aCacheResu
auto tuV4 = TableUpdate::Cast<TableUpdateV4>(aUpdate);
if (tuV4) {
auto result = CacheResult::Cast<CacheResultV4>(aCacheResult);
const CacheResultV4* result = CacheResult::Cast<CacheResultV4>(aCacheResult);
MOZ_ASSERT(result);
if (LOG_ENABLED()) {
@ -1006,7 +1006,7 @@ nsUrlClassifierDBServiceWorker::GetCacheInfo(const nsACString& aTable,
}
bool
nsUrlClassifierDBServiceWorker::IsSameAsLastResults(CacheResultArray& aResult)
nsUrlClassifierDBServiceWorker::IsSameAsLastResults(const CacheResultArray& aResult) const
{
if (!mLastResults || mLastResults->Length() != aResult.Length()) {
return false;

Просмотреть файл

@ -269,7 +269,7 @@ private:
nsresult CacheResultToTableUpdate(CacheResult* aCacheResult,
TableUpdate* aUpdate);
bool IsSameAsLastResults(CacheResultArray& aResult);
bool IsSameAsLastResults(const CacheResultArray& aResult) const;
nsAutoPtr<mozilla::safebrowsing::Classifier> mClassifier;
// The class that actually parses the update chunks.