| File: | root/firefox-clang/obj-x86_64-pc-linux-gnu/netwerk/cache2/./../../../netwerk/cache2/CacheIndex.cpp |
| Warning: | line 2533, column 3 Value stored to 'pos' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | |
| 5 | #include "CacheIndex.h" |
| 6 | |
| 7 | #include <algorithm> |
| 8 | #include <limits> |
| 9 | |
| 10 | #include "CacheCrypto.h" |
| 11 | #include "CacheFileIOManager.h" |
| 12 | #include "CacheFileMetadata.h" |
| 13 | #include "CacheFileUtils.h" |
| 14 | #include "CacheIndexContextIterator.h" |
| 15 | #include "CacheIndexIterator.h" |
| 16 | #include "CacheLog.h" |
| 17 | #include "mozilla/AutoRestore.h" |
| 18 | #include "mozilla/DebugOnly.h" |
| 19 | #include "mozilla/StaticPrefs_browser.h" |
| 20 | #include "mozilla/StaticPrefs_network.h" |
| 21 | #include "mozilla/glean/NetwerkCache2Metrics.h" |
| 22 | #include "nsIFile.h" |
| 23 | #include "nsITimer.h" |
| 24 | #include "nsNetUtil.h" |
| 25 | #include "nsPrintfCString.h" |
| 26 | #include "nsThreadUtils.h" |
| 27 | #include "prinrval.h" |
| 28 | |
| 29 | #define kMaxBufSize16384 16384 |
| 30 | #define kIndexVersion0x0000000D 0x0000000D |
| 31 | #define kTelemetryReportBytesLimit(2U * 1024U * 1024U * 1024U) (2U * 1024U * 1024U * 1024U) // 2GB |
| 32 | |
| 33 | #define INDEX_NAME"index" "index" |
| 34 | #define TEMP_INDEX_NAME"index.tmp" "index.tmp" |
| 35 | #define JOURNAL_NAME"index.log" "index.log" |
| 36 | |
| 37 | namespace mozilla::net { |
| 38 | |
| 39 | namespace { |
| 40 | |
| 41 | class FrecencyComparator { |
| 42 | public: |
| 43 | bool Equals(const RefPtr<CacheIndexRecordWrapper>& a, |
| 44 | const RefPtr<CacheIndexRecordWrapper>& b) const { |
| 45 | if (!a || !b) { |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | return a->Get()->mFrecency == b->Get()->mFrecency; |
| 50 | } |
| 51 | bool LessThan(const RefPtr<CacheIndexRecordWrapper>& a, |
| 52 | const RefPtr<CacheIndexRecordWrapper>& b) const { |
| 53 | // Removed (=null) entries must be at the end of the array. |
| 54 | if (!a) { |
| 55 | return false; |
| 56 | } |
| 57 | if (!b) { |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | // Place entries with frecency 0 at the end of the non-removed entries. |
| 62 | if (a->Get()->mFrecency == 0) { |
| 63 | return false; |
| 64 | } |
| 65 | if (b->Get()->mFrecency == 0) { |
| 66 | return true; |
| 67 | } |
| 68 | |
| 69 | return a->Get()->mFrecency < b->Get()->mFrecency; |
| 70 | } |
| 71 | }; |
| 72 | |
| 73 | } // namespace |
| 74 | |
| 75 | // used to dispatch a wrapper deletion the caller's thread |
| 76 | // cannot be used on IOThread after shutdown begins |
| 77 | class DeleteCacheIndexRecordWrapper : public Runnable { |
| 78 | CacheIndexRecordWrapper* mWrapper; |
| 79 | |
| 80 | public: |
| 81 | explicit DeleteCacheIndexRecordWrapper(CacheIndexRecordWrapper* wrapper) |
| 82 | : Runnable("net::CacheIndex::DeleteCacheIndexRecordWrapper"), |
| 83 | mWrapper(wrapper) {} |
| 84 | NS_IMETHODvirtual nsresult Run() override { |
| 85 | StaticMutexAutoLock lock(CacheIndex::sLock); |
| 86 | |
| 87 | // if somehow the item is still in the frecency storage, remove it |
| 88 | RefPtr<CacheIndex> index = CacheIndex::gInstance; |
| 89 | if (index) { |
| 90 | bool found = index->mFrecencyStorage.RecordExistedUnlocked(mWrapper); |
| 91 | if (found) { |
| 92 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "DeleteCacheIndexRecordWrapper::Run() - record wrapper found in frecency storage during deletion" ); } } while (0) |
| 93 | ("DeleteCacheIndexRecordWrapper::Run() - \do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "DeleteCacheIndexRecordWrapper::Run() - record wrapper found in frecency storage during deletion" ); } } while (0) |
| 94 | record wrapper found in frecency storage during deletion"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "DeleteCacheIndexRecordWrapper::Run() - record wrapper found in frecency storage during deletion" ); } } while (0); |
| 95 | index->mFrecencyStorage.RemoveRecord(mWrapper, lock); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | delete mWrapper; |
| 100 | return NS_OK; |
| 101 | } |
| 102 | }; |
| 103 | |
| 104 | void CacheIndexRecordWrapper::DispatchDeleteSelfToCurrentThread() { |
| 105 | // Dispatch during shutdown will not trigger DeleteCacheIndexRecordWrapper |
| 106 | nsCOMPtr<nsIRunnable> event = new DeleteCacheIndexRecordWrapper(this); |
| 107 | MOZ_ALWAYS_SUCCEEDS(NS_DispatchToCurrentThread(event))do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl (NS_DispatchToCurrentThread(event))), 1)))), 1))) { } else { do { do { } while (false); MOZ_ReportCrash("" "NS_SUCCEEDED(NS_DispatchToCurrentThread(event))" , "./../../../netwerk/cache2/CacheIndex.cpp", 107); AnnotateMozCrashReason ("MOZ_CRASH(" "NS_SUCCEEDED(NS_DispatchToCurrentThread(event))" ")"); do { MOZ_CrashSequence(__null, 107); __attribute__((nomerge )) ::abort(); } while (false); } while (false); } } while (false ); |
| 108 | } |
| 109 | |
| 110 | CacheIndexRecordWrapper::~CacheIndexRecordWrapper() { |
| 111 | #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED1 |
| 112 | CacheIndex::sLock.AssertCurrentThreadOwns(); |
| 113 | RefPtr<CacheIndex> index = CacheIndex::gInstance; |
| 114 | if (index) { |
| 115 | bool found = index->mFrecencyStorage.RecordExistedUnlocked(this); |
| 116 | MOZ_DIAGNOSTIC_ASSERT(!found)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!found)>::isValid, "invalid assertion condition") ; if ((__builtin_expect(!!(!(!!(!found))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!found", "./../../../netwerk/cache2/CacheIndex.cpp" , 116); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "!found" ")"); do { MOZ_CrashSequence(__null, 116); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 117 | } |
| 118 | #endif |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * This helper class is responsible for keeping CacheIndex::mIndexStats and |
| 123 | * CacheIndex::mFrecencyStorage up to date. |
| 124 | */ |
| 125 | class MOZ_RAII CacheIndexEntryAutoManage { |
| 126 | public: |
| 127 | CacheIndexEntryAutoManage(const SHA1Sum::Hash* aHash, CacheIndex* aIndex, |
| 128 | const StaticMutexAutoLock& aProofOfLock) |
| 129 | MOZ_REQUIRES(CacheIndex::sLock)__attribute__((exclusive_locks_required(CacheIndex::sLock))) |
| 130 | : mIndex(aIndex), mProofOfLock(aProofOfLock) { |
| 131 | mHash = aHash; |
| 132 | const CacheIndexEntry* entry = FindEntry(); |
| 133 | mIndex->mIndexStats.BeforeChange(entry); |
| 134 | if (entry && entry->IsInitialized() && !entry->IsRemoved()) { |
| 135 | mOldRecord = entry->mRec; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | ~CacheIndexEntryAutoManage() MOZ_REQUIRES(CacheIndex::sLock)__attribute__((exclusive_locks_required(CacheIndex::sLock))) { |
| 140 | const CacheIndexEntry* entry = FindEntry(); |
| 141 | mIndex->mIndexStats.AfterChange(entry); |
| 142 | if (!entry || !entry->IsInitialized() || entry->IsRemoved()) { |
| 143 | entry = nullptr; |
| 144 | } |
| 145 | |
| 146 | if (entry && !mOldRecord) { |
| 147 | mIndex->mFrecencyStorage.AppendRecord(entry->mRec, mProofOfLock); |
| 148 | mIndex->AddRecordToIterators(entry->mRec, mProofOfLock); |
| 149 | } else if (!entry && mOldRecord) { |
| 150 | mIndex->mFrecencyStorage.RemoveRecord(mOldRecord, mProofOfLock); |
| 151 | mIndex->RemoveRecordFromIterators(mOldRecord, mProofOfLock); |
| 152 | } else if (entry && mOldRecord) { |
| 153 | if (entry->mRec != mOldRecord) { |
| 154 | // record has a different address, we have to replace it |
| 155 | mIndex->ReplaceRecordInIterators(mOldRecord, entry->mRec, mProofOfLock); |
| 156 | |
| 157 | mIndex->mFrecencyStorage.ReplaceRecord(mOldRecord, entry->mRec, |
| 158 | mProofOfLock); |
| 159 | } |
| 160 | } else { |
| 161 | // both entries were removed or not initialized, do nothing |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | // We cannot rely on nsTHashtable::GetEntry() in case we are removing entries |
| 166 | // while iterating. Destructor is called before the entry is removed. Caller |
| 167 | // must call one of following methods to skip lookup in the hashtable. |
| 168 | void DoNotSearchInIndex() { mDoNotSearchInIndex = true; } |
| 169 | void DoNotSearchInUpdates() { mDoNotSearchInUpdates = true; } |
| 170 | |
| 171 | private: |
| 172 | const CacheIndexEntry* FindEntry() MOZ_REQUIRES(CacheIndex::sLock)__attribute__((exclusive_locks_required(CacheIndex::sLock))) { |
| 173 | const CacheIndexEntry* entry = nullptr; |
| 174 | |
| 175 | switch (mIndex->mState) { |
| 176 | case CacheIndex::READING: |
| 177 | case CacheIndex::WRITING: |
| 178 | if (!mDoNotSearchInUpdates) { |
| 179 | entry = mIndex->mPendingUpdates.GetEntry(*mHash); |
| 180 | } |
| 181 | [[fallthrough]]; |
| 182 | case CacheIndex::BUILDING: |
| 183 | case CacheIndex::UPDATING: |
| 184 | case CacheIndex::READY: |
| 185 | if (!entry && !mDoNotSearchInIndex) { |
| 186 | entry = mIndex->mIndex.GetEntry(*mHash); |
| 187 | } |
| 188 | break; |
| 189 | case CacheIndex::INITIAL: |
| 190 | case CacheIndex::SHUTDOWN: |
| 191 | default: |
| 192 | MOZ_ASSERT(false, "Unexpected state!")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Unexpected state!" ")", "./../../../netwerk/cache2/CacheIndex.cpp", 192); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "false" ") (" "Unexpected state!" ")"); do { MOZ_CrashSequence(__null, 192); __attribute__((nomerge)) ::abort (); } while (false); } } while (false); |
| 193 | } |
| 194 | |
| 195 | return entry; |
| 196 | } |
| 197 | |
| 198 | const SHA1Sum::Hash* mHash; |
| 199 | RefPtr<CacheIndex> mIndex; |
| 200 | RefPtr<CacheIndexRecordWrapper> mOldRecord; |
| 201 | bool mDoNotSearchInIndex{false}; |
| 202 | bool mDoNotSearchInUpdates{false}; |
| 203 | const StaticMutexAutoLock& mProofOfLock; |
| 204 | }; |
| 205 | |
| 206 | class FileOpenHelper final : public CacheFileIOListener { |
| 207 | public: |
| 208 | NS_DECL_THREADSAFE_ISUPPORTSpublic: virtual nsresult QueryInterface(const nsIID& aIID , void** aInstancePtr) override; virtual MozExternalRefCountType AddRef(void) override; virtual MozExternalRefCountType Release (void) override; using HasThreadSafeRefCnt = std::true_type; protected : ::mozilla::ThreadSafeAutoRefCnt mRefCnt; nsAutoOwningThread _mOwningThread; public: |
| 209 | |
| 210 | explicit FileOpenHelper(CacheIndex* aIndex) |
| 211 | : mIndex(aIndex), mCanceled(false) {} |
| 212 | |
| 213 | void Cancel() { |
| 214 | CacheIndex::sLock.AssertCurrentThreadOwns(); |
| 215 | mCanceled = true; |
| 216 | } |
| 217 | |
| 218 | private: |
| 219 | virtual ~FileOpenHelper() = default; |
| 220 | |
| 221 | NS_IMETHODvirtual nsresult OnFileOpened(CacheFileHandle* aHandle, nsresult aResult) override; |
| 222 | NS_IMETHODvirtual nsresult OnDataWritten(CacheFileHandle* aHandle, const char* aBuf, |
| 223 | nsresult aResult) override { |
| 224 | MOZ_CRASH("FileOpenHelper::OnDataWritten should not be called!")do { do { } while (false); MOZ_ReportCrash("" "FileOpenHelper::OnDataWritten should not be called!" , "./../../../netwerk/cache2/CacheIndex.cpp", 224); AnnotateMozCrashReason ("MOZ_CRASH(" "FileOpenHelper::OnDataWritten should not be called!" ")"); do { MOZ_CrashSequence(__null, 224); __attribute__((nomerge )) ::abort(); } while (false); } while (false); |
| 225 | return NS_ERROR_UNEXPECTED; |
| 226 | } |
| 227 | NS_IMETHODvirtual nsresult OnDataRead(CacheFileHandle* aHandle, char* aBuf, |
| 228 | nsresult aResult) override { |
| 229 | MOZ_CRASH("FileOpenHelper::OnDataRead should not be called!")do { do { } while (false); MOZ_ReportCrash("" "FileOpenHelper::OnDataRead should not be called!" , "./../../../netwerk/cache2/CacheIndex.cpp", 229); AnnotateMozCrashReason ("MOZ_CRASH(" "FileOpenHelper::OnDataRead should not be called!" ")"); do { MOZ_CrashSequence(__null, 229); __attribute__((nomerge )) ::abort(); } while (false); } while (false); |
| 230 | return NS_ERROR_UNEXPECTED; |
| 231 | } |
| 232 | NS_IMETHODvirtual nsresult OnFileDoomed(CacheFileHandle* aHandle, nsresult aResult) override { |
| 233 | MOZ_CRASH("FileOpenHelper::OnFileDoomed should not be called!")do { do { } while (false); MOZ_ReportCrash("" "FileOpenHelper::OnFileDoomed should not be called!" , "./../../../netwerk/cache2/CacheIndex.cpp", 233); AnnotateMozCrashReason ("MOZ_CRASH(" "FileOpenHelper::OnFileDoomed should not be called!" ")"); do { MOZ_CrashSequence(__null, 233); __attribute__((nomerge )) ::abort(); } while (false); } while (false); |
| 234 | return NS_ERROR_UNEXPECTED; |
| 235 | } |
| 236 | NS_IMETHODvirtual nsresult OnEOFSet(CacheFileHandle* aHandle, nsresult aResult) override { |
| 237 | MOZ_CRASH("FileOpenHelper::OnEOFSet should not be called!")do { do { } while (false); MOZ_ReportCrash("" "FileOpenHelper::OnEOFSet should not be called!" , "./../../../netwerk/cache2/CacheIndex.cpp", 237); AnnotateMozCrashReason ("MOZ_CRASH(" "FileOpenHelper::OnEOFSet should not be called!" ")"); do { MOZ_CrashSequence(__null, 237); __attribute__((nomerge )) ::abort(); } while (false); } while (false); |
| 238 | return NS_ERROR_UNEXPECTED; |
| 239 | } |
| 240 | NS_IMETHODvirtual nsresult OnFileRenamed(CacheFileHandle* aHandle, |
| 241 | nsresult aResult) override { |
| 242 | MOZ_CRASH("FileOpenHelper::OnFileRenamed should not be called!")do { do { } while (false); MOZ_ReportCrash("" "FileOpenHelper::OnFileRenamed should not be called!" , "./../../../netwerk/cache2/CacheIndex.cpp", 242); AnnotateMozCrashReason ("MOZ_CRASH(" "FileOpenHelper::OnFileRenamed should not be called!" ")"); do { MOZ_CrashSequence(__null, 242); __attribute__((nomerge )) ::abort(); } while (false); } while (false); |
| 243 | return NS_ERROR_UNEXPECTED; |
| 244 | } |
| 245 | |
| 246 | RefPtr<CacheIndex> mIndex; |
| 247 | bool mCanceled; |
| 248 | }; |
| 249 | |
| 250 | NS_IMETHODIMPnsresult FileOpenHelper::OnFileOpened(CacheFileHandle* aHandle, |
| 251 | nsresult aResult) { |
| 252 | StaticMutexAutoLock lock(CacheIndex::sLock); |
| 253 | |
| 254 | if (mCanceled) { |
| 255 | if (aHandle) { |
| 256 | CacheFileIOManager::DoomFile(aHandle, nullptr); |
| 257 | } |
| 258 | |
| 259 | return NS_OK; |
| 260 | } |
| 261 | |
| 262 | mIndex->OnFileOpenedInternal(this, aHandle, aResult, lock); |
| 263 | |
| 264 | return NS_OK; |
| 265 | } |
| 266 | |
| 267 | NS_IMPL_ISUPPORTS(FileOpenHelper, CacheFileIOListener)MozExternalRefCountType FileOpenHelper::AddRef(void) { static_assert (!std::is_destructible_v<FileOpenHelper>, "Reference-counted class " "FileOpenHelper" " should not have a public destructor. " "Make this class's destructor non-public" ); do { static_assert( mozilla::detail::AssertionConditionType <decltype(int32_t(mRefCnt) >= 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0" " (" "illegal refcnt" ")", "./../../../netwerk/cache2/CacheIndex.cpp" , 267); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0" ") (" "illegal refcnt" ")"); do { MOZ_CrashSequence(__null, 267 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("FileOpenHelper" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("FileOpenHelper" != nullptr) )), 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"FileOpenHelper\" != nullptr" " (" "Must specify a name" ")", "./../../../netwerk/cache2/CacheIndex.cpp" , 267); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"FileOpenHelper\" != nullptr" ") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null , 267); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership ("FileOpenHelper" " not thread-safe"); nsrefcnt count = ++mRefCnt ; NS_LogAddRef((this), (count), ("FileOpenHelper"), (uint32_t )(sizeof(*this))); return count; } MozExternalRefCountType FileOpenHelper ::Release(void) { do { static_assert( mozilla::detail::AssertionConditionType <decltype(int32_t(mRefCnt) > 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) > 0))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0" " (" "dup release" ")", "./../../../netwerk/cache2/CacheIndex.cpp" , 267); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0" ") (" "dup release" ")"); do { MOZ_CrashSequence(__null, 267 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("FileOpenHelper" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("FileOpenHelper" != nullptr) )), 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"FileOpenHelper\" != nullptr" " (" "Must specify a name" ")", "./../../../netwerk/cache2/CacheIndex.cpp" , 267); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"FileOpenHelper\" != nullptr" ") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null , 267); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership ("FileOpenHelper" " not thread-safe"); const char* const nametmp = "FileOpenHelper"; nsrefcnt count = --mRefCnt; NS_LogRelease ((this), (count), (nametmp)); if (count == 0) { mRefCnt = 1; delete (this); return 0; } return count; } nsresult FileOpenHelper:: QueryInterface(const nsIID& aIID, void** aInstancePtr) { do { if (!(aInstancePtr)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!" , "aInstancePtr", "./../../../netwerk/cache2/CacheIndex.cpp", 267); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE ; static_assert(1 > 0, "Need more arguments to NS_INTERFACE_TABLE" ); static const QITableEntry table[] = { {&mozilla::detail ::kImplementedIID<FileOpenHelper, CacheFileIOListener>, int32_t( reinterpret_cast<char*>(static_cast<CacheFileIOListener *>((FileOpenHelper*)0x1000)) - reinterpret_cast<char*> ((FileOpenHelper*)0x1000))}, {&mozilla::detail::kImplementedIID <FileOpenHelper, nsISupports>, int32_t(reinterpret_cast <char*>(static_cast<nsISupports*>( static_cast< CacheFileIOListener*>((FileOpenHelper*)0x1000))) - reinterpret_cast <char*>((FileOpenHelper*)0x1000))}, { nullptr, 0 } } ; static_assert (std::size(table) > 1, "need at least 1 interface"); rv = NS_TableDrivenQI (static_cast<void*>(this), aIID, aInstancePtr, table); return rv; }; |
| 268 | |
| 269 | StaticRefPtr<CacheIndex> CacheIndex::gInstance; |
| 270 | StaticMutex CacheIndex::sLock; |
| 271 | |
| 272 | NS_IMPL_ADDREF(CacheIndex)MozExternalRefCountType CacheIndex::AddRef(void) { static_assert (!std::is_destructible_v<CacheIndex>, "Reference-counted class " "CacheIndex" " should not have a public destructor. " "Make this class's destructor non-public" ); do { static_assert( mozilla::detail::AssertionConditionType <decltype(int32_t(mRefCnt) >= 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0" " (" "illegal refcnt" ")", "./../../../netwerk/cache2/CacheIndex.cpp" , 272); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0" ") (" "illegal refcnt" ")"); do { MOZ_CrashSequence(__null, 272 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("CacheIndex" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("CacheIndex" != nullptr))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("\"CacheIndex\" != nullptr" " (" "Must specify a name" ")", "./../../../netwerk/cache2/CacheIndex.cpp" , 272); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"CacheIndex\" != nullptr" ") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null , 272); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership ("CacheIndex" " not thread-safe"); nsrefcnt count = ++mRefCnt ; NS_LogAddRef((this), (count), ("CacheIndex"), (uint32_t)(sizeof (*this))); return count; } |
| 273 | NS_IMPL_RELEASE(CacheIndex)MozExternalRefCountType CacheIndex::Release(void) { do { static_assert ( mozilla::detail::AssertionConditionType<decltype(int32_t (mRefCnt) > 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) > 0))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0" " (" "dup release" ")", "./../../../netwerk/cache2/CacheIndex.cpp" , 273); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0" ") (" "dup release" ")"); do { MOZ_CrashSequence(__null, 273 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("CacheIndex" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("CacheIndex" != nullptr))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("\"CacheIndex\" != nullptr" " (" "Must specify a name" ")", "./../../../netwerk/cache2/CacheIndex.cpp" , 273); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"CacheIndex\" != nullptr" ") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null , 273); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership ("CacheIndex" " not thread-safe"); const char* const nametmp = "CacheIndex"; nsrefcnt count = --mRefCnt; NS_LogRelease((this ), (count), (nametmp)); if (count == 0) { mRefCnt = 1; delete (this); return 0; } return count; } |
| 274 | |
| 275 | NS_INTERFACE_MAP_BEGIN(CacheIndex)nsresult CacheIndex::QueryInterface(const nsIID& aIID, void ** aInstancePtr) { do { if (!(aInstancePtr)) { NS_DebugBreak( NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!" , "aInstancePtr", "./../../../netwerk/cache2/CacheIndex.cpp", 275); MOZ_PretendNoReturn(); } } while (0); nsISupports* foundInterface ; |
| 276 | NS_INTERFACE_MAP_ENTRY(mozilla::net::CacheFileIOListener)if (aIID.Equals(mozilla::detail::kImplementedIID<std::remove_reference_t <decltype(*this)>, mozilla::net::CacheFileIOListener> )) foundInterface = static_cast<mozilla::net::CacheFileIOListener *>(this); else |
| 277 | NS_INTERFACE_MAP_ENTRY(nsIRunnable)if (aIID.Equals(mozilla::detail::kImplementedIID<std::remove_reference_t <decltype(*this)>, nsIRunnable>)) foundInterface = static_cast <nsIRunnable*>(this); else |
| 278 | NS_INTERFACE_MAP_ENDfoundInterface = 0; nsresult status; if (!foundInterface) { do { static_assert( mozilla::detail::AssertionConditionType< decltype(!aIID.Equals((nsISupports::kIID)))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!aIID.Equals((nsISupports::kIID ))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("!aIID.Equals((nsISupports::kIID))", "./../../../netwerk/cache2/CacheIndex.cpp" , 278); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aIID.Equals((nsISupports::kIID))" ")"); do { MOZ_CrashSequence(__null, 278); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); status = NS_NOINTERFACE ; } else { (foundInterface)->AddRef(); status = NS_OK; } * aInstancePtr = foundInterface; return status; } |
| 279 | |
| 280 | CacheIndex::CacheIndex() { |
| 281 | sLock.AssertCurrentThreadOwns(); |
| 282 | LOG(("CacheIndex::CacheIndex [this=%p]", this))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::CacheIndex [this=%p]" , this); } } while (0); |
| 283 | MOZ_ASSERT(!gInstance, "multiple CacheIndex instances!")do { static_assert( mozilla::detail::AssertionConditionType< decltype(!gInstance)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!gInstance))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!gInstance" " (" "multiple CacheIndex instances!" ")", "./../../../netwerk/cache2/CacheIndex.cpp", 283); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!gInstance" ") (" "multiple CacheIndex instances!" ")"); do { MOZ_CrashSequence(__null, 283); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 284 | } |
| 285 | |
| 286 | CacheIndex::~CacheIndex() { |
| 287 | sLock.AssertCurrentThreadOwns(); |
| 288 | LOG(("CacheIndex::~CacheIndex [this=%p]", this))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::~CacheIndex [this=%p]" , this); } } while (0); |
| 289 | |
| 290 | ReleaseBuffer(); |
| 291 | } |
| 292 | |
| 293 | // static |
| 294 | nsresult CacheIndex::Init(nsIFile* aCacheDirectory) { |
| 295 | LOG(("CacheIndex::Init()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::Init()" ); } } while (0); |
| 296 | |
| 297 | MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType< decltype(NS_IsMainThread())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()" , "./../../../netwerk/cache2/CacheIndex.cpp", 297); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "NS_IsMainThread()" ")"); do { MOZ_CrashSequence (__null, 297); __attribute__((nomerge)) ::abort(); } while (false ); } } while (false); |
| 298 | |
| 299 | StaticMutexAutoLock lock(sLock); |
| 300 | |
| 301 | if (gInstance) { |
| 302 | return NS_ERROR_ALREADY_INITIALIZED; |
| 303 | } |
| 304 | |
| 305 | RefPtr<CacheIndex> idx = new CacheIndex(); |
| 306 | |
| 307 | nsresult rv = idx->InitInternal(aCacheDirectory, lock); |
| 308 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 308); return rv; } } while (false); |
| 309 | |
| 310 | gInstance = std::move(idx); |
| 311 | return NS_OK; |
| 312 | } |
| 313 | |
| 314 | nsresult CacheIndex::InitInternal(nsIFile* aCacheDirectory, |
| 315 | const StaticMutexAutoLock& aProofOfLock) { |
| 316 | nsresult rv; |
| 317 | sLock.AssertCurrentThreadOwns(); |
| 318 | |
| 319 | rv = aCacheDirectory->Clone(getter_AddRefs(mCacheDirectory)); |
| 320 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 320); return rv; } } while (false); |
| 321 | |
| 322 | mStartTime = TimeStamp::NowLoRes(); |
| 323 | |
| 324 | ReadIndexFromDisk(aProofOfLock); |
| 325 | |
| 326 | return NS_OK; |
| 327 | } |
| 328 | |
| 329 | // static |
| 330 | nsresult CacheIndex::PreShutdown() { |
| 331 | MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType< decltype(NS_IsMainThread())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()" , "./../../../netwerk/cache2/CacheIndex.cpp", 331); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "NS_IsMainThread()" ")"); do { MOZ_CrashSequence (__null, 331); __attribute__((nomerge)) ::abort(); } while (false ); } } while (false); |
| 332 | |
| 333 | StaticMutexAutoLock lock(sLock); |
| 334 | |
| 335 | LOG(("CacheIndex::PreShutdown() [gInstance=%p]", gInstance.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::PreShutdown() [gInstance=%p]" , gInstance.get()); } } while (0); |
| 336 | |
| 337 | nsresult rv; |
| 338 | RefPtr<CacheIndex> index = gInstance; |
| 339 | |
| 340 | if (!index) { |
| 341 | return NS_ERROR_NOT_INITIALIZED; |
| 342 | } |
| 343 | |
| 344 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::PreShutdown() - [state=%d, indexOnDiskIsValid=%d, " "dontMarkIndexClean=%d]", index->mState, index->mIndexOnDiskIsValid , index->mDontMarkIndexClean); } } while (0) |
| 345 | ("CacheIndex::PreShutdown() - [state=%d, indexOnDiskIsValid=%d, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::PreShutdown() - [state=%d, indexOnDiskIsValid=%d, " "dontMarkIndexClean=%d]", index->mState, index->mIndexOnDiskIsValid , index->mDontMarkIndexClean); } } while (0) |
| 346 | "dontMarkIndexClean=%d]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::PreShutdown() - [state=%d, indexOnDiskIsValid=%d, " "dontMarkIndexClean=%d]", index->mState, index->mIndexOnDiskIsValid , index->mDontMarkIndexClean); } } while (0) |
| 347 | index->mState, index->mIndexOnDiskIsValid, index->mDontMarkIndexClean))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::PreShutdown() - [state=%d, indexOnDiskIsValid=%d, " "dontMarkIndexClean=%d]", index->mState, index->mIndexOnDiskIsValid , index->mDontMarkIndexClean); } } while (0); |
| 348 | |
| 349 | LOG(("CacheIndex::PreShutdown() - Closing iterators."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::PreShutdown() - Closing iterators." ); } } while (0); |
| 350 | for (uint32_t i = 0; i < index->mIterators.Length();) { |
| 351 | rv = index->mIterators[i]->CloseInternal(NS_ERROR_FAILURE); |
| 352 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 353 | // CacheIndexIterator::CloseInternal() removes itself from mIteratos iff |
| 354 | // it returns success. |
| 355 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::PreShutdown() - Failed to remove iterator %p. " "[rv=0x%08" "x" "]", index->mIterators[i], static_cast< uint32_t>(rv)); } } while (0) |
| 356 | ("CacheIndex::PreShutdown() - Failed to remove iterator %p. "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::PreShutdown() - Failed to remove iterator %p. " "[rv=0x%08" "x" "]", index->mIterators[i], static_cast< uint32_t>(rv)); } } while (0) |
| 357 | "[rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::PreShutdown() - Failed to remove iterator %p. " "[rv=0x%08" "x" "]", index->mIterators[i], static_cast< uint32_t>(rv)); } } while (0) |
| 358 | index->mIterators[i], static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::PreShutdown() - Failed to remove iterator %p. " "[rv=0x%08" "x" "]", index->mIterators[i], static_cast< uint32_t>(rv)); } } while (0); |
| 359 | i++; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | index->mShuttingDown = true; |
| 364 | |
| 365 | if (index->mState == READY) { |
| 366 | return NS_OK; // nothing to do |
| 367 | } |
| 368 | |
| 369 | nsCOMPtr<nsIRunnable> event; |
| 370 | event = NewRunnableMethod("net::CacheIndex::PreShutdownInternal", index, |
| 371 | &CacheIndex::PreShutdownInternal); |
| 372 | |
| 373 | nsCOMPtr<nsIEventTarget> ioTarget = CacheFileIOManager::IOTarget(); |
| 374 | MOZ_ASSERT(ioTarget)do { static_assert( mozilla::detail::AssertionConditionType< decltype(ioTarget)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(ioTarget))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("ioTarget", "./../../../netwerk/cache2/CacheIndex.cpp" , 374); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ioTarget" ")" ); do { MOZ_CrashSequence(__null, 374); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 375 | |
| 376 | // PreShutdownInternal() will be executed before any queued event on INDEX |
| 377 | // level. That's OK since we don't want to wait for any operation in progess. |
| 378 | rv = ioTarget->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL); |
| 379 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 380 | NS_WARNING("CacheIndex::PreShutdown() - Can't dispatch event")NS_DebugBreak(NS_DEBUG_WARNING, "CacheIndex::PreShutdown() - Can't dispatch event" , nullptr, "./../../../netwerk/cache2/CacheIndex.cpp", 380); |
| 381 | LOG(("CacheIndex::PreShutdown() - Can't dispatch event"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::PreShutdown() - Can't dispatch event" ); } } while (0); |
| 382 | return rv; |
| 383 | } |
| 384 | |
| 385 | return NS_OK; |
| 386 | } |
| 387 | |
| 388 | void CacheIndex::PreShutdownInternal() { |
| 389 | StaticMutexAutoLock lock(sLock); |
| 390 | |
| 391 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::PreShutdownInternal() - [state=%d, indexOnDiskIsValid=%d, " "dontMarkIndexClean=%d]", mState, mIndexOnDiskIsValid, mDontMarkIndexClean ); } } while (0) |
| 392 | ("CacheIndex::PreShutdownInternal() - [state=%d, indexOnDiskIsValid=%d, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::PreShutdownInternal() - [state=%d, indexOnDiskIsValid=%d, " "dontMarkIndexClean=%d]", mState, mIndexOnDiskIsValid, mDontMarkIndexClean ); } } while (0) |
| 393 | "dontMarkIndexClean=%d]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::PreShutdownInternal() - [state=%d, indexOnDiskIsValid=%d, " "dontMarkIndexClean=%d]", mState, mIndexOnDiskIsValid, mDontMarkIndexClean ); } } while (0) |
| 394 | mState, mIndexOnDiskIsValid, mDontMarkIndexClean))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::PreShutdownInternal() - [state=%d, indexOnDiskIsValid=%d, " "dontMarkIndexClean=%d]", mState, mIndexOnDiskIsValid, mDontMarkIndexClean ); } } while (0); |
| 395 | |
| 396 | MOZ_ASSERT(mShuttingDown)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mShuttingDown)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mShuttingDown))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mShuttingDown", "./../../../netwerk/cache2/CacheIndex.cpp", 396); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "mShuttingDown" ")"); do { MOZ_CrashSequence (__null, 396); __attribute__((nomerge)) ::abort(); } while (false ); } } while (false); |
| 397 | |
| 398 | if (mUpdateTimer) { |
| 399 | mUpdateTimer->Cancel(); |
| 400 | mUpdateTimer = nullptr; |
| 401 | } |
| 402 | |
| 403 | switch (mState) { |
| 404 | case WRITING: |
| 405 | FinishWrite(false, lock); |
| 406 | break; |
| 407 | case READY: |
| 408 | // nothing to do, write the journal in Shutdown() |
| 409 | break; |
| 410 | case READING: |
| 411 | FinishRead(false, lock); |
| 412 | break; |
| 413 | case BUILDING: |
| 414 | case UPDATING: |
| 415 | FinishUpdate(false, lock); |
| 416 | break; |
| 417 | default: |
| 418 | MOZ_ASSERT(false, "Implement me!")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Implement me!" ")", "./../../../netwerk/cache2/CacheIndex.cpp", 418); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "false" ") (" "Implement me!" ")"); do { MOZ_CrashSequence (__null, 418); __attribute__((nomerge)) ::abort(); } while (false ); } } while (false); |
| 419 | } |
| 420 | |
| 421 | // We should end up in READY state |
| 422 | MOZ_ASSERT(mState == READY)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mState == READY)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mState == READY))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mState == READY" , "./../../../netwerk/cache2/CacheIndex.cpp", 422); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "mState == READY" ")"); do { MOZ_CrashSequence (__null, 422); __attribute__((nomerge)) ::abort(); } while (false ); } } while (false); |
| 423 | } |
| 424 | |
| 425 | // static |
| 426 | void CacheIndex::WriteIndexToDiskNow() { |
| 427 | StaticMutexAutoLock lock(sLock); |
| 428 | |
| 429 | RefPtr<CacheIndex> index = gInstance; |
| 430 | if (!index || index->mShuttingDown) { |
| 431 | return; |
| 432 | } |
| 433 | |
| 434 | LOG(("CacheIndex::WriteIndexToDiskNow()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::WriteIndexToDiskNow()" ); } } while (0); |
| 435 | |
| 436 | nsCOMPtr<nsIEventTarget> ioTarget = CacheFileIOManager::IOTarget(); |
| 437 | if (!ioTarget) { |
| 438 | return; |
| 439 | } |
| 440 | |
| 441 | nsCOMPtr<nsIRunnable> event = |
| 442 | NewRunnableMethod("net::CacheIndex::WriteIndexToDiskNowInternal", index, |
| 443 | &CacheIndex::WriteIndexToDiskNowInternal); |
| 444 | (void)ioTarget->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL); |
| 445 | } |
| 446 | |
| 447 | void CacheIndex::WriteIndexToDiskNowInternal() { |
| 448 | StaticMutexAutoLock lock(sLock); |
| 449 | |
| 450 | LOG(("CacheIndex::WriteIndexToDiskNowInternal() [state=%d, dirty=%u]", mState,do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::WriteIndexToDiskNowInternal() [state=%d, dirty=%u]" , mState, mIndexStats.Dirty()); } } while (0) |
| 451 | mIndexStats.Dirty()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::WriteIndexToDiskNowInternal() [state=%d, dirty=%u]" , mState, mIndexStats.Dirty()); } } while (0); |
| 452 | |
| 453 | if (mState != READY || mShuttingDown || mRWPending || |
| 454 | mIndexStats.Dirty() == 0) { |
| 455 | return; |
| 456 | } |
| 457 | |
| 458 | WriteIndexToDisk(lock); |
| 459 | } |
| 460 | |
| 461 | // static |
| 462 | nsresult CacheIndex::Shutdown() { |
| 463 | MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType< decltype(NS_IsMainThread())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()" , "./../../../netwerk/cache2/CacheIndex.cpp", 463); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "NS_IsMainThread()" ")"); do { MOZ_CrashSequence (__null, 463); __attribute__((nomerge)) ::abort(); } while (false ); } } while (false); |
| 464 | |
| 465 | StaticMutexAutoLock lock(sLock); |
| 466 | |
| 467 | LOG(("CacheIndex::Shutdown() [gInstance=%p]", gInstance.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::Shutdown() [gInstance=%p]" , gInstance.get()); } } while (0); |
| 468 | |
| 469 | RefPtr<CacheIndex> index = gInstance.forget(); |
| 470 | |
| 471 | if (!index) { |
| 472 | return NS_ERROR_NOT_INITIALIZED; |
| 473 | } |
| 474 | |
| 475 | bool sanitize = CacheObserver::ClearCacheOnShutdown(); |
| 476 | |
| 477 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::Shutdown() - [state=%d, indexOnDiskIsValid=%d, " "dontMarkIndexClean=%d, sanitize=%d]", index->mState, index ->mIndexOnDiskIsValid, index->mDontMarkIndexClean, sanitize ); } } while (0) |
| 478 | ("CacheIndex::Shutdown() - [state=%d, indexOnDiskIsValid=%d, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::Shutdown() - [state=%d, indexOnDiskIsValid=%d, " "dontMarkIndexClean=%d, sanitize=%d]", index->mState, index ->mIndexOnDiskIsValid, index->mDontMarkIndexClean, sanitize ); } } while (0) |
| 479 | "dontMarkIndexClean=%d, sanitize=%d]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::Shutdown() - [state=%d, indexOnDiskIsValid=%d, " "dontMarkIndexClean=%d, sanitize=%d]", index->mState, index ->mIndexOnDiskIsValid, index->mDontMarkIndexClean, sanitize ); } } while (0) |
| 480 | index->mState, index->mIndexOnDiskIsValid, index->mDontMarkIndexClean,do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::Shutdown() - [state=%d, indexOnDiskIsValid=%d, " "dontMarkIndexClean=%d, sanitize=%d]", index->mState, index ->mIndexOnDiskIsValid, index->mDontMarkIndexClean, sanitize ); } } while (0) |
| 481 | sanitize))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::Shutdown() - [state=%d, indexOnDiskIsValid=%d, " "dontMarkIndexClean=%d, sanitize=%d]", index->mState, index ->mIndexOnDiskIsValid, index->mDontMarkIndexClean, sanitize ); } } while (0); |
| 482 | |
| 483 | MOZ_ASSERT(index->mShuttingDown)do { static_assert( mozilla::detail::AssertionConditionType< decltype(index->mShuttingDown)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(index->mShuttingDown))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("index->mShuttingDown" , "./../../../netwerk/cache2/CacheIndex.cpp", 483); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "index->mShuttingDown" ")"); do { MOZ_CrashSequence (__null, 483); __attribute__((nomerge)) ::abort(); } while (false ); } } while (false); |
| 484 | |
| 485 | EState oldState = index->mState; |
| 486 | index->ChangeState(SHUTDOWN, lock); |
| 487 | |
| 488 | if (oldState != READY) { |
| 489 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::Shutdown() - Unexpected state. Did posting of " "PreShutdownInternal() fail?"); } } while (0) |
| 490 | ("CacheIndex::Shutdown() - Unexpected state. Did posting of "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::Shutdown() - Unexpected state. Did posting of " "PreShutdownInternal() fail?"); } } while (0) |
| 491 | "PreShutdownInternal() fail?"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::Shutdown() - Unexpected state. Did posting of " "PreShutdownInternal() fail?"); } } while (0); |
| 492 | } |
| 493 | |
| 494 | switch (oldState) { |
| 495 | case WRITING: |
| 496 | index->FinishWrite(false, lock); |
| 497 | [[fallthrough]]; |
| 498 | case READY: |
| 499 | if (index->mIndexOnDiskIsValid && !index->mDontMarkIndexClean) { |
| 500 | if (!sanitize && NS_FAILED(index->WriteLogToDisk())((bool)(__builtin_expect(!!(NS_FAILED_impl(index->WriteLogToDisk ())), 0)))) { |
| 501 | index->RemoveJournalAndTempFile(); |
| 502 | } |
| 503 | } else { |
| 504 | index->RemoveJournalAndTempFile(); |
| 505 | } |
| 506 | break; |
| 507 | case READING: |
| 508 | index->FinishRead(false, lock); |
| 509 | break; |
| 510 | case BUILDING: |
| 511 | case UPDATING: |
| 512 | index->FinishUpdate(false, lock); |
| 513 | break; |
| 514 | default: |
| 515 | MOZ_ASSERT(false, "Unexpected state!")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Unexpected state!" ")", "./../../../netwerk/cache2/CacheIndex.cpp", 515); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "false" ") (" "Unexpected state!" ")"); do { MOZ_CrashSequence(__null, 515); __attribute__((nomerge)) ::abort (); } while (false); } } while (false); |
| 516 | } |
| 517 | |
| 518 | if (sanitize) { |
| 519 | index->RemoveAllIndexFiles(); |
| 520 | } |
| 521 | |
| 522 | return NS_OK; |
| 523 | } |
| 524 | |
| 525 | // static |
| 526 | nsresult CacheIndex::AddEntry(const SHA1Sum::Hash* aHash) { |
| 527 | LOG(("CacheIndex::AddEntry() [hash=%08x%08x%08x%08x%08x]", LOGSHA1(aHash)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::AddEntry() [hash=%08x%08x%08x%08x%08x]" , PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[0 ]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash)) [1]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash ))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash ))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash ))[4])); } } while (0); |
| 528 | |
| 529 | MOZ_ASSERT(CacheFileIOManager::IsOnIOThread())do { static_assert( mozilla::detail::AssertionConditionType< decltype(CacheFileIOManager::IsOnIOThread())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(CacheFileIOManager::IsOnIOThread ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("CacheFileIOManager::IsOnIOThread()", "./../../../netwerk/cache2/CacheIndex.cpp" , 529); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()" ")"); do { MOZ_CrashSequence(__null, 529); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 530 | |
| 531 | StaticMutexAutoLock lock(sLock); |
| 532 | |
| 533 | RefPtr<CacheIndex> index = gInstance; |
| 534 | |
| 535 | if (!index) { |
| 536 | return NS_ERROR_NOT_INITIALIZED; |
| 537 | } |
| 538 | |
| 539 | if (!index->IsIndexUsable()) { |
| 540 | return NS_ERROR_NOT_AVAILABLE; |
| 541 | } |
| 542 | |
| 543 | // Getters in CacheIndexStats assert when mStateLogged is true since the |
| 544 | // information is incomplete between calls to BeforeChange() and AfterChange() |
| 545 | // (i.e. while CacheIndexEntryAutoManage exists). We need to check whether |
| 546 | // non-fresh entries exists outside the scope of CacheIndexEntryAutoManage. |
| 547 | bool updateIfNonFreshEntriesExist = false; |
| 548 | |
| 549 | { |
| 550 | CacheIndexEntryAutoManage entryMng(aHash, index, lock); |
| 551 | |
| 552 | CacheIndexEntry* entry = index->mIndex.GetEntry(*aHash); |
| 553 | bool entryRemoved = entry && entry->IsRemoved(); |
| 554 | CacheIndexEntryUpdate* updated = nullptr; |
| 555 | |
| 556 | if (index->mState == READY || index->mState == UPDATING || |
| 557 | index->mState == BUILDING) { |
| 558 | MOZ_ASSERT(index->mPendingUpdates.Count() == 0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(index->mPendingUpdates.Count() == 0)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(index->mPendingUpdates.Count() == 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("index->mPendingUpdates.Count() == 0" , "./../../../netwerk/cache2/CacheIndex.cpp", 558); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "index->mPendingUpdates.Count() == 0" ")" ); do { MOZ_CrashSequence(__null, 558); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 559 | |
| 560 | if (entry && !entryRemoved) { |
| 561 | // Found entry in index that shouldn't exist. |
| 562 | |
| 563 | if (entry->IsFresh()) { |
| 564 | // Someone removed the file on disk while FF is running. Update |
| 565 | // process can fix only non-fresh entries (i.e. entries that were not |
| 566 | // added within this session). Start update only if we have such |
| 567 | // entries. |
| 568 | // |
| 569 | // TODO: This should be very rare problem. If it turns out not to be |
| 570 | // true, change the update process so that it also iterates all |
| 571 | // initialized non-empty entries and checks whether the file exists. |
| 572 | |
| 573 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::AddEntry() - Cache file was removed outside FF " "process!"); } } while (0) |
| 574 | ("CacheIndex::AddEntry() - Cache file was removed outside FF "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::AddEntry() - Cache file was removed outside FF " "process!"); } } while (0) |
| 575 | "process!"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::AddEntry() - Cache file was removed outside FF " "process!"); } } while (0); |
| 576 | |
| 577 | updateIfNonFreshEntriesExist = true; |
| 578 | } else if (index->mState == READY) { |
| 579 | // Index is outdated, update it. |
| 580 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::AddEntry() - Found entry that shouldn't exist, " "update is needed"); } } while (0) |
| 581 | ("CacheIndex::AddEntry() - Found entry that shouldn't exist, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::AddEntry() - Found entry that shouldn't exist, " "update is needed"); } } while (0) |
| 582 | "update is needed"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::AddEntry() - Found entry that shouldn't exist, " "update is needed"); } } while (0); |
| 583 | index->mIndexNeedsUpdate = true; |
| 584 | } else { |
| 585 | // We cannot be here when building index since all entries are fresh |
| 586 | // during building. |
| 587 | MOZ_ASSERT(index->mState == UPDATING)do { static_assert( mozilla::detail::AssertionConditionType< decltype(index->mState == UPDATING)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(index->mState == UPDATING ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "index->mState == UPDATING", "./../../../netwerk/cache2/CacheIndex.cpp" , 587); AnnotateMozCrashReason("MOZ_ASSERT" "(" "index->mState == UPDATING" ")"); do { MOZ_CrashSequence(__null, 587); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | if (!entry) { |
| 592 | entry = index->mIndex.PutEntry(*aHash); |
| 593 | } |
| 594 | } else { // WRITING, READING |
| 595 | updated = index->mPendingUpdates.GetEntry(*aHash); |
| 596 | bool updatedRemoved = updated && updated->IsRemoved(); |
| 597 | |
| 598 | if ((updated && !updatedRemoved) || |
| 599 | (!updated && entry && !entryRemoved && entry->IsFresh())) { |
| 600 | // Fresh entry found, so the file was removed outside FF |
| 601 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::AddEntry() - Cache file was removed outside FF " "process!"); } } while (0) |
| 602 | ("CacheIndex::AddEntry() - Cache file was removed outside FF "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::AddEntry() - Cache file was removed outside FF " "process!"); } } while (0) |
| 603 | "process!"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::AddEntry() - Cache file was removed outside FF " "process!"); } } while (0); |
| 604 | |
| 605 | updateIfNonFreshEntriesExist = true; |
| 606 | } else if (!updated && entry && !entryRemoved) { |
| 607 | if (index->mState == WRITING) { |
| 608 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::AddEntry() - Found entry that shouldn't exist, " "update is needed"); } } while (0) |
| 609 | ("CacheIndex::AddEntry() - Found entry that shouldn't exist, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::AddEntry() - Found entry that shouldn't exist, " "update is needed"); } } while (0) |
| 610 | "update is needed"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::AddEntry() - Found entry that shouldn't exist, " "update is needed"); } } while (0); |
| 611 | index->mIndexNeedsUpdate = true; |
| 612 | } |
| 613 | // Ignore if state is READING since the index information is partial |
| 614 | } |
| 615 | |
| 616 | updated = index->mPendingUpdates.PutEntry(*aHash); |
| 617 | } |
| 618 | |
| 619 | if (updated) { |
| 620 | updated->InitNew(); |
| 621 | updated->MarkDirty(); |
| 622 | updated->MarkFresh(); |
| 623 | } else { |
| 624 | entry->InitNew(); |
| 625 | entry->MarkDirty(); |
| 626 | entry->MarkFresh(); |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | if (updateIfNonFreshEntriesExist && |
| 631 | index->mIndexStats.Count() != index->mIndexStats.Fresh()) { |
| 632 | index->mIndexNeedsUpdate = true; |
| 633 | } |
| 634 | |
| 635 | index->StartUpdatingIndexIfNeeded(lock); |
| 636 | index->WriteIndexToDiskIfNeeded(lock); |
| 637 | |
| 638 | return NS_OK; |
| 639 | } |
| 640 | |
| 641 | // static |
| 642 | nsresult CacheIndex::EnsureEntryExists(const SHA1Sum::Hash* aHash) { |
| 643 | LOG(("CacheIndex::EnsureEntryExists() [hash=%08x%08x%08x%08x%08x]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::EnsureEntryExists() [hash=%08x%08x%08x%08x%08x]" , PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[0 ]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash)) [1]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash ))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash ))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash ))[4])); } } while (0) |
| 644 | LOGSHA1(aHash)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::EnsureEntryExists() [hash=%08x%08x%08x%08x%08x]" , PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[0 ]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash)) [1]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash ))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash ))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash ))[4])); } } while (0); |
| 645 | |
| 646 | MOZ_ASSERT(CacheFileIOManager::IsOnIOThread())do { static_assert( mozilla::detail::AssertionConditionType< decltype(CacheFileIOManager::IsOnIOThread())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(CacheFileIOManager::IsOnIOThread ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("CacheFileIOManager::IsOnIOThread()", "./../../../netwerk/cache2/CacheIndex.cpp" , 646); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()" ")"); do { MOZ_CrashSequence(__null, 646); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 647 | |
| 648 | StaticMutexAutoLock lock(sLock); |
| 649 | |
| 650 | RefPtr<CacheIndex> index = gInstance; |
| 651 | |
| 652 | if (!index) { |
| 653 | return NS_ERROR_NOT_INITIALIZED; |
| 654 | } |
| 655 | |
| 656 | if (!index->IsIndexUsable()) { |
| 657 | return NS_ERROR_NOT_AVAILABLE; |
| 658 | } |
| 659 | |
| 660 | { |
| 661 | CacheIndexEntryAutoManage entryMng(aHash, index, lock); |
| 662 | |
| 663 | CacheIndexEntry* entry = index->mIndex.GetEntry(*aHash); |
| 664 | bool entryRemoved = entry && entry->IsRemoved(); |
| 665 | |
| 666 | if (index->mState == READY || index->mState == UPDATING || |
| 667 | index->mState == BUILDING) { |
| 668 | MOZ_ASSERT(index->mPendingUpdates.Count() == 0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(index->mPendingUpdates.Count() == 0)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(index->mPendingUpdates.Count() == 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("index->mPendingUpdates.Count() == 0" , "./../../../netwerk/cache2/CacheIndex.cpp", 668); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "index->mPendingUpdates.Count() == 0" ")" ); do { MOZ_CrashSequence(__null, 668); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 669 | |
| 670 | if (!entry || entryRemoved) { |
| 671 | if (entryRemoved && entry->IsFresh()) { |
| 672 | // This could happen only if somebody copies files to the entries |
| 673 | // directory while FF is running. |
| 674 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::EnsureEntryExists() - Cache file was added outside " "FF process! Update is needed."); } } while (0) |
| 675 | ("CacheIndex::EnsureEntryExists() - Cache file was added outside "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::EnsureEntryExists() - Cache file was added outside " "FF process! Update is needed."); } } while (0) |
| 676 | "FF process! Update is needed."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::EnsureEntryExists() - Cache file was added outside " "FF process! Update is needed."); } } while (0); |
| 677 | index->mIndexNeedsUpdate = true; |
| 678 | } else if (index->mState == READY || |
| 679 | (entryRemoved && !entry->IsFresh())) { |
| 680 | // Removed non-fresh entries can be present as a result of |
| 681 | // MergeJournal() |
| 682 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::EnsureEntryExists() - Didn't find entry that should" " exist, update is needed"); } } while (0) |
| 683 | ("CacheIndex::EnsureEntryExists() - Didn't find entry that should"do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::EnsureEntryExists() - Didn't find entry that should" " exist, update is needed"); } } while (0) |
| 684 | " exist, update is needed"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::EnsureEntryExists() - Didn't find entry that should" " exist, update is needed"); } } while (0); |
| 685 | index->mIndexNeedsUpdate = true; |
| 686 | } |
| 687 | |
| 688 | if (!entry) { |
| 689 | entry = index->mIndex.PutEntry(*aHash); |
| 690 | } |
| 691 | entry->InitNew(); |
| 692 | entry->MarkDirty(); |
| 693 | } |
| 694 | entry->MarkFresh(); |
| 695 | } else { // WRITING, READING |
| 696 | CacheIndexEntryUpdate* updated = index->mPendingUpdates.GetEntry(*aHash); |
| 697 | bool updatedRemoved = updated && updated->IsRemoved(); |
| 698 | |
| 699 | if (updatedRemoved || (!updated && entryRemoved && entry->IsFresh())) { |
| 700 | // Fresh information about missing entry found. This could happen only |
| 701 | // if somebody copies files to the entries directory while FF is |
| 702 | // running. |
| 703 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::EnsureEntryExists() - Cache file was added outside " "FF process! Update is needed."); } } while (0) |
| 704 | ("CacheIndex::EnsureEntryExists() - Cache file was added outside "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::EnsureEntryExists() - Cache file was added outside " "FF process! Update is needed."); } } while (0) |
| 705 | "FF process! Update is needed."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::EnsureEntryExists() - Cache file was added outside " "FF process! Update is needed."); } } while (0); |
| 706 | index->mIndexNeedsUpdate = true; |
| 707 | } else if (!updated && (!entry || entryRemoved)) { |
| 708 | if (index->mState == WRITING) { |
| 709 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::EnsureEntryExists() - Didn't find entry that should" " exist, update is needed"); } } while (0) |
| 710 | ("CacheIndex::EnsureEntryExists() - Didn't find entry that should"do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::EnsureEntryExists() - Didn't find entry that should" " exist, update is needed"); } } while (0) |
| 711 | " exist, update is needed"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::EnsureEntryExists() - Didn't find entry that should" " exist, update is needed"); } } while (0); |
| 712 | index->mIndexNeedsUpdate = true; |
| 713 | } |
| 714 | // Ignore if state is READING since the index information is partial |
| 715 | } |
| 716 | |
| 717 | // We don't need entryRemoved and updatedRemoved info anymore |
| 718 | if (entryRemoved) entry = nullptr; |
| 719 | if (updatedRemoved) updated = nullptr; |
| 720 | |
| 721 | if (updated) { |
| 722 | updated->MarkFresh(); |
| 723 | } else { |
| 724 | if (!entry) { |
| 725 | // Create a new entry |
| 726 | updated = index->mPendingUpdates.PutEntry(*aHash); |
| 727 | updated->InitNew(); |
| 728 | updated->MarkFresh(); |
| 729 | updated->MarkDirty(); |
| 730 | } else { |
| 731 | if (!entry->IsFresh()) { |
| 732 | // To mark the entry fresh we must make a copy of index entry |
| 733 | // since the index is read-only. |
| 734 | updated = index->mPendingUpdates.PutEntry(*aHash); |
| 735 | *updated = *entry; |
| 736 | updated->MarkFresh(); |
| 737 | } |
| 738 | } |
| 739 | } |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | index->StartUpdatingIndexIfNeeded(lock); |
| 744 | index->WriteIndexToDiskIfNeeded(lock); |
| 745 | |
| 746 | return NS_OK; |
| 747 | } |
| 748 | |
| 749 | // static |
| 750 | nsresult CacheIndex::InitEntry(const SHA1Sum::Hash* aHash, |
| 751 | OriginAttrsHash aOriginAttrsHash, |
| 752 | bool aAnonymous, bool aPinned) { |
| 753 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::InitEntry() [hash=%08x%08x%08x%08x%08x, " "originAttrsHash=%" "l" "x" ", anonymous=%d, pinned=%d]", PR_htonl ((reinterpret_cast<const uint32_t*>(aHash))[0]), PR_htonl ((reinterpret_cast<const uint32_t*>(aHash))[1]), PR_htonl ((reinterpret_cast<const uint32_t*>(aHash))[2]), PR_htonl ((reinterpret_cast<const uint32_t*>(aHash))[3]), PR_htonl ((reinterpret_cast<const uint32_t*>(aHash))[4]), aOriginAttrsHash , aAnonymous, aPinned); } } while (0) |
| 754 | ("CacheIndex::InitEntry() [hash=%08x%08x%08x%08x%08x, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::InitEntry() [hash=%08x%08x%08x%08x%08x, " "originAttrsHash=%" "l" "x" ", anonymous=%d, pinned=%d]", PR_htonl ((reinterpret_cast<const uint32_t*>(aHash))[0]), PR_htonl ((reinterpret_cast<const uint32_t*>(aHash))[1]), PR_htonl ((reinterpret_cast<const uint32_t*>(aHash))[2]), PR_htonl ((reinterpret_cast<const uint32_t*>(aHash))[3]), PR_htonl ((reinterpret_cast<const uint32_t*>(aHash))[4]), aOriginAttrsHash , aAnonymous, aPinned); } } while (0) |
| 755 | "originAttrsHash=%" PRIx64 ", anonymous=%d, pinned=%d]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::InitEntry() [hash=%08x%08x%08x%08x%08x, " "originAttrsHash=%" "l" "x" ", anonymous=%d, pinned=%d]", PR_htonl ((reinterpret_cast<const uint32_t*>(aHash))[0]), PR_htonl ((reinterpret_cast<const uint32_t*>(aHash))[1]), PR_htonl ((reinterpret_cast<const uint32_t*>(aHash))[2]), PR_htonl ((reinterpret_cast<const uint32_t*>(aHash))[3]), PR_htonl ((reinterpret_cast<const uint32_t*>(aHash))[4]), aOriginAttrsHash , aAnonymous, aPinned); } } while (0) |
| 756 | LOGSHA1(aHash), aOriginAttrsHash, aAnonymous, aPinned))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::InitEntry() [hash=%08x%08x%08x%08x%08x, " "originAttrsHash=%" "l" "x" ", anonymous=%d, pinned=%d]", PR_htonl ((reinterpret_cast<const uint32_t*>(aHash))[0]), PR_htonl ((reinterpret_cast<const uint32_t*>(aHash))[1]), PR_htonl ((reinterpret_cast<const uint32_t*>(aHash))[2]), PR_htonl ((reinterpret_cast<const uint32_t*>(aHash))[3]), PR_htonl ((reinterpret_cast<const uint32_t*>(aHash))[4]), aOriginAttrsHash , aAnonymous, aPinned); } } while (0); |
| 757 | |
| 758 | MOZ_ASSERT(CacheFileIOManager::IsOnIOThread())do { static_assert( mozilla::detail::AssertionConditionType< decltype(CacheFileIOManager::IsOnIOThread())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(CacheFileIOManager::IsOnIOThread ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("CacheFileIOManager::IsOnIOThread()", "./../../../netwerk/cache2/CacheIndex.cpp" , 758); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()" ")"); do { MOZ_CrashSequence(__null, 758); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 759 | |
| 760 | StaticMutexAutoLock lock(sLock); |
| 761 | |
| 762 | RefPtr<CacheIndex> index = gInstance; |
| 763 | |
| 764 | if (!index) { |
| 765 | return NS_ERROR_NOT_INITIALIZED; |
| 766 | } |
| 767 | |
| 768 | if (!index->IsIndexUsable()) { |
| 769 | return NS_ERROR_NOT_AVAILABLE; |
| 770 | } |
| 771 | |
| 772 | { |
| 773 | CacheIndexEntryAutoManage entryMng(aHash, index, lock); |
| 774 | |
| 775 | CacheIndexEntry* entry = index->mIndex.GetEntry(*aHash); |
| 776 | CacheIndexEntryUpdate* updated = nullptr; |
| 777 | bool reinitEntry = false; |
| 778 | |
| 779 | if (entry && entry->IsRemoved()) { |
| 780 | entry = nullptr; |
| 781 | } |
| 782 | |
| 783 | if (index->mState == READY || index->mState == UPDATING || |
| 784 | index->mState == BUILDING) { |
| 785 | MOZ_ASSERT(index->mPendingUpdates.Count() == 0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(index->mPendingUpdates.Count() == 0)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(index->mPendingUpdates.Count() == 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("index->mPendingUpdates.Count() == 0" , "./../../../netwerk/cache2/CacheIndex.cpp", 785); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "index->mPendingUpdates.Count() == 0" ")" ); do { MOZ_CrashSequence(__null, 785); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 786 | MOZ_ASSERT(entry)do { static_assert( mozilla::detail::AssertionConditionType< decltype(entry)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(entry))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("entry", "./../../../netwerk/cache2/CacheIndex.cpp" , 786); AnnotateMozCrashReason("MOZ_ASSERT" "(" "entry" ")"); do { MOZ_CrashSequence(__null, 786); __attribute__((nomerge) ) ::abort(); } while (false); } } while (false); |
| 787 | MOZ_ASSERT(entry->IsFresh())do { static_assert( mozilla::detail::AssertionConditionType< decltype(entry->IsFresh())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(entry->IsFresh()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("entry->IsFresh()" , "./../../../netwerk/cache2/CacheIndex.cpp", 787); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "entry->IsFresh()" ")"); do { MOZ_CrashSequence (__null, 787); __attribute__((nomerge)) ::abort(); } while (false ); } } while (false); |
| 788 | |
| 789 | if (!entry) { |
| 790 | LOG(("CacheIndex::InitEntry() - Entry was not found in mIndex!"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::InitEntry() - Entry was not found in mIndex!" ); } } while (0); |
| 791 | NS_WARNING(NS_DebugBreak(NS_DEBUG_WARNING, ("CacheIndex::InitEntry() - Entry was not found in mIndex!" ), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp", 792) |
| 792 | ("CacheIndex::InitEntry() - Entry was not found in mIndex!"))NS_DebugBreak(NS_DEBUG_WARNING, ("CacheIndex::InitEntry() - Entry was not found in mIndex!" ), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp", 792); |
| 793 | return NS_ERROR_UNEXPECTED; |
| 794 | } |
| 795 | |
| 796 | if (IsCollision(entry, aOriginAttrsHash, aAnonymous)) { |
| 797 | index->mIndexNeedsUpdate = |
| 798 | true; // TODO Does this really help in case of collision? |
| 799 | reinitEntry = true; |
| 800 | } else { |
| 801 | if (entry->IsInitialized()) { |
| 802 | return NS_OK; |
| 803 | } |
| 804 | } |
| 805 | } else { |
| 806 | updated = index->mPendingUpdates.GetEntry(*aHash); |
| 807 | DebugOnly<bool> removed = updated && updated->IsRemoved(); |
| 808 | |
| 809 | MOZ_ASSERT(updated || !removed)do { static_assert( mozilla::detail::AssertionConditionType< decltype(updated || !removed)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(updated || !removed))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("updated || !removed" , "./../../../netwerk/cache2/CacheIndex.cpp", 809); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "updated || !removed" ")"); do { MOZ_CrashSequence (__null, 809); __attribute__((nomerge)) ::abort(); } while (false ); } } while (false); |
| 810 | MOZ_ASSERT(updated || entry)do { static_assert( mozilla::detail::AssertionConditionType< decltype(updated || entry)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(updated || entry))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("updated || entry" , "./../../../netwerk/cache2/CacheIndex.cpp", 810); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "updated || entry" ")"); do { MOZ_CrashSequence (__null, 810); __attribute__((nomerge)) ::abort(); } while (false ); } } while (false); |
| 811 | |
| 812 | if (!updated && !entry) { |
| 813 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::InitEntry() - Entry was found neither in mIndex nor " "in mPendingUpdates!"); } } while (0) |
| 814 | ("CacheIndex::InitEntry() - Entry was found neither in mIndex nor "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::InitEntry() - Entry was found neither in mIndex nor " "in mPendingUpdates!"); } } while (0) |
| 815 | "in mPendingUpdates!"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::InitEntry() - Entry was found neither in mIndex nor " "in mPendingUpdates!"); } } while (0); |
| 816 | NS_WARNING(NS_DebugBreak(NS_DEBUG_WARNING, ("CacheIndex::InitEntry() - Entry was found neither in " "mIndex nor in mPendingUpdates!"), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 818) |
| 817 | ("CacheIndex::InitEntry() - Entry was found neither in "NS_DebugBreak(NS_DEBUG_WARNING, ("CacheIndex::InitEntry() - Entry was found neither in " "mIndex nor in mPendingUpdates!"), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 818) |
| 818 | "mIndex nor in mPendingUpdates!"))NS_DebugBreak(NS_DEBUG_WARNING, ("CacheIndex::InitEntry() - Entry was found neither in " "mIndex nor in mPendingUpdates!"), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 818); |
| 819 | return NS_ERROR_UNEXPECTED; |
| 820 | } |
| 821 | |
| 822 | if (updated) { |
| 823 | MOZ_ASSERT(updated->IsFresh())do { static_assert( mozilla::detail::AssertionConditionType< decltype(updated->IsFresh())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(updated->IsFresh()))), 0) )) { do { } while (false); MOZ_ReportAssertionFailure("updated->IsFresh()" , "./../../../netwerk/cache2/CacheIndex.cpp", 823); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "updated->IsFresh()" ")"); do { MOZ_CrashSequence (__null, 823); __attribute__((nomerge)) ::abort(); } while (false ); } } while (false); |
| 824 | |
| 825 | if (IsCollision(updated, aOriginAttrsHash, aAnonymous)) { |
| 826 | index->mIndexNeedsUpdate = true; |
| 827 | reinitEntry = true; |
| 828 | } else { |
| 829 | if (updated->IsInitialized()) { |
| 830 | return NS_OK; |
| 831 | } |
| 832 | } |
| 833 | } else { |
| 834 | MOZ_ASSERT(entry->IsFresh())do { static_assert( mozilla::detail::AssertionConditionType< decltype(entry->IsFresh())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(entry->IsFresh()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("entry->IsFresh()" , "./../../../netwerk/cache2/CacheIndex.cpp", 834); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "entry->IsFresh()" ")"); do { MOZ_CrashSequence (__null, 834); __attribute__((nomerge)) ::abort(); } while (false ); } } while (false); |
| 835 | |
| 836 | if (IsCollision(entry, aOriginAttrsHash, aAnonymous)) { |
| 837 | index->mIndexNeedsUpdate = true; |
| 838 | reinitEntry = true; |
| 839 | } else { |
| 840 | if (entry->IsInitialized()) { |
| 841 | return NS_OK; |
| 842 | } |
| 843 | } |
| 844 | |
| 845 | // make a copy of a read-only entry |
| 846 | updated = index->mPendingUpdates.PutEntry(*aHash); |
| 847 | *updated = *entry; |
| 848 | } |
| 849 | } |
| 850 | |
| 851 | if (reinitEntry) { |
| 852 | // There is a collision and we are going to rewrite this entry. Initialize |
| 853 | // it as a new entry. |
| 854 | if (updated) { |
| 855 | updated->InitNew(); |
| 856 | updated->MarkFresh(); |
| 857 | } else { |
| 858 | entry->InitNew(); |
| 859 | entry->MarkFresh(); |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | if (updated) { |
| 864 | updated->Init(aOriginAttrsHash, aAnonymous, aPinned); |
| 865 | updated->MarkDirty(); |
| 866 | } else { |
| 867 | entry->Init(aOriginAttrsHash, aAnonymous, aPinned); |
| 868 | entry->MarkDirty(); |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | index->StartUpdatingIndexIfNeeded(lock); |
| 873 | index->WriteIndexToDiskIfNeeded(lock); |
| 874 | |
| 875 | return NS_OK; |
| 876 | } |
| 877 | |
| 878 | // static |
| 879 | nsresult CacheIndex::RemoveEntry(const SHA1Sum::Hash* aHash, |
| 880 | const nsACString& aKey, |
| 881 | bool aClearDictionary) { |
| 882 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveEntry() [hash=%08x%08x%08x%08x%08x] key=%s " "clear_dictionary=%d", PR_htonl((reinterpret_cast<const uint32_t *>(aHash))[0]), PR_htonl((reinterpret_cast<const uint32_t *>(aHash))[1]), PR_htonl((reinterpret_cast<const uint32_t *>(aHash))[2]), PR_htonl((reinterpret_cast<const uint32_t *>(aHash))[3]), PR_htonl((reinterpret_cast<const uint32_t *>(aHash))[4]), TPromiseFlatString<char>(aKey).get() , aClearDictionary); } } while (0) |
| 883 | ("CacheIndex::RemoveEntry() [hash=%08x%08x%08x%08x%08x] key=%s "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveEntry() [hash=%08x%08x%08x%08x%08x] key=%s " "clear_dictionary=%d", PR_htonl((reinterpret_cast<const uint32_t *>(aHash))[0]), PR_htonl((reinterpret_cast<const uint32_t *>(aHash))[1]), PR_htonl((reinterpret_cast<const uint32_t *>(aHash))[2]), PR_htonl((reinterpret_cast<const uint32_t *>(aHash))[3]), PR_htonl((reinterpret_cast<const uint32_t *>(aHash))[4]), TPromiseFlatString<char>(aKey).get() , aClearDictionary); } } while (0) |
| 884 | "clear_dictionary=%d",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveEntry() [hash=%08x%08x%08x%08x%08x] key=%s " "clear_dictionary=%d", PR_htonl((reinterpret_cast<const uint32_t *>(aHash))[0]), PR_htonl((reinterpret_cast<const uint32_t *>(aHash))[1]), PR_htonl((reinterpret_cast<const uint32_t *>(aHash))[2]), PR_htonl((reinterpret_cast<const uint32_t *>(aHash))[3]), PR_htonl((reinterpret_cast<const uint32_t *>(aHash))[4]), TPromiseFlatString<char>(aKey).get() , aClearDictionary); } } while (0) |
| 885 | LOGSHA1(aHash), PromiseFlatCString(aKey).get(), aClearDictionary))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveEntry() [hash=%08x%08x%08x%08x%08x] key=%s " "clear_dictionary=%d", PR_htonl((reinterpret_cast<const uint32_t *>(aHash))[0]), PR_htonl((reinterpret_cast<const uint32_t *>(aHash))[1]), PR_htonl((reinterpret_cast<const uint32_t *>(aHash))[2]), PR_htonl((reinterpret_cast<const uint32_t *>(aHash))[3]), PR_htonl((reinterpret_cast<const uint32_t *>(aHash))[4]), TPromiseFlatString<char>(aKey).get() , aClearDictionary); } } while (0); |
| 886 | |
| 887 | MOZ_ASSERT(CacheFileIOManager::IsOnIOThread())do { static_assert( mozilla::detail::AssertionConditionType< decltype(CacheFileIOManager::IsOnIOThread())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(CacheFileIOManager::IsOnIOThread ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("CacheFileIOManager::IsOnIOThread()", "./../../../netwerk/cache2/CacheIndex.cpp" , 887); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()" ")"); do { MOZ_CrashSequence(__null, 887); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 888 | |
| 889 | // Remove any dictionary associated with this entry even if we later |
| 890 | // error out - async since removal happens on MainThread. |
| 891 | |
| 892 | // TODO XXX There may be a hole here where a dictionary entry can get |
| 893 | // referenced for a request before RemoveDictionaryOMT can run, but after |
| 894 | // the entry is removed here. |
| 895 | |
| 896 | // Note: we don't want to (re)clear dictionaries when the |
| 897 | // CacheFileContextEvictor purges entries; they've already been cleared |
| 898 | // via CacheIndex::EvictByContext synchronously |
| 899 | if (aClearDictionary) { |
| 900 | DictionaryCache::RemoveDictionaryOMT(aKey); |
| 901 | } |
| 902 | |
| 903 | StaticMutexAutoLock lock(sLock); |
| 904 | |
| 905 | RefPtr<CacheIndex> index = gInstance; |
| 906 | |
| 907 | if (!index) { |
| 908 | return NS_ERROR_NOT_INITIALIZED; |
| 909 | } |
| 910 | |
| 911 | if (!index->IsIndexUsable()) { |
| 912 | return NS_ERROR_NOT_AVAILABLE; |
| 913 | } |
| 914 | |
| 915 | { |
| 916 | CacheIndexEntryAutoManage entryMng(aHash, index, lock); |
| 917 | |
| 918 | CacheIndexEntry* entry = index->mIndex.GetEntry(*aHash); |
| 919 | bool entryRemoved = entry && entry->IsRemoved(); |
| 920 | |
| 921 | if (index->mState == READY || index->mState == UPDATING || |
| 922 | index->mState == BUILDING) { |
| 923 | MOZ_ASSERT(index->mPendingUpdates.Count() == 0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(index->mPendingUpdates.Count() == 0)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(index->mPendingUpdates.Count() == 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("index->mPendingUpdates.Count() == 0" , "./../../../netwerk/cache2/CacheIndex.cpp", 923); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "index->mPendingUpdates.Count() == 0" ")" ); do { MOZ_CrashSequence(__null, 923); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 924 | |
| 925 | if (!entry || entryRemoved) { |
| 926 | if (entryRemoved && entry->IsFresh()) { |
| 927 | // This could happen only if somebody copies files to the entries |
| 928 | // directory while FF is running. |
| 929 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveEntry() - Cache file was added outside FF " "process! Update is needed."); } } while (0) |
| 930 | ("CacheIndex::RemoveEntry() - Cache file was added outside FF "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveEntry() - Cache file was added outside FF " "process! Update is needed."); } } while (0) |
| 931 | "process! Update is needed."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveEntry() - Cache file was added outside FF " "process! Update is needed."); } } while (0); |
| 932 | index->mIndexNeedsUpdate = true; |
| 933 | } else if (index->mState == READY || |
| 934 | (entryRemoved && !entry->IsFresh())) { |
| 935 | // Removed non-fresh entries can be present as a result of |
| 936 | // MergeJournal() |
| 937 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveEntry() - Didn't find entry that should exist" ", update is needed"); } } while (0) |
| 938 | ("CacheIndex::RemoveEntry() - Didn't find entry that should exist"do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveEntry() - Didn't find entry that should exist" ", update is needed"); } } while (0) |
| 939 | ", update is needed"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveEntry() - Didn't find entry that should exist" ", update is needed"); } } while (0); |
| 940 | index->mIndexNeedsUpdate = true; |
| 941 | } |
| 942 | } else { |
| 943 | if (entry) { |
| 944 | if (!entry->IsDirty() && entry->IsFileEmpty()) { |
| 945 | index->mIndex.RemoveEntry(entry); |
| 946 | entry = nullptr; |
| 947 | } else { |
| 948 | entry->MarkRemoved(); |
| 949 | entry->MarkDirty(); |
| 950 | entry->MarkFresh(); |
| 951 | } |
| 952 | } |
| 953 | } |
| 954 | } else { // WRITING, READING |
| 955 | CacheIndexEntryUpdate* updated = index->mPendingUpdates.GetEntry(*aHash); |
| 956 | bool updatedRemoved = updated && updated->IsRemoved(); |
| 957 | |
| 958 | if (updatedRemoved || (!updated && entryRemoved && entry->IsFresh())) { |
| 959 | // Fresh information about missing entry found. This could happen only |
| 960 | // if somebody copies files to the entries directory while FF is |
| 961 | // running. |
| 962 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveEntry() - Cache file was added outside FF " "process! Update is needed."); } } while (0) |
| 963 | ("CacheIndex::RemoveEntry() - Cache file was added outside FF "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveEntry() - Cache file was added outside FF " "process! Update is needed."); } } while (0) |
| 964 | "process! Update is needed."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveEntry() - Cache file was added outside FF " "process! Update is needed."); } } while (0); |
| 965 | index->mIndexNeedsUpdate = true; |
| 966 | } else if (!updated && (!entry || entryRemoved)) { |
| 967 | if (index->mState == WRITING) { |
| 968 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveEntry() - Didn't find entry that should exist" ", update is needed"); } } while (0) |
| 969 | ("CacheIndex::RemoveEntry() - Didn't find entry that should exist"do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveEntry() - Didn't find entry that should exist" ", update is needed"); } } while (0) |
| 970 | ", update is needed"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveEntry() - Didn't find entry that should exist" ", update is needed"); } } while (0); |
| 971 | index->mIndexNeedsUpdate = true; |
| 972 | } |
| 973 | // Ignore if state is READING since the index information is partial |
| 974 | } |
| 975 | |
| 976 | if (!updated) { |
| 977 | updated = index->mPendingUpdates.PutEntry(*aHash); |
| 978 | updated->InitNew(); |
| 979 | } |
| 980 | |
| 981 | updated->MarkRemoved(); |
| 982 | updated->MarkDirty(); |
| 983 | updated->MarkFresh(); |
| 984 | } |
| 985 | } |
| 986 | index->StartUpdatingIndexIfNeeded(lock); |
| 987 | index->WriteIndexToDiskIfNeeded(lock); |
| 988 | |
| 989 | return NS_OK; |
| 990 | } |
| 991 | |
| 992 | // static |
| 993 | nsresult CacheIndex::UpdateEntry(const SHA1Sum::Hash* aHash, |
| 994 | const uint32_t* aFrecency, |
| 995 | const bool* aHasAltData, |
| 996 | const uint32_t* aLastFetched, |
| 997 | const uint32_t* aFetchCount, |
| 998 | const uint8_t* aContentType, |
| 999 | const uint32_t* aSize) { |
| 1000 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateEntry() [hash=%08x%08x%08x%08x%08x, " "frecency=%s, hasAltData=%s, lastFetched=%s, fetchCount=%s, " "contentType=%s, size=%s]", PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[4]), aFrecency ? nsPrintfCString("%u", *aFrecency).get() : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "", aLastFetched ? nsPrintfCString("%u", *aLastFetched ).get() : "", aFetchCount ? nsPrintfCString("%u", *aFetchCount ).get() : "", aContentType ? nsPrintfCString("%u", *aContentType ).get() : "", aSize ? nsPrintfCString("%u", *aSize).get() : "" ); } } while (0) |
| 1001 | ("CacheIndex::UpdateEntry() [hash=%08x%08x%08x%08x%08x, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateEntry() [hash=%08x%08x%08x%08x%08x, " "frecency=%s, hasAltData=%s, lastFetched=%s, fetchCount=%s, " "contentType=%s, size=%s]", PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[4]), aFrecency ? nsPrintfCString("%u", *aFrecency).get() : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "", aLastFetched ? nsPrintfCString("%u", *aLastFetched ).get() : "", aFetchCount ? nsPrintfCString("%u", *aFetchCount ).get() : "", aContentType ? nsPrintfCString("%u", *aContentType ).get() : "", aSize ? nsPrintfCString("%u", *aSize).get() : "" ); } } while (0) |
| 1002 | "frecency=%s, hasAltData=%s, lastFetched=%s, fetchCount=%s, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateEntry() [hash=%08x%08x%08x%08x%08x, " "frecency=%s, hasAltData=%s, lastFetched=%s, fetchCount=%s, " "contentType=%s, size=%s]", PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[4]), aFrecency ? nsPrintfCString("%u", *aFrecency).get() : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "", aLastFetched ? nsPrintfCString("%u", *aLastFetched ).get() : "", aFetchCount ? nsPrintfCString("%u", *aFetchCount ).get() : "", aContentType ? nsPrintfCString("%u", *aContentType ).get() : "", aSize ? nsPrintfCString("%u", *aSize).get() : "" ); } } while (0) |
| 1003 | "contentType=%s, size=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateEntry() [hash=%08x%08x%08x%08x%08x, " "frecency=%s, hasAltData=%s, lastFetched=%s, fetchCount=%s, " "contentType=%s, size=%s]", PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[4]), aFrecency ? nsPrintfCString("%u", *aFrecency).get() : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "", aLastFetched ? nsPrintfCString("%u", *aLastFetched ).get() : "", aFetchCount ? nsPrintfCString("%u", *aFetchCount ).get() : "", aContentType ? nsPrintfCString("%u", *aContentType ).get() : "", aSize ? nsPrintfCString("%u", *aSize).get() : "" ); } } while (0) |
| 1004 | LOGSHA1(aHash), aFrecency ? nsPrintfCString("%u", *aFrecency).get() : "",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateEntry() [hash=%08x%08x%08x%08x%08x, " "frecency=%s, hasAltData=%s, lastFetched=%s, fetchCount=%s, " "contentType=%s, size=%s]", PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[4]), aFrecency ? nsPrintfCString("%u", *aFrecency).get() : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "", aLastFetched ? nsPrintfCString("%u", *aLastFetched ).get() : "", aFetchCount ? nsPrintfCString("%u", *aFetchCount ).get() : "", aContentType ? nsPrintfCString("%u", *aContentType ).get() : "", aSize ? nsPrintfCString("%u", *aSize).get() : "" ); } } while (0) |
| 1005 | aHasAltData ? (*aHasAltData ? "true" : "false") : "",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateEntry() [hash=%08x%08x%08x%08x%08x, " "frecency=%s, hasAltData=%s, lastFetched=%s, fetchCount=%s, " "contentType=%s, size=%s]", PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[4]), aFrecency ? nsPrintfCString("%u", *aFrecency).get() : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "", aLastFetched ? nsPrintfCString("%u", *aLastFetched ).get() : "", aFetchCount ? nsPrintfCString("%u", *aFetchCount ).get() : "", aContentType ? nsPrintfCString("%u", *aContentType ).get() : "", aSize ? nsPrintfCString("%u", *aSize).get() : "" ); } } while (0) |
| 1006 | aLastFetched ? nsPrintfCString("%u", *aLastFetched).get() : "",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateEntry() [hash=%08x%08x%08x%08x%08x, " "frecency=%s, hasAltData=%s, lastFetched=%s, fetchCount=%s, " "contentType=%s, size=%s]", PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[4]), aFrecency ? nsPrintfCString("%u", *aFrecency).get() : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "", aLastFetched ? nsPrintfCString("%u", *aLastFetched ).get() : "", aFetchCount ? nsPrintfCString("%u", *aFetchCount ).get() : "", aContentType ? nsPrintfCString("%u", *aContentType ).get() : "", aSize ? nsPrintfCString("%u", *aSize).get() : "" ); } } while (0) |
| 1007 | aFetchCount ? nsPrintfCString("%u", *aFetchCount).get() : "",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateEntry() [hash=%08x%08x%08x%08x%08x, " "frecency=%s, hasAltData=%s, lastFetched=%s, fetchCount=%s, " "contentType=%s, size=%s]", PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[4]), aFrecency ? nsPrintfCString("%u", *aFrecency).get() : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "", aLastFetched ? nsPrintfCString("%u", *aLastFetched ).get() : "", aFetchCount ? nsPrintfCString("%u", *aFetchCount ).get() : "", aContentType ? nsPrintfCString("%u", *aContentType ).get() : "", aSize ? nsPrintfCString("%u", *aSize).get() : "" ); } } while (0) |
| 1008 | aContentType ? nsPrintfCString("%u", *aContentType).get() : "",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateEntry() [hash=%08x%08x%08x%08x%08x, " "frecency=%s, hasAltData=%s, lastFetched=%s, fetchCount=%s, " "contentType=%s, size=%s]", PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[4]), aFrecency ? nsPrintfCString("%u", *aFrecency).get() : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "", aLastFetched ? nsPrintfCString("%u", *aLastFetched ).get() : "", aFetchCount ? nsPrintfCString("%u", *aFetchCount ).get() : "", aContentType ? nsPrintfCString("%u", *aContentType ).get() : "", aSize ? nsPrintfCString("%u", *aSize).get() : "" ); } } while (0) |
| 1009 | aSize ? nsPrintfCString("%u", *aSize).get() : ""))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateEntry() [hash=%08x%08x%08x%08x%08x, " "frecency=%s, hasAltData=%s, lastFetched=%s, fetchCount=%s, " "contentType=%s, size=%s]", PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(aHash))[4]), aFrecency ? nsPrintfCString("%u", *aFrecency).get() : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "", aLastFetched ? nsPrintfCString("%u", *aLastFetched ).get() : "", aFetchCount ? nsPrintfCString("%u", *aFetchCount ).get() : "", aContentType ? nsPrintfCString("%u", *aContentType ).get() : "", aSize ? nsPrintfCString("%u", *aSize).get() : "" ); } } while (0); |
| 1010 | |
| 1011 | MOZ_ASSERT(CacheFileIOManager::IsOnIOThread())do { static_assert( mozilla::detail::AssertionConditionType< decltype(CacheFileIOManager::IsOnIOThread())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(CacheFileIOManager::IsOnIOThread ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("CacheFileIOManager::IsOnIOThread()", "./../../../netwerk/cache2/CacheIndex.cpp" , 1011); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()" ")"); do { MOZ_CrashSequence(__null, 1011); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1012 | |
| 1013 | StaticMutexAutoLock lock(sLock); |
| 1014 | |
| 1015 | RefPtr<CacheIndex> index = gInstance; |
| 1016 | |
| 1017 | if (!index) { |
| 1018 | return NS_ERROR_NOT_INITIALIZED; |
| 1019 | } |
| 1020 | |
| 1021 | if (!index->IsIndexUsable()) { |
| 1022 | return NS_ERROR_NOT_AVAILABLE; |
| 1023 | } |
| 1024 | |
| 1025 | { |
| 1026 | CacheIndexEntryAutoManage entryMng(aHash, index, lock); |
| 1027 | |
| 1028 | CacheIndexEntry* entry = index->mIndex.GetEntry(*aHash); |
| 1029 | |
| 1030 | if (entry && entry->IsRemoved()) { |
| 1031 | entry = nullptr; |
| 1032 | } |
| 1033 | |
| 1034 | if (index->mState == READY || index->mState == UPDATING || |
| 1035 | index->mState == BUILDING) { |
| 1036 | MOZ_ASSERT(index->mPendingUpdates.Count() == 0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(index->mPendingUpdates.Count() == 0)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(index->mPendingUpdates.Count() == 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("index->mPendingUpdates.Count() == 0" , "./../../../netwerk/cache2/CacheIndex.cpp", 1036); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "index->mPendingUpdates.Count() == 0" ")" ); do { MOZ_CrashSequence(__null, 1036); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1037 | MOZ_ASSERT(entry)do { static_assert( mozilla::detail::AssertionConditionType< decltype(entry)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(entry))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("entry", "./../../../netwerk/cache2/CacheIndex.cpp" , 1037); AnnotateMozCrashReason("MOZ_ASSERT" "(" "entry" ")") ; do { MOZ_CrashSequence(__null, 1037); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1038 | |
| 1039 | if (!entry) { |
| 1040 | LOG(("CacheIndex::UpdateEntry() - Entry was not found in mIndex!"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateEntry() - Entry was not found in mIndex!" ); } } while (0); |
| 1041 | NS_WARNING(NS_DebugBreak(NS_DEBUG_WARNING, ("CacheIndex::UpdateEntry() - Entry was not found in mIndex!" ), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp", 1042) |
| 1042 | ("CacheIndex::UpdateEntry() - Entry was not found in mIndex!"))NS_DebugBreak(NS_DEBUG_WARNING, ("CacheIndex::UpdateEntry() - Entry was not found in mIndex!" ), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp", 1042); |
| 1043 | return NS_ERROR_UNEXPECTED; |
| 1044 | } |
| 1045 | |
| 1046 | if (!HasEntryChanged(entry, aFrecency, aHasAltData, aLastFetched, |
| 1047 | aFetchCount, aContentType, aSize)) { |
| 1048 | return NS_OK; |
| 1049 | } |
| 1050 | |
| 1051 | MOZ_ASSERT(entry->IsFresh())do { static_assert( mozilla::detail::AssertionConditionType< decltype(entry->IsFresh())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(entry->IsFresh()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("entry->IsFresh()" , "./../../../netwerk/cache2/CacheIndex.cpp", 1051); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "entry->IsFresh()" ")"); do { MOZ_CrashSequence (__null, 1051); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 1052 | MOZ_ASSERT(entry->IsInitialized())do { static_assert( mozilla::detail::AssertionConditionType< decltype(entry->IsInitialized())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(entry->IsInitialized()))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("entry->IsInitialized()" , "./../../../netwerk/cache2/CacheIndex.cpp", 1052); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "entry->IsInitialized()" ")"); do { MOZ_CrashSequence (__null, 1052); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 1053 | entry->MarkDirty(); |
| 1054 | |
| 1055 | if (aFrecency) { |
| 1056 | entry->SetFrecency(*aFrecency); |
| 1057 | } |
| 1058 | |
| 1059 | if (aHasAltData) { |
| 1060 | entry->SetHasAltData(*aHasAltData); |
| 1061 | } |
| 1062 | |
| 1063 | if (aLastFetched) { |
| 1064 | entry->SetLastFetched(*aLastFetched); |
| 1065 | } |
| 1066 | |
| 1067 | if (aFetchCount) { |
| 1068 | entry->SetFetchCount(*aFetchCount); |
| 1069 | } |
| 1070 | |
| 1071 | if (aContentType) { |
| 1072 | entry->SetContentType(*aContentType); |
| 1073 | } |
| 1074 | |
| 1075 | if (aSize) { |
| 1076 | entry->SetFileSize(*aSize); |
| 1077 | } |
| 1078 | } else { |
| 1079 | CacheIndexEntryUpdate* updated = index->mPendingUpdates.GetEntry(*aHash); |
| 1080 | DebugOnly<bool> removed = updated && updated->IsRemoved(); |
| 1081 | |
| 1082 | MOZ_ASSERT(updated || !removed)do { static_assert( mozilla::detail::AssertionConditionType< decltype(updated || !removed)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(updated || !removed))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("updated || !removed" , "./../../../netwerk/cache2/CacheIndex.cpp", 1082); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "updated || !removed" ")"); do { MOZ_CrashSequence (__null, 1082); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 1083 | MOZ_ASSERT(updated || entry)do { static_assert( mozilla::detail::AssertionConditionType< decltype(updated || entry)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(updated || entry))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("updated || entry" , "./../../../netwerk/cache2/CacheIndex.cpp", 1083); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "updated || entry" ")"); do { MOZ_CrashSequence (__null, 1083); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 1084 | |
| 1085 | if (!updated) { |
| 1086 | if (!entry) { |
| 1087 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateEntry() - Entry was found neither in mIndex " "nor in mPendingUpdates!"); } } while (0) |
| 1088 | ("CacheIndex::UpdateEntry() - Entry was found neither in mIndex "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateEntry() - Entry was found neither in mIndex " "nor in mPendingUpdates!"); } } while (0) |
| 1089 | "nor in mPendingUpdates!"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateEntry() - Entry was found neither in mIndex " "nor in mPendingUpdates!"); } } while (0); |
| 1090 | NS_WARNING(NS_DebugBreak(NS_DEBUG_WARNING, ("CacheIndex::UpdateEntry() - Entry was found neither in " "mIndex nor in mPendingUpdates!"), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 1092) |
| 1091 | ("CacheIndex::UpdateEntry() - Entry was found neither in "NS_DebugBreak(NS_DEBUG_WARNING, ("CacheIndex::UpdateEntry() - Entry was found neither in " "mIndex nor in mPendingUpdates!"), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 1092) |
| 1092 | "mIndex nor in mPendingUpdates!"))NS_DebugBreak(NS_DEBUG_WARNING, ("CacheIndex::UpdateEntry() - Entry was found neither in " "mIndex nor in mPendingUpdates!"), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 1092); |
| 1093 | return NS_ERROR_UNEXPECTED; |
| 1094 | } |
| 1095 | |
| 1096 | // make a copy of a read-only entry |
| 1097 | updated = index->mPendingUpdates.PutEntry(*aHash); |
| 1098 | *updated = *entry; |
| 1099 | } |
| 1100 | |
| 1101 | MOZ_ASSERT(updated->IsFresh())do { static_assert( mozilla::detail::AssertionConditionType< decltype(updated->IsFresh())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(updated->IsFresh()))), 0) )) { do { } while (false); MOZ_ReportAssertionFailure("updated->IsFresh()" , "./../../../netwerk/cache2/CacheIndex.cpp", 1101); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "updated->IsFresh()" ")"); do { MOZ_CrashSequence (__null, 1101); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 1102 | MOZ_ASSERT(updated->IsInitialized())do { static_assert( mozilla::detail::AssertionConditionType< decltype(updated->IsInitialized())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(updated->IsInitialized()) )), 0))) { do { } while (false); MOZ_ReportAssertionFailure("updated->IsInitialized()" , "./../../../netwerk/cache2/CacheIndex.cpp", 1102); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "updated->IsInitialized()" ")"); do { MOZ_CrashSequence (__null, 1102); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 1103 | updated->MarkDirty(); |
| 1104 | |
| 1105 | if (aFrecency) { |
| 1106 | updated->SetFrecency(*aFrecency); |
| 1107 | } |
| 1108 | |
| 1109 | if (aHasAltData) { |
| 1110 | updated->SetHasAltData(*aHasAltData); |
| 1111 | } |
| 1112 | |
| 1113 | if (aLastFetched) { |
| 1114 | updated->SetLastFetched(*aLastFetched); |
| 1115 | } |
| 1116 | |
| 1117 | if (aFetchCount) { |
| 1118 | updated->SetFetchCount(*aFetchCount); |
| 1119 | } |
| 1120 | |
| 1121 | if (aContentType) { |
| 1122 | updated->SetContentType(*aContentType); |
| 1123 | } |
| 1124 | |
| 1125 | if (aSize) { |
| 1126 | updated->SetFileSize(*aSize); |
| 1127 | } |
| 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | index->WriteIndexToDiskIfNeeded(lock); |
| 1132 | |
| 1133 | return NS_OK; |
| 1134 | } |
| 1135 | |
| 1136 | // Clear the entries from the Index immediately, to comply with |
| 1137 | // https://www.w3.org/TR/clear-site-data/#fetch-integration |
| 1138 | // Note that we will effectively hide the entries until the actual evict |
| 1139 | // happens. |
| 1140 | |
| 1141 | // aOrigin == "" means clear all unless aBaseDomain is set to something |
| 1142 | // static |
| 1143 | void CacheIndex::EvictByContext(const nsAString& aOrigin, |
| 1144 | const nsAString& aBaseDomain) { |
| 1145 | StaticMutexAutoLock lock(sLock); |
| 1146 | |
| 1147 | RefPtr<CacheIndex> index = gInstance; |
| 1148 | |
| 1149 | // Store in hashset that this origin has been evicted; we'll remove it |
| 1150 | // when CacheFileIOManager::EvictByContextInternal() finishes. |
| 1151 | // Not valid to set both aOrigin and aBaseDomain |
| 1152 | if (!aOrigin.IsEmpty() && aBaseDomain.IsEmpty()) { |
| 1153 | // likely CacheStorageService::ClearByPrincipal |
| 1154 | nsCOMPtr<nsIURI> uri; |
| 1155 | if (NS_SUCCEEDED(NS_NewURI(getter_AddRefs(uri), aOrigin))((bool)(__builtin_expect(!!(!NS_FAILED_impl(NS_NewURI(getter_AddRefs (uri), aOrigin))), 1)))) { |
| 1156 | // Remove the dictionary entries for this origin immediately |
| 1157 | DictionaryCache::RemoveDictionariesForOrigin(uri); |
| 1158 | } |
| 1159 | } |
| 1160 | } |
| 1161 | |
| 1162 | // static |
| 1163 | nsresult CacheIndex::RemoveAll() { |
| 1164 | LOG(("CacheIndex::RemoveAll()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveAll()" ); } } while (0); |
| 1165 | |
| 1166 | MOZ_ASSERT(CacheFileIOManager::IsOnIOThread())do { static_assert( mozilla::detail::AssertionConditionType< decltype(CacheFileIOManager::IsOnIOThread())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(CacheFileIOManager::IsOnIOThread ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("CacheFileIOManager::IsOnIOThread()", "./../../../netwerk/cache2/CacheIndex.cpp" , 1166); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()" ")"); do { MOZ_CrashSequence(__null, 1166); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1167 | |
| 1168 | nsCOMPtr<nsIFile> file; |
| 1169 | |
| 1170 | { |
| 1171 | StaticMutexAutoLock lock(sLock); |
| 1172 | |
| 1173 | RefPtr<CacheIndex> index = gInstance; |
| 1174 | |
| 1175 | if (!index) { |
| 1176 | return NS_ERROR_NOT_INITIALIZED; |
| 1177 | } |
| 1178 | |
| 1179 | MOZ_ASSERT(!index->mRemovingAll)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!index->mRemovingAll)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!index->mRemovingAll))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("!index->mRemovingAll" , "./../../../netwerk/cache2/CacheIndex.cpp", 1179); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!index->mRemovingAll" ")"); do { MOZ_CrashSequence (__null, 1179); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 1180 | |
| 1181 | if (!index->IsIndexUsable()) { |
| 1182 | return NS_ERROR_NOT_AVAILABLE; |
| 1183 | } |
| 1184 | |
| 1185 | AutoRestore<bool> saveRemovingAll(index->mRemovingAll); |
| 1186 | index->mRemovingAll = true; |
| 1187 | |
| 1188 | // Doom index and journal handles but don't null them out since this will be |
| 1189 | // done in FinishWrite/FinishRead methods. |
| 1190 | if (index->mIndexHandle) { |
| 1191 | CacheFileIOManager::DoomFile(index->mIndexHandle, nullptr); |
| 1192 | } else { |
| 1193 | // We don't have a handle to index file, so get the file here, but delete |
| 1194 | // it outside the lock. Ignore the result since this is not fatal. |
| 1195 | index->GetFile(nsLiteralCString(INDEX_NAME"index"), getter_AddRefs(file)); |
| 1196 | } |
| 1197 | |
| 1198 | if (index->mJournalHandle) { |
| 1199 | CacheFileIOManager::DoomFile(index->mJournalHandle, nullptr); |
| 1200 | } |
| 1201 | |
| 1202 | switch (index->mState) { |
| 1203 | case WRITING: |
| 1204 | index->FinishWrite(false, lock); |
| 1205 | break; |
| 1206 | case READY: |
| 1207 | // nothing to do |
| 1208 | break; |
| 1209 | case READING: |
| 1210 | index->FinishRead(false, lock); |
| 1211 | break; |
| 1212 | case BUILDING: |
| 1213 | case UPDATING: |
| 1214 | index->FinishUpdate(false, lock); |
| 1215 | break; |
| 1216 | default: |
| 1217 | MOZ_ASSERT(false, "Unexpected state!")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Unexpected state!" ")", "./../../../netwerk/cache2/CacheIndex.cpp", 1217); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "false" ") (" "Unexpected state!" ")"); do { MOZ_CrashSequence(__null, 1217); __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
| 1218 | } |
| 1219 | |
| 1220 | // We should end up in READY state |
| 1221 | MOZ_ASSERT(index->mState == READY)do { static_assert( mozilla::detail::AssertionConditionType< decltype(index->mState == READY)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(index->mState == READY))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("index->mState == READY" , "./../../../netwerk/cache2/CacheIndex.cpp", 1221); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "index->mState == READY" ")"); do { MOZ_CrashSequence (__null, 1221); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 1222 | |
| 1223 | // There should not be any handle |
| 1224 | MOZ_ASSERT(!index->mIndexHandle)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!index->mIndexHandle)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!index->mIndexHandle))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("!index->mIndexHandle" , "./../../../netwerk/cache2/CacheIndex.cpp", 1224); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!index->mIndexHandle" ")"); do { MOZ_CrashSequence (__null, 1224); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 1225 | MOZ_ASSERT(!index->mJournalHandle)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!index->mJournalHandle)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!index->mJournalHandle))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("!index->mJournalHandle" , "./../../../netwerk/cache2/CacheIndex.cpp", 1225); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!index->mJournalHandle" ")"); do { MOZ_CrashSequence (__null, 1225); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 1226 | |
| 1227 | index->mIndexOnDiskIsValid = false; |
| 1228 | index->mIndexNeedsUpdate = false; |
| 1229 | |
| 1230 | index->mIndexStats.Clear(); |
| 1231 | index->mFrecencyStorage.Clear(lock); |
| 1232 | index->mIndex.Clear(); |
| 1233 | |
| 1234 | for (uint32_t i = 0; i < index->mIterators.Length();) { |
| 1235 | nsresult rv = index->mIterators[i]->CloseInternal(NS_ERROR_NOT_AVAILABLE); |
| 1236 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 1237 | // CacheIndexIterator::CloseInternal() removes itself from mIterators |
| 1238 | // iff it returns success. |
| 1239 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveAll() - Failed to remove iterator %p. " "[rv=0x%08" "x" "]", index->mIterators[i], static_cast< uint32_t>(rv)); } } while (0) |
| 1240 | ("CacheIndex::RemoveAll() - Failed to remove iterator %p. "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveAll() - Failed to remove iterator %p. " "[rv=0x%08" "x" "]", index->mIterators[i], static_cast< uint32_t>(rv)); } } while (0) |
| 1241 | "[rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveAll() - Failed to remove iterator %p. " "[rv=0x%08" "x" "]", index->mIterators[i], static_cast< uint32_t>(rv)); } } while (0) |
| 1242 | index->mIterators[i], static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveAll() - Failed to remove iterator %p. " "[rv=0x%08" "x" "]", index->mIterators[i], static_cast< uint32_t>(rv)); } } while (0); |
| 1243 | i++; |
| 1244 | } |
| 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | if (file) { |
| 1249 | // Ignore the result. The file might not exist and the failure is not fatal. |
| 1250 | file->Remove(false); |
| 1251 | } |
| 1252 | |
| 1253 | return NS_OK; |
| 1254 | } |
| 1255 | |
| 1256 | // static |
| 1257 | nsresult CacheIndex::HasEntry( |
| 1258 | const nsACString& aKey, EntryStatus* _retval, |
| 1259 | const std::function<void(const CacheIndexEntry*)>& aCB) { |
| 1260 | LOG(("CacheIndex::HasEntry() [key=%s]", PromiseFlatCString(aKey).get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::HasEntry() [key=%s]" , TPromiseFlatString<char>(aKey).get()); } } while (0); |
| 1261 | |
| 1262 | SHA1Sum sum; |
| 1263 | SHA1Sum::Hash hash; |
| 1264 | sum.update(aKey.BeginReading(), aKey.Length()); |
| 1265 | sum.finish(hash); |
| 1266 | |
| 1267 | return HasEntry(hash, _retval, aCB); |
| 1268 | } |
| 1269 | |
| 1270 | // static |
| 1271 | nsresult CacheIndex::HasEntry( |
| 1272 | const SHA1Sum::Hash& hash, EntryStatus* _retval, |
| 1273 | const std::function<void(const CacheIndexEntry*)>& aCB) { |
| 1274 | StaticMutexAutoLock lock(sLock); |
| 1275 | |
| 1276 | RefPtr<CacheIndex> index = gInstance; |
| 1277 | |
| 1278 | if (!index) { |
| 1279 | return NS_ERROR_NOT_INITIALIZED; |
| 1280 | } |
| 1281 | |
| 1282 | if (!index->IsIndexUsable()) { |
| 1283 | return NS_ERROR_NOT_AVAILABLE; |
| 1284 | } |
| 1285 | |
| 1286 | const CacheIndexEntry* entry = nullptr; |
| 1287 | |
| 1288 | switch (index->mState) { |
| 1289 | case READING: |
| 1290 | case WRITING: |
| 1291 | entry = index->mPendingUpdates.GetEntry(hash); |
| 1292 | [[fallthrough]]; |
| 1293 | case BUILDING: |
| 1294 | case UPDATING: |
| 1295 | case READY: |
| 1296 | if (!entry) { |
| 1297 | entry = index->mIndex.GetEntry(hash); |
| 1298 | } |
| 1299 | break; |
| 1300 | case INITIAL: |
| 1301 | case SHUTDOWN: |
| 1302 | MOZ_ASSERT(false, "Unexpected state!")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Unexpected state!" ")", "./../../../netwerk/cache2/CacheIndex.cpp", 1302); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "false" ") (" "Unexpected state!" ")"); do { MOZ_CrashSequence(__null, 1302); __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
| 1303 | } |
| 1304 | |
| 1305 | if (!entry) { |
| 1306 | if (index->mState == READY || index->mState == WRITING) { |
| 1307 | *_retval = DOES_NOT_EXIST; |
| 1308 | } else { |
| 1309 | *_retval = DO_NOT_KNOW; |
| 1310 | } |
| 1311 | } else { |
| 1312 | if (entry->IsRemoved()) { |
| 1313 | if (entry->IsFresh()) { |
| 1314 | *_retval = DOES_NOT_EXIST; |
| 1315 | } else { |
| 1316 | *_retval = DO_NOT_KNOW; |
| 1317 | } |
| 1318 | } else { |
| 1319 | *_retval = EXISTS; |
| 1320 | if (aCB) { |
| 1321 | aCB(entry); |
| 1322 | } |
| 1323 | } |
| 1324 | } |
| 1325 | |
| 1326 | LOG(("CacheIndex::HasEntry() - result is %u", *_retval))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::HasEntry() - result is %u" , *_retval); } } while (0); |
| 1327 | return NS_OK; |
| 1328 | } |
| 1329 | |
| 1330 | // static |
| 1331 | // GetEntryForEviction is used by OverLimitEvictionInternal where we create and |
| 1332 | // keep our EvictionSortedSnapshot while looping. |
| 1333 | nsresult CacheIndex::GetEntryForEviction(EvictionSortedSnapshot& aSnapshot, |
| 1334 | bool aIgnoreEmptyEntries, |
| 1335 | SHA1Sum::Hash* aHash, uint32_t* aCnt) { |
| 1336 | LOG(("CacheIndex::GetEntryForEviction()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::GetEntryForEviction()" ); } } while (0); |
| 1337 | |
| 1338 | MOZ_ASSERT(CacheFileIOManager::IsOnIOThread())do { static_assert( mozilla::detail::AssertionConditionType< decltype(CacheFileIOManager::IsOnIOThread())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(CacheFileIOManager::IsOnIOThread ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("CacheFileIOManager::IsOnIOThread()", "./../../../netwerk/cache2/CacheIndex.cpp" , 1338); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()" ")"); do { MOZ_CrashSequence(__null, 1338); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1339 | |
| 1340 | StaticMutexAutoLock lock(sLock); |
| 1341 | |
| 1342 | RefPtr<CacheIndex> index = gInstance; |
| 1343 | |
| 1344 | if (!index) return NS_ERROR_NOT_INITIALIZED; |
| 1345 | |
| 1346 | if (!index->IsIndexUsable()) { |
| 1347 | return NS_ERROR_NOT_AVAILABLE; |
| 1348 | } |
| 1349 | |
| 1350 | if (index->mIndexStats.Size() == 0) { |
| 1351 | return NS_ERROR_NOT_AVAILABLE; |
| 1352 | } |
| 1353 | |
| 1354 | int32_t mediaUsage = |
| 1355 | round(static_cast<double>(index->mIndexStats.SizeByType( |
| 1356 | nsICacheEntry::CONTENT_TYPE_MEDIA)) * |
| 1357 | 100.0 / static_cast<double>(index->mIndexStats.Size())); |
| 1358 | int32_t mediaUsageLimit = |
| 1359 | StaticPrefs::browser_cache_disk_content_type_media_limit(); |
| 1360 | bool evictMedia = false; |
| 1361 | if (mediaUsage > mediaUsageLimit) { |
| 1362 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::GetEntryForEviction() - media content type is over the " "limit [mediaUsage=%d, mediaUsageLimit=%d]", mediaUsage, mediaUsageLimit ); } } while (0) |
| 1363 | ("CacheIndex::GetEntryForEviction() - media content type is over the "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::GetEntryForEviction() - media content type is over the " "limit [mediaUsage=%d, mediaUsageLimit=%d]", mediaUsage, mediaUsageLimit ); } } while (0) |
| 1364 | "limit [mediaUsage=%d, mediaUsageLimit=%d]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::GetEntryForEviction() - media content type is over the " "limit [mediaUsage=%d, mediaUsageLimit=%d]", mediaUsage, mediaUsageLimit ); } } while (0) |
| 1365 | mediaUsage, mediaUsageLimit))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::GetEntryForEviction() - media content type is over the " "limit [mediaUsage=%d, mediaUsageLimit=%d]", mediaUsage, mediaUsageLimit ); } } while (0); |
| 1366 | evictMedia = true; |
| 1367 | } |
| 1368 | |
| 1369 | SHA1Sum::Hash hash; |
| 1370 | CacheIndexRecord* foundRecord = nullptr; |
| 1371 | uint32_t skipped = 0; |
| 1372 | size_t recordPosition = 0; |
| 1373 | |
| 1374 | // find first non-forced valid and unpinned entry with the lowest frecency |
| 1375 | for (size_t i = 0; i < aSnapshot.Length(); ++i) { |
| 1376 | if (!aSnapshot[i]) { |
| 1377 | continue; // Skip the null records |
| 1378 | } |
| 1379 | CacheIndexRecord* rec = aSnapshot[i]->Get(); |
| 1380 | if (!rec) { |
| 1381 | continue; // Skip the null records |
| 1382 | } |
| 1383 | |
| 1384 | memcpy(&hash, rec->mHash, sizeof(SHA1Sum::Hash)); |
| 1385 | |
| 1386 | ++skipped; |
| 1387 | |
| 1388 | uint32_t type = CacheIndexEntry::GetContentType(rec); |
| 1389 | |
| 1390 | if (evictMedia && type != nsICacheEntry::CONTENT_TYPE_MEDIA) { |
| 1391 | continue; |
| 1392 | } |
| 1393 | |
| 1394 | if (type == nsICacheEntry::CONTENT_TYPE_DICTIONARY) { |
| 1395 | // Let them be removed by becoming empty and removing themselves |
| 1396 | continue; |
| 1397 | } |
| 1398 | |
| 1399 | if (IsForcedValidEntry(&hash)) { |
| 1400 | continue; |
| 1401 | } |
| 1402 | |
| 1403 | // Skip entries with active (non-doomed) file handles. These are |
| 1404 | // currently being read from or written to. Evicting them would doom |
| 1405 | // the in-progress I/O — in particular, a newly-created entry being |
| 1406 | // written always has the lowest frecency and would otherwise be |
| 1407 | // selected as the first eviction candidate, preventing it from ever |
| 1408 | // being stored. See bug 2031577. |
| 1409 | { |
| 1410 | RefPtr<CacheFileHandle> handle; |
| 1411 | if (CacheFileIOManager::gInstance && |
| 1412 | NS_SUCCEEDED(CacheFileIOManager::gInstance->mHandles.GetHandle(((bool)(__builtin_expect(!!(!NS_FAILED_impl(CacheFileIOManager ::gInstance->mHandles.GetHandle( &hash, getter_AddRefs (handle)))), 1))) |
| 1413 | &hash, getter_AddRefs(handle)))((bool)(__builtin_expect(!!(!NS_FAILED_impl(CacheFileIOManager ::gInstance->mHandles.GetHandle( &hash, getter_AddRefs (handle)))), 1)))) { |
| 1414 | continue; |
| 1415 | } |
| 1416 | } |
| 1417 | |
| 1418 | if (CacheIndexEntry::IsPinned(rec)) { |
| 1419 | continue; |
| 1420 | } |
| 1421 | |
| 1422 | if (aIgnoreEmptyEntries && !CacheIndexEntry::GetFileSize(*rec)) { |
| 1423 | continue; |
| 1424 | } |
| 1425 | |
| 1426 | --skipped; |
| 1427 | foundRecord = rec; |
| 1428 | recordPosition = i; |
| 1429 | break; |
| 1430 | } |
| 1431 | |
| 1432 | if (!foundRecord) return NS_ERROR_NOT_AVAILABLE; |
| 1433 | |
| 1434 | *aCnt = skipped; |
| 1435 | |
| 1436 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::GetEntryForEviction() - returning entry " "[hash=%08x%08x%08x%08x%08x, cnt=%u, frecency=%u, contentType=%u]" , PR_htonl((reinterpret_cast<const uint32_t*>(&hash ))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(& hash))[1]), PR_htonl((reinterpret_cast<const uint32_t*> (&hash))[2]), PR_htonl((reinterpret_cast<const uint32_t *>(&hash))[3]), PR_htonl((reinterpret_cast<const uint32_t *>(&hash))[4]), *aCnt, foundRecord->mFrecency, CacheIndexEntry ::GetContentType(foundRecord)); } } while (0) |
| 1437 | ("CacheIndex::GetEntryForEviction() - returning entry "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::GetEntryForEviction() - returning entry " "[hash=%08x%08x%08x%08x%08x, cnt=%u, frecency=%u, contentType=%u]" , PR_htonl((reinterpret_cast<const uint32_t*>(&hash ))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(& hash))[1]), PR_htonl((reinterpret_cast<const uint32_t*> (&hash))[2]), PR_htonl((reinterpret_cast<const uint32_t *>(&hash))[3]), PR_htonl((reinterpret_cast<const uint32_t *>(&hash))[4]), *aCnt, foundRecord->mFrecency, CacheIndexEntry ::GetContentType(foundRecord)); } } while (0) |
| 1438 | "[hash=%08x%08x%08x%08x%08x, cnt=%u, frecency=%u, contentType=%u]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::GetEntryForEviction() - returning entry " "[hash=%08x%08x%08x%08x%08x, cnt=%u, frecency=%u, contentType=%u]" , PR_htonl((reinterpret_cast<const uint32_t*>(&hash ))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(& hash))[1]), PR_htonl((reinterpret_cast<const uint32_t*> (&hash))[2]), PR_htonl((reinterpret_cast<const uint32_t *>(&hash))[3]), PR_htonl((reinterpret_cast<const uint32_t *>(&hash))[4]), *aCnt, foundRecord->mFrecency, CacheIndexEntry ::GetContentType(foundRecord)); } } while (0) |
| 1439 | LOGSHA1(&hash), *aCnt, foundRecord->mFrecency,do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::GetEntryForEviction() - returning entry " "[hash=%08x%08x%08x%08x%08x, cnt=%u, frecency=%u, contentType=%u]" , PR_htonl((reinterpret_cast<const uint32_t*>(&hash ))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(& hash))[1]), PR_htonl((reinterpret_cast<const uint32_t*> (&hash))[2]), PR_htonl((reinterpret_cast<const uint32_t *>(&hash))[3]), PR_htonl((reinterpret_cast<const uint32_t *>(&hash))[4]), *aCnt, foundRecord->mFrecency, CacheIndexEntry ::GetContentType(foundRecord)); } } while (0) |
| 1440 | CacheIndexEntry::GetContentType(foundRecord)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::GetEntryForEviction() - returning entry " "[hash=%08x%08x%08x%08x%08x, cnt=%u, frecency=%u, contentType=%u]" , PR_htonl((reinterpret_cast<const uint32_t*>(&hash ))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(& hash))[1]), PR_htonl((reinterpret_cast<const uint32_t*> (&hash))[2]), PR_htonl((reinterpret_cast<const uint32_t *>(&hash))[3]), PR_htonl((reinterpret_cast<const uint32_t *>(&hash))[4]), *aCnt, foundRecord->mFrecency, CacheIndexEntry ::GetContentType(foundRecord)); } } while (0); |
| 1441 | |
| 1442 | memcpy(aHash, &hash, sizeof(SHA1Sum::Hash)); |
| 1443 | aSnapshot[recordPosition] = nullptr; // Remove the record from the snapshot |
| 1444 | |
| 1445 | return NS_OK; |
| 1446 | } |
| 1447 | |
| 1448 | // static |
| 1449 | bool CacheIndex::IsForcedValidEntry(const SHA1Sum::Hash* aHash) { |
| 1450 | RefPtr<CacheFileHandle> handle; |
| 1451 | |
| 1452 | CacheFileIOManager::gInstance->mHandles.GetHandle(aHash, |
| 1453 | getter_AddRefs(handle)); |
| 1454 | |
| 1455 | if (!handle) return false; |
| 1456 | |
| 1457 | nsCString hashKey = handle->Key(); |
| 1458 | return CacheStorageService::Self()->IsForcedValidEntry(hashKey); |
| 1459 | } |
| 1460 | |
| 1461 | // static |
| 1462 | nsresult CacheIndex::GetCacheSize(uint32_t* _retval) { |
| 1463 | LOG(("CacheIndex::GetCacheSize()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::GetCacheSize()" ); } } while (0); |
| 1464 | |
| 1465 | StaticMutexAutoLock lock(sLock); |
| 1466 | |
| 1467 | RefPtr<CacheIndex> index = gInstance; |
| 1468 | |
| 1469 | if (!index) return NS_ERROR_NOT_INITIALIZED; |
| 1470 | |
| 1471 | if (!index->IsIndexUsable()) { |
| 1472 | return NS_ERROR_NOT_AVAILABLE; |
| 1473 | } |
| 1474 | |
| 1475 | *_retval = index->mIndexStats.Size(); |
| 1476 | LOG(("CacheIndex::GetCacheSize() - returning %u", *_retval))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::GetCacheSize() - returning %u" , *_retval); } } while (0); |
| 1477 | return NS_OK; |
| 1478 | } |
| 1479 | |
| 1480 | // static |
| 1481 | nsresult CacheIndex::GetEntryFileCount(uint32_t* _retval) { |
| 1482 | LOG(("CacheIndex::GetEntryFileCount()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::GetEntryFileCount()" ); } } while (0); |
| 1483 | |
| 1484 | StaticMutexAutoLock lock(sLock); |
| 1485 | |
| 1486 | RefPtr<CacheIndex> index = gInstance; |
| 1487 | |
| 1488 | if (!index) { |
| 1489 | return NS_ERROR_NOT_INITIALIZED; |
| 1490 | } |
| 1491 | |
| 1492 | if (!index->IsIndexUsable()) { |
| 1493 | return NS_ERROR_NOT_AVAILABLE; |
| 1494 | } |
| 1495 | |
| 1496 | *_retval = index->mIndexStats.ActiveEntriesCount(); |
| 1497 | LOG(("CacheIndex::GetEntryFileCount() - returning %u", *_retval))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::GetEntryFileCount() - returning %u" , *_retval); } } while (0); |
| 1498 | return NS_OK; |
| 1499 | } |
| 1500 | |
| 1501 | // static |
| 1502 | nsresult CacheIndex::GetCacheStats(nsILoadContextInfo* aInfo, uint32_t* aSize, |
| 1503 | uint32_t* aCount) { |
| 1504 | LOG(("CacheIndex::GetCacheStats() [info=%p]", aInfo))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::GetCacheStats() [info=%p]" , aInfo); } } while (0); |
| 1505 | |
| 1506 | StaticMutexAutoLock lock(sLock); |
| 1507 | |
| 1508 | RefPtr<CacheIndex> index = gInstance; |
| 1509 | |
| 1510 | if (!index) { |
| 1511 | return NS_ERROR_NOT_INITIALIZED; |
| 1512 | } |
| 1513 | |
| 1514 | if (!index->IsIndexUsable()) { |
| 1515 | return NS_ERROR_NOT_AVAILABLE; |
| 1516 | } |
| 1517 | |
| 1518 | *aSize = 0; |
| 1519 | *aCount = 0; |
| 1520 | |
| 1521 | for (const auto& item : index->mFrecencyStorage.mRecs) { |
| 1522 | if (aInfo && |
| 1523 | !CacheIndexEntry::RecordMatchesLoadContextInfo(item.GetKey(), aInfo)) { |
| 1524 | continue; |
| 1525 | } |
| 1526 | |
| 1527 | *aSize += CacheIndexEntry::GetFileSize(*(item.GetKey()->Get())); |
| 1528 | ++*aCount; |
| 1529 | } |
| 1530 | |
| 1531 | return NS_OK; |
| 1532 | } |
| 1533 | |
| 1534 | // static |
| 1535 | nsresult CacheIndex::AsyncGetDiskConsumption( |
| 1536 | nsICacheStorageConsumptionObserver* aObserver) { |
| 1537 | LOG(("CacheIndex::AsyncGetDiskConsumption()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::AsyncGetDiskConsumption()" ); } } while (0); |
| 1538 | |
| 1539 | StaticMutexAutoLock lock(sLock); |
| 1540 | |
| 1541 | RefPtr<CacheIndex> index = gInstance; |
| 1542 | |
| 1543 | if (!index) { |
| 1544 | return NS_ERROR_NOT_INITIALIZED; |
| 1545 | } |
| 1546 | |
| 1547 | if (!index->IsIndexUsable()) { |
| 1548 | return NS_ERROR_NOT_AVAILABLE; |
| 1549 | } |
| 1550 | |
| 1551 | RefPtr<DiskConsumptionObserver> observer = |
| 1552 | DiskConsumptionObserver::Init(aObserver); |
| 1553 | |
| 1554 | NS_ENSURE_ARG(observer)do { if ((__builtin_expect(!!(!(observer)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "observer" ") failed", nullptr , "./../../../netwerk/cache2/CacheIndex.cpp", 1554); return NS_ERROR_INVALID_ARG ; } } while (false); |
| 1555 | |
| 1556 | if ((index->mState == READY || index->mState == WRITING) && |
| 1557 | !index->mAsyncGetDiskConsumptionBlocked) { |
| 1558 | LOG(("CacheIndex::AsyncGetDiskConsumption - calling immediately"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::AsyncGetDiskConsumption - calling immediately" ); } } while (0); |
| 1559 | // Safe to call the callback under the lock, |
| 1560 | // we always post to the main thread. |
| 1561 | observer->OnDiskConsumption(index->mIndexStats.Size() << 10); |
| 1562 | return NS_OK; |
| 1563 | } |
| 1564 | |
| 1565 | LOG(("CacheIndex::AsyncGetDiskConsumption - remembering callback"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::AsyncGetDiskConsumption - remembering callback" ); } } while (0); |
| 1566 | // Will be called when the index get to the READY state. |
| 1567 | index->mDiskConsumptionObservers.AppendElement(observer); |
| 1568 | |
| 1569 | // Move forward with index re/building if it is pending |
| 1570 | RefPtr<CacheIOThread> ioThread = CacheFileIOManager::IOThread(); |
| 1571 | if (ioThread) { |
| 1572 | ioThread->Dispatch( |
| 1573 | NS_NewRunnableFunction("net::CacheIndex::AsyncGetDiskConsumption", |
| 1574 | []() -> void { |
| 1575 | StaticMutexAutoLock lock(sLock); |
| 1576 | |
| 1577 | RefPtr<CacheIndex> index = gInstance; |
| 1578 | if (index && index->mUpdateTimer) { |
| 1579 | index->mUpdateTimer->Cancel(); |
| 1580 | index->DelayedUpdateLocked(lock); |
| 1581 | } |
| 1582 | }), |
| 1583 | CacheIOThread::INDEX); |
| 1584 | } |
| 1585 | |
| 1586 | return NS_OK; |
| 1587 | } |
| 1588 | |
| 1589 | // static |
| 1590 | nsresult CacheIndex::GetIterator(nsILoadContextInfo* aInfo, bool aAddNew, |
| 1591 | CacheIndexIterator** _retval) { |
| 1592 | LOG(("CacheIndex::GetIterator() [info=%p, addNew=%d]", aInfo, aAddNew))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::GetIterator() [info=%p, addNew=%d]" , aInfo, aAddNew); } } while (0); |
| 1593 | |
| 1594 | StaticMutexAutoLock lock(sLock); |
| 1595 | |
| 1596 | RefPtr<CacheIndex> index = gInstance; |
| 1597 | |
| 1598 | if (!index) { |
| 1599 | return NS_ERROR_NOT_INITIALIZED; |
| 1600 | } |
| 1601 | |
| 1602 | if (!index->IsIndexUsable()) { |
| 1603 | return NS_ERROR_NOT_AVAILABLE; |
| 1604 | } |
| 1605 | |
| 1606 | RefPtr<CacheIndexIterator> idxIter; |
| 1607 | if (aInfo) { |
| 1608 | idxIter = new CacheIndexContextIterator(index, aAddNew, aInfo); |
| 1609 | } else { |
| 1610 | idxIter = new CacheIndexIterator(index, aAddNew); |
| 1611 | } |
| 1612 | for (const auto& item : index->mFrecencyStorage.mRecs) { |
| 1613 | idxIter->AddRecord(item.GetKey(), lock); |
| 1614 | } |
| 1615 | |
| 1616 | index->mIterators.AppendElement(idxIter); |
| 1617 | idxIter.swap(*_retval); |
| 1618 | return NS_OK; |
| 1619 | } |
| 1620 | |
| 1621 | // static |
| 1622 | nsresult CacheIndex::IsUpToDate(bool* _retval) { |
| 1623 | LOG(("CacheIndex::IsUpToDate()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::IsUpToDate()" ); } } while (0); |
| 1624 | |
| 1625 | StaticMutexAutoLock lock(sLock); |
| 1626 | |
| 1627 | RefPtr<CacheIndex> index = gInstance; |
| 1628 | |
| 1629 | if (!index) { |
| 1630 | return NS_ERROR_NOT_INITIALIZED; |
| 1631 | } |
| 1632 | |
| 1633 | if (!index->IsIndexUsable()) { |
| 1634 | return NS_ERROR_NOT_AVAILABLE; |
| 1635 | } |
| 1636 | |
| 1637 | *_retval = (index->mState == READY || index->mState == WRITING) && |
| 1638 | !index->mIndexNeedsUpdate && !index->mShuttingDown; |
| 1639 | |
| 1640 | LOG(("CacheIndex::IsUpToDate() - returning %d", *_retval))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::IsUpToDate() - returning %d" , *_retval); } } while (0); |
| 1641 | return NS_OK; |
| 1642 | } |
| 1643 | |
| 1644 | bool CacheIndex::IsIndexUsable() { |
| 1645 | MOZ_ASSERT(mState != INITIAL)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mState != INITIAL)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mState != INITIAL))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mState != INITIAL" , "./../../../netwerk/cache2/CacheIndex.cpp", 1645); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "mState != INITIAL" ")"); do { MOZ_CrashSequence (__null, 1645); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 1646 | |
| 1647 | switch (mState) { |
| 1648 | case INITIAL: |
| 1649 | case SHUTDOWN: |
| 1650 | return false; |
| 1651 | |
| 1652 | case READING: |
| 1653 | case WRITING: |
| 1654 | case BUILDING: |
| 1655 | case UPDATING: |
| 1656 | case READY: |
| 1657 | break; |
| 1658 | } |
| 1659 | |
| 1660 | return true; |
| 1661 | } |
| 1662 | |
| 1663 | // static |
| 1664 | bool CacheIndex::IsCollision(CacheIndexEntry* aEntry, |
| 1665 | OriginAttrsHash aOriginAttrsHash, |
| 1666 | bool aAnonymous) { |
| 1667 | if (!aEntry->IsInitialized()) { |
| 1668 | return false; |
| 1669 | } |
| 1670 | |
| 1671 | if (aEntry->Anonymous() != aAnonymous || |
| 1672 | aEntry->OriginAttrsHash() != aOriginAttrsHash) { |
| 1673 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::IsCollision() - Collision detected for entry hash=%08x" "%08x%08x%08x%08x, expected values: originAttrsHash=%" "l" "u" ", " "anonymous=%d; actual values: originAttrsHash=%" "l" "u" ", anonymous=%d]", PR_htonl((reinterpret_cast<const uint32_t *>(aEntry->Hash()))[0]), PR_htonl((reinterpret_cast< const uint32_t*>(aEntry->Hash()))[1]), PR_htonl((reinterpret_cast <const uint32_t*>(aEntry->Hash()))[2]), PR_htonl((reinterpret_cast <const uint32_t*>(aEntry->Hash()))[3]), PR_htonl((reinterpret_cast <const uint32_t*>(aEntry->Hash()))[4]), aOriginAttrsHash , aAnonymous, aEntry->OriginAttrsHash(), aEntry->Anonymous ()); } } while (0) |
| 1674 | ("CacheIndex::IsCollision() - Collision detected for entry hash=%08x"do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::IsCollision() - Collision detected for entry hash=%08x" "%08x%08x%08x%08x, expected values: originAttrsHash=%" "l" "u" ", " "anonymous=%d; actual values: originAttrsHash=%" "l" "u" ", anonymous=%d]", PR_htonl((reinterpret_cast<const uint32_t *>(aEntry->Hash()))[0]), PR_htonl((reinterpret_cast< const uint32_t*>(aEntry->Hash()))[1]), PR_htonl((reinterpret_cast <const uint32_t*>(aEntry->Hash()))[2]), PR_htonl((reinterpret_cast <const uint32_t*>(aEntry->Hash()))[3]), PR_htonl((reinterpret_cast <const uint32_t*>(aEntry->Hash()))[4]), aOriginAttrsHash , aAnonymous, aEntry->OriginAttrsHash(), aEntry->Anonymous ()); } } while (0) |
| 1675 | "%08x%08x%08x%08x, expected values: originAttrsHash=%" PRIu64 ", "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::IsCollision() - Collision detected for entry hash=%08x" "%08x%08x%08x%08x, expected values: originAttrsHash=%" "l" "u" ", " "anonymous=%d; actual values: originAttrsHash=%" "l" "u" ", anonymous=%d]", PR_htonl((reinterpret_cast<const uint32_t *>(aEntry->Hash()))[0]), PR_htonl((reinterpret_cast< const uint32_t*>(aEntry->Hash()))[1]), PR_htonl((reinterpret_cast <const uint32_t*>(aEntry->Hash()))[2]), PR_htonl((reinterpret_cast <const uint32_t*>(aEntry->Hash()))[3]), PR_htonl((reinterpret_cast <const uint32_t*>(aEntry->Hash()))[4]), aOriginAttrsHash , aAnonymous, aEntry->OriginAttrsHash(), aEntry->Anonymous ()); } } while (0) |
| 1676 | "anonymous=%d; actual values: originAttrsHash=%" PRIu64do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::IsCollision() - Collision detected for entry hash=%08x" "%08x%08x%08x%08x, expected values: originAttrsHash=%" "l" "u" ", " "anonymous=%d; actual values: originAttrsHash=%" "l" "u" ", anonymous=%d]", PR_htonl((reinterpret_cast<const uint32_t *>(aEntry->Hash()))[0]), PR_htonl((reinterpret_cast< const uint32_t*>(aEntry->Hash()))[1]), PR_htonl((reinterpret_cast <const uint32_t*>(aEntry->Hash()))[2]), PR_htonl((reinterpret_cast <const uint32_t*>(aEntry->Hash()))[3]), PR_htonl((reinterpret_cast <const uint32_t*>(aEntry->Hash()))[4]), aOriginAttrsHash , aAnonymous, aEntry->OriginAttrsHash(), aEntry->Anonymous ()); } } while (0) |
| 1677 | ", anonymous=%d]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::IsCollision() - Collision detected for entry hash=%08x" "%08x%08x%08x%08x, expected values: originAttrsHash=%" "l" "u" ", " "anonymous=%d; actual values: originAttrsHash=%" "l" "u" ", anonymous=%d]", PR_htonl((reinterpret_cast<const uint32_t *>(aEntry->Hash()))[0]), PR_htonl((reinterpret_cast< const uint32_t*>(aEntry->Hash()))[1]), PR_htonl((reinterpret_cast <const uint32_t*>(aEntry->Hash()))[2]), PR_htonl((reinterpret_cast <const uint32_t*>(aEntry->Hash()))[3]), PR_htonl((reinterpret_cast <const uint32_t*>(aEntry->Hash()))[4]), aOriginAttrsHash , aAnonymous, aEntry->OriginAttrsHash(), aEntry->Anonymous ()); } } while (0) |
| 1678 | LOGSHA1(aEntry->Hash()), aOriginAttrsHash, aAnonymous,do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::IsCollision() - Collision detected for entry hash=%08x" "%08x%08x%08x%08x, expected values: originAttrsHash=%" "l" "u" ", " "anonymous=%d; actual values: originAttrsHash=%" "l" "u" ", anonymous=%d]", PR_htonl((reinterpret_cast<const uint32_t *>(aEntry->Hash()))[0]), PR_htonl((reinterpret_cast< const uint32_t*>(aEntry->Hash()))[1]), PR_htonl((reinterpret_cast <const uint32_t*>(aEntry->Hash()))[2]), PR_htonl((reinterpret_cast <const uint32_t*>(aEntry->Hash()))[3]), PR_htonl((reinterpret_cast <const uint32_t*>(aEntry->Hash()))[4]), aOriginAttrsHash , aAnonymous, aEntry->OriginAttrsHash(), aEntry->Anonymous ()); } } while (0) |
| 1679 | aEntry->OriginAttrsHash(), aEntry->Anonymous()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::IsCollision() - Collision detected for entry hash=%08x" "%08x%08x%08x%08x, expected values: originAttrsHash=%" "l" "u" ", " "anonymous=%d; actual values: originAttrsHash=%" "l" "u" ", anonymous=%d]", PR_htonl((reinterpret_cast<const uint32_t *>(aEntry->Hash()))[0]), PR_htonl((reinterpret_cast< const uint32_t*>(aEntry->Hash()))[1]), PR_htonl((reinterpret_cast <const uint32_t*>(aEntry->Hash()))[2]), PR_htonl((reinterpret_cast <const uint32_t*>(aEntry->Hash()))[3]), PR_htonl((reinterpret_cast <const uint32_t*>(aEntry->Hash()))[4]), aOriginAttrsHash , aAnonymous, aEntry->OriginAttrsHash(), aEntry->Anonymous ()); } } while (0); |
| 1680 | return true; |
| 1681 | } |
| 1682 | |
| 1683 | return false; |
| 1684 | } |
| 1685 | |
| 1686 | // static |
| 1687 | bool CacheIndex::HasEntryChanged( |
| 1688 | CacheIndexEntry* aEntry, const uint32_t* aFrecency, const bool* aHasAltData, |
| 1689 | const uint32_t* aLastFetched, const uint32_t* aFetchCount, |
| 1690 | const uint8_t* aContentType, const uint32_t* aSize) { |
| 1691 | if (aFrecency && *aFrecency != aEntry->GetFrecency()) { |
| 1692 | return true; |
| 1693 | } |
| 1694 | |
| 1695 | if (aHasAltData && *aHasAltData != aEntry->GetHasAltData()) { |
| 1696 | return true; |
| 1697 | } |
| 1698 | |
| 1699 | if (aLastFetched && *aLastFetched != aEntry->GetLastFetched()) { |
| 1700 | return true; |
| 1701 | } |
| 1702 | |
| 1703 | if (aFetchCount && *aFetchCount != aEntry->GetFetchCount()) { |
| 1704 | return true; |
| 1705 | } |
| 1706 | |
| 1707 | if (aContentType && *aContentType != aEntry->GetContentType()) { |
| 1708 | return true; |
| 1709 | } |
| 1710 | |
| 1711 | if (aSize && |
| 1712 | (*aSize & CacheIndexEntry::kFileSizeMask) != aEntry->GetFileSize()) { |
| 1713 | return true; |
| 1714 | } |
| 1715 | |
| 1716 | return false; |
| 1717 | } |
| 1718 | |
| 1719 | void CacheIndex::ProcessPendingOperations( |
| 1720 | const StaticMutexAutoLock& aProofOfLock) { |
| 1721 | sLock.AssertCurrentThreadOwns(); |
| 1722 | LOG(("CacheIndex::ProcessPendingOperations()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ProcessPendingOperations()" ); } } while (0); |
| 1723 | |
| 1724 | for (auto iter = mPendingUpdates.Iter(); !iter.Done(); iter.Next()) { |
| 1725 | CacheIndexEntryUpdate* update = iter.Get(); |
| 1726 | |
| 1727 | LOG(("CacheIndex::ProcessPendingOperations() [hash=%08x%08x%08x%08x%08x]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ProcessPendingOperations() [hash=%08x%08x%08x%08x%08x]" , PR_htonl((reinterpret_cast<const uint32_t*>(update-> Hash()))[0]), PR_htonl((reinterpret_cast<const uint32_t*> (update->Hash()))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(update->Hash()))[2]), PR_htonl((reinterpret_cast <const uint32_t*>(update->Hash()))[3]), PR_htonl((reinterpret_cast <const uint32_t*>(update->Hash()))[4])); } } while ( 0) |
| 1728 | LOGSHA1(update->Hash())))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ProcessPendingOperations() [hash=%08x%08x%08x%08x%08x]" , PR_htonl((reinterpret_cast<const uint32_t*>(update-> Hash()))[0]), PR_htonl((reinterpret_cast<const uint32_t*> (update->Hash()))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(update->Hash()))[2]), PR_htonl((reinterpret_cast <const uint32_t*>(update->Hash()))[3]), PR_htonl((reinterpret_cast <const uint32_t*>(update->Hash()))[4])); } } while ( 0); |
| 1729 | |
| 1730 | MOZ_ASSERT(update->IsFresh())do { static_assert( mozilla::detail::AssertionConditionType< decltype(update->IsFresh())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(update->IsFresh()))), 0)) ) { do { } while (false); MOZ_ReportAssertionFailure("update->IsFresh()" , "./../../../netwerk/cache2/CacheIndex.cpp", 1730); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "update->IsFresh()" ")"); do { MOZ_CrashSequence (__null, 1730); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 1731 | |
| 1732 | CacheIndexEntry* entry = mIndex.GetEntry(*update->Hash()); |
| 1733 | { |
| 1734 | CacheIndexEntryAutoManage emng(update->Hash(), this, aProofOfLock); |
| 1735 | emng.DoNotSearchInUpdates(); |
| 1736 | |
| 1737 | if (update->IsRemoved()) { |
| 1738 | if (entry) { |
| 1739 | if (entry->IsRemoved()) { |
| 1740 | MOZ_ASSERT(entry->IsFresh())do { static_assert( mozilla::detail::AssertionConditionType< decltype(entry->IsFresh())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(entry->IsFresh()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("entry->IsFresh()" , "./../../../netwerk/cache2/CacheIndex.cpp", 1740); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "entry->IsFresh()" ")"); do { MOZ_CrashSequence (__null, 1740); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 1741 | MOZ_ASSERT(entry->IsDirty())do { static_assert( mozilla::detail::AssertionConditionType< decltype(entry->IsDirty())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(entry->IsDirty()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("entry->IsDirty()" , "./../../../netwerk/cache2/CacheIndex.cpp", 1741); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "entry->IsDirty()" ")"); do { MOZ_CrashSequence (__null, 1741); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 1742 | } else if (!entry->IsDirty() && entry->IsFileEmpty()) { |
| 1743 | // Entries with empty file are not stored in index on disk. Just |
| 1744 | // remove the entry, but only in case the entry is not dirty, i.e. |
| 1745 | // the entry file was empty when we wrote the index. |
| 1746 | mIndex.RemoveEntry(entry); |
| 1747 | entry = nullptr; |
| 1748 | } else { |
| 1749 | entry->MarkRemoved(); |
| 1750 | entry->MarkDirty(); |
| 1751 | entry->MarkFresh(); |
| 1752 | } |
| 1753 | } |
| 1754 | } else if (entry) { |
| 1755 | // Some information in mIndex can be newer than in mPendingUpdates (see |
| 1756 | // bug 1074832). This will copy just those values that were really |
| 1757 | // updated. |
| 1758 | update->ApplyUpdate(entry); |
| 1759 | } else { |
| 1760 | // There is no entry in mIndex, copy all information from |
| 1761 | // mPendingUpdates to mIndex. |
| 1762 | entry = mIndex.PutEntry(*update->Hash()); |
| 1763 | *entry = *update; |
| 1764 | } |
| 1765 | } |
| 1766 | iter.Remove(); |
| 1767 | } |
| 1768 | |
| 1769 | MOZ_ASSERT(mPendingUpdates.Count() == 0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mPendingUpdates.Count() == 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mPendingUpdates.Count() == 0 ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "mPendingUpdates.Count() == 0", "./../../../netwerk/cache2/CacheIndex.cpp" , 1769); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mPendingUpdates.Count() == 0" ")"); do { MOZ_CrashSequence(__null, 1769); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1770 | |
| 1771 | EnsureCorrectStats(); |
| 1772 | } |
| 1773 | |
| 1774 | bool CacheIndex::WriteIndexToDiskIfNeeded( |
| 1775 | const StaticMutexAutoLock& aProofOfLock) { |
| 1776 | sLock.AssertCurrentThreadOwns(); |
| 1777 | if (mState != READY || mShuttingDown || mRWPending) { |
| 1778 | return false; |
| 1779 | } |
| 1780 | |
| 1781 | if (mIndexStats.Dirty() == 0) { |
| 1782 | return false; |
| 1783 | } |
| 1784 | |
| 1785 | double sinceLastDump = |
| 1786 | mLastDumpTime.IsNull() |
| 1787 | ? std::numeric_limits<double>::infinity() |
| 1788 | : (TimeStamp::NowLoRes() - mLastDumpTime).ToMilliseconds(); |
| 1789 | |
| 1790 | if (sinceLastDump < |
| 1791 | StaticPrefs::browser_cache_disk_index_min_dump_interval_ms()) { |
| 1792 | return false; |
| 1793 | } |
| 1794 | |
| 1795 | // Write either once enough changes have accumulated, or once the maximum |
| 1796 | // interval has elapsed with any dirty entry. The latter is a safety net so |
| 1797 | // that recently-updated frecency is not lost on a crash or process kill under |
| 1798 | // light browsing, where the dirty-count threshold may never be reached. |
| 1799 | if (mIndexStats.Dirty() < |
| 1800 | StaticPrefs::browser_cache_disk_index_min_unwritten_changes() && |
| 1801 | sinceLastDump < |
| 1802 | StaticPrefs::browser_cache_disk_index_max_dump_interval_ms()) { |
| 1803 | return false; |
| 1804 | } |
| 1805 | |
| 1806 | WriteIndexToDisk(aProofOfLock); |
| 1807 | return true; |
| 1808 | } |
| 1809 | |
| 1810 | void CacheIndex::WriteIndexToDisk(const StaticMutexAutoLock& aProofOfLock) { |
| 1811 | sLock.AssertCurrentThreadOwns(); |
| 1812 | LOG(("CacheIndex::WriteIndexToDisk()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::WriteIndexToDisk()" ); } } while (0); |
| 1813 | mIndexStats.Log(); |
| 1814 | |
| 1815 | nsresult rv; |
| 1816 | |
| 1817 | MOZ_ASSERT(mState == READY)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mState == READY)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mState == READY))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mState == READY" , "./../../../netwerk/cache2/CacheIndex.cpp", 1817); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "mState == READY" ")"); do { MOZ_CrashSequence (__null, 1817); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 1818 | MOZ_ASSERT(!mRWBuf)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mRWBuf)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mRWBuf))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mRWBuf", "./../../../netwerk/cache2/CacheIndex.cpp" , 1818); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mRWBuf" ")" ); do { MOZ_CrashSequence(__null, 1818); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1819 | MOZ_ASSERT(!mRWHash)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mRWHash)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mRWHash))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mRWHash", "./../../../netwerk/cache2/CacheIndex.cpp" , 1819); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mRWHash" ")" ); do { MOZ_CrashSequence(__null, 1819); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1820 | MOZ_ASSERT(!mRWPending)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mRWPending)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mRWPending))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mRWPending", "./../../../netwerk/cache2/CacheIndex.cpp" , 1820); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mRWPending" ")"); do { MOZ_CrashSequence(__null, 1820); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1821 | |
| 1822 | ChangeState(WRITING, aProofOfLock); |
| 1823 | |
| 1824 | mProcessEntries = mIndexStats.ActiveEntriesCount(); |
| 1825 | |
| 1826 | mIndexFileOpener = new FileOpenHelper(this); |
| 1827 | rv = CacheFileIOManager::OpenFile( |
| 1828 | nsLiteralCString(TEMP_INDEX_NAME"index.tmp"), |
| 1829 | CacheFileIOManager::SPECIAL_FILE | CacheFileIOManager::CREATE, |
| 1830 | mIndexFileOpener); |
| 1831 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 1832 | LOG(("CacheIndex::WriteIndexToDisk() - Can't open file [rv=0x%08" PRIx32do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::WriteIndexToDisk() - Can't open file [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while (0) |
| 1833 | "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::WriteIndexToDisk() - Can't open file [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while (0) |
| 1834 | static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::WriteIndexToDisk() - Can't open file [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while (0); |
| 1835 | FinishWrite(false, aProofOfLock); |
| 1836 | return; |
| 1837 | } |
| 1838 | |
| 1839 | // Write index header to a buffer, it will be written to disk together with |
| 1840 | // records in WriteRecords() once we open the file successfully. |
| 1841 | AllocBuffer(); |
| 1842 | mRWHash = new CacheHash(); |
| 1843 | |
| 1844 | mRWBufPos = 0; |
| 1845 | // index version |
| 1846 | NetworkEndian::writeUint32(mRWBuf + mRWBufPos, kIndexVersion0x0000000D); |
| 1847 | mRWBufPos += sizeof(uint32_t); |
| 1848 | // timestamp |
| 1849 | NetworkEndian::writeUint32(mRWBuf + mRWBufPos, |
| 1850 | static_cast<uint32_t>(PR_Now() / PR_USEC_PER_SEC1000000L)); |
| 1851 | mRWBufPos += sizeof(uint32_t); |
| 1852 | // dirty flag |
| 1853 | NetworkEndian::writeUint32(mRWBuf + mRWBufPos, 1); |
| 1854 | mRWBufPos += sizeof(uint32_t); |
| 1855 | // amount of data written to the cache |
| 1856 | NetworkEndian::writeUint32(mRWBuf + mRWBufPos, |
| 1857 | static_cast<uint32_t>(mTotalBytesWritten >> 10)); |
| 1858 | mRWBufPos += sizeof(uint32_t); |
| 1859 | // Whether the entries on disk are encrypted at rest. This is the session's |
| 1860 | // captured pref value, which is fixed at startup -- a mid-session flip only |
| 1861 | // takes effect on the next restart, so reading the live pref here would mask |
| 1862 | // it. Deliberately not IsActive(): a session where encryption is enabled but |
| 1863 | // no cipher could be loaded writes no entries at all, since |
| 1864 | // CacheFile::SetupEncryption() fails them closed, so the entries on disk are |
| 1865 | // still the encrypted ones an earlier session wrote. |
| 1866 | NetworkEndian::writeUint32(mRWBuf + mRWBufPos, |
| 1867 | CacheCrypto::IsEnabled() ? 1 : 0); |
| 1868 | mRWBufPos += sizeof(uint32_t); |
| 1869 | |
| 1870 | mSkipEntries = 0; |
| 1871 | } |
| 1872 | |
| 1873 | void CacheIndex::WriteRecords(const StaticMutexAutoLock& aProofOfLock) { |
| 1874 | sLock.AssertCurrentThreadOwns(); |
| 1875 | LOG(("CacheIndex::WriteRecords()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::WriteRecords()" ); } } while (0); |
| 1876 | |
| 1877 | nsresult rv; |
| 1878 | |
| 1879 | MOZ_ASSERT(mState == WRITING)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mState == WRITING)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mState == WRITING))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mState == WRITING" , "./../../../netwerk/cache2/CacheIndex.cpp", 1879); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "mState == WRITING" ")"); do { MOZ_CrashSequence (__null, 1879); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 1880 | MOZ_ASSERT(!mRWPending)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mRWPending)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mRWPending))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mRWPending", "./../../../netwerk/cache2/CacheIndex.cpp" , 1880); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mRWPending" ")"); do { MOZ_CrashSequence(__null, 1880); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1881 | |
| 1882 | int64_t fileOffset; |
| 1883 | |
| 1884 | if (mSkipEntries) { |
| 1885 | MOZ_ASSERT(mRWBufPos == 0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mRWBufPos == 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mRWBufPos == 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mRWBufPos == 0" , "./../../../netwerk/cache2/CacheIndex.cpp", 1885); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "mRWBufPos == 0" ")"); do { MOZ_CrashSequence (__null, 1885); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 1886 | fileOffset = sizeof(CacheIndexHeader); |
| 1887 | fileOffset += sizeof(CacheIndexRecord) * mSkipEntries; |
| 1888 | } else { |
| 1889 | MOZ_ASSERT(mRWBufPos == sizeof(CacheIndexHeader))do { static_assert( mozilla::detail::AssertionConditionType< decltype(mRWBufPos == sizeof(CacheIndexHeader))>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(! !(mRWBufPos == sizeof(CacheIndexHeader)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mRWBufPos == sizeof(CacheIndexHeader)" , "./../../../netwerk/cache2/CacheIndex.cpp", 1889); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "mRWBufPos == sizeof(CacheIndexHeader)" ")" ); do { MOZ_CrashSequence(__null, 1889); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1890 | fileOffset = 0; |
| 1891 | } |
| 1892 | uint32_t hashOffset = mRWBufPos; |
| 1893 | |
| 1894 | char* buf = mRWBuf + mRWBufPos; |
| 1895 | uint32_t skip = mSkipEntries; |
| 1896 | uint32_t processMax = (mRWBufSize - mRWBufPos) / sizeof(CacheIndexRecord); |
| 1897 | MOZ_ASSERT(processMax != 0 ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(processMax != 0 || mProcessEntries == 0)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(processMax != 0 || mProcessEntries == 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("processMax != 0 || mProcessEntries == 0" , "./../../../netwerk/cache2/CacheIndex.cpp", 1899); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "processMax != 0 || mProcessEntries == 0" ")" ); do { MOZ_CrashSequence(__null, 1899); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
| 1898 | mProcessEntries ==do { static_assert( mozilla::detail::AssertionConditionType< decltype(processMax != 0 || mProcessEntries == 0)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(processMax != 0 || mProcessEntries == 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("processMax != 0 || mProcessEntries == 0" , "./../../../netwerk/cache2/CacheIndex.cpp", 1899); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "processMax != 0 || mProcessEntries == 0" ")" ); do { MOZ_CrashSequence(__null, 1899); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
| 1899 | 0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(processMax != 0 || mProcessEntries == 0)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(processMax != 0 || mProcessEntries == 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("processMax != 0 || mProcessEntries == 0" , "./../../../netwerk/cache2/CacheIndex.cpp", 1899); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "processMax != 0 || mProcessEntries == 0" ")" ); do { MOZ_CrashSequence(__null, 1899); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); // TODO make sure we can write an empty index |
| 1900 | uint32_t processed = 0; |
| 1901 | #ifdef DEBUG1 |
| 1902 | bool hasMore = false; |
| 1903 | #endif |
| 1904 | for (auto iter = mIndex.Iter(); !iter.Done(); iter.Next()) { |
| 1905 | CacheIndexEntry* entry = iter.Get(); |
| 1906 | if (entry->IsRemoved() || !entry->IsInitialized() || entry->IsFileEmpty()) { |
| 1907 | continue; |
| 1908 | } |
| 1909 | |
| 1910 | if (skip) { |
| 1911 | skip--; |
| 1912 | continue; |
| 1913 | } |
| 1914 | |
| 1915 | if (processed == processMax) { |
| 1916 | #ifdef DEBUG1 |
| 1917 | hasMore = true; |
| 1918 | #endif |
| 1919 | break; |
| 1920 | } |
| 1921 | |
| 1922 | entry->WriteToBuf(buf); |
| 1923 | buf += sizeof(CacheIndexRecord); |
| 1924 | processed++; |
| 1925 | } |
| 1926 | |
| 1927 | MOZ_ASSERT(mRWBufPos != static_cast<uint32_t>(buf - mRWBuf) ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(mRWBufPos != static_cast<uint32_t>(buf - mRWBuf ) || mProcessEntries == 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mRWBufPos != static_cast< uint32_t>(buf - mRWBuf) || mProcessEntries == 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mRWBufPos != static_cast<uint32_t>(buf - mRWBuf) || mProcessEntries == 0" , "./../../../netwerk/cache2/CacheIndex.cpp", 1928); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "mRWBufPos != static_cast<uint32_t>(buf - mRWBuf) || mProcessEntries == 0" ")"); do { MOZ_CrashSequence(__null, 1928); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
| 1928 | mProcessEntries == 0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mRWBufPos != static_cast<uint32_t>(buf - mRWBuf ) || mProcessEntries == 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mRWBufPos != static_cast< uint32_t>(buf - mRWBuf) || mProcessEntries == 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mRWBufPos != static_cast<uint32_t>(buf - mRWBuf) || mProcessEntries == 0" , "./../../../netwerk/cache2/CacheIndex.cpp", 1928); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "mRWBufPos != static_cast<uint32_t>(buf - mRWBuf) || mProcessEntries == 0" ")"); do { MOZ_CrashSequence(__null, 1928); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1929 | mRWBufPos = buf - mRWBuf; |
| 1930 | mSkipEntries += processed; |
| 1931 | MOZ_ASSERT(mSkipEntries <= mProcessEntries)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mSkipEntries <= mProcessEntries)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mSkipEntries <= mProcessEntries ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "mSkipEntries <= mProcessEntries", "./../../../netwerk/cache2/CacheIndex.cpp" , 1931); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mSkipEntries <= mProcessEntries" ")"); do { MOZ_CrashSequence(__null, 1931); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1932 | |
| 1933 | mRWHash->Update(mRWBuf + hashOffset, mRWBufPos - hashOffset); |
| 1934 | |
| 1935 | if (mSkipEntries == mProcessEntries) { |
| 1936 | MOZ_ASSERT(!hasMore)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!hasMore)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!hasMore))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!hasMore", "./../../../netwerk/cache2/CacheIndex.cpp" , 1936); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!hasMore" ")" ); do { MOZ_CrashSequence(__null, 1936); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1937 | |
| 1938 | // We've processed all records |
| 1939 | if (mRWBufPos + sizeof(CacheHash::Hash32_t) > mRWBufSize) { |
| 1940 | // realloc buffer to spare another write cycle |
| 1941 | mRWBufSize = mRWBufPos + sizeof(CacheHash::Hash32_t); |
| 1942 | mRWBuf = static_cast<char*>(moz_xrealloc(mRWBuf, mRWBufSize)); |
| 1943 | } |
| 1944 | |
| 1945 | NetworkEndian::writeUint32(mRWBuf + mRWBufPos, mRWHash->GetHash()); |
| 1946 | mRWBufPos += sizeof(CacheHash::Hash32_t); |
| 1947 | } else { |
| 1948 | MOZ_ASSERT(hasMore)do { static_assert( mozilla::detail::AssertionConditionType< decltype(hasMore)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(hasMore))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("hasMore", "./../../../netwerk/cache2/CacheIndex.cpp" , 1948); AnnotateMozCrashReason("MOZ_ASSERT" "(" "hasMore" ")" ); do { MOZ_CrashSequence(__null, 1948); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1949 | } |
| 1950 | |
| 1951 | rv = CacheFileIOManager::Write(mIndexHandle, fileOffset, mRWBuf, mRWBufPos, |
| 1952 | mSkipEntries == mProcessEntries, false, this); |
| 1953 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 1954 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::WriteRecords() - CacheFileIOManager::Write() failed " "synchronously [rv=0x%08" "x" "]", static_cast<uint32_t> (rv)); } } while (0) |
| 1955 | ("CacheIndex::WriteRecords() - CacheFileIOManager::Write() failed "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::WriteRecords() - CacheFileIOManager::Write() failed " "synchronously [rv=0x%08" "x" "]", static_cast<uint32_t> (rv)); } } while (0) |
| 1956 | "synchronously [rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::WriteRecords() - CacheFileIOManager::Write() failed " "synchronously [rv=0x%08" "x" "]", static_cast<uint32_t> (rv)); } } while (0) |
| 1957 | static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::WriteRecords() - CacheFileIOManager::Write() failed " "synchronously [rv=0x%08" "x" "]", static_cast<uint32_t> (rv)); } } while (0); |
| 1958 | FinishWrite(false, aProofOfLock); |
| 1959 | } else { |
| 1960 | mRWPending = true; |
| 1961 | } |
| 1962 | |
| 1963 | mRWBufPos = 0; |
| 1964 | } |
| 1965 | |
| 1966 | void CacheIndex::FinishWrite(bool aSucceeded, |
| 1967 | const StaticMutexAutoLock& aProofOfLock) { |
| 1968 | sLock.AssertCurrentThreadOwns(); |
| 1969 | LOG(("CacheIndex::FinishWrite() [succeeded=%d]", aSucceeded))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::FinishWrite() [succeeded=%d]" , aSucceeded); } } while (0); |
| 1970 | |
| 1971 | MOZ_ASSERT((!aSucceeded && mState == SHUTDOWN) || mState == WRITING)do { static_assert( mozilla::detail::AssertionConditionType< decltype((!aSucceeded && mState == SHUTDOWN) || mState == WRITING)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!((!aSucceeded && mState == SHUTDOWN) || mState == WRITING))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("(!aSucceeded && mState == SHUTDOWN) || mState == WRITING" , "./../../../netwerk/cache2/CacheIndex.cpp", 1971); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "(!aSucceeded && mState == SHUTDOWN) || mState == WRITING" ")"); do { MOZ_CrashSequence(__null, 1971); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1972 | |
| 1973 | // If there is write operation pending we must be cancelling writing of the |
| 1974 | // index when shutting down or removing the whole index. |
| 1975 | MOZ_ASSERT(!mRWPending || (!aSucceeded && (mShuttingDown || mRemovingAll)))do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mRWPending || (!aSucceeded && (mShuttingDown || mRemovingAll)))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mRWPending || (!aSucceeded && (mShuttingDown || mRemovingAll))))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("!mRWPending || (!aSucceeded && (mShuttingDown || mRemovingAll))" , "./../../../netwerk/cache2/CacheIndex.cpp", 1975); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!mRWPending || (!aSucceeded && (mShuttingDown || mRemovingAll))" ")"); do { MOZ_CrashSequence(__null, 1975); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 1976 | |
| 1977 | mIndexHandle = nullptr; |
| 1978 | mRWHash = nullptr; |
| 1979 | ReleaseBuffer(); |
| 1980 | |
| 1981 | if (aSucceeded) { |
| 1982 | // Opening of the file must not be in progress if writing succeeded. |
| 1983 | MOZ_ASSERT(!mIndexFileOpener)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mIndexFileOpener)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mIndexFileOpener))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mIndexFileOpener" , "./../../../netwerk/cache2/CacheIndex.cpp", 1983); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!mIndexFileOpener" ")"); do { MOZ_CrashSequence (__null, 1983); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 1984 | |
| 1985 | for (auto iter = mIndex.Iter(); !iter.Done(); iter.Next()) { |
| 1986 | CacheIndexEntry* entry = iter.Get(); |
| 1987 | |
| 1988 | bool remove = false; |
| 1989 | { |
| 1990 | CacheIndexEntryAutoManage emng(entry->Hash(), this, aProofOfLock); |
| 1991 | |
| 1992 | if (entry->IsRemoved()) { |
| 1993 | emng.DoNotSearchInIndex(); |
| 1994 | remove = true; |
| 1995 | } else if (entry->IsDirty()) { |
| 1996 | entry->ClearDirty(); |
| 1997 | } |
| 1998 | } |
| 1999 | if (remove) { |
| 2000 | iter.Remove(); |
| 2001 | } |
| 2002 | } |
| 2003 | |
| 2004 | mIndexOnDiskIsValid = true; |
| 2005 | } else { |
| 2006 | if (mIndexFileOpener) { |
| 2007 | // If opening of the file is still in progress (e.g. WRITE process was |
| 2008 | // canceled by RemoveAll()) then we need to cancel the opener to make sure |
| 2009 | // that OnFileOpenedInternal() won't be called. |
| 2010 | mIndexFileOpener->Cancel(); |
| 2011 | mIndexFileOpener = nullptr; |
| 2012 | } |
| 2013 | } |
| 2014 | |
| 2015 | ProcessPendingOperations(aProofOfLock); |
| 2016 | mIndexStats.Log(); |
| 2017 | |
| 2018 | if (mState == WRITING) { |
| 2019 | ChangeState(READY, aProofOfLock); |
| 2020 | mLastDumpTime = TimeStamp::NowLoRes(); |
| 2021 | } |
| 2022 | } |
| 2023 | |
| 2024 | nsresult CacheIndex::GetFile(const nsACString& aName, nsIFile** _retval) { |
| 2025 | nsresult rv; |
| 2026 | |
| 2027 | nsCOMPtr<nsIFile> file; |
| 2028 | rv = mCacheDirectory->Clone(getter_AddRefs(file)); |
| 2029 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 2029); return rv; } } while (false); |
| 2030 | |
| 2031 | rv = file->AppendNative(aName); |
| 2032 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 2032); return rv; } } while (false); |
| 2033 | |
| 2034 | file.swap(*_retval); |
| 2035 | return NS_OK; |
| 2036 | } |
| 2037 | |
| 2038 | void CacheIndex::RemoveFile(const nsACString& aName) { |
| 2039 | MOZ_ASSERT(mState == SHUTDOWN)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mState == SHUTDOWN)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mState == SHUTDOWN))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mState == SHUTDOWN" , "./../../../netwerk/cache2/CacheIndex.cpp", 2039); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "mState == SHUTDOWN" ")"); do { MOZ_CrashSequence (__null, 2039); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 2040 | |
| 2041 | nsresult rv; |
| 2042 | |
| 2043 | nsCOMPtr<nsIFile> file; |
| 2044 | rv = GetFile(aName, getter_AddRefs(file)); |
| 2045 | NS_ENSURE_SUCCESS_VOID(rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS_VOID(%s) failed with " "result 0x%" "X" "%s%s%s", "rv", static_cast<uint32_t> (__rv), name ? " (" : "", name ? name : "", name ? ")" : ""); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 2045); return; } } while (false); |
| 2046 | |
| 2047 | rv = file->Remove(false); |
| 2048 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0))) && rv != NS_ERROR_FILE_NOT_FOUND) { |
| 2049 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveFile() - Cannot remove old entry file from disk " "[rv=0x%08" "x" ", name=%s]", static_cast<uint32_t>(rv ), TPromiseFlatString<char>(aName).get()); } } while (0 ) |
| 2050 | ("CacheIndex::RemoveFile() - Cannot remove old entry file from disk "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveFile() - Cannot remove old entry file from disk " "[rv=0x%08" "x" ", name=%s]", static_cast<uint32_t>(rv ), TPromiseFlatString<char>(aName).get()); } } while (0 ) |
| 2051 | "[rv=0x%08" PRIx32 ", name=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveFile() - Cannot remove old entry file from disk " "[rv=0x%08" "x" ", name=%s]", static_cast<uint32_t>(rv ), TPromiseFlatString<char>(aName).get()); } } while (0 ) |
| 2052 | static_cast<uint32_t>(rv), PromiseFlatCString(aName).get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveFile() - Cannot remove old entry file from disk " "[rv=0x%08" "x" ", name=%s]", static_cast<uint32_t>(rv ), TPromiseFlatString<char>(aName).get()); } } while (0 ); |
| 2053 | } |
| 2054 | } |
| 2055 | |
| 2056 | void CacheIndex::RemoveAllIndexFiles() { |
| 2057 | LOG(("CacheIndex::RemoveAllIndexFiles()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveAllIndexFiles()" ); } } while (0); |
| 2058 | RemoveFile(nsLiteralCString(INDEX_NAME"index")); |
| 2059 | RemoveJournalAndTempFile(); |
| 2060 | } |
| 2061 | |
| 2062 | void CacheIndex::RemoveJournalAndTempFile() { |
| 2063 | LOG(("CacheIndex::RemoveJournalAndTempFile()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveJournalAndTempFile()" ); } } while (0); |
| 2064 | RemoveFile(nsLiteralCString(TEMP_INDEX_NAME"index.tmp")); |
| 2065 | RemoveFile(nsLiteralCString(JOURNAL_NAME"index.log")); |
| 2066 | } |
| 2067 | |
| 2068 | class WriteLogHelper { |
| 2069 | public: |
| 2070 | explicit WriteLogHelper(PRFileDesc* aFD) |
| 2071 | : mFD(aFD), mBufSize(kMaxBufSize16384), mBufPos(0) { |
| 2072 | mHash = new CacheHash(); |
| 2073 | mBuf = static_cast<char*>(moz_xmalloc(mBufSize)); |
| 2074 | } |
| 2075 | |
| 2076 | ~WriteLogHelper() { free(mBuf); } |
| 2077 | |
| 2078 | nsresult AddEntry(CacheIndexEntry* aEntry); |
| 2079 | nsresult Finish(); |
| 2080 | |
| 2081 | private: |
| 2082 | nsresult FlushBuffer(); |
| 2083 | |
| 2084 | PRFileDesc* mFD; |
| 2085 | char* mBuf; |
| 2086 | uint32_t mBufSize; |
| 2087 | int32_t mBufPos; |
| 2088 | RefPtr<CacheHash> mHash; |
| 2089 | }; |
| 2090 | |
| 2091 | nsresult WriteLogHelper::AddEntry(CacheIndexEntry* aEntry) { |
| 2092 | nsresult rv; |
| 2093 | |
| 2094 | if (mBufPos + sizeof(CacheIndexRecord) > mBufSize) { |
| 2095 | mHash->Update(mBuf, mBufPos); |
| 2096 | |
| 2097 | rv = FlushBuffer(); |
| 2098 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 2098); return rv; } } while (false); |
| 2099 | MOZ_ASSERT(mBufPos + sizeof(CacheIndexRecord) <= mBufSize)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mBufPos + sizeof(CacheIndexRecord) <= mBufSize)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(mBufPos + sizeof(CacheIndexRecord) <= mBufSize))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("mBufPos + sizeof(CacheIndexRecord) <= mBufSize" , "./../../../netwerk/cache2/CacheIndex.cpp", 2099); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "mBufPos + sizeof(CacheIndexRecord) <= mBufSize" ")"); do { MOZ_CrashSequence(__null, 2099); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 2100 | } |
| 2101 | |
| 2102 | aEntry->WriteToBuf(mBuf + mBufPos); |
| 2103 | mBufPos += sizeof(CacheIndexRecord); |
| 2104 | |
| 2105 | return NS_OK; |
| 2106 | } |
| 2107 | |
| 2108 | nsresult WriteLogHelper::Finish() { |
| 2109 | nsresult rv; |
| 2110 | |
| 2111 | mHash->Update(mBuf, mBufPos); |
| 2112 | if (mBufPos + sizeof(CacheHash::Hash32_t) > mBufSize) { |
| 2113 | rv = FlushBuffer(); |
| 2114 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 2114); return rv; } } while (false); |
| 2115 | MOZ_ASSERT(mBufPos + sizeof(CacheHash::Hash32_t) <= mBufSize)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mBufPos + sizeof(CacheHash::Hash32_t) <= mBufSize )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(mBufPos + sizeof(CacheHash::Hash32_t) <= mBufSize ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "mBufPos + sizeof(CacheHash::Hash32_t) <= mBufSize", "./../../../netwerk/cache2/CacheIndex.cpp" , 2115); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mBufPos + sizeof(CacheHash::Hash32_t) <= mBufSize" ")"); do { MOZ_CrashSequence(__null, 2115); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 2116 | } |
| 2117 | |
| 2118 | NetworkEndian::writeUint32(mBuf + mBufPos, mHash->GetHash()); |
| 2119 | mBufPos += sizeof(CacheHash::Hash32_t); |
| 2120 | |
| 2121 | rv = FlushBuffer(); |
| 2122 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 2122); return rv; } } while (false); |
| 2123 | |
| 2124 | return NS_OK; |
| 2125 | } |
| 2126 | |
| 2127 | nsresult WriteLogHelper::FlushBuffer() { |
| 2128 | if (CacheObserver::IsPastShutdownIOLag()) { |
| 2129 | LOG(("WriteLogHelper::FlushBuffer() - Interrupting writing journal."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "WriteLogHelper::FlushBuffer() - Interrupting writing journal." ); } } while (0); |
| 2130 | return NS_ERROR_FAILURE; |
| 2131 | } |
| 2132 | |
| 2133 | int32_t bytesWritten = PR_Write(mFD, mBuf, mBufPos); |
| 2134 | |
| 2135 | if (bytesWritten != mBufPos) { |
| 2136 | return NS_ERROR_FAILURE; |
| 2137 | } |
| 2138 | |
| 2139 | mBufPos = 0; |
| 2140 | return NS_OK; |
| 2141 | } |
| 2142 | |
| 2143 | nsresult CacheIndex::WriteLogToDisk() { |
| 2144 | LOG(("CacheIndex::WriteLogToDisk()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::WriteLogToDisk()" ); } } while (0); |
| 2145 | |
| 2146 | nsresult rv; |
| 2147 | |
| 2148 | MOZ_ASSERT(mPendingUpdates.Count() == 0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mPendingUpdates.Count() == 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mPendingUpdates.Count() == 0 ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "mPendingUpdates.Count() == 0", "./../../../netwerk/cache2/CacheIndex.cpp" , 2148); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mPendingUpdates.Count() == 0" ")"); do { MOZ_CrashSequence(__null, 2148); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 2149 | MOZ_ASSERT(mState == SHUTDOWN)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mState == SHUTDOWN)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mState == SHUTDOWN))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mState == SHUTDOWN" , "./../../../netwerk/cache2/CacheIndex.cpp", 2149); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "mState == SHUTDOWN" ")"); do { MOZ_CrashSequence (__null, 2149); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 2150 | |
| 2151 | if (CacheObserver::IsPastShutdownIOLag()) { |
| 2152 | LOG(("CacheIndex::WriteLogToDisk() - Skipping writing journal."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::WriteLogToDisk() - Skipping writing journal." ); } } while (0); |
| 2153 | return NS_ERROR_FAILURE; |
| 2154 | } |
| 2155 | |
| 2156 | RemoveFile(nsLiteralCString(TEMP_INDEX_NAME"index.tmp")); |
| 2157 | |
| 2158 | nsCOMPtr<nsIFile> indexFile; |
| 2159 | rv = GetFile(nsLiteralCString(INDEX_NAME"index"), getter_AddRefs(indexFile)); |
| 2160 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 2160); return rv; } } while (false); |
| 2161 | |
| 2162 | nsCOMPtr<nsIFile> logFile; |
| 2163 | rv = GetFile(nsLiteralCString(JOURNAL_NAME"index.log"), getter_AddRefs(logFile)); |
| 2164 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 2164); return rv; } } while (false); |
| 2165 | |
| 2166 | mIndexStats.Log(); |
| 2167 | |
| 2168 | PRFileDesc* fd = nullptr; |
| 2169 | rv = logFile->OpenNSPRFileDesc(PR_RDWR0x04 | PR_CREATE_FILE0x08 | PR_TRUNCATE0x20, 0600, |
| 2170 | &fd); |
| 2171 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 2171); return rv; } } while (false); |
| 2172 | |
| 2173 | WriteLogHelper wlh(fd); |
| 2174 | for (auto iter = mIndex.Iter(); !iter.Done(); iter.Next()) { |
| 2175 | CacheIndexEntry* entry = iter.Get(); |
| 2176 | if (entry->IsRemoved() || entry->IsDirty()) { |
| 2177 | rv = wlh.AddEntry(entry); |
| 2178 | if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv )), 0))), "NS_FAILED(rv)", "./../../../netwerk/cache2/CacheIndex.cpp" , 2178)) { |
| 2179 | return rv; |
| 2180 | } |
| 2181 | } |
| 2182 | } |
| 2183 | |
| 2184 | rv = wlh.Finish(); |
| 2185 | PR_Close(fd); |
| 2186 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 2186); return rv; } } while (false); |
| 2187 | |
| 2188 | rv = indexFile->OpenNSPRFileDesc(PR_RDWR0x04, 0600, &fd); |
| 2189 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 2189); return rv; } } while (false); |
| 2190 | |
| 2191 | // Seek to dirty flag in the index header and clear it. |
| 2192 | static_assert(2 * sizeof(uint32_t) == offsetof(CacheIndexHeader, mIsDirty)__builtin_offsetof(CacheIndexHeader, mIsDirty), |
| 2193 | "Unexpected offset of CacheIndexHeader::mIsDirty"); |
| 2194 | int64_t offset = PR_Seek64(fd, 2 * sizeof(uint32_t), PR_SEEK_SET); |
| 2195 | if (offset == -1) { |
| 2196 | PR_Close(fd); |
| 2197 | return NS_ERROR_FAILURE; |
| 2198 | } |
| 2199 | |
| 2200 | uint32_t isDirty = 0; |
| 2201 | int32_t bytesWritten = PR_Write(fd, &isDirty, sizeof(isDirty)); |
| 2202 | PR_Close(fd); |
| 2203 | if (bytesWritten != sizeof(isDirty)) { |
| 2204 | return NS_ERROR_FAILURE; |
| 2205 | } |
| 2206 | |
| 2207 | return NS_OK; |
| 2208 | } |
| 2209 | |
| 2210 | void CacheIndex::ReadIndexFromDisk(const StaticMutexAutoLock& aProofOfLock) { |
| 2211 | sLock.AssertCurrentThreadOwns(); |
| 2212 | LOG(("CacheIndex::ReadIndexFromDisk()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ReadIndexFromDisk()" ); } } while (0); |
| 2213 | |
| 2214 | nsresult rv; |
| 2215 | |
| 2216 | MOZ_ASSERT(mState == INITIAL)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mState == INITIAL)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mState == INITIAL))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mState == INITIAL" , "./../../../netwerk/cache2/CacheIndex.cpp", 2216); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "mState == INITIAL" ")"); do { MOZ_CrashSequence (__null, 2216); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 2217 | |
| 2218 | ChangeState(READING, aProofOfLock); |
| 2219 | |
| 2220 | mIndexFileOpener = new FileOpenHelper(this); |
| 2221 | rv = CacheFileIOManager::OpenFile( |
| 2222 | nsLiteralCString(INDEX_NAME"index"), |
| 2223 | CacheFileIOManager::SPECIAL_FILE | CacheFileIOManager::OPEN, |
| 2224 | mIndexFileOpener); |
| 2225 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 2226 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ReadIndexFromDisk() - CacheFileIOManager::OpenFile() " "failed [rv=0x%08" "x" ", file=%s]", static_cast<uint32_t >(rv), "index"); } } while (0) |
| 2227 | ("CacheIndex::ReadIndexFromDisk() - CacheFileIOManager::OpenFile() "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ReadIndexFromDisk() - CacheFileIOManager::OpenFile() " "failed [rv=0x%08" "x" ", file=%s]", static_cast<uint32_t >(rv), "index"); } } while (0) |
| 2228 | "failed [rv=0x%08" PRIx32 ", file=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ReadIndexFromDisk() - CacheFileIOManager::OpenFile() " "failed [rv=0x%08" "x" ", file=%s]", static_cast<uint32_t >(rv), "index"); } } while (0) |
| 2229 | static_cast<uint32_t>(rv), INDEX_NAME))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ReadIndexFromDisk() - CacheFileIOManager::OpenFile() " "failed [rv=0x%08" "x" ", file=%s]", static_cast<uint32_t >(rv), "index"); } } while (0); |
| 2230 | FinishRead(false, aProofOfLock); |
| 2231 | return; |
| 2232 | } |
| 2233 | |
| 2234 | mJournalFileOpener = new FileOpenHelper(this); |
| 2235 | rv = CacheFileIOManager::OpenFile( |
| 2236 | nsLiteralCString(JOURNAL_NAME"index.log"), |
| 2237 | CacheFileIOManager::SPECIAL_FILE | CacheFileIOManager::OPEN, |
| 2238 | mJournalFileOpener); |
| 2239 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 2240 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ReadIndexFromDisk() - CacheFileIOManager::OpenFile() " "failed [rv=0x%08" "x" ", file=%s]", static_cast<uint32_t >(rv), "index.log"); } } while (0) |
| 2241 | ("CacheIndex::ReadIndexFromDisk() - CacheFileIOManager::OpenFile() "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ReadIndexFromDisk() - CacheFileIOManager::OpenFile() " "failed [rv=0x%08" "x" ", file=%s]", static_cast<uint32_t >(rv), "index.log"); } } while (0) |
| 2242 | "failed [rv=0x%08" PRIx32 ", file=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ReadIndexFromDisk() - CacheFileIOManager::OpenFile() " "failed [rv=0x%08" "x" ", file=%s]", static_cast<uint32_t >(rv), "index.log"); } } while (0) |
| 2243 | static_cast<uint32_t>(rv), JOURNAL_NAME))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ReadIndexFromDisk() - CacheFileIOManager::OpenFile() " "failed [rv=0x%08" "x" ", file=%s]", static_cast<uint32_t >(rv), "index.log"); } } while (0); |
| 2244 | FinishRead(false, aProofOfLock); |
| 2245 | } |
| 2246 | |
| 2247 | mTmpFileOpener = new FileOpenHelper(this); |
| 2248 | rv = CacheFileIOManager::OpenFile( |
| 2249 | nsLiteralCString(TEMP_INDEX_NAME"index.tmp"), |
| 2250 | CacheFileIOManager::SPECIAL_FILE | CacheFileIOManager::OPEN, |
| 2251 | mTmpFileOpener); |
| 2252 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 2253 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ReadIndexFromDisk() - CacheFileIOManager::OpenFile() " "failed [rv=0x%08" "x" ", file=%s]", static_cast<uint32_t >(rv), "index.tmp"); } } while (0) |
| 2254 | ("CacheIndex::ReadIndexFromDisk() - CacheFileIOManager::OpenFile() "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ReadIndexFromDisk() - CacheFileIOManager::OpenFile() " "failed [rv=0x%08" "x" ", file=%s]", static_cast<uint32_t >(rv), "index.tmp"); } } while (0) |
| 2255 | "failed [rv=0x%08" PRIx32 ", file=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ReadIndexFromDisk() - CacheFileIOManager::OpenFile() " "failed [rv=0x%08" "x" ", file=%s]", static_cast<uint32_t >(rv), "index.tmp"); } } while (0) |
| 2256 | static_cast<uint32_t>(rv), TEMP_INDEX_NAME))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ReadIndexFromDisk() - CacheFileIOManager::OpenFile() " "failed [rv=0x%08" "x" ", file=%s]", static_cast<uint32_t >(rv), "index.tmp"); } } while (0); |
| 2257 | FinishRead(false, aProofOfLock); |
| 2258 | } |
| 2259 | } |
| 2260 | |
| 2261 | void CacheIndex::StartReadingIndex(const StaticMutexAutoLock& aProofOfLock) { |
| 2262 | sLock.AssertCurrentThreadOwns(); |
| 2263 | LOG(("CacheIndex::StartReadingIndex()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartReadingIndex()" ); } } while (0); |
| 2264 | |
| 2265 | nsresult rv; |
| 2266 | |
| 2267 | MOZ_ASSERT(mIndexHandle)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mIndexHandle)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mIndexHandle))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mIndexHandle", "./../../../netwerk/cache2/CacheIndex.cpp" , 2267); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIndexHandle" ")"); do { MOZ_CrashSequence(__null, 2267); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 2268 | MOZ_ASSERT(mState == READING)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mState == READING)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mState == READING))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mState == READING" , "./../../../netwerk/cache2/CacheIndex.cpp", 2268); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "mState == READING" ")"); do { MOZ_CrashSequence (__null, 2268); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 2269 | MOZ_ASSERT(!mIndexOnDiskIsValid)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mIndexOnDiskIsValid)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mIndexOnDiskIsValid))), 0)) ) { do { } while (false); MOZ_ReportAssertionFailure("!mIndexOnDiskIsValid" , "./../../../netwerk/cache2/CacheIndex.cpp", 2269); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!mIndexOnDiskIsValid" ")"); do { MOZ_CrashSequence (__null, 2269); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 2270 | MOZ_ASSERT(!mDontMarkIndexClean)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mDontMarkIndexClean)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mDontMarkIndexClean))), 0)) ) { do { } while (false); MOZ_ReportAssertionFailure("!mDontMarkIndexClean" , "./../../../netwerk/cache2/CacheIndex.cpp", 2270); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!mDontMarkIndexClean" ")"); do { MOZ_CrashSequence (__null, 2270); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 2271 | MOZ_ASSERT(!mJournalReadSuccessfully)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mJournalReadSuccessfully)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mJournalReadSuccessfully))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mJournalReadSuccessfully" , "./../../../netwerk/cache2/CacheIndex.cpp", 2271); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!mJournalReadSuccessfully" ")"); do { MOZ_CrashSequence (__null, 2271); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 2272 | MOZ_ASSERT(mIndexHandle->FileSize() >= 0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mIndexHandle->FileSize() >= 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mIndexHandle->FileSize() >= 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("mIndexHandle->FileSize() >= 0", "./../../../netwerk/cache2/CacheIndex.cpp" , 2272); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIndexHandle->FileSize() >= 0" ")"); do { MOZ_CrashSequence(__null, 2272); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 2273 | MOZ_ASSERT(!mRWPending)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mRWPending)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mRWPending))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mRWPending", "./../../../netwerk/cache2/CacheIndex.cpp" , 2273); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mRWPending" ")"); do { MOZ_CrashSequence(__null, 2273); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 2274 | |
| 2275 | int64_t entriesSize = mIndexHandle->FileSize() - sizeof(CacheIndexHeader) - |
| 2276 | sizeof(CacheHash::Hash32_t); |
| 2277 | |
| 2278 | if (entriesSize < 0 || entriesSize % sizeof(CacheIndexRecord)) { |
| 2279 | LOG(("CacheIndex::StartReadingIndex() - Index is corrupted"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartReadingIndex() - Index is corrupted" ); } } while (0); |
| 2280 | FinishRead(false, aProofOfLock); |
| 2281 | return; |
| 2282 | } |
| 2283 | |
| 2284 | AllocBuffer(); |
| 2285 | mSkipEntries = 0; |
| 2286 | mRWHash = new CacheHash(); |
| 2287 | |
| 2288 | mRWBufPos = |
| 2289 | std::min(mRWBufSize, static_cast<uint32_t>(mIndexHandle->FileSize())); |
| 2290 | |
| 2291 | rv = CacheFileIOManager::Read(mIndexHandle, 0, mRWBuf, mRWBufPos, this); |
| 2292 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 2293 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartReadingIndex() - CacheFileIOManager::Read() failed " "synchronously [rv=0x%08" "x" "]", static_cast<uint32_t> (rv)); } } while (0) |
| 2294 | ("CacheIndex::StartReadingIndex() - CacheFileIOManager::Read() failed "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartReadingIndex() - CacheFileIOManager::Read() failed " "synchronously [rv=0x%08" "x" "]", static_cast<uint32_t> (rv)); } } while (0) |
| 2295 | "synchronously [rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartReadingIndex() - CacheFileIOManager::Read() failed " "synchronously [rv=0x%08" "x" "]", static_cast<uint32_t> (rv)); } } while (0) |
| 2296 | static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartReadingIndex() - CacheFileIOManager::Read() failed " "synchronously [rv=0x%08" "x" "]", static_cast<uint32_t> (rv)); } } while (0); |
| 2297 | FinishRead(false, aProofOfLock); |
| 2298 | } else { |
| 2299 | mRWPending = true; |
| 2300 | } |
| 2301 | } |
| 2302 | |
| 2303 | void CacheIndex::ParseRecords(const StaticMutexAutoLock& aProofOfLock) { |
| 2304 | sLock.AssertCurrentThreadOwns(); |
| 2305 | LOG(("CacheIndex::ParseRecords()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseRecords()" ); } } while (0); |
| 2306 | |
| 2307 | nsresult rv; |
| 2308 | |
| 2309 | MOZ_ASSERT(!mRWPending)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mRWPending)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mRWPending))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mRWPending", "./../../../netwerk/cache2/CacheIndex.cpp" , 2309); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mRWPending" ")"); do { MOZ_CrashSequence(__null, 2309); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 2310 | |
| 2311 | uint32_t entryCnt = (mIndexHandle->FileSize() - sizeof(CacheIndexHeader) - |
| 2312 | sizeof(CacheHash::Hash32_t)) / |
| 2313 | sizeof(CacheIndexRecord); |
| 2314 | uint32_t pos = 0; |
| 2315 | |
| 2316 | if (!mSkipEntries) { |
| 2317 | if (NetworkEndian::readUint32(mRWBuf + pos) != kIndexVersion0x0000000D) { |
| 2318 | FinishRead(false, aProofOfLock); |
| 2319 | return; |
| 2320 | } |
| 2321 | pos += sizeof(uint32_t); |
| 2322 | |
| 2323 | mIndexTimeStamp = NetworkEndian::readUint32(mRWBuf + pos); |
| 2324 | pos += sizeof(uint32_t); |
| 2325 | |
| 2326 | if (NetworkEndian::readUint32(mRWBuf + pos)) { |
| 2327 | if (mJournalHandle) { |
| 2328 | CacheFileIOManager::DoomFile(mJournalHandle, nullptr); |
| 2329 | mJournalHandle = nullptr; |
| 2330 | } |
| 2331 | } else { |
| 2332 | uint32_t* isDirty = |
| 2333 | reinterpret_cast<uint32_t*>(moz_xmalloc(sizeof(uint32_t))); |
| 2334 | NetworkEndian::writeUint32(isDirty, 1); |
| 2335 | |
| 2336 | // Mark index dirty. The buffer will be freed by CacheFileIOManager. |
| 2337 | CacheFileIOManager::WriteWithoutCallback( |
| 2338 | mIndexHandle, 2 * sizeof(uint32_t), reinterpret_cast<char*>(isDirty), |
| 2339 | sizeof(uint32_t), true, false); |
| 2340 | } |
| 2341 | pos += sizeof(uint32_t); |
| 2342 | |
| 2343 | uint64_t dataWritten = NetworkEndian::readUint32(mRWBuf + pos); |
| 2344 | pos += sizeof(uint32_t); |
| 2345 | dataWritten <<= 10; |
| 2346 | mTotalBytesWritten += dataWritten; |
| 2347 | |
| 2348 | bool wasEncrypted = !!NetworkEndian::readUint32(mRWBuf + pos); |
| 2349 | pos += sizeof(uint32_t); |
| 2350 | // The pref rather than IsActive(), matching what WriteRecords() stores: a |
| 2351 | // keystore that is temporarily unavailable must not be read as "the user |
| 2352 | // turned encryption off" and cost them the whole cache. |
| 2353 | bool nowEncrypted = CacheCrypto::IsEnabled(); |
| 2354 | if (wasEncrypted != nowEncrypted) { |
| 2355 | // The at-rest encryption setting changed since the cache was written, so |
| 2356 | // the entries on disk no longer match the current setting. Purge the |
| 2357 | // whole cache rather than keep a mix of encrypted and plaintext entries. |
| 2358 | // EvictAll() dooms open handles, trashes the entries directory and drives |
| 2359 | // the index back to a clean (empty) state via RemoveAll(), so we just |
| 2360 | // hand off and return. |
| 2361 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseRecords() - Encryption setting changed " "[wasEncrypted=%d, nowEncrypted=%d], purging cache", wasEncrypted , nowEncrypted); } } while (0) |
| 2362 | ("CacheIndex::ParseRecords() - Encryption setting changed "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseRecords() - Encryption setting changed " "[wasEncrypted=%d, nowEncrypted=%d], purging cache", wasEncrypted , nowEncrypted); } } while (0) |
| 2363 | "[wasEncrypted=%d, nowEncrypted=%d], purging cache",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseRecords() - Encryption setting changed " "[wasEncrypted=%d, nowEncrypted=%d], purging cache", wasEncrypted , nowEncrypted); } } while (0) |
| 2364 | wasEncrypted, nowEncrypted))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseRecords() - Encryption setting changed " "[wasEncrypted=%d, nowEncrypted=%d], purging cache", wasEncrypted , nowEncrypted); } } while (0); |
| 2365 | CacheFileIOManager::EvictAll(); |
| 2366 | return; |
| 2367 | } |
| 2368 | } |
| 2369 | |
| 2370 | uint32_t hashOffset = pos; |
| 2371 | |
| 2372 | while (pos + sizeof(CacheIndexRecord) <= mRWBufPos && |
| 2373 | mSkipEntries != entryCnt) { |
| 2374 | CacheIndexRecord* rec = reinterpret_cast<CacheIndexRecord*>(mRWBuf + pos); |
| 2375 | CacheIndexEntry tmpEntry(&rec->mHash); |
| 2376 | tmpEntry.ReadFromBuf(mRWBuf + pos); |
| 2377 | |
| 2378 | if (tmpEntry.IsDirty() || !tmpEntry.IsInitialized() || |
| 2379 | tmpEntry.IsFileEmpty() || tmpEntry.IsFresh() || tmpEntry.IsRemoved()) { |
| 2380 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseRecords() - Invalid entry found in index, removing" " whole index [dirty=%d, initialized=%d, fileEmpty=%d, fresh=%d, " "removed=%d]", tmpEntry.IsDirty(), tmpEntry.IsInitialized(), tmpEntry.IsFileEmpty(), tmpEntry.IsFresh(), tmpEntry.IsRemoved ()); } } while (0) |
| 2381 | ("CacheIndex::ParseRecords() - Invalid entry found in index, removing"do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseRecords() - Invalid entry found in index, removing" " whole index [dirty=%d, initialized=%d, fileEmpty=%d, fresh=%d, " "removed=%d]", tmpEntry.IsDirty(), tmpEntry.IsInitialized(), tmpEntry.IsFileEmpty(), tmpEntry.IsFresh(), tmpEntry.IsRemoved ()); } } while (0) |
| 2382 | " whole index [dirty=%d, initialized=%d, fileEmpty=%d, fresh=%d, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseRecords() - Invalid entry found in index, removing" " whole index [dirty=%d, initialized=%d, fileEmpty=%d, fresh=%d, " "removed=%d]", tmpEntry.IsDirty(), tmpEntry.IsInitialized(), tmpEntry.IsFileEmpty(), tmpEntry.IsFresh(), tmpEntry.IsRemoved ()); } } while (0) |
| 2383 | "removed=%d]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseRecords() - Invalid entry found in index, removing" " whole index [dirty=%d, initialized=%d, fileEmpty=%d, fresh=%d, " "removed=%d]", tmpEntry.IsDirty(), tmpEntry.IsInitialized(), tmpEntry.IsFileEmpty(), tmpEntry.IsFresh(), tmpEntry.IsRemoved ()); } } while (0) |
| 2384 | tmpEntry.IsDirty(), tmpEntry.IsInitialized(), tmpEntry.IsFileEmpty(),do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseRecords() - Invalid entry found in index, removing" " whole index [dirty=%d, initialized=%d, fileEmpty=%d, fresh=%d, " "removed=%d]", tmpEntry.IsDirty(), tmpEntry.IsInitialized(), tmpEntry.IsFileEmpty(), tmpEntry.IsFresh(), tmpEntry.IsRemoved ()); } } while (0) |
| 2385 | tmpEntry.IsFresh(), tmpEntry.IsRemoved()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseRecords() - Invalid entry found in index, removing" " whole index [dirty=%d, initialized=%d, fileEmpty=%d, fresh=%d, " "removed=%d]", tmpEntry.IsDirty(), tmpEntry.IsInitialized(), tmpEntry.IsFileEmpty(), tmpEntry.IsFresh(), tmpEntry.IsRemoved ()); } } while (0); |
| 2386 | FinishRead(false, aProofOfLock); |
| 2387 | return; |
| 2388 | } |
| 2389 | |
| 2390 | CacheIndexEntryAutoManage emng(tmpEntry.Hash(), this, aProofOfLock); |
| 2391 | |
| 2392 | CacheIndexEntry* entry = mIndex.PutEntry(*tmpEntry.Hash()); |
| 2393 | *entry = tmpEntry; |
| 2394 | |
| 2395 | pos += sizeof(CacheIndexRecord); |
| 2396 | mSkipEntries++; |
| 2397 | } |
| 2398 | |
| 2399 | mRWHash->Update(mRWBuf + hashOffset, pos - hashOffset); |
| 2400 | |
| 2401 | if (pos != mRWBufPos) { |
| 2402 | memmove(mRWBuf, mRWBuf + pos, mRWBufPos - pos); |
| 2403 | } |
| 2404 | |
| 2405 | mRWBufPos -= pos; |
| 2406 | pos = 0; |
| 2407 | |
| 2408 | int64_t fileOffset = sizeof(CacheIndexHeader) + |
| 2409 | mSkipEntries * sizeof(CacheIndexRecord) + mRWBufPos; |
| 2410 | |
| 2411 | MOZ_ASSERT(fileOffset <= mIndexHandle->FileSize())do { static_assert( mozilla::detail::AssertionConditionType< decltype(fileOffset <= mIndexHandle->FileSize())>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(fileOffset <= mIndexHandle->FileSize()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("fileOffset <= mIndexHandle->FileSize()" , "./../../../netwerk/cache2/CacheIndex.cpp", 2411); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "fileOffset <= mIndexHandle->FileSize()" ")"); do { MOZ_CrashSequence(__null, 2411); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 2412 | if (fileOffset == mIndexHandle->FileSize()) { |
| 2413 | uint32_t expectedHash = NetworkEndian::readUint32(mRWBuf); |
| 2414 | if (mRWHash->GetHash() != expectedHash) { |
| 2415 | LOG(("CacheIndex::ParseRecords() - Hash mismatch, [is %x, should be %x]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseRecords() - Hash mismatch, [is %x, should be %x]" , mRWHash->GetHash(), expectedHash); } } while (0) |
| 2416 | mRWHash->GetHash(), expectedHash))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseRecords() - Hash mismatch, [is %x, should be %x]" , mRWHash->GetHash(), expectedHash); } } while (0); |
| 2417 | FinishRead(false, aProofOfLock); |
| 2418 | return; |
| 2419 | } |
| 2420 | |
| 2421 | mIndexOnDiskIsValid = true; |
| 2422 | mJournalReadSuccessfully = false; |
| 2423 | |
| 2424 | if (mJournalHandle) { |
| 2425 | StartReadingJournal(aProofOfLock); |
| 2426 | } else { |
| 2427 | FinishRead(false, aProofOfLock); |
| 2428 | } |
| 2429 | |
| 2430 | return; |
| 2431 | } |
| 2432 | |
| 2433 | pos = mRWBufPos; |
| 2434 | uint32_t toRead = |
| 2435 | std::min(mRWBufSize - pos, |
| 2436 | static_cast<uint32_t>(mIndexHandle->FileSize() - fileOffset)); |
| 2437 | mRWBufPos = pos + toRead; |
| 2438 | |
| 2439 | rv = CacheFileIOManager::Read(mIndexHandle, fileOffset, mRWBuf + pos, toRead, |
| 2440 | this); |
| 2441 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 2442 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseRecords() - CacheFileIOManager::Read() failed " "synchronously [rv=0x%08" "x" "]", static_cast<uint32_t> (rv)); } } while (0) |
| 2443 | ("CacheIndex::ParseRecords() - CacheFileIOManager::Read() failed "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseRecords() - CacheFileIOManager::Read() failed " "synchronously [rv=0x%08" "x" "]", static_cast<uint32_t> (rv)); } } while (0) |
| 2444 | "synchronously [rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseRecords() - CacheFileIOManager::Read() failed " "synchronously [rv=0x%08" "x" "]", static_cast<uint32_t> (rv)); } } while (0) |
| 2445 | static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseRecords() - CacheFileIOManager::Read() failed " "synchronously [rv=0x%08" "x" "]", static_cast<uint32_t> (rv)); } } while (0); |
| 2446 | FinishRead(false, aProofOfLock); |
| 2447 | return; |
| 2448 | } |
| 2449 | mRWPending = true; |
| 2450 | } |
| 2451 | |
| 2452 | void CacheIndex::StartReadingJournal(const StaticMutexAutoLock& aProofOfLock) { |
| 2453 | sLock.AssertCurrentThreadOwns(); |
| 2454 | LOG(("CacheIndex::StartReadingJournal()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartReadingJournal()" ); } } while (0); |
| 2455 | |
| 2456 | nsresult rv; |
| 2457 | |
| 2458 | MOZ_ASSERT(mJournalHandle)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mJournalHandle)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mJournalHandle))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mJournalHandle" , "./../../../netwerk/cache2/CacheIndex.cpp", 2458); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "mJournalHandle" ")"); do { MOZ_CrashSequence (__null, 2458); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 2459 | MOZ_ASSERT(mIndexOnDiskIsValid)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mIndexOnDiskIsValid)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mIndexOnDiskIsValid))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mIndexOnDiskIsValid" , "./../../../netwerk/cache2/CacheIndex.cpp", 2459); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "mIndexOnDiskIsValid" ")"); do { MOZ_CrashSequence (__null, 2459); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 2460 | MOZ_ASSERT(mTmpJournal.Count() == 0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mTmpJournal.Count() == 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mTmpJournal.Count() == 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mTmpJournal.Count() == 0" , "./../../../netwerk/cache2/CacheIndex.cpp", 2460); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "mTmpJournal.Count() == 0" ")"); do { MOZ_CrashSequence (__null, 2460); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 2461 | MOZ_ASSERT(mJournalHandle->FileSize() >= 0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mJournalHandle->FileSize() >= 0)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(! !(mJournalHandle->FileSize() >= 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mJournalHandle->FileSize() >= 0" , "./../../../netwerk/cache2/CacheIndex.cpp", 2461); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "mJournalHandle->FileSize() >= 0" ")" ); do { MOZ_CrashSequence(__null, 2461); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 2462 | MOZ_ASSERT(!mRWPending)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mRWPending)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mRWPending))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mRWPending", "./../../../netwerk/cache2/CacheIndex.cpp" , 2462); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mRWPending" ")"); do { MOZ_CrashSequence(__null, 2462); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 2463 | |
| 2464 | int64_t entriesSize = |
| 2465 | mJournalHandle->FileSize() - sizeof(CacheHash::Hash32_t); |
| 2466 | |
| 2467 | if (entriesSize < 0 || entriesSize % sizeof(CacheIndexRecord)) { |
| 2468 | LOG(("CacheIndex::StartReadingJournal() - Journal is corrupted"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartReadingJournal() - Journal is corrupted" ); } } while (0); |
| 2469 | FinishRead(false, aProofOfLock); |
| 2470 | return; |
| 2471 | } |
| 2472 | |
| 2473 | mSkipEntries = 0; |
| 2474 | mRWHash = new CacheHash(); |
| 2475 | |
| 2476 | mRWBufPos = |
| 2477 | std::min(mRWBufSize, static_cast<uint32_t>(mJournalHandle->FileSize())); |
| 2478 | |
| 2479 | rv = CacheFileIOManager::Read(mJournalHandle, 0, mRWBuf, mRWBufPos, this); |
| 2480 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 2481 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartReadingJournal() - CacheFileIOManager::Read() failed" " synchronously [rv=0x%08" "x" "]", static_cast<uint32_t> (rv)); } } while (0) |
| 2482 | ("CacheIndex::StartReadingJournal() - CacheFileIOManager::Read() failed"do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartReadingJournal() - CacheFileIOManager::Read() failed" " synchronously [rv=0x%08" "x" "]", static_cast<uint32_t> (rv)); } } while (0) |
| 2483 | " synchronously [rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartReadingJournal() - CacheFileIOManager::Read() failed" " synchronously [rv=0x%08" "x" "]", static_cast<uint32_t> (rv)); } } while (0) |
| 2484 | static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartReadingJournal() - CacheFileIOManager::Read() failed" " synchronously [rv=0x%08" "x" "]", static_cast<uint32_t> (rv)); } } while (0); |
| 2485 | FinishRead(false, aProofOfLock); |
| 2486 | } else { |
| 2487 | mRWPending = true; |
| 2488 | } |
| 2489 | } |
| 2490 | |
| 2491 | void CacheIndex::ParseJournal(const StaticMutexAutoLock& aProofOfLock) { |
| 2492 | sLock.AssertCurrentThreadOwns(); |
| 2493 | LOG(("CacheIndex::ParseJournal()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseJournal()" ); } } while (0); |
| 2494 | |
| 2495 | nsresult rv; |
| 2496 | |
| 2497 | MOZ_ASSERT(!mRWPending)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mRWPending)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mRWPending))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mRWPending", "./../../../netwerk/cache2/CacheIndex.cpp" , 2497); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mRWPending" ")"); do { MOZ_CrashSequence(__null, 2497); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 2498 | |
| 2499 | uint32_t entryCnt = |
| 2500 | (mJournalHandle->FileSize() - sizeof(CacheHash::Hash32_t)) / |
| 2501 | sizeof(CacheIndexRecord); |
| 2502 | |
| 2503 | uint32_t pos = 0; |
| 2504 | |
| 2505 | while (pos + sizeof(CacheIndexRecord) <= mRWBufPos && |
| 2506 | mSkipEntries != entryCnt) { |
| 2507 | CacheIndexEntry tmpEntry(reinterpret_cast<SHA1Sum::Hash*>(mRWBuf + pos)); |
| 2508 | tmpEntry.ReadFromBuf(mRWBuf + pos); |
| 2509 | |
| 2510 | CacheIndexEntry* entry = mTmpJournal.PutEntry(*tmpEntry.Hash()); |
| 2511 | *entry = tmpEntry; |
| 2512 | |
| 2513 | if (entry->IsDirty() || entry->IsFresh()) { |
| 2514 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseJournal() - Invalid entry found in journal, " "ignoring whole journal [dirty=%d, fresh=%d]", entry->IsDirty (), entry->IsFresh()); } } while (0) |
| 2515 | ("CacheIndex::ParseJournal() - Invalid entry found in journal, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseJournal() - Invalid entry found in journal, " "ignoring whole journal [dirty=%d, fresh=%d]", entry->IsDirty (), entry->IsFresh()); } } while (0) |
| 2516 | "ignoring whole journal [dirty=%d, fresh=%d]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseJournal() - Invalid entry found in journal, " "ignoring whole journal [dirty=%d, fresh=%d]", entry->IsDirty (), entry->IsFresh()); } } while (0) |
| 2517 | entry->IsDirty(), entry->IsFresh()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseJournal() - Invalid entry found in journal, " "ignoring whole journal [dirty=%d, fresh=%d]", entry->IsDirty (), entry->IsFresh()); } } while (0); |
| 2518 | FinishRead(false, aProofOfLock); |
| 2519 | return; |
| 2520 | } |
| 2521 | |
| 2522 | pos += sizeof(CacheIndexRecord); |
| 2523 | mSkipEntries++; |
| 2524 | } |
| 2525 | |
| 2526 | mRWHash->Update(mRWBuf, pos); |
| 2527 | |
| 2528 | if (pos != mRWBufPos) { |
| 2529 | memmove(mRWBuf, mRWBuf + pos, mRWBufPos - pos); |
| 2530 | } |
| 2531 | |
| 2532 | mRWBufPos -= pos; |
| 2533 | pos = 0; |
Value stored to 'pos' is never read | |
| 2534 | |
| 2535 | int64_t fileOffset = mSkipEntries * sizeof(CacheIndexRecord) + mRWBufPos; |
| 2536 | |
| 2537 | MOZ_ASSERT(fileOffset <= mJournalHandle->FileSize())do { static_assert( mozilla::detail::AssertionConditionType< decltype(fileOffset <= mJournalHandle->FileSize())>:: isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(fileOffset <= mJournalHandle->FileSize()))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("fileOffset <= mJournalHandle->FileSize()" , "./../../../netwerk/cache2/CacheIndex.cpp", 2537); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "fileOffset <= mJournalHandle->FileSize()" ")"); do { MOZ_CrashSequence(__null, 2537); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 2538 | if (fileOffset == mJournalHandle->FileSize()) { |
| 2539 | uint32_t expectedHash = NetworkEndian::readUint32(mRWBuf); |
| 2540 | if (mRWHash->GetHash() != expectedHash) { |
| 2541 | LOG(("CacheIndex::ParseJournal() - Hash mismatch, [is %x, should be %x]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseJournal() - Hash mismatch, [is %x, should be %x]" , mRWHash->GetHash(), expectedHash); } } while (0) |
| 2542 | mRWHash->GetHash(), expectedHash))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseJournal() - Hash mismatch, [is %x, should be %x]" , mRWHash->GetHash(), expectedHash); } } while (0); |
| 2543 | FinishRead(false, aProofOfLock); |
| 2544 | return; |
| 2545 | } |
| 2546 | |
| 2547 | mJournalReadSuccessfully = true; |
| 2548 | FinishRead(true, aProofOfLock); |
| 2549 | return; |
| 2550 | } |
| 2551 | |
| 2552 | pos = mRWBufPos; |
| 2553 | uint32_t toRead = |
| 2554 | std::min(mRWBufSize - pos, |
| 2555 | static_cast<uint32_t>(mJournalHandle->FileSize() - fileOffset)); |
| 2556 | mRWBufPos = pos + toRead; |
| 2557 | |
| 2558 | rv = CacheFileIOManager::Read(mJournalHandle, fileOffset, mRWBuf + pos, |
| 2559 | toRead, this); |
| 2560 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 2561 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseJournal() - CacheFileIOManager::Read() failed " "synchronously [rv=0x%08" "x" "]", static_cast<uint32_t> (rv)); } } while (0) |
| 2562 | ("CacheIndex::ParseJournal() - CacheFileIOManager::Read() failed "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseJournal() - CacheFileIOManager::Read() failed " "synchronously [rv=0x%08" "x" "]", static_cast<uint32_t> (rv)); } } while (0) |
| 2563 | "synchronously [rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseJournal() - CacheFileIOManager::Read() failed " "synchronously [rv=0x%08" "x" "]", static_cast<uint32_t> (rv)); } } while (0) |
| 2564 | static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ParseJournal() - CacheFileIOManager::Read() failed " "synchronously [rv=0x%08" "x" "]", static_cast<uint32_t> (rv)); } } while (0); |
| 2565 | FinishRead(false, aProofOfLock); |
| 2566 | return; |
| 2567 | } |
| 2568 | mRWPending = true; |
| 2569 | } |
| 2570 | |
| 2571 | void CacheIndex::MergeJournal(const StaticMutexAutoLock& aProofOfLock) { |
| 2572 | sLock.AssertCurrentThreadOwns(); |
| 2573 | LOG(("CacheIndex::MergeJournal()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::MergeJournal()" ); } } while (0); |
| 2574 | |
| 2575 | for (auto iter = mTmpJournal.Iter(); !iter.Done(); iter.Next()) { |
| 2576 | CacheIndexEntry* entry = iter.Get(); |
| 2577 | |
| 2578 | LOG(("CacheIndex::MergeJournal() [hash=%08x%08x%08x%08x%08x]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::MergeJournal() [hash=%08x%08x%08x%08x%08x]" , PR_htonl((reinterpret_cast<const uint32_t*>(entry-> Hash()))[0]), PR_htonl((reinterpret_cast<const uint32_t*> (entry->Hash()))[1]), PR_htonl((reinterpret_cast<const uint32_t *>(entry->Hash()))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(entry->Hash()))[3]), PR_htonl((reinterpret_cast <const uint32_t*>(entry->Hash()))[4])); } } while (0 ) |
| 2579 | LOGSHA1(entry->Hash())))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::MergeJournal() [hash=%08x%08x%08x%08x%08x]" , PR_htonl((reinterpret_cast<const uint32_t*>(entry-> Hash()))[0]), PR_htonl((reinterpret_cast<const uint32_t*> (entry->Hash()))[1]), PR_htonl((reinterpret_cast<const uint32_t *>(entry->Hash()))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(entry->Hash()))[3]), PR_htonl((reinterpret_cast <const uint32_t*>(entry->Hash()))[4])); } } while (0 ); |
| 2580 | |
| 2581 | CacheIndexEntry* entry2 = mIndex.GetEntry(*entry->Hash()); |
| 2582 | { |
| 2583 | CacheIndexEntryAutoManage emng(entry->Hash(), this, aProofOfLock); |
| 2584 | if (entry->IsRemoved()) { |
| 2585 | if (entry2) { |
| 2586 | entry2->MarkRemoved(); |
| 2587 | entry2->MarkDirty(); |
| 2588 | } |
| 2589 | } else { |
| 2590 | if (!entry2) { |
| 2591 | entry2 = mIndex.PutEntry(*entry->Hash()); |
| 2592 | } |
| 2593 | |
| 2594 | *entry2 = *entry; |
| 2595 | entry2->MarkDirty(); |
| 2596 | } |
| 2597 | } |
| 2598 | iter.Remove(); |
| 2599 | } |
| 2600 | |
| 2601 | MOZ_ASSERT(mTmpJournal.Count() == 0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mTmpJournal.Count() == 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mTmpJournal.Count() == 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mTmpJournal.Count() == 0" , "./../../../netwerk/cache2/CacheIndex.cpp", 2601); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "mTmpJournal.Count() == 0" ")"); do { MOZ_CrashSequence (__null, 2601); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 2602 | } |
| 2603 | |
| 2604 | void CacheIndex::EnsureNoFreshEntry() { |
| 2605 | #ifdef DEBUG_STATS1 |
| 2606 | CacheIndexStats debugStats; |
| 2607 | debugStats.DisableLogging(); |
| 2608 | for (auto iter = mIndex.Iter(); !iter.Done(); iter.Next()) { |
| 2609 | debugStats.BeforeChange(nullptr); |
| 2610 | debugStats.AfterChange(iter.Get()); |
| 2611 | } |
| 2612 | MOZ_ASSERT(debugStats.Fresh() == 0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(debugStats.Fresh() == 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(debugStats.Fresh() == 0))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("debugStats.Fresh() == 0" , "./../../../netwerk/cache2/CacheIndex.cpp", 2612); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "debugStats.Fresh() == 0" ")"); do { MOZ_CrashSequence (__null, 2612); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 2613 | #endif |
| 2614 | } |
| 2615 | |
| 2616 | void CacheIndex::EnsureCorrectStats() { |
| 2617 | #ifdef DEBUG_STATS1 |
| 2618 | MOZ_ASSERT(mPendingUpdates.Count() == 0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mPendingUpdates.Count() == 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mPendingUpdates.Count() == 0 ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "mPendingUpdates.Count() == 0", "./../../../netwerk/cache2/CacheIndex.cpp" , 2618); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mPendingUpdates.Count() == 0" ")"); do { MOZ_CrashSequence(__null, 2618); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 2619 | CacheIndexStats debugStats; |
| 2620 | debugStats.DisableLogging(); |
| 2621 | for (auto iter = mIndex.Iter(); !iter.Done(); iter.Next()) { |
| 2622 | debugStats.BeforeChange(nullptr); |
| 2623 | debugStats.AfterChange(iter.Get()); |
| 2624 | } |
| 2625 | MOZ_ASSERT(debugStats == mIndexStats)do { static_assert( mozilla::detail::AssertionConditionType< decltype(debugStats == mIndexStats)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(debugStats == mIndexStats))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("debugStats == mIndexStats" , "./../../../netwerk/cache2/CacheIndex.cpp", 2625); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "debugStats == mIndexStats" ")"); do { MOZ_CrashSequence (__null, 2625); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 2626 | #endif |
| 2627 | } |
| 2628 | |
| 2629 | void CacheIndex::FinishRead(bool aSucceeded, |
| 2630 | const StaticMutexAutoLock& aProofOfLock) { |
| 2631 | sLock.AssertCurrentThreadOwns(); |
| 2632 | LOG(("CacheIndex::FinishRead() [succeeded=%d]", aSucceeded))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::FinishRead() [succeeded=%d]" , aSucceeded); } } while (0); |
| 2633 | |
| 2634 | MOZ_ASSERT((!aSucceeded && mState == SHUTDOWN) || mState == READING)do { static_assert( mozilla::detail::AssertionConditionType< decltype((!aSucceeded && mState == SHUTDOWN) || mState == READING)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!((!aSucceeded && mState == SHUTDOWN) || mState == READING))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("(!aSucceeded && mState == SHUTDOWN) || mState == READING" , "./../../../netwerk/cache2/CacheIndex.cpp", 2634); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "(!aSucceeded && mState == SHUTDOWN) || mState == READING" ")"); do { MOZ_CrashSequence(__null, 2634); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 2635 | |
| 2636 | MOZ_ASSERT(do { static_assert( mozilla::detail::AssertionConditionType< decltype((!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!((!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("(!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)" , "./../../../netwerk/cache2/CacheIndex.cpp", 2642); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "(!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)" ")"); do { MOZ_CrashSequence(__null, 2642); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
| 2637 | // -> rebuilddo { static_assert( mozilla::detail::AssertionConditionType< decltype((!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!((!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("(!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)" , "./../../../netwerk/cache2/CacheIndex.cpp", 2642); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "(!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)" ")"); do { MOZ_CrashSequence(__null, 2642); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
| 2638 | (!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) ||do { static_assert( mozilla::detail::AssertionConditionType< decltype((!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!((!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("(!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)" , "./../../../netwerk/cache2/CacheIndex.cpp", 2642); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "(!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)" ")"); do { MOZ_CrashSequence(__null, 2642); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
| 2639 | // -> updatedo { static_assert( mozilla::detail::AssertionConditionType< decltype((!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!((!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("(!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)" , "./../../../netwerk/cache2/CacheIndex.cpp", 2642); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "(!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)" ")"); do { MOZ_CrashSequence(__null, 2642); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
| 2640 | (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) ||do { static_assert( mozilla::detail::AssertionConditionType< decltype((!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!((!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("(!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)" , "./../../../netwerk/cache2/CacheIndex.cpp", 2642); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "(!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)" ")"); do { MOZ_CrashSequence(__null, 2642); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
| 2641 | // -> readydo { static_assert( mozilla::detail::AssertionConditionType< decltype((!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!((!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("(!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)" , "./../../../netwerk/cache2/CacheIndex.cpp", 2642); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "(!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)" ")"); do { MOZ_CrashSequence(__null, 2642); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
| 2642 | (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully))do { static_assert( mozilla::detail::AssertionConditionType< decltype((!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!((!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("(!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)" , "./../../../netwerk/cache2/CacheIndex.cpp", 2642); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "(!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)" ")"); do { MOZ_CrashSequence(__null, 2642); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 2643 | |
| 2644 | // If there is read operation pending we must be cancelling reading of the |
| 2645 | // index when shutting down or removing the whole index. |
| 2646 | MOZ_ASSERT(!mRWPending || (!aSucceeded && (mShuttingDown || mRemovingAll)))do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mRWPending || (!aSucceeded && (mShuttingDown || mRemovingAll)))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mRWPending || (!aSucceeded && (mShuttingDown || mRemovingAll))))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("!mRWPending || (!aSucceeded && (mShuttingDown || mRemovingAll))" , "./../../../netwerk/cache2/CacheIndex.cpp", 2646); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!mRWPending || (!aSucceeded && (mShuttingDown || mRemovingAll))" ")"); do { MOZ_CrashSequence(__null, 2646); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 2647 | |
| 2648 | if (mState == SHUTDOWN) { |
| 2649 | RemoveFile(nsLiteralCString(TEMP_INDEX_NAME"index.tmp")); |
| 2650 | RemoveFile(nsLiteralCString(JOURNAL_NAME"index.log")); |
| 2651 | } else { |
| 2652 | if (mIndexHandle && !mIndexOnDiskIsValid) { |
| 2653 | CacheFileIOManager::DoomFile(mIndexHandle, nullptr); |
| 2654 | } |
| 2655 | |
| 2656 | if (mJournalHandle) { |
| 2657 | CacheFileIOManager::DoomFile(mJournalHandle, nullptr); |
| 2658 | } |
| 2659 | } |
| 2660 | |
| 2661 | if (mIndexFileOpener) { |
| 2662 | mIndexFileOpener->Cancel(); |
| 2663 | mIndexFileOpener = nullptr; |
| 2664 | } |
| 2665 | if (mJournalFileOpener) { |
| 2666 | mJournalFileOpener->Cancel(); |
| 2667 | mJournalFileOpener = nullptr; |
| 2668 | } |
| 2669 | if (mTmpFileOpener) { |
| 2670 | mTmpFileOpener->Cancel(); |
| 2671 | mTmpFileOpener = nullptr; |
| 2672 | } |
| 2673 | |
| 2674 | mIndexHandle = nullptr; |
| 2675 | mJournalHandle = nullptr; |
| 2676 | mRWHash = nullptr; |
| 2677 | ReleaseBuffer(); |
| 2678 | |
| 2679 | if (mState == SHUTDOWN) { |
| 2680 | return; |
| 2681 | } |
| 2682 | |
| 2683 | if (!mIndexOnDiskIsValid) { |
| 2684 | MOZ_ASSERT(mTmpJournal.Count() == 0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mTmpJournal.Count() == 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mTmpJournal.Count() == 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mTmpJournal.Count() == 0" , "./../../../netwerk/cache2/CacheIndex.cpp", 2684); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "mTmpJournal.Count() == 0" ")"); do { MOZ_CrashSequence (__null, 2684); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 2685 | EnsureNoFreshEntry(); |
| 2686 | ProcessPendingOperations(aProofOfLock); |
| 2687 | // Remove all entries that we haven't seen during this session |
| 2688 | RemoveNonFreshEntries(aProofOfLock); |
| 2689 | StartUpdatingIndex(true, aProofOfLock); |
| 2690 | return; |
| 2691 | } |
| 2692 | |
| 2693 | if (!mJournalReadSuccessfully) { |
| 2694 | mTmpJournal.Clear(); |
| 2695 | EnsureNoFreshEntry(); |
| 2696 | ProcessPendingOperations(aProofOfLock); |
| 2697 | StartUpdatingIndex(false, aProofOfLock); |
| 2698 | return; |
| 2699 | } |
| 2700 | |
| 2701 | MergeJournal(aProofOfLock); |
| 2702 | EnsureNoFreshEntry(); |
| 2703 | ProcessPendingOperations(aProofOfLock); |
| 2704 | mIndexStats.Log(); |
| 2705 | |
| 2706 | ChangeState(READY, aProofOfLock); |
| 2707 | mLastDumpTime = TimeStamp::NowLoRes(); // Do not dump new index immediately |
| 2708 | } |
| 2709 | |
| 2710 | // static |
| 2711 | void CacheIndex::DelayedUpdate(nsITimer* aTimer, void* aClosure) { |
| 2712 | LOG(("CacheIndex::DelayedUpdate()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::DelayedUpdate()" ); } } while (0); |
| 2713 | |
| 2714 | StaticMutexAutoLock lock(sLock); |
| 2715 | RefPtr<CacheIndex> index = gInstance; |
| 2716 | |
| 2717 | if (!index) { |
| 2718 | return; |
| 2719 | } |
| 2720 | |
| 2721 | index->DelayedUpdateLocked(lock); |
| 2722 | } |
| 2723 | |
| 2724 | // static |
| 2725 | void CacheIndex::DelayedUpdateLocked(const StaticMutexAutoLock& aProofOfLock) { |
| 2726 | sLock.AssertCurrentThreadOwns(); |
| 2727 | LOG(("CacheIndex::DelayedUpdateLocked()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::DelayedUpdateLocked()" ); } } while (0); |
| 2728 | |
| 2729 | nsresult rv; |
| 2730 | |
| 2731 | mUpdateTimer = nullptr; |
| 2732 | |
| 2733 | if (!IsIndexUsable()) { |
| 2734 | return; |
| 2735 | } |
| 2736 | |
| 2737 | if (mState == READY && mShuttingDown) { |
| 2738 | return; |
| 2739 | } |
| 2740 | |
| 2741 | // mUpdateEventPending must be false here since StartUpdatingIndex() won't |
| 2742 | // schedule timer if it is true. |
| 2743 | MOZ_ASSERT(!mUpdateEventPending)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mUpdateEventPending)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mUpdateEventPending))), 0)) ) { do { } while (false); MOZ_ReportAssertionFailure("!mUpdateEventPending" , "./../../../netwerk/cache2/CacheIndex.cpp", 2743); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!mUpdateEventPending" ")"); do { MOZ_CrashSequence (__null, 2743); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 2744 | if (mState != BUILDING && mState != UPDATING) { |
| 2745 | LOG(("CacheIndex::DelayedUpdateLocked() - Update was canceled"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::DelayedUpdateLocked() - Update was canceled" ); } } while (0); |
| 2746 | return; |
| 2747 | } |
| 2748 | |
| 2749 | // We need to redispatch to run with lower priority |
| 2750 | RefPtr<CacheIOThread> ioThread = CacheFileIOManager::IOThread(); |
| 2751 | MOZ_ASSERT(ioThread)do { static_assert( mozilla::detail::AssertionConditionType< decltype(ioThread)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(ioThread))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("ioThread", "./../../../netwerk/cache2/CacheIndex.cpp" , 2751); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ioThread" ")" ); do { MOZ_CrashSequence(__null, 2751); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 2752 | |
| 2753 | mUpdateEventPending = true; |
| 2754 | rv = ioThread->Dispatch(this, CacheIOThread::INDEX); |
| 2755 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 2756 | mUpdateEventPending = false; |
| 2757 | NS_WARNING("CacheIndex::DelayedUpdateLocked() - Can't dispatch event")NS_DebugBreak(NS_DEBUG_WARNING, "CacheIndex::DelayedUpdateLocked() - Can't dispatch event" , nullptr, "./../../../netwerk/cache2/CacheIndex.cpp", 2757); |
| 2758 | LOG(("CacheIndex::DelayedUpdate() - Can't dispatch event"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::DelayedUpdate() - Can't dispatch event" ); } } while (0); |
| 2759 | FinishUpdate(false, aProofOfLock); |
| 2760 | } |
| 2761 | } |
| 2762 | |
| 2763 | nsresult CacheIndex::ScheduleUpdateTimer(uint32_t aDelay) { |
| 2764 | LOG(("CacheIndex::ScheduleUpdateTimer() [delay=%u]", aDelay))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ScheduleUpdateTimer() [delay=%u]" , aDelay); } } while (0); |
| 2765 | |
| 2766 | MOZ_ASSERT(!mUpdateTimer)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mUpdateTimer)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mUpdateTimer))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mUpdateTimer", "./../../../netwerk/cache2/CacheIndex.cpp", 2766); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!mUpdateTimer" ")"); do { MOZ_CrashSequence (__null, 2766); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 2767 | |
| 2768 | nsCOMPtr<nsIEventTarget> ioTarget = CacheFileIOManager::IOTarget(); |
| 2769 | MOZ_ASSERT(ioTarget)do { static_assert( mozilla::detail::AssertionConditionType< decltype(ioTarget)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(ioTarget))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("ioTarget", "./../../../netwerk/cache2/CacheIndex.cpp" , 2769); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ioTarget" ")" ); do { MOZ_CrashSequence(__null, 2769); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 2770 | |
| 2771 | return NS_NewTimerWithFuncCallback( |
| 2772 | getter_AddRefs(mUpdateTimer), CacheIndex::DelayedUpdate, nullptr, aDelay, |
| 2773 | nsITimer::TYPE_ONE_SHOT, "net::CacheIndex::ScheduleUpdateTimer"_ns, |
| 2774 | ioTarget); |
| 2775 | } |
| 2776 | |
| 2777 | nsresult CacheIndex::SetupDirectoryEnumerator() { |
| 2778 | MOZ_ASSERT(!NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType< decltype(!NS_IsMainThread())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!NS_IsMainThread()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!NS_IsMainThread()" , "./../../../netwerk/cache2/CacheIndex.cpp", 2778); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!NS_IsMainThread()" ")"); do { MOZ_CrashSequence (__null, 2778); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 2779 | MOZ_ASSERT(!mDirEnumerator)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mDirEnumerator)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mDirEnumerator))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mDirEnumerator" , "./../../../netwerk/cache2/CacheIndex.cpp", 2779); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!mDirEnumerator" ")"); do { MOZ_CrashSequence (__null, 2779); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 2780 | |
| 2781 | nsresult rv; |
| 2782 | nsCOMPtr<nsIFile> file; |
| 2783 | |
| 2784 | rv = mCacheDirectory->Clone(getter_AddRefs(file)); |
| 2785 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 2785); return rv; } } while (false); |
| 2786 | |
| 2787 | rv = file->AppendNative(nsLiteralCString(ENTRIES_DIR"entries")); |
| 2788 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 2788); return rv; } } while (false); |
| 2789 | |
| 2790 | bool exists; |
| 2791 | rv = file->Exists(&exists); |
| 2792 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 2792); return rv; } } while (false); |
| 2793 | |
| 2794 | if (!exists) { |
| 2795 | NS_WARNING(NS_DebugBreak(NS_DEBUG_WARNING, "CacheIndex::SetupDirectoryEnumerator() - Entries directory " "doesn't exist!", nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 2797) |
| 2796 | "CacheIndex::SetupDirectoryEnumerator() - Entries directory "NS_DebugBreak(NS_DEBUG_WARNING, "CacheIndex::SetupDirectoryEnumerator() - Entries directory " "doesn't exist!", nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 2797) |
| 2797 | "doesn't exist!")NS_DebugBreak(NS_DEBUG_WARNING, "CacheIndex::SetupDirectoryEnumerator() - Entries directory " "doesn't exist!", nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 2797); |
| 2798 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::SetupDirectoryEnumerator() - Entries directory doesn't " "exist!"); } } while (0) |
| 2799 | ("CacheIndex::SetupDirectoryEnumerator() - Entries directory doesn't "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::SetupDirectoryEnumerator() - Entries directory doesn't " "exist!"); } } while (0) |
| 2800 | "exist!"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::SetupDirectoryEnumerator() - Entries directory doesn't " "exist!"); } } while (0); |
| 2801 | return NS_ERROR_UNEXPECTED; |
| 2802 | } |
| 2803 | |
| 2804 | // Do not do IO under the lock. |
| 2805 | nsCOMPtr<nsIDirectoryEnumerator> dirEnumerator; |
| 2806 | { |
| 2807 | StaticMutexAutoUnlock unlock(sLock); |
| 2808 | rv = file->GetDirectoryEntries(getter_AddRefs(dirEnumerator)); |
| 2809 | } |
| 2810 | mDirEnumerator = dirEnumerator.forget(); |
| 2811 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp" , 2811); return rv; } } while (false); |
| 2812 | |
| 2813 | return NS_OK; |
| 2814 | } |
| 2815 | |
| 2816 | nsresult CacheIndex::InitEntryFromDiskData(CacheIndexEntry* aEntry, |
| 2817 | CacheFileMetadata* aMetaData, |
| 2818 | int64_t aFileSize) { |
| 2819 | nsresult rv; |
| 2820 | |
| 2821 | aEntry->InitNew(); |
| 2822 | aEntry->MarkDirty(); |
| 2823 | aEntry->MarkFresh(); |
| 2824 | |
| 2825 | aEntry->Init(GetOriginAttrsHash(aMetaData->OriginAttributes()), |
| 2826 | aMetaData->IsAnonymous(), aMetaData->Pinned()); |
| 2827 | |
| 2828 | aEntry->SetFrecency(aMetaData->GetFrecency()); |
| 2829 | |
| 2830 | const char* altData = aMetaData->GetElement(CacheFileUtils::kAltDataKey); |
| 2831 | bool hasAltData = altData != nullptr; |
| 2832 | if (hasAltData && NS_FAILED(CacheFileUtils::ParseAlternativeDataInfo(((bool)(__builtin_expect(!!(NS_FAILED_impl(CacheFileUtils::ParseAlternativeDataInfo ( altData, nullptr, nullptr))), 0))) |
| 2833 | altData, nullptr, nullptr))((bool)(__builtin_expect(!!(NS_FAILED_impl(CacheFileUtils::ParseAlternativeDataInfo ( altData, nullptr, nullptr))), 0)))) { |
| 2834 | return NS_ERROR_FAILURE; |
| 2835 | } |
| 2836 | aEntry->SetHasAltData(hasAltData); |
| 2837 | |
| 2838 | aEntry->SetLastFetched(aMetaData->GetLastFetched()); |
| 2839 | aEntry->SetFetchCount(aMetaData->GetFetchCount()); |
| 2840 | |
| 2841 | const char* contentTypeStr = aMetaData->GetElement("ctid"); |
| 2842 | uint8_t contentType = nsICacheEntry::CONTENT_TYPE_UNKNOWN; |
| 2843 | if (contentTypeStr) { |
| 2844 | int64_t n64 = nsDependentCString(contentTypeStr).ToInteger64(&rv); |
| 2845 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0))) || n64 < nsICacheEntry::CONTENT_TYPE_UNKNOWN || |
| 2846 | n64 >= nsICacheEntry::CONTENT_TYPE_LAST) { |
| 2847 | n64 = nsICacheEntry::CONTENT_TYPE_UNKNOWN; |
| 2848 | } |
| 2849 | contentType = n64; |
| 2850 | } |
| 2851 | aEntry->SetContentType(contentType); |
| 2852 | |
| 2853 | aEntry->SetFileSize(static_cast<uint32_t>(std::min( |
| 2854 | static_cast<int64_t>(PR_UINT32_MAX4294967295U), (aFileSize + 0x3FF) >> 10))); |
| 2855 | return NS_OK; |
| 2856 | } |
| 2857 | |
| 2858 | bool CacheIndex::IsUpdatePending() { |
| 2859 | sLock.AssertCurrentThreadOwns(); |
| 2860 | |
| 2861 | return mUpdateTimer || mUpdateEventPending; |
| 2862 | } |
| 2863 | |
| 2864 | void CacheIndex::BuildIndex(const StaticMutexAutoLock& aProofOfLock) { |
| 2865 | sLock.AssertCurrentThreadOwns(); |
| 2866 | LOG(("CacheIndex::BuildIndex()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex()" ); } } while (0); |
| 2867 | |
| 2868 | MOZ_ASSERT(mPendingUpdates.Count() == 0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mPendingUpdates.Count() == 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mPendingUpdates.Count() == 0 ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "mPendingUpdates.Count() == 0", "./../../../netwerk/cache2/CacheIndex.cpp" , 2868); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mPendingUpdates.Count() == 0" ")"); do { MOZ_CrashSequence(__null, 2868); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 2869 | |
| 2870 | nsresult rv; |
| 2871 | |
| 2872 | if (!mDirEnumerator) { |
| 2873 | rv = SetupDirectoryEnumerator(); |
| 2874 | if (mState == SHUTDOWN) { |
| 2875 | // The index was shut down while we released the lock. FinishUpdate() was |
| 2876 | // already called from Shutdown(), so just simply return here. |
| 2877 | return; |
| 2878 | } |
| 2879 | |
| 2880 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 2881 | FinishUpdate(false, aProofOfLock); |
| 2882 | return; |
| 2883 | } |
| 2884 | } |
| 2885 | |
| 2886 | while (true) { |
| 2887 | if (CacheIOThread::YieldAndRerun()) { |
| 2888 | LOG((do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - Breaking loop for higher level events." ); } } while (0) |
| 2889 | "CacheIndex::BuildIndex() - Breaking loop for higher level events."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - Breaking loop for higher level events." ); } } while (0); |
| 2890 | mUpdateEventPending = true; |
| 2891 | return; |
| 2892 | } |
| 2893 | |
| 2894 | bool fileExists = false; |
| 2895 | nsCOMPtr<nsIFile> file; |
| 2896 | { |
| 2897 | // Do not do IO under the lock. |
| 2898 | nsCOMPtr<nsIDirectoryEnumerator> dirEnumerator(mDirEnumerator); |
| 2899 | sLock.AssertCurrentThreadOwns(); |
| 2900 | StaticMutexAutoUnlock unlock(sLock); |
| 2901 | rv = dirEnumerator->GetNextFile(getter_AddRefs(file)); |
| 2902 | |
| 2903 | if (file) { |
| 2904 | file->Exists(&fileExists); |
| 2905 | } |
| 2906 | } |
| 2907 | if (mState == SHUTDOWN) { |
| 2908 | return; |
| 2909 | } |
| 2910 | if (!file) { |
| 2911 | FinishUpdate(NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))), aProofOfLock); |
| 2912 | return; |
| 2913 | } |
| 2914 | |
| 2915 | nsAutoCString leaf; |
| 2916 | rv = file->GetNativeLeafName(leaf); |
| 2917 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 2918 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - GetNativeLeafName() failed! Skipping " "file."); } } while (0) |
| 2919 | ("CacheIndex::BuildIndex() - GetNativeLeafName() failed! Skipping "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - GetNativeLeafName() failed! Skipping " "file."); } } while (0) |
| 2920 | "file."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - GetNativeLeafName() failed! Skipping " "file."); } } while (0); |
| 2921 | mDontMarkIndexClean = true; |
| 2922 | continue; |
| 2923 | } |
| 2924 | |
| 2925 | if (!fileExists) { |
| 2926 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - File returned by the iterator was " "removed in the meantime [name=%s]", leaf.get()); } } while ( 0) |
| 2927 | ("CacheIndex::BuildIndex() - File returned by the iterator was "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - File returned by the iterator was " "removed in the meantime [name=%s]", leaf.get()); } } while ( 0) |
| 2928 | "removed in the meantime [name=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - File returned by the iterator was " "removed in the meantime [name=%s]", leaf.get()); } } while ( 0) |
| 2929 | leaf.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - File returned by the iterator was " "removed in the meantime [name=%s]", leaf.get()); } } while ( 0); |
| 2930 | continue; |
| 2931 | } |
| 2932 | |
| 2933 | SHA1Sum::Hash hash; |
| 2934 | rv = CacheFileIOManager::StrToHash(leaf, &hash); |
| 2935 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 2936 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - Filename is not a hash, removing file. " "[name=%s]", leaf.get()); } } while (0) |
| 2937 | ("CacheIndex::BuildIndex() - Filename is not a hash, removing file. "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - Filename is not a hash, removing file. " "[name=%s]", leaf.get()); } } while (0) |
| 2938 | "[name=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - Filename is not a hash, removing file. " "[name=%s]", leaf.get()); } } while (0) |
| 2939 | leaf.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - Filename is not a hash, removing file. " "[name=%s]", leaf.get()); } } while (0); |
| 2940 | file->Remove(false); |
| 2941 | continue; |
| 2942 | } |
| 2943 | |
| 2944 | CacheIndexEntry* entry = mIndex.GetEntry(hash); |
| 2945 | if (entry && entry->IsRemoved()) { |
| 2946 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - Found file that should not exist. " "[name=%s]", leaf.get()); } } while (0) |
| 2947 | ("CacheIndex::BuildIndex() - Found file that should not exist. "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - Found file that should not exist. " "[name=%s]", leaf.get()); } } while (0) |
| 2948 | "[name=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - Found file that should not exist. " "[name=%s]", leaf.get()); } } while (0) |
| 2949 | leaf.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - Found file that should not exist. " "[name=%s]", leaf.get()); } } while (0); |
| 2950 | entry->Log(); |
| 2951 | MOZ_ASSERT(entry->IsFresh())do { static_assert( mozilla::detail::AssertionConditionType< decltype(entry->IsFresh())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(entry->IsFresh()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("entry->IsFresh()" , "./../../../netwerk/cache2/CacheIndex.cpp", 2951); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "entry->IsFresh()" ")"); do { MOZ_CrashSequence (__null, 2951); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 2952 | entry = nullptr; |
| 2953 | } |
| 2954 | |
| 2955 | #ifdef DEBUG1 |
| 2956 | RefPtr<CacheFileHandle> handle; |
| 2957 | CacheFileIOManager::gInstance->mHandles.GetHandle(&hash, |
| 2958 | getter_AddRefs(handle)); |
| 2959 | #endif |
| 2960 | |
| 2961 | if (entry) { |
| 2962 | // the entry is up to date |
| 2963 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - Skipping file because the entry is up to" " date. [name=%s]", leaf.get()); } } while (0) |
| 2964 | ("CacheIndex::BuildIndex() - Skipping file because the entry is up to"do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - Skipping file because the entry is up to" " date. [name=%s]", leaf.get()); } } while (0) |
| 2965 | " date. [name=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - Skipping file because the entry is up to" " date. [name=%s]", leaf.get()); } } while (0) |
| 2966 | leaf.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - Skipping file because the entry is up to" " date. [name=%s]", leaf.get()); } } while (0); |
| 2967 | entry->Log(); |
| 2968 | MOZ_ASSERT(entry->IsFresh())do { static_assert( mozilla::detail::AssertionConditionType< decltype(entry->IsFresh())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(entry->IsFresh()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("entry->IsFresh()" , "./../../../netwerk/cache2/CacheIndex.cpp", 2968); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "entry->IsFresh()" ")"); do { MOZ_CrashSequence (__null, 2968); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); // The entry must be from this session |
| 2969 | // there must be an active CacheFile if the entry is not initialized |
| 2970 | MOZ_ASSERT(entry->IsInitialized() || handle)do { static_assert( mozilla::detail::AssertionConditionType< decltype(entry->IsInitialized() || handle)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(entry->IsInitialized() || handle))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("entry->IsInitialized() || handle", "./../../../netwerk/cache2/CacheIndex.cpp" , 2970); AnnotateMozCrashReason("MOZ_ASSERT" "(" "entry->IsInitialized() || handle" ")"); do { MOZ_CrashSequence(__null, 2970); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 2971 | continue; |
| 2972 | } |
| 2973 | |
| 2974 | MOZ_ASSERT(!handle)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!handle)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!handle))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!handle", "./../../../netwerk/cache2/CacheIndex.cpp" , 2974); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!handle" ")" ); do { MOZ_CrashSequence(__null, 2974); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 2975 | |
| 2976 | RefPtr<CacheFileMetadata> meta = new CacheFileMetadata(); |
| 2977 | int64_t size = 0; |
| 2978 | |
| 2979 | { |
| 2980 | // Do not do IO under the lock. |
| 2981 | StaticMutexAutoUnlock unlock(sLock); |
| 2982 | rv = meta->SyncReadMetadata(file); |
| 2983 | |
| 2984 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
| 2985 | rv = file->GetFileSize(&size); |
| 2986 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 2987 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - Cannot get filesize of file that was" " successfully parsed. [name=%s]", leaf.get()); } } while (0 ) |
| 2988 | ("CacheIndex::BuildIndex() - Cannot get filesize of file that was"do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - Cannot get filesize of file that was" " successfully parsed. [name=%s]", leaf.get()); } } while (0 ) |
| 2989 | " successfully parsed. [name=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - Cannot get filesize of file that was" " successfully parsed. [name=%s]", leaf.get()); } } while (0 ) |
| 2990 | leaf.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - Cannot get filesize of file that was" " successfully parsed. [name=%s]", leaf.get()); } } while (0 ); |
| 2991 | } |
| 2992 | } |
| 2993 | } |
| 2994 | if (mState == SHUTDOWN) { |
| 2995 | return; |
| 2996 | } |
| 2997 | |
| 2998 | // Nobody could add the entry while the lock was released since we modify |
| 2999 | // the index only on IO thread and this loop is executed on IO thread too. |
| 3000 | entry = mIndex.GetEntry(hash); |
| 3001 | MOZ_ASSERT(!entry || entry->IsRemoved())do { static_assert( mozilla::detail::AssertionConditionType< decltype(!entry || entry->IsRemoved())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!entry || entry->IsRemoved ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("!entry || entry->IsRemoved()", "./../../../netwerk/cache2/CacheIndex.cpp" , 3001); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!entry || entry->IsRemoved()" ")"); do { MOZ_CrashSequence(__null, 3001); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 3002 | |
| 3003 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 3004 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - CacheFileMetadata::SyncReadMetadata() " "failed, removing file. [name=%s]", leaf.get()); } } while ( 0) |
| 3005 | ("CacheIndex::BuildIndex() - CacheFileMetadata::SyncReadMetadata() "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - CacheFileMetadata::SyncReadMetadata() " "failed, removing file. [name=%s]", leaf.get()); } } while ( 0) |
| 3006 | "failed, removing file. [name=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - CacheFileMetadata::SyncReadMetadata() " "failed, removing file. [name=%s]", leaf.get()); } } while ( 0) |
| 3007 | leaf.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - CacheFileMetadata::SyncReadMetadata() " "failed, removing file. [name=%s]", leaf.get()); } } while ( 0); |
| 3008 | file->Remove(false); |
| 3009 | } else { |
| 3010 | CacheIndexEntryAutoManage entryMng(&hash, this, aProofOfLock); |
| 3011 | entry = mIndex.PutEntry(hash); |
| 3012 | if (NS_FAILED(InitEntryFromDiskData(entry, meta, size))((bool)(__builtin_expect(!!(NS_FAILED_impl(InitEntryFromDiskData (entry, meta, size))), 0)))) { |
| 3013 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - CacheFile::InitEntryFromDiskData() " "failed, removing file. [name=%s]", leaf.get()); } } while ( 0) |
| 3014 | ("CacheIndex::BuildIndex() - CacheFile::InitEntryFromDiskData() "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - CacheFile::InitEntryFromDiskData() " "failed, removing file. [name=%s]", leaf.get()); } } while ( 0) |
| 3015 | "failed, removing file. [name=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - CacheFile::InitEntryFromDiskData() " "failed, removing file. [name=%s]", leaf.get()); } } while ( 0) |
| 3016 | leaf.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - CacheFile::InitEntryFromDiskData() " "failed, removing file. [name=%s]", leaf.get()); } } while ( 0); |
| 3017 | file->Remove(false); |
| 3018 | entry->MarkRemoved(); |
| 3019 | } else { |
| 3020 | LOG(("CacheIndex::BuildIndex() - Added entry to index. [name=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - Added entry to index. [name=%s]" , leaf.get()); } } while (0) |
| 3021 | leaf.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::BuildIndex() - Added entry to index. [name=%s]" , leaf.get()); } } while (0); |
| 3022 | entry->Log(); |
| 3023 | } |
| 3024 | } |
| 3025 | } |
| 3026 | |
| 3027 | MOZ_ASSERT_UNREACHABLE("We should never get here")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "MOZ_ASSERT_UNREACHABLE: " "We should never get here" ")", "./../../../netwerk/cache2/CacheIndex.cpp" , 3027); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "MOZ_ASSERT_UNREACHABLE: " "We should never get here" ")"); do { MOZ_CrashSequence(__null, 3027); __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
| 3028 | } |
| 3029 | |
| 3030 | bool CacheIndex::StartUpdatingIndexIfNeeded( |
| 3031 | const StaticMutexAutoLock& aProofOfLock, bool aSwitchingToReadyState) { |
| 3032 | sLock.AssertCurrentThreadOwns(); |
| 3033 | // Start updating process when we are in or we are switching to READY state |
| 3034 | // and index needs update, but not during shutdown or when removing all |
| 3035 | // entries. |
| 3036 | if ((mState == READY || aSwitchingToReadyState) && mIndexNeedsUpdate && |
| 3037 | !mShuttingDown && !mRemovingAll) { |
| 3038 | LOG(("CacheIndex::StartUpdatingIndexIfNeeded() - starting update process"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartUpdatingIndexIfNeeded() - starting update process" ); } } while (0); |
| 3039 | mIndexNeedsUpdate = false; |
| 3040 | StartUpdatingIndex(false, aProofOfLock); |
| 3041 | return true; |
| 3042 | } |
| 3043 | |
| 3044 | return false; |
| 3045 | } |
| 3046 | |
| 3047 | void CacheIndex::StartUpdatingIndex(bool aRebuild, |
| 3048 | const StaticMutexAutoLock& aProofOfLock) { |
| 3049 | sLock.AssertCurrentThreadOwns(); |
| 3050 | LOG(("CacheIndex::StartUpdatingIndex() [rebuild=%d]", aRebuild))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartUpdatingIndex() [rebuild=%d]" , aRebuild); } } while (0); |
| 3051 | |
| 3052 | nsresult rv; |
| 3053 | |
| 3054 | mIndexStats.Log(); |
| 3055 | |
| 3056 | ChangeState(aRebuild ? BUILDING : UPDATING, aProofOfLock); |
| 3057 | mDontMarkIndexClean = false; |
| 3058 | |
| 3059 | if (mShuttingDown || mRemovingAll) { |
| 3060 | FinishUpdate(false, aProofOfLock); |
| 3061 | return; |
| 3062 | } |
| 3063 | |
| 3064 | if (IsUpdatePending()) { |
| 3065 | LOG(("CacheIndex::StartUpdatingIndex() - Update is already pending"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartUpdatingIndex() - Update is already pending" ); } } while (0); |
| 3066 | return; |
| 3067 | } |
| 3068 | |
| 3069 | uint32_t elapsed = (TimeStamp::NowLoRes() - mStartTime).ToMilliseconds(); |
| 3070 | uint32_t startDelay = |
| 3071 | StaticPrefs::browser_cache_disk_index_update_start_delay_ms(); |
| 3072 | if (elapsed < startDelay) { |
| 3073 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartUpdatingIndex() - %u ms elapsed since startup, " "scheduling timer to fire in %u ms.", elapsed, startDelay - elapsed ); } } while (0) |
| 3074 | ("CacheIndex::StartUpdatingIndex() - %u ms elapsed since startup, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartUpdatingIndex() - %u ms elapsed since startup, " "scheduling timer to fire in %u ms.", elapsed, startDelay - elapsed ); } } while (0) |
| 3075 | "scheduling timer to fire in %u ms.",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartUpdatingIndex() - %u ms elapsed since startup, " "scheduling timer to fire in %u ms.", elapsed, startDelay - elapsed ); } } while (0) |
| 3076 | elapsed, startDelay - elapsed))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartUpdatingIndex() - %u ms elapsed since startup, " "scheduling timer to fire in %u ms.", elapsed, startDelay - elapsed ); } } while (0); |
| 3077 | rv = ScheduleUpdateTimer(startDelay - elapsed); |
| 3078 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
| 3079 | return; |
| 3080 | } |
| 3081 | |
| 3082 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartUpdatingIndex() - ScheduleUpdateTimer() failed. " "Starting update immediately."); } } while (0) |
| 3083 | ("CacheIndex::StartUpdatingIndex() - ScheduleUpdateTimer() failed. "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartUpdatingIndex() - ScheduleUpdateTimer() failed. " "Starting update immediately."); } } while (0) |
| 3084 | "Starting update immediately."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartUpdatingIndex() - ScheduleUpdateTimer() failed. " "Starting update immediately."); } } while (0); |
| 3085 | } else { |
| 3086 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartUpdatingIndex() - %u ms elapsed since startup, " "starting update now.", elapsed); } } while (0) |
| 3087 | ("CacheIndex::StartUpdatingIndex() - %u ms elapsed since startup, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartUpdatingIndex() - %u ms elapsed since startup, " "starting update now.", elapsed); } } while (0) |
| 3088 | "starting update now.",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartUpdatingIndex() - %u ms elapsed since startup, " "starting update now.", elapsed); } } while (0) |
| 3089 | elapsed))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartUpdatingIndex() - %u ms elapsed since startup, " "starting update now.", elapsed); } } while (0); |
| 3090 | } |
| 3091 | |
| 3092 | RefPtr<CacheIOThread> ioThread = CacheFileIOManager::IOThread(); |
| 3093 | MOZ_ASSERT(ioThread)do { static_assert( mozilla::detail::AssertionConditionType< decltype(ioThread)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(ioThread))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("ioThread", "./../../../netwerk/cache2/CacheIndex.cpp" , 3093); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ioThread" ")" ); do { MOZ_CrashSequence(__null, 3093); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 3094 | |
| 3095 | // We need to dispatch an event even if we are on IO thread since we need to |
| 3096 | // update the index with the correct priority. |
| 3097 | mUpdateEventPending = true; |
| 3098 | rv = ioThread->Dispatch(this, CacheIOThread::INDEX); |
| 3099 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 3100 | mUpdateEventPending = false; |
| 3101 | NS_WARNING("CacheIndex::StartUpdatingIndex() - Can't dispatch event")NS_DebugBreak(NS_DEBUG_WARNING, "CacheIndex::StartUpdatingIndex() - Can't dispatch event" , nullptr, "./../../../netwerk/cache2/CacheIndex.cpp", 3101); |
| 3102 | LOG(("CacheIndex::StartUpdatingIndex() - Can't dispatch event"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::StartUpdatingIndex() - Can't dispatch event" ); } } while (0); |
| 3103 | FinishUpdate(false, aProofOfLock); |
| 3104 | } |
| 3105 | } |
| 3106 | |
| 3107 | void CacheIndex::UpdateIndex(const StaticMutexAutoLock& aProofOfLock) { |
| 3108 | sLock.AssertCurrentThreadOwns(); |
| 3109 | LOG(("CacheIndex::UpdateIndex()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex()" ); } } while (0); |
| 3110 | |
| 3111 | MOZ_ASSERT(mPendingUpdates.Count() == 0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mPendingUpdates.Count() == 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mPendingUpdates.Count() == 0 ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "mPendingUpdates.Count() == 0", "./../../../netwerk/cache2/CacheIndex.cpp" , 3111); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mPendingUpdates.Count() == 0" ")"); do { MOZ_CrashSequence(__null, 3111); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 3112 | sLock.AssertCurrentThreadOwns(); |
| 3113 | |
| 3114 | nsresult rv; |
| 3115 | |
| 3116 | if (!mDirEnumerator) { |
| 3117 | rv = SetupDirectoryEnumerator(); |
| 3118 | if (mState == SHUTDOWN) { |
| 3119 | // The index was shut down while we released the lock. FinishUpdate() was |
| 3120 | // already called from Shutdown(), so just simply return here. |
| 3121 | return; |
| 3122 | } |
| 3123 | |
| 3124 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 3125 | FinishUpdate(false, aProofOfLock); |
| 3126 | return; |
| 3127 | } |
| 3128 | } |
| 3129 | |
| 3130 | while (true) { |
| 3131 | if (CacheIOThread::YieldAndRerun()) { |
| 3132 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Breaking loop for higher level " "events."); } } while (0) |
| 3133 | ("CacheIndex::UpdateIndex() - Breaking loop for higher level "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Breaking loop for higher level " "events."); } } while (0) |
| 3134 | "events."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Breaking loop for higher level " "events."); } } while (0); |
| 3135 | mUpdateEventPending = true; |
| 3136 | return; |
| 3137 | } |
| 3138 | |
| 3139 | bool fileExists = false; |
| 3140 | nsCOMPtr<nsIFile> file; |
| 3141 | { |
| 3142 | // Do not do IO under the lock. |
| 3143 | nsCOMPtr<nsIDirectoryEnumerator> dirEnumerator(mDirEnumerator); |
| 3144 | StaticMutexAutoUnlock unlock(sLock); |
| 3145 | rv = dirEnumerator->GetNextFile(getter_AddRefs(file)); |
| 3146 | |
| 3147 | if (file) { |
| 3148 | file->Exists(&fileExists); |
| 3149 | } |
| 3150 | } |
| 3151 | if (mState == SHUTDOWN) { |
| 3152 | return; |
| 3153 | } |
| 3154 | if (!file) { |
| 3155 | FinishUpdate(NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))), aProofOfLock); |
| 3156 | return; |
| 3157 | } |
| 3158 | |
| 3159 | nsAutoCString leaf; |
| 3160 | rv = file->GetNativeLeafName(leaf); |
| 3161 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 3162 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - GetNativeLeafName() failed! Skipping " "file."); } } while (0) |
| 3163 | ("CacheIndex::UpdateIndex() - GetNativeLeafName() failed! Skipping "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - GetNativeLeafName() failed! Skipping " "file."); } } while (0) |
| 3164 | "file."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - GetNativeLeafName() failed! Skipping " "file."); } } while (0); |
| 3165 | mDontMarkIndexClean = true; |
| 3166 | continue; |
| 3167 | } |
| 3168 | |
| 3169 | if (!fileExists) { |
| 3170 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - File returned by the iterator was " "removed in the meantime [name=%s]", leaf.get()); } } while ( 0) |
| 3171 | ("CacheIndex::UpdateIndex() - File returned by the iterator was "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - File returned by the iterator was " "removed in the meantime [name=%s]", leaf.get()); } } while ( 0) |
| 3172 | "removed in the meantime [name=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - File returned by the iterator was " "removed in the meantime [name=%s]", leaf.get()); } } while ( 0) |
| 3173 | leaf.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - File returned by the iterator was " "removed in the meantime [name=%s]", leaf.get()); } } while ( 0); |
| 3174 | continue; |
| 3175 | } |
| 3176 | |
| 3177 | SHA1Sum::Hash hash; |
| 3178 | rv = CacheFileIOManager::StrToHash(leaf, &hash); |
| 3179 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 3180 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Filename is not a hash, removing file. " "[name=%s]", leaf.get()); } } while (0) |
| 3181 | ("CacheIndex::UpdateIndex() - Filename is not a hash, removing file. "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Filename is not a hash, removing file. " "[name=%s]", leaf.get()); } } while (0) |
| 3182 | "[name=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Filename is not a hash, removing file. " "[name=%s]", leaf.get()); } } while (0) |
| 3183 | leaf.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Filename is not a hash, removing file. " "[name=%s]", leaf.get()); } } while (0); |
| 3184 | file->Remove(false); |
| 3185 | continue; |
| 3186 | } |
| 3187 | |
| 3188 | CacheIndexEntry* entry = mIndex.GetEntry(hash); |
| 3189 | if (entry && entry->IsRemoved()) { |
| 3190 | if (entry->IsFresh()) { |
| 3191 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Found file that should not exist. " "[name=%s]", leaf.get()); } } while (0) |
| 3192 | ("CacheIndex::UpdateIndex() - Found file that should not exist. "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Found file that should not exist. " "[name=%s]", leaf.get()); } } while (0) |
| 3193 | "[name=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Found file that should not exist. " "[name=%s]", leaf.get()); } } while (0) |
| 3194 | leaf.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Found file that should not exist. " "[name=%s]", leaf.get()); } } while (0); |
| 3195 | entry->Log(); |
| 3196 | } |
| 3197 | entry = nullptr; |
| 3198 | } |
| 3199 | |
| 3200 | #ifdef DEBUG1 |
| 3201 | RefPtr<CacheFileHandle> handle; |
| 3202 | CacheFileIOManager::gInstance->mHandles.GetHandle(&hash, |
| 3203 | getter_AddRefs(handle)); |
| 3204 | #endif |
| 3205 | |
| 3206 | if (entry && entry->IsFresh()) { |
| 3207 | // the entry is up to date |
| 3208 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Skipping file because the entry is up " " to date. [name=%s]", leaf.get()); } } while (0) |
| 3209 | ("CacheIndex::UpdateIndex() - Skipping file because the entry is up "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Skipping file because the entry is up " " to date. [name=%s]", leaf.get()); } } while (0) |
| 3210 | " to date. [name=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Skipping file because the entry is up " " to date. [name=%s]", leaf.get()); } } while (0) |
| 3211 | leaf.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Skipping file because the entry is up " " to date. [name=%s]", leaf.get()); } } while (0); |
| 3212 | entry->Log(); |
| 3213 | // there must be an active CacheFile if the entry is not initialized |
| 3214 | MOZ_ASSERT(entry->IsInitialized() || handle)do { static_assert( mozilla::detail::AssertionConditionType< decltype(entry->IsInitialized() || handle)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(entry->IsInitialized() || handle))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("entry->IsInitialized() || handle", "./../../../netwerk/cache2/CacheIndex.cpp" , 3214); AnnotateMozCrashReason("MOZ_ASSERT" "(" "entry->IsInitialized() || handle" ")"); do { MOZ_CrashSequence(__null, 3214); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 3215 | continue; |
| 3216 | } |
| 3217 | |
| 3218 | MOZ_ASSERT(!handle)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!handle)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!handle))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!handle", "./../../../netwerk/cache2/CacheIndex.cpp" , 3218); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!handle" ")" ); do { MOZ_CrashSequence(__null, 3218); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 3219 | |
| 3220 | if (entry) { |
| 3221 | PRTime lastModifiedTime; |
| 3222 | { |
| 3223 | // Do not do IO under the lock. |
| 3224 | StaticMutexAutoUnlock unlock(sLock); |
| 3225 | rv = file->GetLastModifiedTime(&lastModifiedTime); |
| 3226 | } |
| 3227 | if (mState == SHUTDOWN) { |
| 3228 | return; |
| 3229 | } |
| 3230 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 3231 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Cannot get lastModifiedTime. " "[name=%s]", leaf.get()); } } while (0) |
| 3232 | ("CacheIndex::UpdateIndex() - Cannot get lastModifiedTime. "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Cannot get lastModifiedTime. " "[name=%s]", leaf.get()); } } while (0) |
| 3233 | "[name=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Cannot get lastModifiedTime. " "[name=%s]", leaf.get()); } } while (0) |
| 3234 | leaf.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Cannot get lastModifiedTime. " "[name=%s]", leaf.get()); } } while (0); |
| 3235 | // Assume the file is newer than index |
| 3236 | } else { |
| 3237 | if (mIndexTimeStamp > (lastModifiedTime / PR_MSEC_PER_SEC1000L)) { |
| 3238 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Skipping file because of last " "modified time. [name=%s, indexTimeStamp=%" "u" ", " "lastModifiedTime=%" "l" "d" "]", leaf.get(), mIndexTimeStamp, lastModifiedTime / 1000L); } } while (0) |
| 3239 | ("CacheIndex::UpdateIndex() - Skipping file because of last "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Skipping file because of last " "modified time. [name=%s, indexTimeStamp=%" "u" ", " "lastModifiedTime=%" "l" "d" "]", leaf.get(), mIndexTimeStamp, lastModifiedTime / 1000L); } } while (0) |
| 3240 | "modified time. [name=%s, indexTimeStamp=%" PRIu32 ", "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Skipping file because of last " "modified time. [name=%s, indexTimeStamp=%" "u" ", " "lastModifiedTime=%" "l" "d" "]", leaf.get(), mIndexTimeStamp, lastModifiedTime / 1000L); } } while (0) |
| 3241 | "lastModifiedTime=%" PRId64 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Skipping file because of last " "modified time. [name=%s, indexTimeStamp=%" "u" ", " "lastModifiedTime=%" "l" "d" "]", leaf.get(), mIndexTimeStamp, lastModifiedTime / 1000L); } } while (0) |
| 3242 | leaf.get(), mIndexTimeStamp,do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Skipping file because of last " "modified time. [name=%s, indexTimeStamp=%" "u" ", " "lastModifiedTime=%" "l" "d" "]", leaf.get(), mIndexTimeStamp, lastModifiedTime / 1000L); } } while (0) |
| 3243 | lastModifiedTime / PR_MSEC_PER_SEC))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Skipping file because of last " "modified time. [name=%s, indexTimeStamp=%" "u" ", " "lastModifiedTime=%" "l" "d" "]", leaf.get(), mIndexTimeStamp, lastModifiedTime / 1000L); } } while (0); |
| 3244 | |
| 3245 | CacheIndexEntryAutoManage entryMng(&hash, this, aProofOfLock); |
| 3246 | entry->MarkFresh(); |
| 3247 | continue; |
| 3248 | } |
| 3249 | } |
| 3250 | } |
| 3251 | |
| 3252 | RefPtr<CacheFileMetadata> meta = new CacheFileMetadata(); |
| 3253 | int64_t size = 0; |
| 3254 | |
| 3255 | { |
| 3256 | // Do not do IO under the lock. |
| 3257 | StaticMutexAutoUnlock unlock(sLock); |
| 3258 | rv = meta->SyncReadMetadata(file); |
| 3259 | |
| 3260 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
| 3261 | rv = file->GetFileSize(&size); |
| 3262 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 3263 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Cannot get filesize of file that " "was successfully parsed. [name=%s]", leaf.get()); } } while (0) |
| 3264 | ("CacheIndex::UpdateIndex() - Cannot get filesize of file that "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Cannot get filesize of file that " "was successfully parsed. [name=%s]", leaf.get()); } } while (0) |
| 3265 | "was successfully parsed. [name=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Cannot get filesize of file that " "was successfully parsed. [name=%s]", leaf.get()); } } while (0) |
| 3266 | leaf.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Cannot get filesize of file that " "was successfully parsed. [name=%s]", leaf.get()); } } while (0); |
| 3267 | } |
| 3268 | } |
| 3269 | } |
| 3270 | if (mState == SHUTDOWN) { |
| 3271 | return; |
| 3272 | } |
| 3273 | |
| 3274 | // Nobody could add the entry while the lock was released since we modify |
| 3275 | // the index only on IO thread and this loop is executed on IO thread too. |
| 3276 | entry = mIndex.GetEntry(hash); |
| 3277 | MOZ_ASSERT(!entry || !entry->IsFresh())do { static_assert( mozilla::detail::AssertionConditionType< decltype(!entry || !entry->IsFresh())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!entry || !entry->IsFresh ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("!entry || !entry->IsFresh()", "./../../../netwerk/cache2/CacheIndex.cpp" , 3277); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!entry || !entry->IsFresh()" ")"); do { MOZ_CrashSequence(__null, 3277); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 3278 | |
| 3279 | CacheIndexEntryAutoManage entryMng(&hash, this, aProofOfLock); |
| 3280 | |
| 3281 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 3282 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - CacheFileMetadata::SyncReadMetadata() " "failed, removing file. [name=%s]", leaf.get()); } } while ( 0) |
| 3283 | ("CacheIndex::UpdateIndex() - CacheFileMetadata::SyncReadMetadata() "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - CacheFileMetadata::SyncReadMetadata() " "failed, removing file. [name=%s]", leaf.get()); } } while ( 0) |
| 3284 | "failed, removing file. [name=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - CacheFileMetadata::SyncReadMetadata() " "failed, removing file. [name=%s]", leaf.get()); } } while ( 0) |
| 3285 | leaf.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - CacheFileMetadata::SyncReadMetadata() " "failed, removing file. [name=%s]", leaf.get()); } } while ( 0); |
| 3286 | } else { |
| 3287 | entry = mIndex.PutEntry(hash); |
| 3288 | rv = InitEntryFromDiskData(entry, meta, size); |
| 3289 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 3290 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - CacheIndex::InitEntryFromDiskData " "failed, removing file. [name=%s]", leaf.get()); } } while ( 0) |
| 3291 | ("CacheIndex::UpdateIndex() - CacheIndex::InitEntryFromDiskData "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - CacheIndex::InitEntryFromDiskData " "failed, removing file. [name=%s]", leaf.get()); } } while ( 0) |
| 3292 | "failed, removing file. [name=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - CacheIndex::InitEntryFromDiskData " "failed, removing file. [name=%s]", leaf.get()); } } while ( 0) |
| 3293 | leaf.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - CacheIndex::InitEntryFromDiskData " "failed, removing file. [name=%s]", leaf.get()); } } while ( 0); |
| 3294 | } |
| 3295 | } |
| 3296 | |
| 3297 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 3298 | file->Remove(false); |
| 3299 | if (entry) { |
| 3300 | entry->MarkRemoved(); |
| 3301 | entry->MarkFresh(); |
| 3302 | entry->MarkDirty(); |
| 3303 | } |
| 3304 | } else { |
| 3305 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Added/updated entry to/in index. " "[name=%s]", leaf.get()); } } while (0) |
| 3306 | ("CacheIndex::UpdateIndex() - Added/updated entry to/in index. "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Added/updated entry to/in index. " "[name=%s]", leaf.get()); } } while (0) |
| 3307 | "[name=%s]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Added/updated entry to/in index. " "[name=%s]", leaf.get()); } } while (0) |
| 3308 | leaf.get()))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::UpdateIndex() - Added/updated entry to/in index. " "[name=%s]", leaf.get()); } } while (0); |
| 3309 | entry->Log(); |
| 3310 | } |
| 3311 | } |
| 3312 | |
| 3313 | MOZ_ASSERT_UNREACHABLE("We should never get here")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "MOZ_ASSERT_UNREACHABLE: " "We should never get here" ")", "./../../../netwerk/cache2/CacheIndex.cpp" , 3313); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "MOZ_ASSERT_UNREACHABLE: " "We should never get here" ")"); do { MOZ_CrashSequence(__null, 3313); __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
| 3314 | } |
| 3315 | |
| 3316 | void CacheIndex::FinishUpdate(bool aSucceeded, |
| 3317 | const StaticMutexAutoLock& aProofOfLock) { |
| 3318 | LOG(("CacheIndex::FinishUpdate() [succeeded=%d]", aSucceeded))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::FinishUpdate() [succeeded=%d]" , aSucceeded); } } while (0); |
| 3319 | |
| 3320 | MOZ_ASSERT(mState == UPDATING || mState == BUILDING ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(mState == UPDATING || mState == BUILDING || (!aSucceeded && mState == SHUTDOWN))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mState == UPDATING || mState == BUILDING || (!aSucceeded && mState == SHUTDOWN))) ), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mState == UPDATING || mState == BUILDING || (!aSucceeded && mState == SHUTDOWN)" , "./../../../netwerk/cache2/CacheIndex.cpp", 3321); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "mState == UPDATING || mState == BUILDING || (!aSucceeded && mState == SHUTDOWN)" ")"); do { MOZ_CrashSequence(__null, 3321); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
| 3321 | (!aSucceeded && mState == SHUTDOWN))do { static_assert( mozilla::detail::AssertionConditionType< decltype(mState == UPDATING || mState == BUILDING || (!aSucceeded && mState == SHUTDOWN))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mState == UPDATING || mState == BUILDING || (!aSucceeded && mState == SHUTDOWN))) ), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mState == UPDATING || mState == BUILDING || (!aSucceeded && mState == SHUTDOWN)" , "./../../../netwerk/cache2/CacheIndex.cpp", 3321); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "mState == UPDATING || mState == BUILDING || (!aSucceeded && mState == SHUTDOWN)" ")"); do { MOZ_CrashSequence(__null, 3321); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 3322 | |
| 3323 | if (mDirEnumerator) { |
| 3324 | if (NS_IsMainThread()) { |
| 3325 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::FinishUpdate() - posting of PreShutdownInternal failed?" " Cannot safely release mDirEnumerator, leaking it!"); } } while (0) |
| 3326 | ("CacheIndex::FinishUpdate() - posting of PreShutdownInternal failed?"do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::FinishUpdate() - posting of PreShutdownInternal failed?" " Cannot safely release mDirEnumerator, leaking it!"); } } while (0) |
| 3327 | " Cannot safely release mDirEnumerator, leaking it!"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::FinishUpdate() - posting of PreShutdownInternal failed?" " Cannot safely release mDirEnumerator, leaking it!"); } } while (0); |
| 3328 | NS_WARNING(("CacheIndex::FinishUpdate() - Leaking mDirEnumerator!"))NS_DebugBreak(NS_DEBUG_WARNING, ("CacheIndex::FinishUpdate() - Leaking mDirEnumerator!" ), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp", 3328); |
| 3329 | // This can happen only in case dispatching event to IO thread failed in |
| 3330 | // CacheIndex::PreShutdown(). |
| 3331 | mDirEnumerator.forget() |
| 3332 | .leak(); // Leak it since dir enumerator is not threadsafe |
| 3333 | } else { |
| 3334 | mDirEnumerator->Close(); |
| 3335 | mDirEnumerator = nullptr; |
| 3336 | } |
| 3337 | } |
| 3338 | |
| 3339 | if (!aSucceeded) { |
| 3340 | mDontMarkIndexClean = true; |
| 3341 | } |
| 3342 | |
| 3343 | if (mState == SHUTDOWN) { |
| 3344 | return; |
| 3345 | } |
| 3346 | |
| 3347 | if (mState == UPDATING && aSucceeded) { |
| 3348 | // If we've iterated over all entries successfully then all entries that |
| 3349 | // really exist on the disk are now marked as fresh. All non-fresh entries |
| 3350 | // don't exist anymore and must be removed from the index. |
| 3351 | RemoveNonFreshEntries(aProofOfLock); |
| 3352 | } |
| 3353 | |
| 3354 | // Make sure we won't start update. If the build or update failed, there is no |
| 3355 | // reason to believe that it will succeed next time. |
| 3356 | mIndexNeedsUpdate = false; |
| 3357 | |
| 3358 | ChangeState(READY, aProofOfLock); |
| 3359 | mLastDumpTime = TimeStamp::NowLoRes(); // Do not dump new index immediately |
| 3360 | } |
| 3361 | |
| 3362 | void CacheIndex::RemoveNonFreshEntries( |
| 3363 | const StaticMutexAutoLock& aProofOfLock) { |
| 3364 | sLock.AssertCurrentThreadOwns(); |
| 3365 | for (auto iter = mIndex.Iter(); !iter.Done(); iter.Next()) { |
| 3366 | CacheIndexEntry* entry = iter.Get(); |
| 3367 | if (entry->IsFresh()) { |
| 3368 | continue; |
| 3369 | } |
| 3370 | |
| 3371 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveNonFreshEntries() - Removing entry. " "[hash=%08x%08x%08x%08x%08x]", PR_htonl((reinterpret_cast< const uint32_t*>(entry->Hash()))[0]), PR_htonl((reinterpret_cast <const uint32_t*>(entry->Hash()))[1]), PR_htonl((reinterpret_cast <const uint32_t*>(entry->Hash()))[2]), PR_htonl((reinterpret_cast <const uint32_t*>(entry->Hash()))[3]), PR_htonl((reinterpret_cast <const uint32_t*>(entry->Hash()))[4])); } } while (0 ) |
| 3372 | ("CacheIndex::RemoveNonFreshEntries() - Removing entry. "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveNonFreshEntries() - Removing entry. " "[hash=%08x%08x%08x%08x%08x]", PR_htonl((reinterpret_cast< const uint32_t*>(entry->Hash()))[0]), PR_htonl((reinterpret_cast <const uint32_t*>(entry->Hash()))[1]), PR_htonl((reinterpret_cast <const uint32_t*>(entry->Hash()))[2]), PR_htonl((reinterpret_cast <const uint32_t*>(entry->Hash()))[3]), PR_htonl((reinterpret_cast <const uint32_t*>(entry->Hash()))[4])); } } while (0 ) |
| 3373 | "[hash=%08x%08x%08x%08x%08x]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveNonFreshEntries() - Removing entry. " "[hash=%08x%08x%08x%08x%08x]", PR_htonl((reinterpret_cast< const uint32_t*>(entry->Hash()))[0]), PR_htonl((reinterpret_cast <const uint32_t*>(entry->Hash()))[1]), PR_htonl((reinterpret_cast <const uint32_t*>(entry->Hash()))[2]), PR_htonl((reinterpret_cast <const uint32_t*>(entry->Hash()))[3]), PR_htonl((reinterpret_cast <const uint32_t*>(entry->Hash()))[4])); } } while (0 ) |
| 3374 | LOGSHA1(entry->Hash())))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::RemoveNonFreshEntries() - Removing entry. " "[hash=%08x%08x%08x%08x%08x]", PR_htonl((reinterpret_cast< const uint32_t*>(entry->Hash()))[0]), PR_htonl((reinterpret_cast <const uint32_t*>(entry->Hash()))[1]), PR_htonl((reinterpret_cast <const uint32_t*>(entry->Hash()))[2]), PR_htonl((reinterpret_cast <const uint32_t*>(entry->Hash()))[3]), PR_htonl((reinterpret_cast <const uint32_t*>(entry->Hash()))[4])); } } while (0 ); |
| 3375 | |
| 3376 | { |
| 3377 | CacheIndexEntryAutoManage emng(entry->Hash(), this, aProofOfLock); |
| 3378 | emng.DoNotSearchInIndex(); |
| 3379 | } |
| 3380 | |
| 3381 | iter.Remove(); |
| 3382 | } |
| 3383 | } |
| 3384 | |
| 3385 | // static |
| 3386 | char const* CacheIndex::StateString(EState aState) { |
| 3387 | switch (aState) { |
| 3388 | case INITIAL: |
| 3389 | return "INITIAL"; |
| 3390 | case READING: |
| 3391 | return "READING"; |
| 3392 | case WRITING: |
| 3393 | return "WRITING"; |
| 3394 | case BUILDING: |
| 3395 | return "BUILDING"; |
| 3396 | case UPDATING: |
| 3397 | return "UPDATING"; |
| 3398 | case READY: |
| 3399 | return "READY"; |
| 3400 | case SHUTDOWN: |
| 3401 | return "SHUTDOWN"; |
| 3402 | } |
| 3403 | |
| 3404 | MOZ_ASSERT(false, "Unexpected state!")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Unexpected state!" ")", "./../../../netwerk/cache2/CacheIndex.cpp", 3404); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "false" ") (" "Unexpected state!" ")"); do { MOZ_CrashSequence(__null, 3404); __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
| 3405 | return "?"; |
| 3406 | } |
| 3407 | |
| 3408 | void CacheIndex::ChangeState(EState aNewState, |
| 3409 | const StaticMutexAutoLock& aProofOfLock) { |
| 3410 | sLock.AssertCurrentThreadOwns(); |
| 3411 | LOG(("CacheIndex::ChangeState() changing state %s -> %s", StateString(mState),do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ChangeState() changing state %s -> %s" , StateString(mState), StateString(aNewState)); } } while (0) |
| 3412 | StateString(aNewState)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ChangeState() changing state %s -> %s" , StateString(mState), StateString(aNewState)); } } while (0); |
| 3413 | |
| 3414 | // All pending updates should be processed before changing state |
| 3415 | MOZ_ASSERT(mPendingUpdates.Count() == 0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mPendingUpdates.Count() == 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mPendingUpdates.Count() == 0 ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "mPendingUpdates.Count() == 0", "./../../../netwerk/cache2/CacheIndex.cpp" , 3415); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mPendingUpdates.Count() == 0" ")"); do { MOZ_CrashSequence(__null, 3415); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 3416 | |
| 3417 | // PreShutdownInternal() should change the state to READY from every state. It |
| 3418 | // may go through different states, but once we are in READY state the only |
| 3419 | // possible transition is to SHUTDOWN state. |
| 3420 | MOZ_ASSERT(!mShuttingDown || mState != READY || aNewState == SHUTDOWN)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mShuttingDown || mState != READY || aNewState == SHUTDOWN )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(!mShuttingDown || mState != READY || aNewState == SHUTDOWN ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "!mShuttingDown || mState != READY || aNewState == SHUTDOWN", "./../../../netwerk/cache2/CacheIndex.cpp", 3420); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!mShuttingDown || mState != READY || aNewState == SHUTDOWN" ")"); do { MOZ_CrashSequence(__null, 3420); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 3421 | |
| 3422 | // Start updating process when switching to READY state if needed |
| 3423 | if (aNewState == READY && StartUpdatingIndexIfNeeded(aProofOfLock, true)) { |
| 3424 | return; |
| 3425 | } |
| 3426 | |
| 3427 | // Try to evict entries over limit everytime we're leaving state READING, |
| 3428 | // BUILDING or UPDATING, but not during shutdown or when removing all |
| 3429 | // entries. |
| 3430 | if (!mShuttingDown && !mRemovingAll && aNewState != SHUTDOWN && |
| 3431 | (mState == READING || mState == BUILDING || mState == UPDATING)) { |
| 3432 | CacheFileIOManager::EvictIfOverLimit(); |
| 3433 | } |
| 3434 | |
| 3435 | mState = aNewState; |
| 3436 | |
| 3437 | if (mState != SHUTDOWN) { |
| 3438 | CacheFileIOManager::CacheIndexStateChanged(); |
| 3439 | } |
| 3440 | |
| 3441 | NotifyAsyncGetDiskConsumptionCallbacks(); |
| 3442 | } |
| 3443 | |
| 3444 | void CacheIndex::NotifyAsyncGetDiskConsumptionCallbacks() { |
| 3445 | if ((mState == READY || mState == WRITING) && |
| 3446 | !mAsyncGetDiskConsumptionBlocked && mDiskConsumptionObservers.Length()) { |
| 3447 | for (uint32_t i = 0; i < mDiskConsumptionObservers.Length(); ++i) { |
| 3448 | DiskConsumptionObserver* o = mDiskConsumptionObservers[i]; |
| 3449 | // Safe to call under the lock. We always post to the main thread. |
| 3450 | o->OnDiskConsumption(mIndexStats.Size() << 10); |
| 3451 | } |
| 3452 | |
| 3453 | mDiskConsumptionObservers.Clear(); |
| 3454 | } |
| 3455 | } |
| 3456 | |
| 3457 | void CacheIndex::AllocBuffer() { |
| 3458 | switch (mState) { |
| 3459 | case WRITING: |
| 3460 | mRWBufSize = sizeof(CacheIndexHeader) + sizeof(CacheHash::Hash32_t) + |
| 3461 | mProcessEntries * sizeof(CacheIndexRecord); |
| 3462 | if (mRWBufSize > kMaxBufSize16384) { |
| 3463 | mRWBufSize = kMaxBufSize16384; |
| 3464 | } |
| 3465 | break; |
| 3466 | case READING: |
| 3467 | mRWBufSize = kMaxBufSize16384; |
| 3468 | break; |
| 3469 | default: |
| 3470 | MOZ_ASSERT(false, "Unexpected state!")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Unexpected state!" ")", "./../../../netwerk/cache2/CacheIndex.cpp", 3470); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "false" ") (" "Unexpected state!" ")"); do { MOZ_CrashSequence(__null, 3470); __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
| 3471 | } |
| 3472 | |
| 3473 | mRWBuf = static_cast<char*>(moz_xmalloc(mRWBufSize)); |
| 3474 | } |
| 3475 | |
| 3476 | void CacheIndex::ReleaseBuffer() { |
| 3477 | sLock.AssertCurrentThreadOwns(); |
| 3478 | |
| 3479 | if (!mRWBuf || mRWPending) { |
| 3480 | return; |
| 3481 | } |
| 3482 | |
| 3483 | LOG(("CacheIndex::ReleaseBuffer() releasing buffer"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::ReleaseBuffer() releasing buffer" ); } } while (0); |
| 3484 | |
| 3485 | free(mRWBuf); |
| 3486 | mRWBuf = nullptr; |
| 3487 | mRWBufSize = 0; |
| 3488 | mRWBufPos = 0; |
| 3489 | } |
| 3490 | |
| 3491 | void CacheIndex::FrecencyStorage::AppendRecord( |
| 3492 | CacheIndexRecordWrapper* aRecord, const StaticMutexAutoLock& aProofOfLock) { |
| 3493 | sLock.AssertCurrentThreadOwns(); |
| 3494 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::FrecencyStorage::AppendRecord() [record=%p, " "hash=%08x%08x%08x" "%08x%08x]", aRecord, PR_htonl((reinterpret_cast <const uint32_t*>(aRecord->Get()->mHash))[0]), PR_htonl ((reinterpret_cast<const uint32_t*>(aRecord->Get()-> mHash))[1]), PR_htonl((reinterpret_cast<const uint32_t*> (aRecord->Get()->mHash))[2]), PR_htonl((reinterpret_cast <const uint32_t*>(aRecord->Get()->mHash))[3]), PR_htonl ((reinterpret_cast<const uint32_t*>(aRecord->Get()-> mHash))[4])); } } while (0) |
| 3495 | ("CacheIndex::FrecencyStorage::AppendRecord() [record=%p, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::FrecencyStorage::AppendRecord() [record=%p, " "hash=%08x%08x%08x" "%08x%08x]", aRecord, PR_htonl((reinterpret_cast <const uint32_t*>(aRecord->Get()->mHash))[0]), PR_htonl ((reinterpret_cast<const uint32_t*>(aRecord->Get()-> mHash))[1]), PR_htonl((reinterpret_cast<const uint32_t*> (aRecord->Get()->mHash))[2]), PR_htonl((reinterpret_cast <const uint32_t*>(aRecord->Get()->mHash))[3]), PR_htonl ((reinterpret_cast<const uint32_t*>(aRecord->Get()-> mHash))[4])); } } while (0) |
| 3496 | "hash=%08x%08x%08x"do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::FrecencyStorage::AppendRecord() [record=%p, " "hash=%08x%08x%08x" "%08x%08x]", aRecord, PR_htonl((reinterpret_cast <const uint32_t*>(aRecord->Get()->mHash))[0]), PR_htonl ((reinterpret_cast<const uint32_t*>(aRecord->Get()-> mHash))[1]), PR_htonl((reinterpret_cast<const uint32_t*> (aRecord->Get()->mHash))[2]), PR_htonl((reinterpret_cast <const uint32_t*>(aRecord->Get()->mHash))[3]), PR_htonl ((reinterpret_cast<const uint32_t*>(aRecord->Get()-> mHash))[4])); } } while (0) |
| 3497 | "%08x%08x]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::FrecencyStorage::AppendRecord() [record=%p, " "hash=%08x%08x%08x" "%08x%08x]", aRecord, PR_htonl((reinterpret_cast <const uint32_t*>(aRecord->Get()->mHash))[0]), PR_htonl ((reinterpret_cast<const uint32_t*>(aRecord->Get()-> mHash))[1]), PR_htonl((reinterpret_cast<const uint32_t*> (aRecord->Get()->mHash))[2]), PR_htonl((reinterpret_cast <const uint32_t*>(aRecord->Get()->mHash))[3]), PR_htonl ((reinterpret_cast<const uint32_t*>(aRecord->Get()-> mHash))[4])); } } while (0) |
| 3498 | aRecord, LOGSHA1(aRecord->Get()->mHash)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::FrecencyStorage::AppendRecord() [record=%p, " "hash=%08x%08x%08x" "%08x%08x]", aRecord, PR_htonl((reinterpret_cast <const uint32_t*>(aRecord->Get()->mHash))[0]), PR_htonl ((reinterpret_cast<const uint32_t*>(aRecord->Get()-> mHash))[1]), PR_htonl((reinterpret_cast<const uint32_t*> (aRecord->Get()->mHash))[2]), PR_htonl((reinterpret_cast <const uint32_t*>(aRecord->Get()->mHash))[3]), PR_htonl ((reinterpret_cast<const uint32_t*>(aRecord->Get()-> mHash))[4])); } } while (0); |
| 3499 | MOZ_DIAGNOSTIC_ASSERT(!mRecs.Contains(aRecord))do { static_assert( mozilla::detail::AssertionConditionType< decltype(!mRecs.Contains(aRecord))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mRecs.Contains(aRecord)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!mRecs.Contains(aRecord)" , "./../../../netwerk/cache2/CacheIndex.cpp", 3499); AnnotateMozCrashReason ("MOZ_DIAGNOSTIC_ASSERT" "(" "!mRecs.Contains(aRecord)" ")"); do { MOZ_CrashSequence(__null, 3499); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 3500 | mRecs.PutEntry(aRecord); |
| 3501 | } |
| 3502 | |
| 3503 | void CacheIndex::FrecencyStorage::RemoveRecord( |
| 3504 | CacheIndexRecordWrapper* aRecord, const StaticMutexAutoLock& aProofOfLock) { |
| 3505 | sLock.AssertCurrentThreadOwns(); |
| 3506 | LOG(("CacheIndex::FrecencyStorage::RemoveRecord() [record=%p]", aRecord))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::FrecencyStorage::RemoveRecord() [record=%p]" , aRecord); } } while (0); |
| 3507 | MOZ_RELEASE_ASSERT(mRecs.Contains(aRecord))do { static_assert( mozilla::detail::AssertionConditionType< decltype(mRecs.Contains(aRecord))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mRecs.Contains(aRecord)))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("mRecs.Contains(aRecord)" , "./../../../netwerk/cache2/CacheIndex.cpp", 3507); AnnotateMozCrashReason ("MOZ_RELEASE_ASSERT" "(" "mRecs.Contains(aRecord)" ")"); do { MOZ_CrashSequence(__null, 3507); __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
| 3508 | mRecs.RemoveEntry(aRecord); |
| 3509 | } |
| 3510 | |
| 3511 | void CacheIndex::FrecencyStorage::ReplaceRecord( |
| 3512 | CacheIndexRecordWrapper* aOldRecord, CacheIndexRecordWrapper* aNewRecord, |
| 3513 | const StaticMutexAutoLock& aProofOfLock) { |
| 3514 | sLock.AssertCurrentThreadOwns(); |
| 3515 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::FrecencyStorage::ReplaceRecord() [oldRecord=%p, " "newRecord=%p]", aOldRecord, aNewRecord); } } while (0) |
| 3516 | ("CacheIndex::FrecencyStorage::ReplaceRecord() [oldRecord=%p, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::FrecencyStorage::ReplaceRecord() [oldRecord=%p, " "newRecord=%p]", aOldRecord, aNewRecord); } } while (0) |
| 3517 | "newRecord=%p]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::FrecencyStorage::ReplaceRecord() [oldRecord=%p, " "newRecord=%p]", aOldRecord, aNewRecord); } } while (0) |
| 3518 | aOldRecord, aNewRecord))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::FrecencyStorage::ReplaceRecord() [oldRecord=%p, " "newRecord=%p]", aOldRecord, aNewRecord); } } while (0); |
| 3519 | |
| 3520 | MOZ_RELEASE_ASSERT(mRecs.Contains(aOldRecord),do { static_assert( mozilla::detail::AssertionConditionType< decltype(mRecs.Contains(aOldRecord))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mRecs.Contains(aOldRecord))) ), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mRecs.Contains(aOldRecord)" " (" "Tried to replace a record that doesn't exist" ")", "./../../../netwerk/cache2/CacheIndex.cpp" , 3521); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "mRecs.Contains(aOldRecord)" ") (" "Tried to replace a record that doesn't exist" ")"); do { MOZ_CrashSequence(__null, 3521); __attribute__((nomerge)) :: abort(); } while (false); } } while (false) |
| 3521 | "Tried to replace a record that doesn't exist")do { static_assert( mozilla::detail::AssertionConditionType< decltype(mRecs.Contains(aOldRecord))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mRecs.Contains(aOldRecord))) ), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mRecs.Contains(aOldRecord)" " (" "Tried to replace a record that doesn't exist" ")", "./../../../netwerk/cache2/CacheIndex.cpp" , 3521); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "mRecs.Contains(aOldRecord)" ") (" "Tried to replace a record that doesn't exist" ")"); do { MOZ_CrashSequence(__null, 3521); __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
| 3522 | mRecs.RemoveEntry(aOldRecord); |
| 3523 | mRecs.PutEntry(aNewRecord); |
| 3524 | } |
| 3525 | |
| 3526 | // static |
| 3527 | CacheIndex::EvictionSortedSnapshot CacheIndex::GetSortedSnapshotForEviction() { |
| 3528 | StaticMutexAutoLock lock(sLock); |
| 3529 | RefPtr<CacheIndex> index = gInstance; |
| 3530 | return index->mFrecencyStorage.GetSortedSnapshotForEviction(); |
| 3531 | } |
| 3532 | |
| 3533 | CacheIndex::EvictionSortedSnapshot |
| 3534 | CacheIndex::FrecencyStorage::GetSortedSnapshotForEviction() { |
| 3535 | CacheIndex::EvictionSortedSnapshot snapshot; |
| 3536 | snapshot.SetCapacity(mRecs.Count()); |
| 3537 | for (const auto& item : mRecs) { |
| 3538 | snapshot.AppendElement(item.GetKey()); |
| 3539 | } |
| 3540 | snapshot.Sort(FrecencyComparator()); |
| 3541 | return snapshot; |
| 3542 | } |
| 3543 | |
| 3544 | bool CacheIndex::FrecencyStorage::RecordExistedUnlocked( |
| 3545 | CacheIndexRecordWrapper* aRecord) { |
| 3546 | return mRecs.Contains(aRecord); |
| 3547 | } |
| 3548 | |
| 3549 | void CacheIndex::AddRecordToIterators(CacheIndexRecordWrapper* aRecord, |
| 3550 | const StaticMutexAutoLock& aProofOfLock) { |
| 3551 | sLock.AssertCurrentThreadOwns(); |
| 3552 | for (uint32_t i = 0; i < mIterators.Length(); ++i) { |
| 3553 | // Add a new record only when iterator is supposed to be updated. |
| 3554 | if (mIterators[i]->ShouldBeNewAdded()) { |
| 3555 | mIterators[i]->AddRecord(aRecord, aProofOfLock); |
| 3556 | } |
| 3557 | } |
| 3558 | } |
| 3559 | |
| 3560 | void CacheIndex::RemoveRecordFromIterators( |
| 3561 | CacheIndexRecordWrapper* aRecord, const StaticMutexAutoLock& aProofOfLock) { |
| 3562 | sLock.AssertCurrentThreadOwns(); |
| 3563 | for (uint32_t i = 0; i < mIterators.Length(); ++i) { |
| 3564 | // Remove the record from iterator always, it makes no sence to return |
| 3565 | // non-existing entries. Also the pointer to the record is no longer valid |
| 3566 | // once the entry is removed from index. |
| 3567 | mIterators[i]->RemoveRecord(aRecord, aProofOfLock); |
| 3568 | } |
| 3569 | } |
| 3570 | |
| 3571 | void CacheIndex::ReplaceRecordInIterators( |
| 3572 | CacheIndexRecordWrapper* aOldRecord, CacheIndexRecordWrapper* aNewRecord, |
| 3573 | const StaticMutexAutoLock& aProofOfLock) { |
| 3574 | sLock.AssertCurrentThreadOwns(); |
| 3575 | for (uint32_t i = 0; i < mIterators.Length(); ++i) { |
| 3576 | // We have to replace the record always since the pointer is no longer |
| 3577 | // valid after this point. NOTE: Replacing the record doesn't mean that |
| 3578 | // a new entry was added, it just means that the data in the entry was |
| 3579 | // changed (e.g. a file size) and we had to track this change in |
| 3580 | // mPendingUpdates since mIndex was read-only. |
| 3581 | mIterators[i]->ReplaceRecord(aOldRecord, aNewRecord, aProofOfLock); |
| 3582 | } |
| 3583 | } |
| 3584 | |
| 3585 | nsresult CacheIndex::Run() { |
| 3586 | LOG(("CacheIndex::Run()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::Run()" ); } } while (0); |
| 3587 | |
| 3588 | StaticMutexAutoLock lock(sLock); |
| 3589 | |
| 3590 | if (!IsIndexUsable()) { |
| 3591 | return NS_ERROR_NOT_AVAILABLE; |
| 3592 | } |
| 3593 | |
| 3594 | if (mState == READY && mShuttingDown) { |
| 3595 | return NS_OK; |
| 3596 | } |
| 3597 | |
| 3598 | mUpdateEventPending = false; |
| 3599 | |
| 3600 | switch (mState) { |
| 3601 | case BUILDING: |
| 3602 | BuildIndex(lock); |
| 3603 | break; |
| 3604 | case UPDATING: |
| 3605 | UpdateIndex(lock); |
| 3606 | break; |
| 3607 | default: |
| 3608 | LOG(("CacheIndex::Run() - Update/Build was canceled"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::Run() - Update/Build was canceled" ); } } while (0); |
| 3609 | } |
| 3610 | |
| 3611 | return NS_OK; |
| 3612 | } |
| 3613 | |
| 3614 | void CacheIndex::OnFileOpenedInternal(FileOpenHelper* aOpener, |
| 3615 | CacheFileHandle* aHandle, |
| 3616 | nsresult aResult, |
| 3617 | const StaticMutexAutoLock& aProofOfLock) { |
| 3618 | sLock.AssertCurrentThreadOwns(); |
| 3619 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileOpenedInternal() [opener=%p, handle=%p, " "result=0x%08" "x" "]", aOpener, aHandle, static_cast<uint32_t >(aResult)); } } while (0) |
| 3620 | ("CacheIndex::OnFileOpenedInternal() [opener=%p, handle=%p, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileOpenedInternal() [opener=%p, handle=%p, " "result=0x%08" "x" "]", aOpener, aHandle, static_cast<uint32_t >(aResult)); } } while (0) |
| 3621 | "result=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileOpenedInternal() [opener=%p, handle=%p, " "result=0x%08" "x" "]", aOpener, aHandle, static_cast<uint32_t >(aResult)); } } while (0) |
| 3622 | aOpener, aHandle, static_cast<uint32_t>(aResult)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileOpenedInternal() [opener=%p, handle=%p, " "result=0x%08" "x" "]", aOpener, aHandle, static_cast<uint32_t >(aResult)); } } while (0); |
| 3623 | MOZ_ASSERT(CacheFileIOManager::IsOnIOThread())do { static_assert( mozilla::detail::AssertionConditionType< decltype(CacheFileIOManager::IsOnIOThread())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(CacheFileIOManager::IsOnIOThread ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("CacheFileIOManager::IsOnIOThread()", "./../../../netwerk/cache2/CacheIndex.cpp" , 3623); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()" ")"); do { MOZ_CrashSequence(__null, 3623); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 3624 | |
| 3625 | nsresult rv; |
| 3626 | |
| 3627 | MOZ_RELEASE_ASSERT(IsIndexUsable())do { static_assert( mozilla::detail::AssertionConditionType< decltype(IsIndexUsable())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(IsIndexUsable()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("IsIndexUsable()" , "./../../../netwerk/cache2/CacheIndex.cpp", 3627); AnnotateMozCrashReason ("MOZ_RELEASE_ASSERT" "(" "IsIndexUsable()" ")"); do { MOZ_CrashSequence (__null, 3627); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 3628 | |
| 3629 | if (mState == READY && mShuttingDown) { |
| 3630 | return; |
| 3631 | } |
| 3632 | |
| 3633 | switch (mState) { |
| 3634 | case WRITING: |
| 3635 | MOZ_ASSERT(aOpener == mIndexFileOpener)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aOpener == mIndexFileOpener)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aOpener == mIndexFileOpener) )), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aOpener == mIndexFileOpener" , "./../../../netwerk/cache2/CacheIndex.cpp", 3635); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "aOpener == mIndexFileOpener" ")"); do { MOZ_CrashSequence (__null, 3635); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 3636 | mIndexFileOpener = nullptr; |
| 3637 | |
| 3638 | if (NS_FAILED(aResult)((bool)(__builtin_expect(!!(NS_FAILED_impl(aResult)), 0)))) { |
| 3639 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileOpenedInternal() - Can't open index file for " "writing [rv=0x%08" "x" "]", static_cast<uint32_t>(aResult )); } } while (0) |
| 3640 | ("CacheIndex::OnFileOpenedInternal() - Can't open index file for "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileOpenedInternal() - Can't open index file for " "writing [rv=0x%08" "x" "]", static_cast<uint32_t>(aResult )); } } while (0) |
| 3641 | "writing [rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileOpenedInternal() - Can't open index file for " "writing [rv=0x%08" "x" "]", static_cast<uint32_t>(aResult )); } } while (0) |
| 3642 | static_cast<uint32_t>(aResult)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileOpenedInternal() - Can't open index file for " "writing [rv=0x%08" "x" "]", static_cast<uint32_t>(aResult )); } } while (0); |
| 3643 | FinishWrite(false, aProofOfLock); |
| 3644 | } else { |
| 3645 | mIndexHandle = aHandle; |
| 3646 | WriteRecords(aProofOfLock); |
| 3647 | } |
| 3648 | break; |
| 3649 | case READING: |
| 3650 | if (aOpener == mIndexFileOpener) { |
| 3651 | mIndexFileOpener = nullptr; |
| 3652 | |
| 3653 | if (NS_SUCCEEDED(aResult)((bool)(__builtin_expect(!!(!NS_FAILED_impl(aResult)), 1)))) { |
| 3654 | if (aHandle->FileSize() == 0) { |
| 3655 | FinishRead(false, aProofOfLock); |
| 3656 | CacheFileIOManager::DoomFile(aHandle, nullptr); |
| 3657 | break; |
| 3658 | } |
| 3659 | mIndexHandle = aHandle; |
| 3660 | } else { |
| 3661 | FinishRead(false, aProofOfLock); |
| 3662 | break; |
| 3663 | } |
| 3664 | } else if (aOpener == mJournalFileOpener) { |
| 3665 | mJournalFileOpener = nullptr; |
| 3666 | mJournalHandle = aHandle; |
| 3667 | } else if (aOpener == mTmpFileOpener) { |
| 3668 | mTmpFileOpener = nullptr; |
| 3669 | mTmpHandle = aHandle; |
| 3670 | } else { |
| 3671 | MOZ_ASSERT(false, "Unexpected state!")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Unexpected state!" ")", "./../../../netwerk/cache2/CacheIndex.cpp", 3671); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "false" ") (" "Unexpected state!" ")"); do { MOZ_CrashSequence(__null, 3671); __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
| 3672 | } |
| 3673 | |
| 3674 | if (mIndexFileOpener || mJournalFileOpener || mTmpFileOpener) { |
| 3675 | // Some opener still didn't finish |
| 3676 | break; |
| 3677 | } |
| 3678 | |
| 3679 | // We fail and cancel all other openers when we opening index file fails. |
| 3680 | MOZ_ASSERT(mIndexHandle)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mIndexHandle)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mIndexHandle))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mIndexHandle", "./../../../netwerk/cache2/CacheIndex.cpp" , 3680); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIndexHandle" ")"); do { MOZ_CrashSequence(__null, 3680); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 3681 | |
| 3682 | if (mTmpHandle) { |
| 3683 | CacheFileIOManager::DoomFile(mTmpHandle, nullptr); |
| 3684 | mTmpHandle = nullptr; |
| 3685 | |
| 3686 | if (mJournalHandle) { // this shouldn't normally happen |
| 3687 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileOpenedInternal() - Unexpected state, all " "files [%s, %s, %s] should never exist. Removing whole index." , "index", "index.log", "index.tmp"); } } while (0) |
| 3688 | ("CacheIndex::OnFileOpenedInternal() - Unexpected state, all "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileOpenedInternal() - Unexpected state, all " "files [%s, %s, %s] should never exist. Removing whole index." , "index", "index.log", "index.tmp"); } } while (0) |
| 3689 | "files [%s, %s, %s] should never exist. Removing whole index.",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileOpenedInternal() - Unexpected state, all " "files [%s, %s, %s] should never exist. Removing whole index." , "index", "index.log", "index.tmp"); } } while (0) |
| 3690 | INDEX_NAME, JOURNAL_NAME, TEMP_INDEX_NAME))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileOpenedInternal() - Unexpected state, all " "files [%s, %s, %s] should never exist. Removing whole index." , "index", "index.log", "index.tmp"); } } while (0); |
| 3691 | FinishRead(false, aProofOfLock); |
| 3692 | break; |
| 3693 | } |
| 3694 | } |
| 3695 | |
| 3696 | if (mJournalHandle) { |
| 3697 | // Rename journal to make sure we update index on next start in case |
| 3698 | // firefox crashes |
| 3699 | rv = CacheFileIOManager::RenameFile( |
| 3700 | mJournalHandle, nsLiteralCString(TEMP_INDEX_NAME"index.tmp"), this); |
| 3701 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 3702 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileOpenedInternal() - CacheFileIOManager::" "RenameFile() failed synchronously [rv=0x%08" "x" "]", static_cast <uint32_t>(rv)); } } while (0) |
| 3703 | ("CacheIndex::OnFileOpenedInternal() - CacheFileIOManager::"do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileOpenedInternal() - CacheFileIOManager::" "RenameFile() failed synchronously [rv=0x%08" "x" "]", static_cast <uint32_t>(rv)); } } while (0) |
| 3704 | "RenameFile() failed synchronously [rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileOpenedInternal() - CacheFileIOManager::" "RenameFile() failed synchronously [rv=0x%08" "x" "]", static_cast <uint32_t>(rv)); } } while (0) |
| 3705 | static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileOpenedInternal() - CacheFileIOManager::" "RenameFile() failed synchronously [rv=0x%08" "x" "]", static_cast <uint32_t>(rv)); } } while (0); |
| 3706 | FinishRead(false, aProofOfLock); |
| 3707 | break; |
| 3708 | } |
| 3709 | } else { |
| 3710 | StartReadingIndex(aProofOfLock); |
| 3711 | } |
| 3712 | |
| 3713 | break; |
| 3714 | default: |
| 3715 | MOZ_ASSERT(false, "Unexpected state!")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Unexpected state!" ")", "./../../../netwerk/cache2/CacheIndex.cpp", 3715); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "false" ") (" "Unexpected state!" ")"); do { MOZ_CrashSequence(__null, 3715); __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
| 3716 | } |
| 3717 | } |
| 3718 | |
| 3719 | nsresult CacheIndex::OnFileOpened(CacheFileHandle* aHandle, nsresult aResult) { |
| 3720 | MOZ_CRASH("CacheIndex::OnFileOpened should not be called!")do { do { } while (false); MOZ_ReportCrash("" "CacheIndex::OnFileOpened should not be called!" , "./../../../netwerk/cache2/CacheIndex.cpp", 3720); AnnotateMozCrashReason ("MOZ_CRASH(" "CacheIndex::OnFileOpened should not be called!" ")"); do { MOZ_CrashSequence(__null, 3720); __attribute__((nomerge )) ::abort(); } while (false); } while (false); |
| 3721 | return NS_ERROR_UNEXPECTED; |
| 3722 | } |
| 3723 | |
| 3724 | nsresult CacheIndex::OnDataWritten(CacheFileHandle* aHandle, const char* aBuf, |
| 3725 | nsresult aResult) { |
| 3726 | LOG(("CacheIndex::OnDataWritten() [handle=%p, result=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnDataWritten() [handle=%p, result=0x%08" "x" "]", aHandle, static_cast<uint32_t>(aResult)); } } while (0) |
| 3727 | aHandle, static_cast<uint32_t>(aResult)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnDataWritten() [handle=%p, result=0x%08" "x" "]", aHandle, static_cast<uint32_t>(aResult)); } } while (0); |
| 3728 | |
| 3729 | MOZ_ASSERT(CacheFileIOManager::IsOnIOThread())do { static_assert( mozilla::detail::AssertionConditionType< decltype(CacheFileIOManager::IsOnIOThread())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(CacheFileIOManager::IsOnIOThread ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("CacheFileIOManager::IsOnIOThread()", "./../../../netwerk/cache2/CacheIndex.cpp" , 3729); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()" ")"); do { MOZ_CrashSequence(__null, 3729); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 3730 | |
| 3731 | nsresult rv; |
| 3732 | |
| 3733 | StaticMutexAutoLock lock(sLock); |
| 3734 | |
| 3735 | MOZ_RELEASE_ASSERT(IsIndexUsable())do { static_assert( mozilla::detail::AssertionConditionType< decltype(IsIndexUsable())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(IsIndexUsable()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("IsIndexUsable()" , "./../../../netwerk/cache2/CacheIndex.cpp", 3735); AnnotateMozCrashReason ("MOZ_RELEASE_ASSERT" "(" "IsIndexUsable()" ")"); do { MOZ_CrashSequence (__null, 3735); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 3736 | MOZ_RELEASE_ASSERT(mRWPending)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mRWPending)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mRWPending))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mRWPending", "./../../../netwerk/cache2/CacheIndex.cpp" , 3736); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "mRWPending" ")"); do { MOZ_CrashSequence(__null, 3736); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 3737 | mRWPending = false; |
| 3738 | |
| 3739 | if (mState == READY && mShuttingDown) { |
| 3740 | return NS_OK; |
| 3741 | } |
| 3742 | |
| 3743 | switch (mState) { |
| 3744 | case WRITING: |
| 3745 | MOZ_ASSERT(mIndexHandle == aHandle)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mIndexHandle == aHandle)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mIndexHandle == aHandle))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("mIndexHandle == aHandle" , "./../../../netwerk/cache2/CacheIndex.cpp", 3745); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "mIndexHandle == aHandle" ")"); do { MOZ_CrashSequence (__null, 3745); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 3746 | |
| 3747 | if (NS_FAILED(aResult)((bool)(__builtin_expect(!!(NS_FAILED_impl(aResult)), 0)))) { |
| 3748 | FinishWrite(false, lock); |
| 3749 | } else { |
| 3750 | if (mSkipEntries == mProcessEntries) { |
| 3751 | rv = CacheFileIOManager::RenameFile( |
| 3752 | mIndexHandle, nsLiteralCString(INDEX_NAME"index"), this); |
| 3753 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 3754 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnDataWritten() - CacheFileIOManager::" "RenameFile() failed synchronously [rv=0x%08" "x" "]", static_cast <uint32_t>(rv)); } } while (0) |
| 3755 | ("CacheIndex::OnDataWritten() - CacheFileIOManager::"do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnDataWritten() - CacheFileIOManager::" "RenameFile() failed synchronously [rv=0x%08" "x" "]", static_cast <uint32_t>(rv)); } } while (0) |
| 3756 | "RenameFile() failed synchronously [rv=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnDataWritten() - CacheFileIOManager::" "RenameFile() failed synchronously [rv=0x%08" "x" "]", static_cast <uint32_t>(rv)); } } while (0) |
| 3757 | static_cast<uint32_t>(rv)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnDataWritten() - CacheFileIOManager::" "RenameFile() failed synchronously [rv=0x%08" "x" "]", static_cast <uint32_t>(rv)); } } while (0); |
| 3758 | FinishWrite(false, lock); |
| 3759 | } |
| 3760 | } else { |
| 3761 | WriteRecords(lock); |
| 3762 | } |
| 3763 | } |
| 3764 | break; |
| 3765 | default: |
| 3766 | // Writing was canceled. |
| 3767 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnDataWritten() - ignoring notification since the " "operation was previously canceled [state=%d]", mState); } } while (0) |
| 3768 | ("CacheIndex::OnDataWritten() - ignoring notification since the "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnDataWritten() - ignoring notification since the " "operation was previously canceled [state=%d]", mState); } } while (0) |
| 3769 | "operation was previously canceled [state=%d]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnDataWritten() - ignoring notification since the " "operation was previously canceled [state=%d]", mState); } } while (0) |
| 3770 | mState))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnDataWritten() - ignoring notification since the " "operation was previously canceled [state=%d]", mState); } } while (0); |
| 3771 | ReleaseBuffer(); |
| 3772 | } |
| 3773 | |
| 3774 | return NS_OK; |
| 3775 | } |
| 3776 | |
| 3777 | nsresult CacheIndex::OnDataRead(CacheFileHandle* aHandle, char* aBuf, |
| 3778 | nsresult aResult) { |
| 3779 | LOG(("CacheIndex::OnDataRead() [handle=%p, result=0x%08" PRIx32 "]", aHandle,do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnDataRead() [handle=%p, result=0x%08" "x" "]", aHandle, static_cast<uint32_t>(aResult)); } } while (0) |
| 3780 | static_cast<uint32_t>(aResult)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnDataRead() [handle=%p, result=0x%08" "x" "]", aHandle, static_cast<uint32_t>(aResult)); } } while (0); |
| 3781 | |
| 3782 | MOZ_ASSERT(CacheFileIOManager::IsOnIOThread())do { static_assert( mozilla::detail::AssertionConditionType< decltype(CacheFileIOManager::IsOnIOThread())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(CacheFileIOManager::IsOnIOThread ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("CacheFileIOManager::IsOnIOThread()", "./../../../netwerk/cache2/CacheIndex.cpp" , 3782); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()" ")"); do { MOZ_CrashSequence(__null, 3782); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 3783 | |
| 3784 | StaticMutexAutoLock lock(sLock); |
| 3785 | |
| 3786 | MOZ_RELEASE_ASSERT(IsIndexUsable())do { static_assert( mozilla::detail::AssertionConditionType< decltype(IsIndexUsable())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(IsIndexUsable()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("IsIndexUsable()" , "./../../../netwerk/cache2/CacheIndex.cpp", 3786); AnnotateMozCrashReason ("MOZ_RELEASE_ASSERT" "(" "IsIndexUsable()" ")"); do { MOZ_CrashSequence (__null, 3786); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 3787 | MOZ_RELEASE_ASSERT(mRWPending)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mRWPending)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mRWPending))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mRWPending", "./../../../netwerk/cache2/CacheIndex.cpp" , 3787); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "mRWPending" ")"); do { MOZ_CrashSequence(__null, 3787); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 3788 | mRWPending = false; |
| 3789 | |
| 3790 | switch (mState) { |
| 3791 | case READING: |
| 3792 | MOZ_ASSERT(mIndexHandle == aHandle || mJournalHandle == aHandle)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mIndexHandle == aHandle || mJournalHandle == aHandle )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(mIndexHandle == aHandle || mJournalHandle == aHandle ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "mIndexHandle == aHandle || mJournalHandle == aHandle", "./../../../netwerk/cache2/CacheIndex.cpp" , 3792); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIndexHandle == aHandle || mJournalHandle == aHandle" ")"); do { MOZ_CrashSequence(__null, 3792); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 3793 | |
| 3794 | if (NS_FAILED(aResult)((bool)(__builtin_expect(!!(NS_FAILED_impl(aResult)), 0)))) { |
| 3795 | FinishRead(false, lock); |
| 3796 | } else { |
| 3797 | if (!mIndexOnDiskIsValid) { |
| 3798 | ParseRecords(lock); |
| 3799 | } else { |
| 3800 | ParseJournal(lock); |
| 3801 | } |
| 3802 | } |
| 3803 | break; |
| 3804 | default: |
| 3805 | // Reading was canceled. |
| 3806 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnDataRead() - ignoring notification since the " "operation was previously canceled [state=%d]", mState); } } while (0) |
| 3807 | ("CacheIndex::OnDataRead() - ignoring notification since the "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnDataRead() - ignoring notification since the " "operation was previously canceled [state=%d]", mState); } } while (0) |
| 3808 | "operation was previously canceled [state=%d]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnDataRead() - ignoring notification since the " "operation was previously canceled [state=%d]", mState); } } while (0) |
| 3809 | mState))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnDataRead() - ignoring notification since the " "operation was previously canceled [state=%d]", mState); } } while (0); |
| 3810 | ReleaseBuffer(); |
| 3811 | } |
| 3812 | |
| 3813 | return NS_OK; |
| 3814 | } |
| 3815 | |
| 3816 | nsresult CacheIndex::OnFileDoomed(CacheFileHandle* aHandle, nsresult aResult) { |
| 3817 | MOZ_CRASH("CacheIndex::OnFileDoomed should not be called!")do { do { } while (false); MOZ_ReportCrash("" "CacheIndex::OnFileDoomed should not be called!" , "./../../../netwerk/cache2/CacheIndex.cpp", 3817); AnnotateMozCrashReason ("MOZ_CRASH(" "CacheIndex::OnFileDoomed should not be called!" ")"); do { MOZ_CrashSequence(__null, 3817); __attribute__((nomerge )) ::abort(); } while (false); } while (false); |
| 3818 | return NS_ERROR_UNEXPECTED; |
| 3819 | } |
| 3820 | |
| 3821 | nsresult CacheIndex::OnEOFSet(CacheFileHandle* aHandle, nsresult aResult) { |
| 3822 | MOZ_CRASH("CacheIndex::OnEOFSet should not be called!")do { do { } while (false); MOZ_ReportCrash("" "CacheIndex::OnEOFSet should not be called!" , "./../../../netwerk/cache2/CacheIndex.cpp", 3822); AnnotateMozCrashReason ("MOZ_CRASH(" "CacheIndex::OnEOFSet should not be called!" ")" ); do { MOZ_CrashSequence(__null, 3822); __attribute__((nomerge )) ::abort(); } while (false); } while (false); |
| 3823 | return NS_ERROR_UNEXPECTED; |
| 3824 | } |
| 3825 | |
| 3826 | nsresult CacheIndex::OnFileRenamed(CacheFileHandle* aHandle, nsresult aResult) { |
| 3827 | LOG(("CacheIndex::OnFileRenamed() [handle=%p, result=0x%08" PRIx32 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileRenamed() [handle=%p, result=0x%08" "x" "]", aHandle, static_cast<uint32_t>(aResult)); } } while (0) |
| 3828 | aHandle, static_cast<uint32_t>(aResult)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileRenamed() [handle=%p, result=0x%08" "x" "]", aHandle, static_cast<uint32_t>(aResult)); } } while (0); |
| 3829 | |
| 3830 | MOZ_ASSERT(CacheFileIOManager::IsOnIOThread())do { static_assert( mozilla::detail::AssertionConditionType< decltype(CacheFileIOManager::IsOnIOThread())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(CacheFileIOManager::IsOnIOThread ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("CacheFileIOManager::IsOnIOThread()", "./../../../netwerk/cache2/CacheIndex.cpp" , 3830); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()" ")"); do { MOZ_CrashSequence(__null, 3830); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 3831 | |
| 3832 | StaticMutexAutoLock lock(sLock); |
| 3833 | |
| 3834 | MOZ_RELEASE_ASSERT(IsIndexUsable())do { static_assert( mozilla::detail::AssertionConditionType< decltype(IsIndexUsable())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(IsIndexUsable()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("IsIndexUsable()" , "./../../../netwerk/cache2/CacheIndex.cpp", 3834); AnnotateMozCrashReason ("MOZ_RELEASE_ASSERT" "(" "IsIndexUsable()" ")"); do { MOZ_CrashSequence (__null, 3834); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 3835 | |
| 3836 | if (mState == READY && mShuttingDown) { |
| 3837 | return NS_OK; |
| 3838 | } |
| 3839 | |
| 3840 | switch (mState) { |
| 3841 | case WRITING: |
| 3842 | // This is a result of renaming the new index written to tmpfile to index |
| 3843 | // file. This is the last step when writing the index and the whole |
| 3844 | // writing process is successful iff renaming was successful. |
| 3845 | |
| 3846 | if (mIndexHandle != aHandle) { |
| 3847 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileRenamed() - ignoring notification since it " "belongs to previously canceled operation [state=%d]", mState ); } } while (0) |
| 3848 | ("CacheIndex::OnFileRenamed() - ignoring notification since it "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileRenamed() - ignoring notification since it " "belongs to previously canceled operation [state=%d]", mState ); } } while (0) |
| 3849 | "belongs to previously canceled operation [state=%d]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileRenamed() - ignoring notification since it " "belongs to previously canceled operation [state=%d]", mState ); } } while (0) |
| 3850 | mState))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileRenamed() - ignoring notification since it " "belongs to previously canceled operation [state=%d]", mState ); } } while (0); |
| 3851 | break; |
| 3852 | } |
| 3853 | |
| 3854 | FinishWrite(NS_SUCCEEDED(aResult)((bool)(__builtin_expect(!!(!NS_FAILED_impl(aResult)), 1))), lock); |
| 3855 | break; |
| 3856 | case READING: |
| 3857 | // This is a result of renaming journal file to tmpfile. It is renamed |
| 3858 | // before we start reading index and journal file and it should normally |
| 3859 | // succeed. If it fails give up reading of index. |
| 3860 | |
| 3861 | if (mJournalHandle != aHandle) { |
| 3862 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileRenamed() - ignoring notification since it " "belongs to previously canceled operation [state=%d]", mState ); } } while (0) |
| 3863 | ("CacheIndex::OnFileRenamed() - ignoring notification since it "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileRenamed() - ignoring notification since it " "belongs to previously canceled operation [state=%d]", mState ); } } while (0) |
| 3864 | "belongs to previously canceled operation [state=%d]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileRenamed() - ignoring notification since it " "belongs to previously canceled operation [state=%d]", mState ); } } while (0) |
| 3865 | mState))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileRenamed() - ignoring notification since it " "belongs to previously canceled operation [state=%d]", mState ); } } while (0); |
| 3866 | break; |
| 3867 | } |
| 3868 | |
| 3869 | if (NS_FAILED(aResult)((bool)(__builtin_expect(!!(NS_FAILED_impl(aResult)), 0)))) { |
| 3870 | FinishRead(false, lock); |
| 3871 | } else { |
| 3872 | StartReadingIndex(lock); |
| 3873 | } |
| 3874 | break; |
| 3875 | default: |
| 3876 | // Reading/writing was canceled. |
| 3877 | LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileRenamed() - ignoring notification since the " "operation was previously canceled [state=%d]", mState); } } while (0) |
| 3878 | ("CacheIndex::OnFileRenamed() - ignoring notification since the "do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileRenamed() - ignoring notification since the " "operation was previously canceled [state=%d]", mState); } } while (0) |
| 3879 | "operation was previously canceled [state=%d]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileRenamed() - ignoring notification since the " "operation was previously canceled [state=%d]", mState); } } while (0) |
| 3880 | mState))do { const ::mozilla::LogModule* moz_real_module = gCache2Log ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CacheIndex::OnFileRenamed() - ignoring notification since the " "operation was previously canceled [state=%d]", mState); } } while (0); |
| 3881 | } |
| 3882 | |
| 3883 | return NS_OK; |
| 3884 | } |
| 3885 | |
| 3886 | // Memory reporting |
| 3887 | |
| 3888 | size_t CacheIndex::SizeOfExcludingThisInternal( |
| 3889 | mozilla::MallocSizeOf mallocSizeOf) const { |
| 3890 | sLock.AssertCurrentThreadOwns(); |
| 3891 | |
| 3892 | size_t n = 0; |
| 3893 | |
| 3894 | // mIndexHandle and mJournalHandle are reported via SizeOfHandlesRunnable |
| 3895 | // in CacheFileIOManager::SizeOfExcludingThisInternal as part of special |
| 3896 | // handles array. |
| 3897 | |
| 3898 | // mCacheDirectory is an nsIFile which we don't have reporting for. |
| 3899 | |
| 3900 | // mUpdateTimer is an nsITimer which we don't have reporting for. |
| 3901 | |
| 3902 | n += mallocSizeOf(mRWBuf); |
| 3903 | n += mallocSizeOf(mRWHash); |
| 3904 | |
| 3905 | n += mIndex.SizeOfExcludingThis(mallocSizeOf); |
| 3906 | n += mPendingUpdates.SizeOfExcludingThis(mallocSizeOf); |
| 3907 | n += mTmpJournal.SizeOfExcludingThis(mallocSizeOf); |
| 3908 | |
| 3909 | // mFrecencyStorage items are reported by mIndex/mPendingUpdates |
| 3910 | n += mFrecencyStorage.mRecs.ShallowSizeOfExcludingThis(mallocSizeOf); |
| 3911 | n += mDiskConsumptionObservers.ShallowSizeOfExcludingThis(mallocSizeOf); |
| 3912 | |
| 3913 | return n; |
| 3914 | } |
| 3915 | |
| 3916 | // static |
| 3917 | size_t CacheIndex::SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) { |
| 3918 | StaticMutexAutoLock lock(sLock); |
| 3919 | |
| 3920 | if (!gInstance) return 0; |
| 3921 | |
| 3922 | return gInstance->SizeOfExcludingThisInternal(mallocSizeOf); |
| 3923 | } |
| 3924 | |
| 3925 | // static |
| 3926 | size_t CacheIndex::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) { |
| 3927 | StaticMutexAutoLock lock(sLock); |
| 3928 | |
| 3929 | return mallocSizeOf(gInstance) + |
| 3930 | (gInstance ? gInstance->SizeOfExcludingThisInternal(mallocSizeOf) : 0); |
| 3931 | } |
| 3932 | |
| 3933 | // static |
| 3934 | void CacheIndex::UpdateTotalBytesWritten(uint32_t aBytesWritten) { |
| 3935 | StaticMutexAutoLock lock(sLock); |
| 3936 | |
| 3937 | RefPtr<CacheIndex> index = gInstance; |
| 3938 | if (!index) { |
| 3939 | return; |
| 3940 | } |
| 3941 | |
| 3942 | index->mTotalBytesWritten += aBytesWritten; |
| 3943 | |
| 3944 | // Do telemetry report if enough data has been written and the index is |
| 3945 | // in READY state. The data is available also in WRITING state, but we would |
| 3946 | // need to deal with pending updates. |
| 3947 | if (index->mTotalBytesWritten >= kTelemetryReportBytesLimit(2U * 1024U * 1024U * 1024U) && |
| 3948 | index->mState == READY && !index->mIndexNeedsUpdate && |
| 3949 | !index->mShuttingDown) { |
| 3950 | index->DoTelemetryReport(); |
| 3951 | index->mTotalBytesWritten = 0; |
| 3952 | return; |
| 3953 | } |
| 3954 | } |
| 3955 | |
| 3956 | void CacheIndex::DoTelemetryReport() { |
| 3957 | static const nsLiteralCString |
| 3958 | contentTypeNames[nsICacheEntry::CONTENT_TYPE_LAST] = { |
| 3959 | "UNKNOWN"_ns, "OTHER"_ns, "JAVASCRIPT"_ns, "IMAGE"_ns, |
| 3960 | "MEDIA"_ns, "STYLESHEET"_ns, "WASM"_ns, "DICTIONARY"_ns}; |
| 3961 | |
| 3962 | for (uint32_t i = 0; i < nsICacheEntry::CONTENT_TYPE_LAST; ++i) { |
| 3963 | if (mIndexStats.Size() > 0) { |
| 3964 | glean::network::cache_size_share.Get(contentTypeNames[i]) |
| 3965 | .AccumulateSingleSample( |
| 3966 | round(static_cast<double>(mIndexStats.SizeByType(i)) * 100.0 / |
| 3967 | static_cast<double>(mIndexStats.Size()))); |
| 3968 | } |
| 3969 | |
| 3970 | if (mIndexStats.Count() > 0) { |
| 3971 | glean::network::cache_entry_count_share.Get(contentTypeNames[i]) |
| 3972 | .AccumulateSingleSample( |
| 3973 | round(static_cast<double>(mIndexStats.CountByType(i)) * 100.0 / |
| 3974 | static_cast<double>(mIndexStats.Count()))); |
| 3975 | } |
| 3976 | } |
| 3977 | |
| 3978 | nsCString probeKey; |
| 3979 | if (CacheObserver::SmartCacheSizeEnabled()) { |
| 3980 | probeKey = "SMARTSIZE"_ns; |
| 3981 | } else { |
| 3982 | probeKey = "USERDEFINEDSIZE"_ns; |
| 3983 | } |
| 3984 | glean::network::cache_entry_count.Get(probeKey).AccumulateSingleSample( |
| 3985 | mIndexStats.Count()); |
| 3986 | glean::network::cache_size.Get(probeKey).Accumulate(mIndexStats.Size() >> 10); |
| 3987 | } |
| 3988 | |
| 3989 | // static |
| 3990 | void CacheIndex::OnAsyncEviction(bool aEvicting) { |
| 3991 | StaticMutexAutoLock lock(sLock); |
| 3992 | |
| 3993 | RefPtr<CacheIndex> index = gInstance; |
| 3994 | if (!index) { |
| 3995 | return; |
| 3996 | } |
| 3997 | |
| 3998 | index->mAsyncGetDiskConsumptionBlocked = aEvicting; |
| 3999 | if (!aEvicting) { |
| 4000 | index->NotifyAsyncGetDiskConsumptionCallbacks(); |
| 4001 | } |
| 4002 | } |
| 4003 | } // namespace mozilla::net |