Bug Summary

File:root/firefox-clang/obj-x86_64-pc-linux-gnu/netwerk/cache2/./../../../netwerk/cache2/CacheIndex.cpp
Warning:line 2477, column 3
Value stored to 'pos' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name Unified_cpp_netwerk_cache20.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/netwerk/cache2 -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/netwerk/cache2 -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/config/gcc_hidden.h -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/stl_wrappers -D _GLIBCXX_ASSERTIONS=1 -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -D MOZ_SUPPORT_LEAKCHECKING -D STATIC_EXPORTABLE_JS_API -I /root/firefox-clang/netwerk/cache2 -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/netwerk/cache2 -I /root/firefox-clang/netwerk/base -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/ipc/ipdl/_ipdlheaders -I /root/firefox-clang/ipc/chromium/src -I /root/firefox-clang/third_party/abseil-cpp -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/x86_64-linux-gnu/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16/backward -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=pessimizing-move -Wno-error=large-by-value-copy=128 -Wno-error=implicit-int-float-conversion -Wno-error=thread-safety-analysis -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-vla-cxx-extension -Wno-unknown-warning-option -Wno-character-conversion -std=gnu++20 -fdeprecated-macro -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fno-sized-deallocation -fno-aligned-allocation -fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -mllvm -dwarf-linkage-names=Abstract -faddrsig -fdwarf2-cfi-asm -o /tmp/scan-build-2026-10-17-231001-351276-1 -x c++ Unified_cpp_netwerk_cache20.cpp
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
37namespace mozilla::net {
38
39namespace {
40
41class 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/**
76 * This helper class is responsible for keeping CacheIndex::mIndexStats and
77 * CacheIndex::mFrecencyStorage up to date.
78 */
79class MOZ_RAII CacheIndexEntryAutoManage {
80 public:
81 CacheIndexEntryAutoManage(const SHA1Sum::Hash* aHash, CacheIndex* aIndex,
82 const StaticMutexAutoLock& aProofOfLock)
83 MOZ_REQUIRES(CacheIndex::sLock)__attribute__((exclusive_locks_required(CacheIndex::sLock)))
84 : mIndex(aIndex), mProofOfLock(aProofOfLock) {
85 mHash = aHash;
86 const CacheIndexEntry* entry = FindEntry();
87 mIndex->mIndexStats.BeforeChange(entry);
88 if (entry && entry->IsInitialized() && !entry->IsRemoved()) {
89 mOldRecord = entry->mRec;
90 }
91 }
92
93 ~CacheIndexEntryAutoManage() MOZ_REQUIRES(CacheIndex::sLock)__attribute__((exclusive_locks_required(CacheIndex::sLock))) {
94 const CacheIndexEntry* entry = FindEntry();
95 mIndex->mIndexStats.AfterChange(entry);
96 if (!entry || !entry->IsInitialized() || entry->IsRemoved()) {
97 entry = nullptr;
98 }
99
100 if (entry && !mOldRecord) {
101 mIndex->mFrecencyStorage.AppendRecord(entry->mRec, mProofOfLock);
102 mIndex->AddRecordToIterators(entry->mRec, mProofOfLock);
103 } else if (!entry && mOldRecord) {
104 mIndex->mFrecencyStorage.RemoveRecord(mOldRecord, mProofOfLock);
105 mIndex->RemoveRecordFromIterators(mOldRecord, mProofOfLock);
106 } else if (entry && mOldRecord) {
107 if (entry->mRec != mOldRecord) {
108 // record has a different address, we have to replace it
109 mIndex->ReplaceRecordInIterators(mOldRecord, entry->mRec, mProofOfLock);
110
111 mIndex->mFrecencyStorage.ReplaceRecord(mOldRecord, entry->mRec,
112 mProofOfLock);
113 }
114 } else {
115 // both entries were removed or not initialized, do nothing
116 }
117 }
118
119 // We cannot rely on nsTHashtable::GetEntry() in case we are removing entries
120 // while iterating. Destructor is called before the entry is removed. Caller
121 // must call one of following methods to skip lookup in the hashtable.
122 void DoNotSearchInIndex() { mDoNotSearchInIndex = true; }
123 void DoNotSearchInUpdates() { mDoNotSearchInUpdates = true; }
124
125 private:
126 const CacheIndexEntry* FindEntry() MOZ_REQUIRES(CacheIndex::sLock)__attribute__((exclusive_locks_required(CacheIndex::sLock))) {
127 const CacheIndexEntry* entry = nullptr;
128
129 switch (mIndex->mState) {
130 case CacheIndex::READING:
131 case CacheIndex::WRITING:
132 if (!mDoNotSearchInUpdates) {
133 entry = mIndex->mPendingUpdates.GetEntry(*mHash);
134 }
135 [[fallthrough]];
136 case CacheIndex::BUILDING:
137 case CacheIndex::UPDATING:
138 case CacheIndex::READY:
139 if (!entry && !mDoNotSearchInIndex) {
140 entry = mIndex->mIndex.GetEntry(*mHash);
141 }
142 break;
143 case CacheIndex::INITIAL:
144 case CacheIndex::SHUTDOWN:
145 default:
146 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", 146); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "false" ") (" "Unexpected state!" ")"); do {
MOZ_CrashSequence(__null, 146); __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
147 }
148
149 return entry;
150 }
151
152 const SHA1Sum::Hash* mHash;
153 RefPtr<CacheIndex> mIndex;
154 RefPtr<CacheIndexRecordWrapper> mOldRecord;
155 bool mDoNotSearchInIndex{false};
156 bool mDoNotSearchInUpdates{false};
157 const StaticMutexAutoLock& mProofOfLock;
158};
159
160class FileOpenHelper final : public CacheFileIOListener {
161 public:
162 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:
163
164 explicit FileOpenHelper(CacheIndex* aIndex)
165 : mIndex(aIndex), mCanceled(false) {}
166
167 void Cancel() {
168 CacheIndex::sLock.AssertCurrentThreadOwns();
169 mCanceled = true;
170 }
171
172 private:
173 virtual ~FileOpenHelper() = default;
174
175 NS_IMETHODvirtual nsresult OnFileOpened(CacheFileHandle* aHandle, nsresult aResult) override;
176 NS_IMETHODvirtual nsresult OnDataWritten(CacheFileHandle* aHandle, const char* aBuf,
177 nsresult aResult) override {
178 MOZ_CRASH("FileOpenHelper::OnDataWritten should not be called!")do { do { } while (false); MOZ_ReportCrash("" "FileOpenHelper::OnDataWritten should not be called!"
, "./../../../netwerk/cache2/CacheIndex.cpp", 178); AnnotateMozCrashReason
("MOZ_CRASH(" "FileOpenHelper::OnDataWritten should not be called!"
")"); do { MOZ_CrashSequence(__null, 178); __attribute__((nomerge
)) ::abort(); } while (false); } while (false)
;
179 return NS_ERROR_UNEXPECTED;
180 }
181 NS_IMETHODvirtual nsresult OnDataRead(CacheFileHandle* aHandle, char* aBuf,
182 nsresult aResult) override {
183 MOZ_CRASH("FileOpenHelper::OnDataRead should not be called!")do { do { } while (false); MOZ_ReportCrash("" "FileOpenHelper::OnDataRead should not be called!"
, "./../../../netwerk/cache2/CacheIndex.cpp", 183); AnnotateMozCrashReason
("MOZ_CRASH(" "FileOpenHelper::OnDataRead should not be called!"
")"); do { MOZ_CrashSequence(__null, 183); __attribute__((nomerge
)) ::abort(); } while (false); } while (false)
;
184 return NS_ERROR_UNEXPECTED;
185 }
186 NS_IMETHODvirtual nsresult OnFileDoomed(CacheFileHandle* aHandle, nsresult aResult) override {
187 MOZ_CRASH("FileOpenHelper::OnFileDoomed should not be called!")do { do { } while (false); MOZ_ReportCrash("" "FileOpenHelper::OnFileDoomed should not be called!"
, "./../../../netwerk/cache2/CacheIndex.cpp", 187); AnnotateMozCrashReason
("MOZ_CRASH(" "FileOpenHelper::OnFileDoomed should not be called!"
")"); do { MOZ_CrashSequence(__null, 187); __attribute__((nomerge
)) ::abort(); } while (false); } while (false)
;
188 return NS_ERROR_UNEXPECTED;
189 }
190 NS_IMETHODvirtual nsresult OnEOFSet(CacheFileHandle* aHandle, nsresult aResult) override {
191 MOZ_CRASH("FileOpenHelper::OnEOFSet should not be called!")do { do { } while (false); MOZ_ReportCrash("" "FileOpenHelper::OnEOFSet should not be called!"
, "./../../../netwerk/cache2/CacheIndex.cpp", 191); AnnotateMozCrashReason
("MOZ_CRASH(" "FileOpenHelper::OnEOFSet should not be called!"
")"); do { MOZ_CrashSequence(__null, 191); __attribute__((nomerge
)) ::abort(); } while (false); } while (false)
;
192 return NS_ERROR_UNEXPECTED;
193 }
194 NS_IMETHODvirtual nsresult OnFileRenamed(CacheFileHandle* aHandle,
195 nsresult aResult) override {
196 MOZ_CRASH("FileOpenHelper::OnFileRenamed should not be called!")do { do { } while (false); MOZ_ReportCrash("" "FileOpenHelper::OnFileRenamed should not be called!"
, "./../../../netwerk/cache2/CacheIndex.cpp", 196); AnnotateMozCrashReason
("MOZ_CRASH(" "FileOpenHelper::OnFileRenamed should not be called!"
")"); do { MOZ_CrashSequence(__null, 196); __attribute__((nomerge
)) ::abort(); } while (false); } while (false)
;
197 return NS_ERROR_UNEXPECTED;
198 }
199
200 RefPtr<CacheIndex> mIndex;
201 bool mCanceled;
202};
203
204NS_IMETHODIMPnsresult FileOpenHelper::OnFileOpened(CacheFileHandle* aHandle,
205 nsresult aResult) {
206 StaticMutexAutoLock lock(CacheIndex::sLock);
207
208 if (mCanceled) {
209 if (aHandle) {
210 CacheFileIOManager::DoomFile(aHandle, nullptr);
211 }
212
213 return NS_OK;
214 }
215
216 mIndex->OnFileOpenedInternal(this, aHandle, aResult, lock);
217
218 return NS_OK;
219}
220
221NS_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"
, 221); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { MOZ_CrashSequence(__null, 221
); __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"
, 221); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"FileOpenHelper\" != nullptr"
") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null
, 221); __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"
, 221); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { MOZ_CrashSequence(__null, 221
); __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"
, 221); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"FileOpenHelper\" != nullptr"
") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null
, 221); __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",
221); 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; }
;
222
223StaticRefPtr<CacheIndex> CacheIndex::gInstance;
224StaticMutex CacheIndex::sLock;
225
226NS_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"
, 226); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { MOZ_CrashSequence(__null, 226
); __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"
, 226); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"CacheIndex\" != nullptr"
") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null
, 226); __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; }
227NS_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"
, 227); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { MOZ_CrashSequence(__null, 227
); __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"
, 227); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"CacheIndex\" != nullptr"
") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null
, 227); __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; }
228
229NS_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",
229); MOZ_PretendNoReturn(); } } while (0); nsISupports* foundInterface
;
230 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
231 NS_INTERFACE_MAP_ENTRY(nsIRunnable)if (aIID.Equals(mozilla::detail::kImplementedIID<std::remove_reference_t
<decltype(*this)>, nsIRunnable>)) foundInterface = static_cast
<nsIRunnable*>(this); else
232NS_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"
, 232); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aIID.Equals((nsISupports::kIID))"
")"); do { MOZ_CrashSequence(__null, 232); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); status = NS_NOINTERFACE
; } else { (foundInterface)->AddRef(); status = NS_OK; } *
aInstancePtr = foundInterface; return status; }
233
234CacheIndex::CacheIndex() {
235 sLock.AssertCurrentThreadOwns();
236 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)
;
237 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", 237); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!gInstance" ") (" "multiple CacheIndex instances!"
")"); do { MOZ_CrashSequence(__null, 237); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
238}
239
240CacheIndex::~CacheIndex() {
241 sLock.AssertCurrentThreadOwns();
242 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)
;
243
244 ReleaseBuffer();
245}
246
247// static
248nsresult CacheIndex::Init(nsIFile* aCacheDirectory) {
249 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)
;
250
251 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", 251); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "NS_IsMainThread()" ")"); do { MOZ_CrashSequence
(__null, 251); __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
252
253 StaticMutexAutoLock lock(sLock);
254
255 if (gInstance) {
256 return NS_ERROR_ALREADY_INITIALIZED;
257 }
258
259 RefPtr<CacheIndex> idx = new CacheIndex();
260
261 nsresult rv = idx->InitInternal(aCacheDirectory, lock);
262 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"
, 262); return rv; } } while (false)
;
263
264 gInstance = std::move(idx);
265 return NS_OK;
266}
267
268nsresult CacheIndex::InitInternal(nsIFile* aCacheDirectory,
269 const StaticMutexAutoLock& aProofOfLock) {
270 nsresult rv;
271 sLock.AssertCurrentThreadOwns();
272
273 rv = aCacheDirectory->Clone(getter_AddRefs(mCacheDirectory));
274 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"
, 274); return rv; } } while (false)
;
275
276 mStartTime = TimeStamp::NowLoRes();
277
278 ReadIndexFromDisk(aProofOfLock);
279
280 return NS_OK;
281}
282
283// static
284nsresult CacheIndex::PreShutdown() {
285 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", 285); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "NS_IsMainThread()" ")"); do { MOZ_CrashSequence
(__null, 285); __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
286
287 StaticMutexAutoLock lock(sLock);
288
289 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)
;
290
291 nsresult rv;
292 RefPtr<CacheIndex> index = gInstance;
293
294 if (!index) {
295 return NS_ERROR_NOT_INITIALIZED;
296 }
297
298 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)
299 ("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)
300 "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)
301 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)
;
302
303 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)
;
304 for (uint32_t i = 0; i < index->mIterators.Length();) {
305 rv = index->mIterators[i]->CloseInternal(NS_ERROR_FAILURE);
306 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
307 // CacheIndexIterator::CloseInternal() removes itself from mIteratos iff
308 // it returns success.
309 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)
310 ("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)
311 "[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)
312 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)
;
313 i++;
314 }
315 }
316
317 index->mShuttingDown = true;
318
319 if (index->mState == READY) {
320 return NS_OK; // nothing to do
321 }
322
323 nsCOMPtr<nsIRunnable> event;
324 event = NewRunnableMethod("net::CacheIndex::PreShutdownInternal", index,
325 &CacheIndex::PreShutdownInternal);
326
327 nsCOMPtr<nsIEventTarget> ioTarget = CacheFileIOManager::IOTarget();
328 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"
, 328); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ioTarget" ")"
); do { MOZ_CrashSequence(__null, 328); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
329
330 // PreShutdownInternal() will be executed before any queued event on INDEX
331 // level. That's OK since we don't want to wait for any operation in progess.
332 rv = ioTarget->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL);
333 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
334 NS_WARNING("CacheIndex::PreShutdown() - Can't dispatch event")NS_DebugBreak(NS_DEBUG_WARNING, "CacheIndex::PreShutdown() - Can't dispatch event"
, nullptr, "./../../../netwerk/cache2/CacheIndex.cpp", 334)
;
335 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)
;
336 return rv;
337 }
338
339 return NS_OK;
340}
341
342void CacheIndex::PreShutdownInternal() {
343 StaticMutexAutoLock lock(sLock);
344
345 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)
346 ("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)
347 "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)
348 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)
;
349
350 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", 350); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mShuttingDown" ")"); do { MOZ_CrashSequence
(__null, 350); __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
351
352 if (mUpdateTimer) {
353 mUpdateTimer->Cancel();
354 mUpdateTimer = nullptr;
355 }
356
357 switch (mState) {
358 case WRITING:
359 FinishWrite(false, lock);
360 break;
361 case READY:
362 // nothing to do, write the journal in Shutdown()
363 break;
364 case READING:
365 FinishRead(false, lock);
366 break;
367 case BUILDING:
368 case UPDATING:
369 FinishUpdate(false, lock);
370 break;
371 default:
372 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", 372); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "false" ") (" "Implement me!" ")"); do { MOZ_CrashSequence
(__null, 372); __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
373 }
374
375 // We should end up in READY state
376 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", 376); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mState == READY" ")"); do { MOZ_CrashSequence
(__null, 376); __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
377}
378
379// static
380void CacheIndex::WriteIndexToDiskNow() {
381 StaticMutexAutoLock lock(sLock);
382
383 RefPtr<CacheIndex> index = gInstance;
384 if (!index || index->mShuttingDown) {
385 return;
386 }
387
388 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)
;
389
390 nsCOMPtr<nsIEventTarget> ioTarget = CacheFileIOManager::IOTarget();
391 if (!ioTarget) {
392 return;
393 }
394
395 nsCOMPtr<nsIRunnable> event =
396 NewRunnableMethod("net::CacheIndex::WriteIndexToDiskNowInternal", index,
397 &CacheIndex::WriteIndexToDiskNowInternal);
398 (void)ioTarget->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL);
399}
400
401void CacheIndex::WriteIndexToDiskNowInternal() {
402 StaticMutexAutoLock lock(sLock);
403
404 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)
405 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)
;
406
407 if (mState != READY || mShuttingDown || mRWPending ||
408 mIndexStats.Dirty() == 0) {
409 return;
410 }
411
412 WriteIndexToDisk(lock);
413}
414
415// static
416nsresult CacheIndex::Shutdown() {
417 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", 417); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "NS_IsMainThread()" ")"); do { MOZ_CrashSequence
(__null, 417); __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
418
419 StaticMutexAutoLock lock(sLock);
420
421 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)
;
422
423 RefPtr<CacheIndex> index = gInstance.forget();
424
425 if (!index) {
426 return NS_ERROR_NOT_INITIALIZED;
427 }
428
429 bool sanitize = CacheObserver::ClearCacheOnShutdown();
430
431 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)
432 ("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)
433 "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)
434 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)
435 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)
;
436
437 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", 437); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "index->mShuttingDown" ")"); do { MOZ_CrashSequence
(__null, 437); __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
438
439 EState oldState = index->mState;
440 index->ChangeState(SHUTDOWN, lock);
441
442 if (oldState != READY) {
443 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)
444 ("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)
445 "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)
;
446 }
447
448 switch (oldState) {
449 case WRITING:
450 index->FinishWrite(false, lock);
451 [[fallthrough]];
452 case READY:
453 if (index->mIndexOnDiskIsValid && !index->mDontMarkIndexClean) {
454 if (!sanitize && NS_FAILED(index->WriteLogToDisk())((bool)(__builtin_expect(!!(NS_FAILED_impl(index->WriteLogToDisk
())), 0)))
) {
455 index->RemoveJournalAndTempFile();
456 }
457 } else {
458 index->RemoveJournalAndTempFile();
459 }
460 break;
461 case READING:
462 index->FinishRead(false, lock);
463 break;
464 case BUILDING:
465 case UPDATING:
466 index->FinishUpdate(false, lock);
467 break;
468 default:
469 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", 469); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "false" ") (" "Unexpected state!" ")"); do {
MOZ_CrashSequence(__null, 469); __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
470 }
471
472 if (sanitize) {
473 index->RemoveAllIndexFiles();
474 }
475
476 return NS_OK;
477}
478
479// static
480nsresult CacheIndex::AddEntry(const SHA1Sum::Hash* aHash) {
481 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)
;
482
483 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"
, 483); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()"
")"); do { MOZ_CrashSequence(__null, 483); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
484
485 StaticMutexAutoLock lock(sLock);
486
487 RefPtr<CacheIndex> index = gInstance;
488
489 if (!index) {
490 return NS_ERROR_NOT_INITIALIZED;
491 }
492
493 if (!index->IsIndexUsable()) {
494 return NS_ERROR_NOT_AVAILABLE;
495 }
496
497 // Getters in CacheIndexStats assert when mStateLogged is true since the
498 // information is incomplete between calls to BeforeChange() and AfterChange()
499 // (i.e. while CacheIndexEntryAutoManage exists). We need to check whether
500 // non-fresh entries exists outside the scope of CacheIndexEntryAutoManage.
501 bool updateIfNonFreshEntriesExist = false;
502
503 {
504 CacheIndexEntryAutoManage entryMng(aHash, index, lock);
505
506 CacheIndexEntry* entry = index->mIndex.GetEntry(*aHash);
507 bool entryRemoved = entry && entry->IsRemoved();
508 CacheIndexEntryUpdate* updated = nullptr;
509
510 if (index->mState == READY || index->mState == UPDATING ||
511 index->mState == BUILDING) {
512 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", 512); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "index->mPendingUpdates.Count() == 0" ")"
); do { MOZ_CrashSequence(__null, 512); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
513
514 if (entry && !entryRemoved) {
515 // Found entry in index that shouldn't exist.
516
517 if (entry->IsFresh()) {
518 // Someone removed the file on disk while FF is running. Update
519 // process can fix only non-fresh entries (i.e. entries that were not
520 // added within this session). Start update only if we have such
521 // entries.
522 //
523 // TODO: This should be very rare problem. If it turns out not to be
524 // true, change the update process so that it also iterates all
525 // initialized non-empty entries and checks whether the file exists.
526
527 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)
528 ("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)
529 "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)
;
530
531 updateIfNonFreshEntriesExist = true;
532 } else if (index->mState == READY) {
533 // Index is outdated, update it.
534 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)
535 ("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)
536 "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)
;
537 index->mIndexNeedsUpdate = true;
538 } else {
539 // We cannot be here when building index since all entries are fresh
540 // during building.
541 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"
, 541); AnnotateMozCrashReason("MOZ_ASSERT" "(" "index->mState == UPDATING"
")"); do { MOZ_CrashSequence(__null, 541); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
542 }
543 }
544
545 if (!entry) {
546 entry = index->mIndex.PutEntry(*aHash);
547 }
548 } else { // WRITING, READING
549 updated = index->mPendingUpdates.GetEntry(*aHash);
550 bool updatedRemoved = updated && updated->IsRemoved();
551
552 if ((updated && !updatedRemoved) ||
553 (!updated && entry && !entryRemoved && entry->IsFresh())) {
554 // Fresh entry found, so the file was removed outside FF
555 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)
556 ("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)
557 "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)
;
558
559 updateIfNonFreshEntriesExist = true;
560 } else if (!updated && entry && !entryRemoved) {
561 if (index->mState == WRITING) {
562 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)
563 ("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)
564 "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)
;
565 index->mIndexNeedsUpdate = true;
566 }
567 // Ignore if state is READING since the index information is partial
568 }
569
570 updated = index->mPendingUpdates.PutEntry(*aHash);
571 }
572
573 if (updated) {
574 updated->InitNew();
575 updated->MarkDirty();
576 updated->MarkFresh();
577 } else {
578 entry->InitNew();
579 entry->MarkDirty();
580 entry->MarkFresh();
581 }
582 }
583
584 if (updateIfNonFreshEntriesExist &&
585 index->mIndexStats.Count() != index->mIndexStats.Fresh()) {
586 index->mIndexNeedsUpdate = true;
587 }
588
589 index->StartUpdatingIndexIfNeeded(lock);
590 index->WriteIndexToDiskIfNeeded(lock);
591
592 return NS_OK;
593}
594
595// static
596nsresult CacheIndex::EnsureEntryExists(const SHA1Sum::Hash* aHash) {
597 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)
598 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)
;
599
600 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"
, 600); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()"
")"); do { MOZ_CrashSequence(__null, 600); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
601
602 StaticMutexAutoLock lock(sLock);
603
604 RefPtr<CacheIndex> index = gInstance;
605
606 if (!index) {
607 return NS_ERROR_NOT_INITIALIZED;
608 }
609
610 if (!index->IsIndexUsable()) {
611 return NS_ERROR_NOT_AVAILABLE;
612 }
613
614 {
615 CacheIndexEntryAutoManage entryMng(aHash, index, lock);
616
617 CacheIndexEntry* entry = index->mIndex.GetEntry(*aHash);
618 bool entryRemoved = entry && entry->IsRemoved();
619
620 if (index->mState == READY || index->mState == UPDATING ||
621 index->mState == BUILDING) {
622 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", 622); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "index->mPendingUpdates.Count() == 0" ")"
); do { MOZ_CrashSequence(__null, 622); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
623
624 if (!entry || entryRemoved) {
625 if (entryRemoved && entry->IsFresh()) {
626 // This could happen only if somebody copies files to the entries
627 // directory while FF is running.
628 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)
629 ("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)
630 "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)
;
631 index->mIndexNeedsUpdate = true;
632 } else if (index->mState == READY ||
633 (entryRemoved && !entry->IsFresh())) {
634 // Removed non-fresh entries can be present as a result of
635 // MergeJournal()
636 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)
637 ("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)
638 " 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)
;
639 index->mIndexNeedsUpdate = true;
640 }
641
642 if (!entry) {
643 entry = index->mIndex.PutEntry(*aHash);
644 }
645 entry->InitNew();
646 entry->MarkDirty();
647 }
648 entry->MarkFresh();
649 } else { // WRITING, READING
650 CacheIndexEntryUpdate* updated = index->mPendingUpdates.GetEntry(*aHash);
651 bool updatedRemoved = updated && updated->IsRemoved();
652
653 if (updatedRemoved || (!updated && entryRemoved && entry->IsFresh())) {
654 // Fresh information about missing entry found. This could happen only
655 // if somebody copies files to the entries directory while FF is
656 // running.
657 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)
658 ("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)
659 "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)
;
660 index->mIndexNeedsUpdate = true;
661 } else if (!updated && (!entry || entryRemoved)) {
662 if (index->mState == WRITING) {
663 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)
664 ("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)
665 " 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)
;
666 index->mIndexNeedsUpdate = true;
667 }
668 // Ignore if state is READING since the index information is partial
669 }
670
671 // We don't need entryRemoved and updatedRemoved info anymore
672 if (entryRemoved) entry = nullptr;
673 if (updatedRemoved) updated = nullptr;
674
675 if (updated) {
676 updated->MarkFresh();
677 } else {
678 if (!entry) {
679 // Create a new entry
680 updated = index->mPendingUpdates.PutEntry(*aHash);
681 updated->InitNew();
682 updated->MarkFresh();
683 updated->MarkDirty();
684 } else {
685 if (!entry->IsFresh()) {
686 // To mark the entry fresh we must make a copy of index entry
687 // since the index is read-only.
688 updated = index->mPendingUpdates.PutEntry(*aHash);
689 *updated = *entry;
690 updated->MarkFresh();
691 }
692 }
693 }
694 }
695 }
696
697 index->StartUpdatingIndexIfNeeded(lock);
698 index->WriteIndexToDiskIfNeeded(lock);
699
700 return NS_OK;
701}
702
703// static
704nsresult CacheIndex::InitEntry(const SHA1Sum::Hash* aHash,
705 OriginAttrsHash aOriginAttrsHash,
706 bool aAnonymous, bool aPinned) {
707 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)
708 ("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)
709 "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)
710 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)
;
711
712 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"
, 712); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()"
")"); do { MOZ_CrashSequence(__null, 712); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
713
714 StaticMutexAutoLock lock(sLock);
715
716 RefPtr<CacheIndex> index = gInstance;
717
718 if (!index) {
719 return NS_ERROR_NOT_INITIALIZED;
720 }
721
722 if (!index->IsIndexUsable()) {
723 return NS_ERROR_NOT_AVAILABLE;
724 }
725
726 {
727 CacheIndexEntryAutoManage entryMng(aHash, index, lock);
728
729 CacheIndexEntry* entry = index->mIndex.GetEntry(*aHash);
730 CacheIndexEntryUpdate* updated = nullptr;
731 bool reinitEntry = false;
732
733 if (entry && entry->IsRemoved()) {
734 entry = nullptr;
735 }
736
737 if (index->mState == READY || index->mState == UPDATING ||
738 index->mState == BUILDING) {
739 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", 739); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "index->mPendingUpdates.Count() == 0" ")"
); do { MOZ_CrashSequence(__null, 739); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
740 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"
, 740); AnnotateMozCrashReason("MOZ_ASSERT" "(" "entry" ")");
do { MOZ_CrashSequence(__null, 740); __attribute__((nomerge)
) ::abort(); } while (false); } } while (false)
;
741 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", 741); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "entry->IsFresh()" ")"); do { MOZ_CrashSequence
(__null, 741); __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
742
743 if (!entry) {
744 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)
;
745 NS_WARNING(NS_DebugBreak(NS_DEBUG_WARNING, ("CacheIndex::InitEntry() - Entry was not found in mIndex!"
), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp", 746)
746 ("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", 746)
;
747 return NS_ERROR_UNEXPECTED;
748 }
749
750 if (IsCollision(entry, aOriginAttrsHash, aAnonymous)) {
751 index->mIndexNeedsUpdate =
752 true; // TODO Does this really help in case of collision?
753 reinitEntry = true;
754 } else {
755 if (entry->IsInitialized()) {
756 return NS_OK;
757 }
758 }
759 } else {
760 updated = index->mPendingUpdates.GetEntry(*aHash);
761 DebugOnly<bool> removed = updated && updated->IsRemoved();
762
763 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", 763); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "updated || !removed" ")"); do { MOZ_CrashSequence
(__null, 763); __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
764 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", 764); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "updated || entry" ")"); do { MOZ_CrashSequence
(__null, 764); __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
765
766 if (!updated && !entry) {
767 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)
768 ("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)
769 "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)
;
770 NS_WARNING(NS_DebugBreak(NS_DEBUG_WARNING, ("CacheIndex::InitEntry() - Entry was found neither in "
"mIndex nor in mPendingUpdates!"), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp"
, 772)
771 ("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"
, 772)
772 "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"
, 772)
;
773 return NS_ERROR_UNEXPECTED;
774 }
775
776 if (updated) {
777 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", 777); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "updated->IsFresh()" ")"); do { MOZ_CrashSequence
(__null, 777); __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
778
779 if (IsCollision(updated, aOriginAttrsHash, aAnonymous)) {
780 index->mIndexNeedsUpdate = true;
781 reinitEntry = true;
782 } else {
783 if (updated->IsInitialized()) {
784 return NS_OK;
785 }
786 }
787 } else {
788 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", 788); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "entry->IsFresh()" ")"); do { MOZ_CrashSequence
(__null, 788); __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
789
790 if (IsCollision(entry, aOriginAttrsHash, aAnonymous)) {
791 index->mIndexNeedsUpdate = true;
792 reinitEntry = true;
793 } else {
794 if (entry->IsInitialized()) {
795 return NS_OK;
796 }
797 }
798
799 // make a copy of a read-only entry
800 updated = index->mPendingUpdates.PutEntry(*aHash);
801 *updated = *entry;
802 }
803 }
804
805 if (reinitEntry) {
806 // There is a collision and we are going to rewrite this entry. Initialize
807 // it as a new entry.
808 if (updated) {
809 updated->InitNew();
810 updated->MarkFresh();
811 } else {
812 entry->InitNew();
813 entry->MarkFresh();
814 }
815 }
816
817 if (updated) {
818 updated->Init(aOriginAttrsHash, aAnonymous, aPinned);
819 updated->MarkDirty();
820 } else {
821 entry->Init(aOriginAttrsHash, aAnonymous, aPinned);
822 entry->MarkDirty();
823 }
824 }
825
826 index->StartUpdatingIndexIfNeeded(lock);
827 index->WriteIndexToDiskIfNeeded(lock);
828
829 return NS_OK;
830}
831
832// static
833nsresult CacheIndex::RemoveEntry(const SHA1Sum::Hash* aHash,
834 const nsACString& aKey,
835 bool aClearDictionary) {
836 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)
837 ("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)
838 "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)
839 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)
;
840
841 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"
, 841); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()"
")"); do { MOZ_CrashSequence(__null, 841); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
842
843 // Remove any dictionary associated with this entry even if we later
844 // error out - async since removal happens on MainThread.
845
846 // TODO XXX There may be a hole here where a dictionary entry can get
847 // referenced for a request before RemoveDictionaryOMT can run, but after
848 // the entry is removed here.
849
850 // Note: we don't want to (re)clear dictionaries when the
851 // CacheFileContextEvictor purges entries; they've already been cleared
852 // via CacheIndex::EvictByContext synchronously
853 if (aClearDictionary) {
854 nsAutoCString uriSpec;
855 nsCOMPtr<nsILoadContextInfo> lci =
856 CacheFileUtils::ParseKey(aKey, nullptr, &uriSpec);
857 if (lci) {
858 DictionaryCache::RemoveDictionaryOMT(uriSpec, lci);
859 }
860 }
861
862 StaticMutexAutoLock lock(sLock);
863
864 RefPtr<CacheIndex> index = gInstance;
865
866 if (!index) {
867 return NS_ERROR_NOT_INITIALIZED;
868 }
869
870 if (!index->IsIndexUsable()) {
871 return NS_ERROR_NOT_AVAILABLE;
872 }
873
874 {
875 CacheIndexEntryAutoManage entryMng(aHash, index, lock);
876
877 CacheIndexEntry* entry = index->mIndex.GetEntry(*aHash);
878 bool entryRemoved = entry && entry->IsRemoved();
879
880 if (index->mState == READY || index->mState == UPDATING ||
881 index->mState == BUILDING) {
882 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", 882); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "index->mPendingUpdates.Count() == 0" ")"
); do { MOZ_CrashSequence(__null, 882); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
883
884 if (!entry || entryRemoved) {
885 if (entryRemoved && entry->IsFresh()) {
886 // This could happen only if somebody copies files to the entries
887 // directory while FF is running.
888 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)
889 ("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)
890 "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)
;
891 index->mIndexNeedsUpdate = true;
892 } else if (index->mState == READY ||
893 (entryRemoved && !entry->IsFresh())) {
894 // Removed non-fresh entries can be present as a result of
895 // MergeJournal()
896 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)
897 ("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)
898 ", 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)
;
899 index->mIndexNeedsUpdate = true;
900 }
901 } else {
902 if (entry) {
903 if (!entry->IsDirty() && entry->IsFileEmpty()) {
904 index->mIndex.RemoveEntry(entry);
905 entry = nullptr;
906 } else {
907 entry->MarkRemoved();
908 entry->MarkDirty();
909 entry->MarkFresh();
910 }
911 }
912 }
913 } else { // WRITING, READING
914 CacheIndexEntryUpdate* updated = index->mPendingUpdates.GetEntry(*aHash);
915 bool updatedRemoved = updated && updated->IsRemoved();
916
917 if (updatedRemoved || (!updated && entryRemoved && entry->IsFresh())) {
918 // Fresh information about missing entry found. This could happen only
919 // if somebody copies files to the entries directory while FF is
920 // running.
921 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)
922 ("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)
923 "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)
;
924 index->mIndexNeedsUpdate = true;
925 } else if (!updated && (!entry || entryRemoved)) {
926 if (index->mState == WRITING) {
927 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)
928 ("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)
929 ", 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)
;
930 index->mIndexNeedsUpdate = true;
931 }
932 // Ignore if state is READING since the index information is partial
933 }
934
935 if (!updated) {
936 updated = index->mPendingUpdates.PutEntry(*aHash);
937 updated->InitNew();
938 }
939
940 updated->MarkRemoved();
941 updated->MarkDirty();
942 updated->MarkFresh();
943 }
944 }
945 index->StartUpdatingIndexIfNeeded(lock);
946 index->WriteIndexToDiskIfNeeded(lock);
947
948 return NS_OK;
949}
950
951// static
952nsresult CacheIndex::UpdateEntry(const SHA1Sum::Hash* aHash,
953 const uint32_t* aFrecency,
954 const bool* aHasAltData,
955 const uint32_t* aLastFetched,
956 const uint32_t* aFetchCount,
957 const uint8_t* aContentType,
958 const uint32_t* aSize) {
959 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)
960 ("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)
961 "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)
962 "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)
963 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)
964 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)
965 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)
966 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)
967 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)
968 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)
;
969
970 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"
, 970); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()"
")"); do { MOZ_CrashSequence(__null, 970); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
971
972 StaticMutexAutoLock lock(sLock);
973
974 RefPtr<CacheIndex> index = gInstance;
975
976 if (!index) {
977 return NS_ERROR_NOT_INITIALIZED;
978 }
979
980 if (!index->IsIndexUsable()) {
981 return NS_ERROR_NOT_AVAILABLE;
982 }
983
984 {
985 CacheIndexEntryAutoManage entryMng(aHash, index, lock);
986
987 CacheIndexEntry* entry = index->mIndex.GetEntry(*aHash);
988
989 if (entry && entry->IsRemoved()) {
990 entry = nullptr;
991 }
992
993 if (index->mState == READY || index->mState == UPDATING ||
994 index->mState == BUILDING) {
995 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", 995); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "index->mPendingUpdates.Count() == 0" ")"
); do { MOZ_CrashSequence(__null, 995); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
996 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"
, 996); AnnotateMozCrashReason("MOZ_ASSERT" "(" "entry" ")");
do { MOZ_CrashSequence(__null, 996); __attribute__((nomerge)
) ::abort(); } while (false); } } while (false)
;
997
998 if (!entry) {
999 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)
;
1000 NS_WARNING(NS_DebugBreak(NS_DEBUG_WARNING, ("CacheIndex::UpdateEntry() - Entry was not found in mIndex!"
), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp", 1001)
1001 ("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", 1001)
;
1002 return NS_ERROR_UNEXPECTED;
1003 }
1004
1005 if (!HasEntryChanged(entry, aFrecency, aHasAltData, aLastFetched,
1006 aFetchCount, aContentType, aSize)) {
1007 return NS_OK;
1008 }
1009
1010 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", 1010); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "entry->IsFresh()" ")"); do { MOZ_CrashSequence
(__null, 1010); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1011 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", 1011); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "entry->IsInitialized()" ")"); do { MOZ_CrashSequence
(__null, 1011); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1012 entry->MarkDirty();
1013
1014 if (aFrecency) {
1015 entry->SetFrecency(*aFrecency);
1016 }
1017
1018 if (aHasAltData) {
1019 entry->SetHasAltData(*aHasAltData);
1020 }
1021
1022 if (aLastFetched) {
1023 entry->SetLastFetched(*aLastFetched);
1024 }
1025
1026 if (aFetchCount) {
1027 entry->SetFetchCount(*aFetchCount);
1028 }
1029
1030 if (aContentType) {
1031 entry->SetContentType(*aContentType);
1032 }
1033
1034 if (aSize) {
1035 entry->SetFileSize(*aSize);
1036 }
1037 } else {
1038 CacheIndexEntryUpdate* updated = index->mPendingUpdates.GetEntry(*aHash);
1039 DebugOnly<bool> removed = updated && updated->IsRemoved();
1040
1041 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", 1041); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "updated || !removed" ")"); do { MOZ_CrashSequence
(__null, 1041); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1042 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", 1042); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "updated || entry" ")"); do { MOZ_CrashSequence
(__null, 1042); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1043
1044 if (!updated) {
1045 if (!entry) {
1046 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)
1047 ("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)
1048 "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)
;
1049 NS_WARNING(NS_DebugBreak(NS_DEBUG_WARNING, ("CacheIndex::UpdateEntry() - Entry was found neither in "
"mIndex nor in mPendingUpdates!"), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp"
, 1051)
1050 ("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"
, 1051)
1051 "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"
, 1051)
;
1052 return NS_ERROR_UNEXPECTED;
1053 }
1054
1055 // make a copy of a read-only entry
1056 updated = index->mPendingUpdates.PutEntry(*aHash);
1057 *updated = *entry;
1058 }
1059
1060 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", 1060); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "updated->IsFresh()" ")"); do { MOZ_CrashSequence
(__null, 1060); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1061 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", 1061); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "updated->IsInitialized()" ")"); do { MOZ_CrashSequence
(__null, 1061); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1062 updated->MarkDirty();
1063
1064 if (aFrecency) {
1065 updated->SetFrecency(*aFrecency);
1066 }
1067
1068 if (aHasAltData) {
1069 updated->SetHasAltData(*aHasAltData);
1070 }
1071
1072 if (aLastFetched) {
1073 updated->SetLastFetched(*aLastFetched);
1074 }
1075
1076 if (aFetchCount) {
1077 updated->SetFetchCount(*aFetchCount);
1078 }
1079
1080 if (aContentType) {
1081 updated->SetContentType(*aContentType);
1082 }
1083
1084 if (aSize) {
1085 updated->SetFileSize(*aSize);
1086 }
1087 }
1088 }
1089
1090 index->WriteIndexToDiskIfNeeded(lock);
1091
1092 return NS_OK;
1093}
1094
1095// Clear the entries from the Index immediately, to comply with
1096// https://www.w3.org/TR/clear-site-data/#fetch-integration
1097// Note that we will effectively hide the entries until the actual evict
1098// happens.
1099
1100// aOrigin == "" means clear all unless aBaseDomain is set to something
1101// static
1102void CacheIndex::EvictByContext(const nsAString& aOrigin,
1103 const nsAString& aBaseDomain) {
1104 StaticMutexAutoLock lock(sLock);
1105
1106 RefPtr<CacheIndex> index = gInstance;
1107
1108 // Store in hashset that this origin has been evicted; we'll remove it
1109 // when CacheFileIOManager::EvictByContextInternal() finishes.
1110 // Not valid to set both aOrigin and aBaseDomain
1111 if (!aOrigin.IsEmpty() && aBaseDomain.IsEmpty()) {
1112 // likely CacheStorageService::ClearByPrincipal
1113 nsCOMPtr<nsIURI> uri;
1114 if (NS_SUCCEEDED(NS_NewURI(getter_AddRefs(uri), aOrigin))((bool)(__builtin_expect(!!(!NS_FAILED_impl(NS_NewURI(getter_AddRefs
(uri), aOrigin))), 1)))
) {
1115 // Remove the dictionary entries for this origin immediately
1116 DictionaryCache::RemoveDictionariesForOrigin(uri);
1117 }
1118 }
1119}
1120
1121// static
1122nsresult CacheIndex::RemoveAll() {
1123 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)
;
1124
1125 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"
, 1125); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()"
")"); do { MOZ_CrashSequence(__null, 1125); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1126
1127 nsCOMPtr<nsIFile> file;
1128
1129 {
1130 StaticMutexAutoLock lock(sLock);
1131
1132 RefPtr<CacheIndex> index = gInstance;
1133
1134 if (!index) {
1135 return NS_ERROR_NOT_INITIALIZED;
1136 }
1137
1138 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", 1138); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!index->mRemovingAll" ")"); do { MOZ_CrashSequence
(__null, 1138); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1139
1140 if (!index->IsIndexUsable()) {
1141 return NS_ERROR_NOT_AVAILABLE;
1142 }
1143
1144 AutoRestore<bool> saveRemovingAll(index->mRemovingAll);
1145 index->mRemovingAll = true;
1146
1147 // Doom index and journal handles but don't null them out since this will be
1148 // done in FinishWrite/FinishRead methods.
1149 if (index->mIndexHandle) {
1150 CacheFileIOManager::DoomFile(index->mIndexHandle, nullptr);
1151 } else {
1152 // We don't have a handle to index file, so get the file here, but delete
1153 // it outside the lock. Ignore the result since this is not fatal.
1154 index->GetFile(nsLiteralCString(INDEX_NAME"index"), getter_AddRefs(file));
1155 }
1156
1157 if (index->mJournalHandle) {
1158 CacheFileIOManager::DoomFile(index->mJournalHandle, nullptr);
1159 }
1160
1161 switch (index->mState) {
1162 case WRITING:
1163 index->FinishWrite(false, lock);
1164 break;
1165 case READY:
1166 // nothing to do
1167 break;
1168 case READING:
1169 index->FinishRead(false, lock);
1170 break;
1171 case BUILDING:
1172 case UPDATING:
1173 index->FinishUpdate(false, lock);
1174 break;
1175 default:
1176 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", 1176); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "false" ") (" "Unexpected state!" ")"); do {
MOZ_CrashSequence(__null, 1176); __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
1177 }
1178
1179 // We should end up in READY state
1180 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", 1180); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "index->mState == READY" ")"); do { MOZ_CrashSequence
(__null, 1180); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1181
1182 // There should not be any handle
1183 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", 1183); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!index->mIndexHandle" ")"); do { MOZ_CrashSequence
(__null, 1183); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1184 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", 1184); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!index->mJournalHandle" ")"); do { MOZ_CrashSequence
(__null, 1184); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1185
1186 index->mIndexOnDiskIsValid = false;
1187 index->mIndexNeedsUpdate = false;
1188
1189 index->mIndexStats.Clear();
1190 index->mFrecencyStorage.Clear(lock);
1191 index->mIndex.Clear();
1192
1193 for (uint32_t i = 0; i < index->mIterators.Length();) {
1194 nsresult rv = index->mIterators[i]->CloseInternal(NS_ERROR_NOT_AVAILABLE);
1195 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1196 // CacheIndexIterator::CloseInternal() removes itself from mIterators
1197 // iff it returns success.
1198 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)
1199 ("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)
1200 "[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)
1201 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)
;
1202 i++;
1203 }
1204 }
1205 }
1206
1207 if (file) {
1208 // Ignore the result. The file might not exist and the failure is not fatal.
1209 file->Remove(false);
1210 }
1211
1212 return NS_OK;
1213}
1214
1215// static
1216nsresult CacheIndex::HasEntry(
1217 const nsACString& aKey, EntryStatus* _retval,
1218 const std::function<void(const CacheIndexEntry*)>& aCB) {
1219 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)
;
1220
1221 SHA1Sum sum;
1222 SHA1Sum::Hash hash;
1223 sum.update(aKey.BeginReading(), aKey.Length());
1224 sum.finish(hash);
1225
1226 return HasEntry(hash, _retval, aCB);
1227}
1228
1229// static
1230nsresult CacheIndex::HasEntry(
1231 const SHA1Sum::Hash& hash, EntryStatus* _retval,
1232 const std::function<void(const CacheIndexEntry*)>& aCB) {
1233 StaticMutexAutoLock lock(sLock);
1234
1235 RefPtr<CacheIndex> index = gInstance;
1236
1237 if (!index) {
1238 return NS_ERROR_NOT_INITIALIZED;
1239 }
1240
1241 if (!index->IsIndexUsable()) {
1242 return NS_ERROR_NOT_AVAILABLE;
1243 }
1244
1245 const CacheIndexEntry* entry = nullptr;
1246
1247 switch (index->mState) {
1248 case READING:
1249 case WRITING:
1250 entry = index->mPendingUpdates.GetEntry(hash);
1251 [[fallthrough]];
1252 case BUILDING:
1253 case UPDATING:
1254 case READY:
1255 if (!entry) {
1256 entry = index->mIndex.GetEntry(hash);
1257 }
1258 break;
1259 case INITIAL:
1260 case SHUTDOWN:
1261 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", 1261); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "false" ") (" "Unexpected state!" ")"); do {
MOZ_CrashSequence(__null, 1261); __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
1262 }
1263
1264 if (!entry) {
1265 if (index->mState == READY || index->mState == WRITING) {
1266 *_retval = DOES_NOT_EXIST;
1267 } else {
1268 *_retval = DO_NOT_KNOW;
1269 }
1270 } else {
1271 if (entry->IsRemoved()) {
1272 if (entry->IsFresh()) {
1273 *_retval = DOES_NOT_EXIST;
1274 } else {
1275 *_retval = DO_NOT_KNOW;
1276 }
1277 } else {
1278 *_retval = EXISTS;
1279 if (aCB) {
1280 aCB(entry);
1281 }
1282 }
1283 }
1284
1285 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)
;
1286 return NS_OK;
1287}
1288
1289// static
1290// GetEntryForEviction is used by OverLimitEvictionInternal where we create and
1291// keep our EvictionSortedSnapshot while looping.
1292nsresult CacheIndex::GetEntryForEviction(EvictionSortedSnapshot& aSnapshot,
1293 bool aIgnoreEmptyEntries,
1294 SHA1Sum::Hash* aHash, uint32_t* aCnt) {
1295 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)
;
1296
1297 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"
, 1297); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()"
")"); do { MOZ_CrashSequence(__null, 1297); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1298
1299 StaticMutexAutoLock lock(sLock);
1300
1301 RefPtr<CacheIndex> index = gInstance;
1302
1303 if (!index) return NS_ERROR_NOT_INITIALIZED;
1304
1305 if (!index->IsIndexUsable()) {
1306 return NS_ERROR_NOT_AVAILABLE;
1307 }
1308
1309 if (index->mIndexStats.Size() == 0) {
1310 return NS_ERROR_NOT_AVAILABLE;
1311 }
1312
1313 int32_t mediaUsage =
1314 round(static_cast<double>(index->mIndexStats.SizeByType(
1315 nsICacheEntry::CONTENT_TYPE_MEDIA)) *
1316 100.0 / static_cast<double>(index->mIndexStats.Size()));
1317 int32_t mediaUsageLimit =
1318 StaticPrefs::browser_cache_disk_content_type_media_limit();
1319 bool evictMedia = false;
1320 if (mediaUsage > mediaUsageLimit) {
1321 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)
1322 ("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)
1323 "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)
1324 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)
;
1325 evictMedia = true;
1326 }
1327
1328 SHA1Sum::Hash hash;
1329 CacheIndexRecord* foundRecord = nullptr;
1330 uint32_t skipped = 0;
1331 size_t recordPosition = 0;
1332
1333 // find the first evictable entry with the lowest frecency
1334 for (size_t i = 0; i < aSnapshot.Length(); ++i) {
1335 if (!aSnapshot[i]) {
1336 continue; // Skip the null records
1337 }
1338 CacheIndexRecord* rec = aSnapshot[i]->Get();
1339 if (!rec) {
1340 continue; // Skip the null records
1341 }
1342
1343 memcpy(&hash, rec->mHash, sizeof(SHA1Sum::Hash));
1344
1345 ++skipped;
1346
1347 uint32_t type = CacheIndexEntry::GetContentType(rec);
1348
1349 if (evictMedia && type != nsICacheEntry::CONTENT_TYPE_MEDIA) {
1350 continue;
1351 }
1352
1353 if (type == nsICacheEntry::CONTENT_TYPE_DICTIONARY) {
1354 // Let them be removed by becoming empty and removing themselves
1355 continue;
1356 }
1357
1358 // Skip entries with active (non-doomed) file handles. These are
1359 // currently being read from or written to. Evicting them would doom
1360 // the in-progress I/O — in particular, a newly-created entry being
1361 // written always has the lowest frecency and would otherwise be
1362 // selected as the first eviction candidate, preventing it from ever
1363 // being stored. See bug 2031577.
1364 //
1365 // The previous IsForcedValidEntry check itself required a handle to
1366 // return true, so this handle check already subsumes it.
1367 {
1368 RefPtr<CacheFileHandle> handle;
1369 if (CacheFileIOManager::gInstance &&
1370 NS_SUCCEEDED(CacheFileIOManager::gInstance->mHandles.GetHandle(((bool)(__builtin_expect(!!(!NS_FAILED_impl(CacheFileIOManager
::gInstance->mHandles.GetHandle( &hash, getter_AddRefs
(handle)))), 1)))
1371 &hash, getter_AddRefs(handle)))((bool)(__builtin_expect(!!(!NS_FAILED_impl(CacheFileIOManager
::gInstance->mHandles.GetHandle( &hash, getter_AddRefs
(handle)))), 1)))
) {
1372 continue;
1373 }
1374 }
1375
1376 if (CacheIndexEntry::IsPinned(rec)) {
1377 continue;
1378 }
1379
1380 if (aIgnoreEmptyEntries && !CacheIndexEntry::GetFileSize(*rec)) {
1381 continue;
1382 }
1383
1384 --skipped;
1385 foundRecord = rec;
1386 recordPosition = i;
1387 break;
1388 }
1389
1390 if (!foundRecord) return NS_ERROR_NOT_AVAILABLE;
1391
1392 *aCnt = skipped;
1393
1394 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)
1395 ("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)
1396 "[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)
1397 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)
1398 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)
;
1399
1400 memcpy(aHash, &hash, sizeof(SHA1Sum::Hash));
1401 aSnapshot[recordPosition] = nullptr; // Remove the record from the snapshot
1402
1403 return NS_OK;
1404}
1405
1406// static
1407nsresult CacheIndex::GetCacheSize(uint32_t* _retval) {
1408 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)
;
1409
1410 StaticMutexAutoLock lock(sLock);
1411
1412 RefPtr<CacheIndex> index = gInstance;
1413
1414 if (!index) return NS_ERROR_NOT_INITIALIZED;
1415
1416 if (!index->IsIndexUsable()) {
1417 return NS_ERROR_NOT_AVAILABLE;
1418 }
1419
1420 *_retval = index->mIndexStats.Size();
1421 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)
;
1422 return NS_OK;
1423}
1424
1425// static
1426nsresult CacheIndex::GetEntryFileCount(uint32_t* _retval) {
1427 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)
;
1428
1429 StaticMutexAutoLock lock(sLock);
1430
1431 RefPtr<CacheIndex> index = gInstance;
1432
1433 if (!index) {
1434 return NS_ERROR_NOT_INITIALIZED;
1435 }
1436
1437 if (!index->IsIndexUsable()) {
1438 return NS_ERROR_NOT_AVAILABLE;
1439 }
1440
1441 *_retval = index->mIndexStats.ActiveEntriesCount();
1442 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)
;
1443 return NS_OK;
1444}
1445
1446// static
1447nsresult CacheIndex::GetCacheStats(nsILoadContextInfo* aInfo, uint32_t* aSize,
1448 uint32_t* aCount) {
1449 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)
;
1450
1451 StaticMutexAutoLock lock(sLock);
1452
1453 RefPtr<CacheIndex> index = gInstance;
1454
1455 if (!index) {
1456 return NS_ERROR_NOT_INITIALIZED;
1457 }
1458
1459 if (!index->IsIndexUsable()) {
1460 return NS_ERROR_NOT_AVAILABLE;
1461 }
1462
1463 *aSize = 0;
1464 *aCount = 0;
1465
1466 for (const auto& item : index->mFrecencyStorage.mRecs) {
1467 if (aInfo &&
1468 !CacheIndexEntry::RecordMatchesLoadContextInfo(item.GetKey(), aInfo)) {
1469 continue;
1470 }
1471
1472 *aSize += CacheIndexEntry::GetFileSize(*(item.GetKey()->Get()));
1473 ++*aCount;
1474 }
1475
1476 return NS_OK;
1477}
1478
1479// static
1480nsresult CacheIndex::AsyncGetDiskConsumption(
1481 nsICacheStorageConsumptionObserver* aObserver) {
1482 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)
;
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 RefPtr<DiskConsumptionObserver> observer =
1497 DiskConsumptionObserver::Init(aObserver);
1498
1499 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", 1499); return NS_ERROR_INVALID_ARG
; } } while (false)
;
1500
1501 if ((index->mState == READY || index->mState == WRITING) &&
1502 !index->mAsyncGetDiskConsumptionBlocked) {
1503 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)
;
1504 // Safe to call the callback under the lock,
1505 // we always post to the main thread.
1506 observer->OnDiskConsumption(index->mIndexStats.Size() << 10);
1507 return NS_OK;
1508 }
1509
1510 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)
;
1511 // Will be called when the index get to the READY state.
1512 index->mDiskConsumptionObservers.AppendElement(observer);
1513
1514 // Move forward with index re/building if it is pending
1515 RefPtr<CacheIOThread> ioThread = CacheFileIOManager::IOThread();
1516 if (ioThread) {
1517 ioThread->Dispatch(
1518 NS_NewRunnableFunction("net::CacheIndex::AsyncGetDiskConsumption",
1519 []() -> void {
1520 StaticMutexAutoLock lock(sLock);
1521
1522 RefPtr<CacheIndex> index = gInstance;
1523 if (index && index->mUpdateTimer) {
1524 index->mUpdateTimer->Cancel();
1525 index->DelayedUpdateLocked(lock);
1526 }
1527 }),
1528 CacheIOThread::INDEX);
1529 }
1530
1531 return NS_OK;
1532}
1533
1534// static
1535nsresult CacheIndex::GetIterator(nsILoadContextInfo* aInfo, bool aAddNew,
1536 CacheIndexIterator** _retval) {
1537 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)
;
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<CacheIndexIterator> idxIter;
1552 if (aInfo) {
1553 idxIter = new CacheIndexContextIterator(index, aAddNew, aInfo);
1554 } else {
1555 idxIter = new CacheIndexIterator(index, aAddNew);
1556 }
1557 for (const auto& item : index->mFrecencyStorage.mRecs) {
1558 idxIter->AddRecord(item.GetKey(), lock);
1559 }
1560
1561 index->mIterators.AppendElement(idxIter);
1562 idxIter.swap(*_retval);
1563 return NS_OK;
1564}
1565
1566// static
1567nsresult CacheIndex::IsUpToDate(bool* _retval) {
1568 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)
;
1569
1570 StaticMutexAutoLock lock(sLock);
1571
1572 RefPtr<CacheIndex> index = gInstance;
1573
1574 if (!index) {
1575 return NS_ERROR_NOT_INITIALIZED;
1576 }
1577
1578 if (!index->IsIndexUsable()) {
1579 return NS_ERROR_NOT_AVAILABLE;
1580 }
1581
1582 *_retval = (index->mState == READY || index->mState == WRITING) &&
1583 !index->mIndexNeedsUpdate && !index->mShuttingDown;
1584
1585 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)
;
1586 return NS_OK;
1587}
1588
1589bool CacheIndex::IsIndexUsable() {
1590 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", 1590); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mState != INITIAL" ")"); do { MOZ_CrashSequence
(__null, 1590); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1591
1592 switch (mState) {
1593 case INITIAL:
1594 case SHUTDOWN:
1595 return false;
1596
1597 case READING:
1598 case WRITING:
1599 case BUILDING:
1600 case UPDATING:
1601 case READY:
1602 break;
1603 }
1604
1605 return true;
1606}
1607
1608// static
1609bool CacheIndex::IsCollision(CacheIndexEntry* aEntry,
1610 OriginAttrsHash aOriginAttrsHash,
1611 bool aAnonymous) {
1612 if (!aEntry->IsInitialized()) {
1613 return false;
1614 }
1615
1616 if (aEntry->Anonymous() != aAnonymous ||
1617 aEntry->OriginAttrsHash() != aOriginAttrsHash) {
1618 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)
1619 ("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)
1620 "%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)
1621 "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)
1622 ", 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)
1623 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)
1624 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)
;
1625 return true;
1626 }
1627
1628 return false;
1629}
1630
1631// static
1632bool CacheIndex::HasEntryChanged(
1633 CacheIndexEntry* aEntry, const uint32_t* aFrecency, const bool* aHasAltData,
1634 const uint32_t* aLastFetched, const uint32_t* aFetchCount,
1635 const uint8_t* aContentType, const uint32_t* aSize) {
1636 if (aFrecency && *aFrecency != aEntry->GetFrecency()) {
1637 return true;
1638 }
1639
1640 if (aHasAltData && *aHasAltData != aEntry->GetHasAltData()) {
1641 return true;
1642 }
1643
1644 if (aLastFetched && *aLastFetched != aEntry->GetLastFetched()) {
1645 return true;
1646 }
1647
1648 if (aFetchCount && *aFetchCount != aEntry->GetFetchCount()) {
1649 return true;
1650 }
1651
1652 if (aContentType && *aContentType != aEntry->GetContentType()) {
1653 return true;
1654 }
1655
1656 if (aSize &&
1657 (*aSize & CacheIndexEntry::kFileSizeMask) != aEntry->GetFileSize()) {
1658 return true;
1659 }
1660
1661 return false;
1662}
1663
1664void CacheIndex::ProcessPendingOperations(
1665 const StaticMutexAutoLock& aProofOfLock) {
1666 sLock.AssertCurrentThreadOwns();
1667 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)
;
1668
1669 for (auto iter = mPendingUpdates.Iter(); !iter.Done(); iter.Next()) {
1670 CacheIndexEntryUpdate* update = iter.Get();
1671
1672 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)
1673 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)
;
1674
1675 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", 1675); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "update->IsFresh()" ")"); do { MOZ_CrashSequence
(__null, 1675); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1676
1677 CacheIndexEntry* entry = mIndex.GetEntry(*update->Hash());
1678 {
1679 CacheIndexEntryAutoManage emng(update->Hash(), this, aProofOfLock);
1680 emng.DoNotSearchInUpdates();
1681
1682 if (update->IsRemoved()) {
1683 if (entry) {
1684 if (entry->IsRemoved()) {
1685 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", 1685); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "entry->IsFresh()" ")"); do { MOZ_CrashSequence
(__null, 1685); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1686 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", 1686); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "entry->IsDirty()" ")"); do { MOZ_CrashSequence
(__null, 1686); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1687 } else if (!entry->IsDirty() && entry->IsFileEmpty()) {
1688 // Entries with empty file are not stored in index on disk. Just
1689 // remove the entry, but only in case the entry is not dirty, i.e.
1690 // the entry file was empty when we wrote the index.
1691 mIndex.RemoveEntry(entry);
1692 entry = nullptr;
1693 } else {
1694 entry->MarkRemoved();
1695 entry->MarkDirty();
1696 entry->MarkFresh();
1697 }
1698 }
1699 } else if (entry) {
1700 // Some information in mIndex can be newer than in mPendingUpdates (see
1701 // bug 1074832). This will copy just those values that were really
1702 // updated.
1703 update->ApplyUpdate(entry);
1704 } else {
1705 // There is no entry in mIndex, copy all information from
1706 // mPendingUpdates to mIndex.
1707 entry = mIndex.PutEntry(*update->Hash());
1708 *entry = *update;
1709 }
1710 }
1711 iter.Remove();
1712 }
1713
1714 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"
, 1714); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mPendingUpdates.Count() == 0"
")"); do { MOZ_CrashSequence(__null, 1714); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1715
1716 EnsureCorrectStats();
1717}
1718
1719bool CacheIndex::WriteIndexToDiskIfNeeded(
1720 const StaticMutexAutoLock& aProofOfLock) {
1721 sLock.AssertCurrentThreadOwns();
1722 if (mState != READY || mShuttingDown || mRWPending) {
1723 return false;
1724 }
1725
1726 if (mIndexStats.Dirty() == 0) {
1727 return false;
1728 }
1729
1730 double sinceLastDump =
1731 mLastDumpTime.IsNull()
1732 ? std::numeric_limits<double>::infinity()
1733 : (TimeStamp::NowLoRes() - mLastDumpTime).ToMilliseconds();
1734
1735 if (sinceLastDump <
1736 StaticPrefs::browser_cache_disk_index_min_dump_interval_ms()) {
1737 return false;
1738 }
1739
1740 // Write either once enough changes have accumulated, or once the maximum
1741 // interval has elapsed with any dirty entry. The latter is a safety net so
1742 // that recently-updated frecency is not lost on a crash or process kill under
1743 // light browsing, where the dirty-count threshold may never be reached.
1744 if (mIndexStats.Dirty() <
1745 StaticPrefs::browser_cache_disk_index_min_unwritten_changes() &&
1746 sinceLastDump <
1747 StaticPrefs::browser_cache_disk_index_max_dump_interval_ms()) {
1748 return false;
1749 }
1750
1751 WriteIndexToDisk(aProofOfLock);
1752 return true;
1753}
1754
1755void CacheIndex::WriteIndexToDisk(const StaticMutexAutoLock& aProofOfLock) {
1756 sLock.AssertCurrentThreadOwns();
1757 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)
;
1758 mIndexStats.Log();
1759
1760 nsresult rv;
1761
1762 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", 1762); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mState == READY" ")"); do { MOZ_CrashSequence
(__null, 1762); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1763 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"
, 1763); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mRWBuf" ")"
); do { MOZ_CrashSequence(__null, 1763); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1764 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"
, 1764); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mRWHash" ")"
); do { MOZ_CrashSequence(__null, 1764); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1765 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"
, 1765); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mRWPending"
")"); do { MOZ_CrashSequence(__null, 1765); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1766
1767 ChangeState(WRITING, aProofOfLock);
1768
1769 mRWEntries.Clear();
1770 mRWEntries.SetCapacity(mIndexStats.ActiveEntriesCount());
1771 for (auto iter = mIndex.Iter(); !iter.Done(); iter.Next()) {
1772 CacheIndexEntry* entry = iter.Get();
1773 if (entry->IsRemoved() || !entry->IsInitialized() || entry->IsFileEmpty()) {
1774 continue;
1775 }
1776 mRWEntries.AppendElement(entry);
1777 }
1778 MOZ_ASSERT(mRWEntries.Length() == mIndexStats.ActiveEntriesCount())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mRWEntries.Length() == mIndexStats.ActiveEntriesCount
())>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(mRWEntries.Length() == mIndexStats.ActiveEntriesCount
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mRWEntries.Length() == mIndexStats.ActiveEntriesCount()", "./../../../netwerk/cache2/CacheIndex.cpp"
, 1778); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mRWEntries.Length() == mIndexStats.ActiveEntriesCount()"
")"); do { MOZ_CrashSequence(__null, 1778); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1779 mProcessEntries = static_cast<uint32_t>(mRWEntries.Length());
1780
1781 mIndexFileOpener = new FileOpenHelper(this);
1782 rv = CacheFileIOManager::OpenFile(
1783 nsLiteralCString(TEMP_INDEX_NAME"index.tmp"),
1784 CacheFileIOManager::SPECIAL_FILE | CacheFileIOManager::CREATE,
1785 mIndexFileOpener);
1786 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1787 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)
1788 "]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__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)
1789 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)
;
1790 FinishWrite(false, aProofOfLock);
1791 return;
1792 }
1793
1794 // Write index header to a buffer, it will be written to disk together with
1795 // records in WriteRecords() once we open the file successfully.
1796 AllocBuffer();
1797 mRWHash = new CacheHash();
1798
1799 mRWBufPos = 0;
1800 // index version
1801 NetworkEndian::writeUint32(mRWBuf + mRWBufPos, kIndexVersion0x0000000D);
1802 mRWBufPos += sizeof(uint32_t);
1803 // timestamp
1804 NetworkEndian::writeUint32(mRWBuf + mRWBufPos,
1805 static_cast<uint32_t>(PR_Now() / PR_USEC_PER_SEC1000000L));
1806 mRWBufPos += sizeof(uint32_t);
1807 // dirty flag
1808 NetworkEndian::writeUint32(mRWBuf + mRWBufPos, 1);
1809 mRWBufPos += sizeof(uint32_t);
1810 // amount of data written to the cache
1811 NetworkEndian::writeUint32(mRWBuf + mRWBufPos,
1812 static_cast<uint32_t>(mTotalBytesWritten >> 10));
1813 mRWBufPos += sizeof(uint32_t);
1814 // Whether the entries on disk are encrypted at rest. This is the session's
1815 // captured pref value, which is fixed at startup -- a mid-session flip only
1816 // takes effect on the next restart, so reading the live pref here would mask
1817 // it. Deliberately not IsActive(): a session where encryption is enabled but
1818 // no cipher could be loaded writes no entries at all, since
1819 // CacheFile::SetupEncryption() fails them closed, so the entries on disk are
1820 // still the encrypted ones an earlier session wrote.
1821 NetworkEndian::writeUint32(mRWBuf + mRWBufPos,
1822 CacheCrypto::IsEnabled() ? 1 : 0);
1823 mRWBufPos += sizeof(uint32_t);
1824
1825 mSkipEntries = 0;
1826}
1827
1828void CacheIndex::WriteRecords(const StaticMutexAutoLock& aProofOfLock) {
1829 sLock.AssertCurrentThreadOwns();
1830 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)
;
1831
1832 nsresult rv;
1833
1834 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", 1834); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mState == WRITING" ")"); do { MOZ_CrashSequence
(__null, 1834); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1835 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"
, 1835); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mRWPending"
")"); do { MOZ_CrashSequence(__null, 1835); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1836
1837 int64_t fileOffset;
1838
1839 if (mSkipEntries) {
1840 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", 1840); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mRWBufPos == 0" ")"); do { MOZ_CrashSequence
(__null, 1840); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1841 fileOffset = sizeof(CacheIndexHeader);
1842 fileOffset += sizeof(CacheIndexRecord) * mSkipEntries;
1843 } else {
1844 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", 1844); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mRWBufPos == sizeof(CacheIndexHeader)" ")"
); do { MOZ_CrashSequence(__null, 1844); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1845 fileOffset = 0;
1846 }
1847 uint32_t hashOffset = mRWBufPos;
1848
1849 char* buf = mRWBuf + mRWBufPos;
1850 uint32_t processMax = (mRWBufSize - mRWBufPos) / sizeof(CacheIndexRecord);
1851 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", 1853); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "processMax != 0 || mProcessEntries == 0" ")"
); do { MOZ_CrashSequence(__null, 1853); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1852 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", 1853); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "processMax != 0 || mProcessEntries == 0" ")"
); do { MOZ_CrashSequence(__null, 1853); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1853 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", 1853); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "processMax != 0 || mProcessEntries == 0" ")"
); do { MOZ_CrashSequence(__null, 1853); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
; // TODO make sure we can write an empty index
1854 uint32_t processed = 0;
1855 for (uint32_t i = mSkipEntries; i < mRWEntries.Length(); ++i) {
1856 if (processed == processMax) {
1857 break;
1858 }
1859
1860 mRWEntries[i]->WriteToBuf(buf);
1861 buf += sizeof(CacheIndexRecord);
1862 processed++;
1863 }
1864#ifdef DEBUG1
1865 bool hasMore = mSkipEntries + processed < mRWEntries.Length();
1866#endif
1867
1868 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", 1869); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mRWBufPos != static_cast<uint32_t>(buf - mRWBuf) || mProcessEntries == 0"
")"); do { MOZ_CrashSequence(__null, 1869); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1869 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", 1869); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mRWBufPos != static_cast<uint32_t>(buf - mRWBuf) || mProcessEntries == 0"
")"); do { MOZ_CrashSequence(__null, 1869); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1870 mRWBufPos = buf - mRWBuf;
1871 mSkipEntries += processed;
1872 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"
, 1872); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mSkipEntries <= mProcessEntries"
")"); do { MOZ_CrashSequence(__null, 1872); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1873
1874 mRWHash->Update(mRWBuf + hashOffset, mRWBufPos - hashOffset);
1875
1876 if (mSkipEntries == mProcessEntries) {
1877 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"
, 1877); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!hasMore" ")"
); do { MOZ_CrashSequence(__null, 1877); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1878
1879 // We've processed all records
1880 if (mRWBufPos + sizeof(CacheHash::Hash32_t) > mRWBufSize) {
1881 // realloc buffer to spare another write cycle
1882 mRWBufSize = mRWBufPos + sizeof(CacheHash::Hash32_t);
1883 mRWBuf = static_cast<char*>(moz_xrealloc(mRWBuf, mRWBufSize));
1884 }
1885
1886 NetworkEndian::writeUint32(mRWBuf + mRWBufPos, mRWHash->GetHash());
1887 mRWBufPos += sizeof(CacheHash::Hash32_t);
1888 } else {
1889 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"
, 1889); AnnotateMozCrashReason("MOZ_ASSERT" "(" "hasMore" ")"
); do { MOZ_CrashSequence(__null, 1889); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1890 }
1891
1892 rv = CacheFileIOManager::Write(mIndexHandle, fileOffset, mRWBuf, mRWBufPos,
1893 mSkipEntries == mProcessEntries, false, this);
1894 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1895 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)
1896 ("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)
1897 "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)
1898 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)
;
1899 FinishWrite(false, aProofOfLock);
1900 } else {
1901 mRWPending = true;
1902 }
1903
1904 mRWBufPos = 0;
1905}
1906
1907void CacheIndex::FinishWrite(bool aSucceeded,
1908 const StaticMutexAutoLock& aProofOfLock) {
1909 sLock.AssertCurrentThreadOwns();
1910 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)
;
1911
1912 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", 1912); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "(!aSucceeded && mState == SHUTDOWN) || mState == WRITING"
")"); do { MOZ_CrashSequence(__null, 1912); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1913
1914 // If there is write operation pending we must be cancelling writing of the
1915 // index when shutting down or removing the whole index.
1916 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", 1916); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!mRWPending || (!aSucceeded && (mShuttingDown || mRemovingAll))"
")"); do { MOZ_CrashSequence(__null, 1916); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1917
1918 mIndexHandle = nullptr;
1919 mRWHash = nullptr;
1920 ReleaseBuffer();
1921 // ReleaseBuffer() keeps the buffer while a write is still pending, but the
1922 // entries below are about to be removed from mIndex.
1923 mRWEntries.Clear();
1924
1925 if (aSucceeded) {
1926 // Opening of the file must not be in progress if writing succeeded.
1927 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", 1927); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!mIndexFileOpener" ")"); do { MOZ_CrashSequence
(__null, 1927); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1928
1929 for (auto iter = mIndex.Iter(); !iter.Done(); iter.Next()) {
1930 CacheIndexEntry* entry = iter.Get();
1931
1932 bool remove = false;
1933 {
1934 CacheIndexEntryAutoManage emng(entry->Hash(), this, aProofOfLock);
1935
1936 if (entry->IsRemoved()) {
1937 emng.DoNotSearchInIndex();
1938 remove = true;
1939 } else if (entry->IsDirty()) {
1940 entry->ClearDirty();
1941 }
1942 }
1943 if (remove) {
1944 iter.Remove();
1945 }
1946 }
1947
1948 mIndexOnDiskIsValid = true;
1949 } else {
1950 if (mIndexFileOpener) {
1951 // If opening of the file is still in progress (e.g. WRITE process was
1952 // canceled by RemoveAll()) then we need to cancel the opener to make sure
1953 // that OnFileOpenedInternal() won't be called.
1954 mIndexFileOpener->Cancel();
1955 mIndexFileOpener = nullptr;
1956 }
1957 }
1958
1959 ProcessPendingOperations(aProofOfLock);
1960 mIndexStats.Log();
1961
1962 if (mState == WRITING) {
1963 ChangeState(READY, aProofOfLock);
1964 mLastDumpTime = TimeStamp::NowLoRes();
1965 }
1966}
1967
1968nsresult CacheIndex::GetFile(const nsACString& aName, nsIFile** _retval) {
1969 nsresult rv;
1970
1971 nsCOMPtr<nsIFile> file;
1972 rv = mCacheDirectory->Clone(getter_AddRefs(file));
1973 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"
, 1973); return rv; } } while (false)
;
1974
1975 rv = file->AppendNative(aName);
1976 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"
, 1976); return rv; } } while (false)
;
1977
1978 file.swap(*_retval);
1979 return NS_OK;
1980}
1981
1982void CacheIndex::RemoveFile(const nsACString& aName) {
1983 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", 1983); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mState == SHUTDOWN" ")"); do { MOZ_CrashSequence
(__null, 1983); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1984
1985 nsresult rv;
1986
1987 nsCOMPtr<nsIFile> file;
1988 rv = GetFile(aName, getter_AddRefs(file));
1989 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"
, 1989); return; } } while (false)
;
1990
1991 rv = file->Remove(false);
1992 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0))) && rv != NS_ERROR_FILE_NOT_FOUND) {
1993 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
)
1994 ("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
)
1995 "[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
)
1996 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
)
;
1997 }
1998}
1999
2000void CacheIndex::RemoveAllIndexFiles() {
2001 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)
;
2002 RemoveFile(nsLiteralCString(INDEX_NAME"index"));
2003 RemoveJournalAndTempFile();
2004}
2005
2006void CacheIndex::RemoveJournalAndTempFile() {
2007 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)
;
2008 RemoveFile(nsLiteralCString(TEMP_INDEX_NAME"index.tmp"));
2009 RemoveFile(nsLiteralCString(JOURNAL_NAME"index.log"));
2010}
2011
2012class WriteLogHelper {
2013 public:
2014 explicit WriteLogHelper(PRFileDesc* aFD)
2015 : mFD(aFD), mBufSize(kMaxBufSize16384), mBufPos(0) {
2016 mHash = new CacheHash();
2017 mBuf = static_cast<char*>(moz_xmalloc(mBufSize));
2018 }
2019
2020 ~WriteLogHelper() { free(mBuf); }
2021
2022 nsresult AddEntry(CacheIndexEntry* aEntry);
2023 nsresult Finish();
2024
2025 private:
2026 nsresult FlushBuffer();
2027
2028 PRFileDesc* mFD;
2029 char* mBuf;
2030 uint32_t mBufSize;
2031 int32_t mBufPos;
2032 RefPtr<CacheHash> mHash;
2033};
2034
2035nsresult WriteLogHelper::AddEntry(CacheIndexEntry* aEntry) {
2036 nsresult rv;
2037
2038 if (mBufPos + sizeof(CacheIndexRecord) > mBufSize) {
2039 mHash->Update(mBuf, mBufPos);
2040
2041 rv = FlushBuffer();
2042 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"
, 2042); return rv; } } while (false)
;
2043 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", 2043); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mBufPos + sizeof(CacheIndexRecord) <= mBufSize"
")"); do { MOZ_CrashSequence(__null, 2043); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2044 }
2045
2046 aEntry->WriteToBuf(mBuf + mBufPos);
2047 mBufPos += sizeof(CacheIndexRecord);
2048
2049 return NS_OK;
2050}
2051
2052nsresult WriteLogHelper::Finish() {
2053 nsresult rv;
2054
2055 mHash->Update(mBuf, mBufPos);
2056 if (mBufPos + sizeof(CacheHash::Hash32_t) > mBufSize) {
2057 rv = FlushBuffer();
2058 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"
, 2058); return rv; } } while (false)
;
2059 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"
, 2059); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mBufPos + sizeof(CacheHash::Hash32_t) <= mBufSize"
")"); do { MOZ_CrashSequence(__null, 2059); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2060 }
2061
2062 NetworkEndian::writeUint32(mBuf + mBufPos, mHash->GetHash());
2063 mBufPos += sizeof(CacheHash::Hash32_t);
2064
2065 rv = FlushBuffer();
2066 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"
, 2066); return rv; } } while (false)
;
2067
2068 return NS_OK;
2069}
2070
2071nsresult WriteLogHelper::FlushBuffer() {
2072 if (CacheObserver::IsPastShutdownIOLag()) {
2073 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)
;
2074 return NS_ERROR_FAILURE;
2075 }
2076
2077 int32_t bytesWritten = PR_Write(mFD, mBuf, mBufPos);
2078
2079 if (bytesWritten != mBufPos) {
2080 return NS_ERROR_FAILURE;
2081 }
2082
2083 mBufPos = 0;
2084 return NS_OK;
2085}
2086
2087nsresult CacheIndex::WriteLogToDisk() {
2088 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)
;
2089
2090 nsresult rv;
2091
2092 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"
, 2092); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mPendingUpdates.Count() == 0"
")"); do { MOZ_CrashSequence(__null, 2092); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2093 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", 2093); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mState == SHUTDOWN" ")"); do { MOZ_CrashSequence
(__null, 2093); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2094
2095 if (CacheObserver::IsPastShutdownIOLag()) {
2096 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)
;
2097 return NS_ERROR_FAILURE;
2098 }
2099
2100 RemoveFile(nsLiteralCString(TEMP_INDEX_NAME"index.tmp"));
2101
2102 nsCOMPtr<nsIFile> indexFile;
2103 rv = GetFile(nsLiteralCString(INDEX_NAME"index"), getter_AddRefs(indexFile));
2104 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"
, 2104); return rv; } } while (false)
;
2105
2106 nsCOMPtr<nsIFile> logFile;
2107 rv = GetFile(nsLiteralCString(JOURNAL_NAME"index.log"), getter_AddRefs(logFile));
2108 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"
, 2108); return rv; } } while (false)
;
2109
2110 mIndexStats.Log();
2111
2112 PRFileDesc* fd = nullptr;
2113 rv = logFile->OpenNSPRFileDesc(PR_RDWR0x04 | PR_CREATE_FILE0x08 | PR_TRUNCATE0x20, 0600,
2114 &fd);
2115 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"
, 2115); return rv; } } while (false)
;
2116
2117 WriteLogHelper wlh(fd);
2118 for (auto iter = mIndex.Iter(); !iter.Done(); iter.Next()) {
2119 CacheIndexEntry* entry = iter.Get();
2120 if (entry->IsRemoved() || entry->IsDirty()) {
2121 rv = wlh.AddEntry(entry);
2122 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"
, 2122)
) {
2123 return rv;
2124 }
2125 }
2126 }
2127
2128 rv = wlh.Finish();
2129 PR_Close(fd);
2130 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"
, 2130); return rv; } } while (false)
;
2131
2132 rv = indexFile->OpenNSPRFileDesc(PR_RDWR0x04, 0600, &fd);
2133 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"
, 2133); return rv; } } while (false)
;
2134
2135 // Seek to dirty flag in the index header and clear it.
2136 static_assert(2 * sizeof(uint32_t) == offsetof(CacheIndexHeader, mIsDirty)__builtin_offsetof(CacheIndexHeader, mIsDirty),
2137 "Unexpected offset of CacheIndexHeader::mIsDirty");
2138 int64_t offset = PR_Seek64(fd, 2 * sizeof(uint32_t), PR_SEEK_SET);
2139 if (offset == -1) {
2140 PR_Close(fd);
2141 return NS_ERROR_FAILURE;
2142 }
2143
2144 uint32_t isDirty = 0;
2145 int32_t bytesWritten = PR_Write(fd, &isDirty, sizeof(isDirty));
2146 PR_Close(fd);
2147 if (bytesWritten != sizeof(isDirty)) {
2148 return NS_ERROR_FAILURE;
2149 }
2150
2151 return NS_OK;
2152}
2153
2154void CacheIndex::ReadIndexFromDisk(const StaticMutexAutoLock& aProofOfLock) {
2155 sLock.AssertCurrentThreadOwns();
2156 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)
;
2157
2158 nsresult rv;
2159
2160 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", 2160); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mState == INITIAL" ")"); do { MOZ_CrashSequence
(__null, 2160); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2161
2162 ChangeState(READING, aProofOfLock);
2163
2164 mIndexFileOpener = new FileOpenHelper(this);
2165 rv = CacheFileIOManager::OpenFile(
2166 nsLiteralCString(INDEX_NAME"index"),
2167 CacheFileIOManager::SPECIAL_FILE | CacheFileIOManager::OPEN,
2168 mIndexFileOpener);
2169 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2170 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)
2171 ("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)
2172 "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)
2173 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)
;
2174 FinishRead(false, aProofOfLock);
2175 return;
2176 }
2177
2178 mJournalFileOpener = new FileOpenHelper(this);
2179 rv = CacheFileIOManager::OpenFile(
2180 nsLiteralCString(JOURNAL_NAME"index.log"),
2181 CacheFileIOManager::SPECIAL_FILE | CacheFileIOManager::OPEN,
2182 mJournalFileOpener);
2183 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2184 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)
2185 ("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)
2186 "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)
2187 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)
;
2188 FinishRead(false, aProofOfLock);
2189 }
2190
2191 mTmpFileOpener = new FileOpenHelper(this);
2192 rv = CacheFileIOManager::OpenFile(
2193 nsLiteralCString(TEMP_INDEX_NAME"index.tmp"),
2194 CacheFileIOManager::SPECIAL_FILE | CacheFileIOManager::OPEN,
2195 mTmpFileOpener);
2196 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2197 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)
2198 ("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)
2199 "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)
2200 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)
;
2201 FinishRead(false, aProofOfLock);
2202 }
2203}
2204
2205void CacheIndex::StartReadingIndex(const StaticMutexAutoLock& aProofOfLock) {
2206 sLock.AssertCurrentThreadOwns();
2207 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)
;
2208
2209 nsresult rv;
2210
2211 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"
, 2211); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIndexHandle"
")"); do { MOZ_CrashSequence(__null, 2211); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2212 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", 2212); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mState == READING" ")"); do { MOZ_CrashSequence
(__null, 2212); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2213 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", 2213); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!mIndexOnDiskIsValid" ")"); do { MOZ_CrashSequence
(__null, 2213); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2214 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", 2214); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!mDontMarkIndexClean" ")"); do { MOZ_CrashSequence
(__null, 2214); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2215 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", 2215); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!mJournalReadSuccessfully" ")"); do { MOZ_CrashSequence
(__null, 2215); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2216 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"
, 2216); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIndexHandle->FileSize() >= 0"
")"); do { MOZ_CrashSequence(__null, 2216); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2217 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"
, 2217); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mRWPending"
")"); do { MOZ_CrashSequence(__null, 2217); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2218
2219 int64_t entriesSize = mIndexHandle->FileSize() - sizeof(CacheIndexHeader) -
2220 sizeof(CacheHash::Hash32_t);
2221
2222 if (entriesSize < 0 || entriesSize % sizeof(CacheIndexRecord)) {
2223 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)
;
2224 FinishRead(false, aProofOfLock);
2225 return;
2226 }
2227
2228 AllocBuffer();
2229 mSkipEntries = 0;
2230 mRWHash = new CacheHash();
2231
2232 mRWBufPos =
2233 std::min(mRWBufSize, static_cast<uint32_t>(mIndexHandle->FileSize()));
2234
2235 rv = CacheFileIOManager::Read(mIndexHandle, 0, mRWBuf, mRWBufPos, this);
2236 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2237 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)
2238 ("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)
2239 "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)
2240 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)
;
2241 FinishRead(false, aProofOfLock);
2242 } else {
2243 mRWPending = true;
2244 }
2245}
2246
2247void CacheIndex::ParseRecords(const StaticMutexAutoLock& aProofOfLock) {
2248 sLock.AssertCurrentThreadOwns();
2249 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)
;
2250
2251 nsresult rv;
2252
2253 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"
, 2253); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mRWPending"
")"); do { MOZ_CrashSequence(__null, 2253); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2254
2255 uint32_t entryCnt = (mIndexHandle->FileSize() - sizeof(CacheIndexHeader) -
2256 sizeof(CacheHash::Hash32_t)) /
2257 sizeof(CacheIndexRecord);
2258 uint32_t pos = 0;
2259
2260 if (!mSkipEntries) {
2261 if (NetworkEndian::readUint32(mRWBuf + pos) != kIndexVersion0x0000000D) {
2262 FinishRead(false, aProofOfLock);
2263 return;
2264 }
2265 pos += sizeof(uint32_t);
2266
2267 mIndexTimeStamp = NetworkEndian::readUint32(mRWBuf + pos);
2268 pos += sizeof(uint32_t);
2269
2270 if (NetworkEndian::readUint32(mRWBuf + pos)) {
2271 if (mJournalHandle) {
2272 CacheFileIOManager::DoomFile(mJournalHandle, nullptr);
2273 mJournalHandle = nullptr;
2274 }
2275 } else {
2276 uint32_t* isDirty =
2277 reinterpret_cast<uint32_t*>(moz_xmalloc(sizeof(uint32_t)));
2278 NetworkEndian::writeUint32(isDirty, 1);
2279
2280 // Mark index dirty. The buffer will be freed by CacheFileIOManager.
2281 CacheFileIOManager::WriteWithoutCallback(
2282 mIndexHandle, 2 * sizeof(uint32_t), reinterpret_cast<char*>(isDirty),
2283 sizeof(uint32_t), true, false);
2284 }
2285 pos += sizeof(uint32_t);
2286
2287 uint64_t dataWritten = NetworkEndian::readUint32(mRWBuf + pos);
2288 pos += sizeof(uint32_t);
2289 dataWritten <<= 10;
2290 mTotalBytesWritten += dataWritten;
2291
2292 bool wasEncrypted = !!NetworkEndian::readUint32(mRWBuf + pos);
2293 pos += sizeof(uint32_t);
2294 // The pref rather than IsActive(), matching what WriteRecords() stores: a
2295 // keystore that is temporarily unavailable must not be read as "the user
2296 // turned encryption off" and cost them the whole cache.
2297 bool nowEncrypted = CacheCrypto::IsEnabled();
2298 if (wasEncrypted != nowEncrypted) {
2299 // The at-rest encryption setting changed since the cache was written, so
2300 // the entries on disk no longer match the current setting. Purge the
2301 // whole cache rather than keep a mix of encrypted and plaintext entries.
2302 // EvictAll() dooms open handles, trashes the entries directory and drives
2303 // the index back to a clean (empty) state via RemoveAll(), so we just
2304 // hand off and return.
2305 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)
2306 ("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)
2307 "[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)
2308 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)
;
2309 CacheFileIOManager::EvictAll();
2310 return;
2311 }
2312 }
2313
2314 uint32_t hashOffset = pos;
2315
2316 while (pos + sizeof(CacheIndexRecord) <= mRWBufPos &&
2317 mSkipEntries != entryCnt) {
2318 CacheIndexRecord* rec = reinterpret_cast<CacheIndexRecord*>(mRWBuf + pos);
2319 CacheIndexEntry tmpEntry(&rec->mHash);
2320 tmpEntry.ReadFromBuf(mRWBuf + pos);
2321
2322 if (tmpEntry.IsDirty() || !tmpEntry.IsInitialized() ||
2323 tmpEntry.IsFileEmpty() || tmpEntry.IsFresh() || tmpEntry.IsRemoved()) {
2324 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)
2325 ("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)
2326 " 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)
2327 "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)
2328 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)
2329 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)
;
2330 FinishRead(false, aProofOfLock);
2331 return;
2332 }
2333
2334 CacheIndexEntryAutoManage emng(tmpEntry.Hash(), this, aProofOfLock);
2335
2336 CacheIndexEntry* entry = mIndex.PutEntry(*tmpEntry.Hash());
2337 *entry = tmpEntry;
2338
2339 pos += sizeof(CacheIndexRecord);
2340 mSkipEntries++;
2341 }
2342
2343 mRWHash->Update(mRWBuf + hashOffset, pos - hashOffset);
2344
2345 if (pos != mRWBufPos) {
2346 memmove(mRWBuf, mRWBuf + pos, mRWBufPos - pos);
2347 }
2348
2349 mRWBufPos -= pos;
2350 pos = 0;
2351
2352 int64_t fileOffset = sizeof(CacheIndexHeader) +
2353 mSkipEntries * sizeof(CacheIndexRecord) + mRWBufPos;
2354
2355 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", 2355); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "fileOffset <= mIndexHandle->FileSize()"
")"); do { MOZ_CrashSequence(__null, 2355); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2356 if (fileOffset == mIndexHandle->FileSize()) {
2357 uint32_t expectedHash = NetworkEndian::readUint32(mRWBuf);
2358 if (mRWHash->GetHash() != expectedHash) {
2359 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)
2360 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)
;
2361 FinishRead(false, aProofOfLock);
2362 return;
2363 }
2364
2365 mIndexOnDiskIsValid = true;
2366 mJournalReadSuccessfully = false;
2367
2368 if (mJournalHandle) {
2369 StartReadingJournal(aProofOfLock);
2370 } else {
2371 FinishRead(false, aProofOfLock);
2372 }
2373
2374 return;
2375 }
2376
2377 pos = mRWBufPos;
2378 uint32_t toRead =
2379 std::min(mRWBufSize - pos,
2380 static_cast<uint32_t>(mIndexHandle->FileSize() - fileOffset));
2381 mRWBufPos = pos + toRead;
2382
2383 rv = CacheFileIOManager::Read(mIndexHandle, fileOffset, mRWBuf + pos, toRead,
2384 this);
2385 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2386 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)
2387 ("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)
2388 "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)
2389 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)
;
2390 FinishRead(false, aProofOfLock);
2391 return;
2392 }
2393 mRWPending = true;
2394}
2395
2396void CacheIndex::StartReadingJournal(const StaticMutexAutoLock& aProofOfLock) {
2397 sLock.AssertCurrentThreadOwns();
2398 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)
;
2399
2400 nsresult rv;
2401
2402 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", 2402); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mJournalHandle" ")"); do { MOZ_CrashSequence
(__null, 2402); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2403 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", 2403); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mIndexOnDiskIsValid" ")"); do { MOZ_CrashSequence
(__null, 2403); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2404 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", 2404); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mTmpJournal.Count() == 0" ")"); do { MOZ_CrashSequence
(__null, 2404); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2405 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", 2405); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mJournalHandle->FileSize() >= 0" ")"
); do { MOZ_CrashSequence(__null, 2405); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2406 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"
, 2406); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mRWPending"
")"); do { MOZ_CrashSequence(__null, 2406); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2407
2408 int64_t entriesSize =
2409 mJournalHandle->FileSize() - sizeof(CacheHash::Hash32_t);
2410
2411 if (entriesSize < 0 || entriesSize % sizeof(CacheIndexRecord)) {
2412 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)
;
2413 FinishRead(false, aProofOfLock);
2414 return;
2415 }
2416
2417 mSkipEntries = 0;
2418 mRWHash = new CacheHash();
2419
2420 mRWBufPos =
2421 std::min(mRWBufSize, static_cast<uint32_t>(mJournalHandle->FileSize()));
2422
2423 rv = CacheFileIOManager::Read(mJournalHandle, 0, mRWBuf, mRWBufPos, this);
2424 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2425 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)
2426 ("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)
2427 " 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)
2428 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)
;
2429 FinishRead(false, aProofOfLock);
2430 } else {
2431 mRWPending = true;
2432 }
2433}
2434
2435void CacheIndex::ParseJournal(const StaticMutexAutoLock& aProofOfLock) {
2436 sLock.AssertCurrentThreadOwns();
2437 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)
;
2438
2439 nsresult rv;
2440
2441 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"
, 2441); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mRWPending"
")"); do { MOZ_CrashSequence(__null, 2441); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2442
2443 uint32_t entryCnt =
2444 (mJournalHandle->FileSize() - sizeof(CacheHash::Hash32_t)) /
2445 sizeof(CacheIndexRecord);
2446
2447 uint32_t pos = 0;
2448
2449 while (pos + sizeof(CacheIndexRecord) <= mRWBufPos &&
2450 mSkipEntries != entryCnt) {
2451 CacheIndexEntry tmpEntry(reinterpret_cast<SHA1Sum::Hash*>(mRWBuf + pos));
2452 tmpEntry.ReadFromBuf(mRWBuf + pos);
2453
2454 CacheIndexEntry* entry = mTmpJournal.PutEntry(*tmpEntry.Hash());
2455 *entry = tmpEntry;
2456
2457 if (entry->IsDirty() || entry->IsFresh()) {
2458 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)
2459 ("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)
2460 "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)
2461 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)
;
2462 FinishRead(false, aProofOfLock);
2463 return;
2464 }
2465
2466 pos += sizeof(CacheIndexRecord);
2467 mSkipEntries++;
2468 }
2469
2470 mRWHash->Update(mRWBuf, pos);
2471
2472 if (pos != mRWBufPos) {
2473 memmove(mRWBuf, mRWBuf + pos, mRWBufPos - pos);
2474 }
2475
2476 mRWBufPos -= pos;
2477 pos = 0;
Value stored to 'pos' is never read
2478
2479 int64_t fileOffset = mSkipEntries * sizeof(CacheIndexRecord) + mRWBufPos;
2480
2481 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", 2481); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "fileOffset <= mJournalHandle->FileSize()"
")"); do { MOZ_CrashSequence(__null, 2481); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2482 if (fileOffset == mJournalHandle->FileSize()) {
2483 uint32_t expectedHash = NetworkEndian::readUint32(mRWBuf);
2484 if (mRWHash->GetHash() != expectedHash) {
2485 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)
2486 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)
;
2487 FinishRead(false, aProofOfLock);
2488 return;
2489 }
2490
2491 mJournalReadSuccessfully = true;
2492 FinishRead(true, aProofOfLock);
2493 return;
2494 }
2495
2496 pos = mRWBufPos;
2497 uint32_t toRead =
2498 std::min(mRWBufSize - pos,
2499 static_cast<uint32_t>(mJournalHandle->FileSize() - fileOffset));
2500 mRWBufPos = pos + toRead;
2501
2502 rv = CacheFileIOManager::Read(mJournalHandle, fileOffset, mRWBuf + pos,
2503 toRead, this);
2504 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2505 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)
2506 ("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)
2507 "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)
2508 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)
;
2509 FinishRead(false, aProofOfLock);
2510 return;
2511 }
2512 mRWPending = true;
2513}
2514
2515void CacheIndex::MergeJournal(const StaticMutexAutoLock& aProofOfLock) {
2516 sLock.AssertCurrentThreadOwns();
2517 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)
;
2518
2519 for (auto iter = mTmpJournal.Iter(); !iter.Done(); iter.Next()) {
2520 CacheIndexEntry* entry = iter.Get();
2521
2522 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
)
2523 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
)
;
2524
2525 CacheIndexEntry* entry2 = mIndex.GetEntry(*entry->Hash());
2526 {
2527 CacheIndexEntryAutoManage emng(entry->Hash(), this, aProofOfLock);
2528 if (entry->IsRemoved()) {
2529 if (entry2) {
2530 entry2->MarkRemoved();
2531 entry2->MarkDirty();
2532 }
2533 } else {
2534 if (!entry2) {
2535 entry2 = mIndex.PutEntry(*entry->Hash());
2536 }
2537
2538 *entry2 = *entry;
2539 entry2->MarkDirty();
2540 }
2541 }
2542 iter.Remove();
2543 }
2544
2545 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", 2545); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mTmpJournal.Count() == 0" ")"); do { MOZ_CrashSequence
(__null, 2545); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2546}
2547
2548void CacheIndex::EnsureNoFreshEntry() {
2549#ifdef DEBUG_STATS1
2550 CacheIndexStats debugStats;
2551 debugStats.DisableLogging();
2552 for (auto iter = mIndex.Iter(); !iter.Done(); iter.Next()) {
2553 debugStats.BeforeChange(nullptr);
2554 debugStats.AfterChange(iter.Get());
2555 }
2556 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", 2556); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "debugStats.Fresh() == 0" ")"); do { MOZ_CrashSequence
(__null, 2556); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2557#endif
2558}
2559
2560void CacheIndex::EnsureCorrectStats() {
2561#ifdef DEBUG_STATS1
2562 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"
, 2562); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mPendingUpdates.Count() == 0"
")"); do { MOZ_CrashSequence(__null, 2562); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2563 CacheIndexStats debugStats;
2564 debugStats.DisableLogging();
2565 for (auto iter = mIndex.Iter(); !iter.Done(); iter.Next()) {
2566 debugStats.BeforeChange(nullptr);
2567 debugStats.AfterChange(iter.Get());
2568 }
2569 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", 2569); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "debugStats == mIndexStats" ")"); do { MOZ_CrashSequence
(__null, 2569); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2570#endif
2571}
2572
2573void CacheIndex::FinishRead(bool aSucceeded,
2574 const StaticMutexAutoLock& aProofOfLock) {
2575 sLock.AssertCurrentThreadOwns();
2576 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)
;
2577
2578 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", 2578); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "(!aSucceeded && mState == SHUTDOWN) || mState == READING"
")"); do { MOZ_CrashSequence(__null, 2578); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2579
2580 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", 2586); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "(!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)"
")"); do { MOZ_CrashSequence(__null, 2586); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2581 // -> 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", 2586); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "(!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)"
")"); do { MOZ_CrashSequence(__null, 2586); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2582 (!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", 2586); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "(!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)"
")"); do { MOZ_CrashSequence(__null, 2586); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2583 // -> 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", 2586); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "(!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)"
")"); do { MOZ_CrashSequence(__null, 2586); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2584 (!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", 2586); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "(!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)"
")"); do { MOZ_CrashSequence(__null, 2586); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2585 // -> 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", 2586); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "(!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)"
")"); do { MOZ_CrashSequence(__null, 2586); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
2586 (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", 2586); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "(!aSucceeded && !mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (!aSucceeded && mIndexOnDiskIsValid && !mJournalReadSuccessfully) || (aSucceeded && mIndexOnDiskIsValid && mJournalReadSuccessfully)"
")"); do { MOZ_CrashSequence(__null, 2586); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2587
2588 // If there is read operation pending we must be cancelling reading of the
2589 // index when shutting down or removing the whole index.
2590 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", 2590); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!mRWPending || (!aSucceeded && (mShuttingDown || mRemovingAll))"
")"); do { MOZ_CrashSequence(__null, 2590); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2591
2592 if (mState == SHUTDOWN) {
2593 RemoveFile(nsLiteralCString(TEMP_INDEX_NAME"index.tmp"));
2594 RemoveFile(nsLiteralCString(JOURNAL_NAME"index.log"));
2595 } else {
2596 if (mIndexHandle && !mIndexOnDiskIsValid) {
2597 CacheFileIOManager::DoomFile(mIndexHandle, nullptr);
2598 }
2599
2600 if (mJournalHandle) {
2601 CacheFileIOManager::DoomFile(mJournalHandle, nullptr);
2602 }
2603 }
2604
2605 if (mIndexFileOpener) {
2606 mIndexFileOpener->Cancel();
2607 mIndexFileOpener = nullptr;
2608 }
2609 if (mJournalFileOpener) {
2610 mJournalFileOpener->Cancel();
2611 mJournalFileOpener = nullptr;
2612 }
2613 if (mTmpFileOpener) {
2614 mTmpFileOpener->Cancel();
2615 mTmpFileOpener = nullptr;
2616 }
2617
2618 mIndexHandle = nullptr;
2619 mJournalHandle = nullptr;
2620 mRWHash = nullptr;
2621 ReleaseBuffer();
2622
2623 if (mState == SHUTDOWN) {
2624 return;
2625 }
2626
2627 if (!mIndexOnDiskIsValid) {
2628 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", 2628); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mTmpJournal.Count() == 0" ")"); do { MOZ_CrashSequence
(__null, 2628); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2629 EnsureNoFreshEntry();
2630 ProcessPendingOperations(aProofOfLock);
2631 // Remove all entries that we haven't seen during this session
2632 RemoveNonFreshEntries(aProofOfLock);
2633 StartUpdatingIndex(true, aProofOfLock);
2634 return;
2635 }
2636
2637 if (!mJournalReadSuccessfully) {
2638 mTmpJournal.Clear();
2639 EnsureNoFreshEntry();
2640 ProcessPendingOperations(aProofOfLock);
2641 StartUpdatingIndex(false, aProofOfLock);
2642 return;
2643 }
2644
2645 MergeJournal(aProofOfLock);
2646 EnsureNoFreshEntry();
2647 ProcessPendingOperations(aProofOfLock);
2648 mIndexStats.Log();
2649
2650 ChangeState(READY, aProofOfLock);
2651 mLastDumpTime = TimeStamp::NowLoRes(); // Do not dump new index immediately
2652}
2653
2654// static
2655void CacheIndex::DelayedUpdate(nsITimer* aTimer, void* aClosure) {
2656 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)
;
2657
2658 StaticMutexAutoLock lock(sLock);
2659 RefPtr<CacheIndex> index = gInstance;
2660
2661 if (!index) {
2662 return;
2663 }
2664
2665 index->DelayedUpdateLocked(lock);
2666}
2667
2668// static
2669void CacheIndex::DelayedUpdateLocked(const StaticMutexAutoLock& aProofOfLock) {
2670 sLock.AssertCurrentThreadOwns();
2671 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)
;
2672
2673 nsresult rv;
2674
2675 mUpdateTimer = nullptr;
2676
2677 if (!IsIndexUsable()) {
2678 return;
2679 }
2680
2681 if (mState == READY && mShuttingDown) {
2682 return;
2683 }
2684
2685 // mUpdateEventPending must be false here since StartUpdatingIndex() won't
2686 // schedule timer if it is true.
2687 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", 2687); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!mUpdateEventPending" ")"); do { MOZ_CrashSequence
(__null, 2687); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2688 if (mState != BUILDING && mState != UPDATING) {
2689 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)
;
2690 return;
2691 }
2692
2693 // We need to redispatch to run with lower priority
2694 RefPtr<CacheIOThread> ioThread = CacheFileIOManager::IOThread();
2695 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"
, 2695); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ioThread" ")"
); do { MOZ_CrashSequence(__null, 2695); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2696
2697 mUpdateEventPending = true;
2698 rv = ioThread->Dispatch(this, CacheIOThread::INDEX);
2699 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2700 mUpdateEventPending = false;
2701 NS_WARNING("CacheIndex::DelayedUpdateLocked() - Can't dispatch event")NS_DebugBreak(NS_DEBUG_WARNING, "CacheIndex::DelayedUpdateLocked() - Can't dispatch event"
, nullptr, "./../../../netwerk/cache2/CacheIndex.cpp", 2701)
;
2702 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)
;
2703 FinishUpdate(false, aProofOfLock);
2704 }
2705}
2706
2707nsresult CacheIndex::ScheduleUpdateTimer(uint32_t aDelay) {
2708 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)
;
2709
2710 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", 2710); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!mUpdateTimer" ")"); do { MOZ_CrashSequence
(__null, 2710); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2711
2712 nsCOMPtr<nsIEventTarget> ioTarget = CacheFileIOManager::IOTarget();
2713 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"
, 2713); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ioTarget" ")"
); do { MOZ_CrashSequence(__null, 2713); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2714
2715 return NS_NewTimerWithFuncCallback(
2716 getter_AddRefs(mUpdateTimer), CacheIndex::DelayedUpdate, nullptr, aDelay,
2717 nsITimer::TYPE_ONE_SHOT, "net::CacheIndex::ScheduleUpdateTimer"_ns,
2718 ioTarget);
2719}
2720
2721nsresult CacheIndex::SetupDirectoryEnumerator() {
2722 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", 2722); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!NS_IsMainThread()" ")"); do { MOZ_CrashSequence
(__null, 2722); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2723 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", 2723); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!mDirEnumerator" ")"); do { MOZ_CrashSequence
(__null, 2723); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2724
2725 nsresult rv;
2726 nsCOMPtr<nsIFile> file;
2727
2728 rv = mCacheDirectory->Clone(getter_AddRefs(file));
2729 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"
, 2729); return rv; } } while (false)
;
2730
2731 rv = file->AppendNative(nsLiteralCString(ENTRIES_DIR"entries"));
2732 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"
, 2732); return rv; } } while (false)
;
2733
2734 bool exists;
2735 rv = file->Exists(&exists);
2736 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"
, 2736); return rv; } } while (false)
;
2737
2738 if (!exists) {
2739 NS_WARNING(NS_DebugBreak(NS_DEBUG_WARNING, "CacheIndex::SetupDirectoryEnumerator() - Entries directory "
"doesn't exist!", nullptr, "./../../../netwerk/cache2/CacheIndex.cpp"
, 2741)
2740 "CacheIndex::SetupDirectoryEnumerator() - Entries directory "NS_DebugBreak(NS_DEBUG_WARNING, "CacheIndex::SetupDirectoryEnumerator() - Entries directory "
"doesn't exist!", nullptr, "./../../../netwerk/cache2/CacheIndex.cpp"
, 2741)
2741 "doesn't exist!")NS_DebugBreak(NS_DEBUG_WARNING, "CacheIndex::SetupDirectoryEnumerator() - Entries directory "
"doesn't exist!", nullptr, "./../../../netwerk/cache2/CacheIndex.cpp"
, 2741)
;
2742 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)
2743 ("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)
2744 "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)
;
2745 return NS_ERROR_UNEXPECTED;
2746 }
2747
2748 // Do not do IO under the lock.
2749 nsCOMPtr<nsIDirectoryEnumerator> dirEnumerator;
2750 {
2751 StaticMutexAutoUnlock unlock(sLock);
2752 rv = file->GetDirectoryEntries(getter_AddRefs(dirEnumerator));
2753 }
2754 mDirEnumerator = dirEnumerator.forget();
2755 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"
, 2755); return rv; } } while (false)
;
2756
2757 return NS_OK;
2758}
2759
2760nsresult CacheIndex::InitEntryFromDiskData(CacheIndexEntry* aEntry,
2761 CacheFileMetadata* aMetaData,
2762 int64_t aFileSize) {
2763 nsresult rv;
2764
2765 aEntry->InitNew();
2766 aEntry->MarkDirty();
2767 aEntry->MarkFresh();
2768
2769 aEntry->Init(GetOriginAttrsHash(aMetaData->OriginAttributes()),
2770 aMetaData->IsAnonymous(), aMetaData->Pinned());
2771
2772 aEntry->SetFrecency(aMetaData->GetFrecency());
2773
2774 const char* altData = aMetaData->GetElement(CacheFileUtils::kAltDataKey);
2775 bool hasAltData = altData != nullptr;
2776 if (hasAltData && NS_FAILED(CacheFileUtils::ParseAlternativeDataInfo(((bool)(__builtin_expect(!!(NS_FAILED_impl(CacheFileUtils::ParseAlternativeDataInfo
( altData, nullptr, nullptr))), 0)))
2777 altData, nullptr, nullptr))((bool)(__builtin_expect(!!(NS_FAILED_impl(CacheFileUtils::ParseAlternativeDataInfo
( altData, nullptr, nullptr))), 0)))
) {
2778 return NS_ERROR_FAILURE;
2779 }
2780 aEntry->SetHasAltData(hasAltData);
2781
2782 aEntry->SetLastFetched(aMetaData->GetLastFetched());
2783 aEntry->SetFetchCount(aMetaData->GetFetchCount());
2784
2785 const char* contentTypeStr = aMetaData->GetElement("ctid");
2786 uint8_t contentType = nsICacheEntry::CONTENT_TYPE_UNKNOWN;
2787 if (contentTypeStr) {
2788 int64_t n64 = nsDependentCString(contentTypeStr).ToInteger64(&rv);
2789 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0))) || n64 < nsICacheEntry::CONTENT_TYPE_UNKNOWN ||
2790 n64 >= nsICacheEntry::CONTENT_TYPE_LAST) {
2791 n64 = nsICacheEntry::CONTENT_TYPE_UNKNOWN;
2792 }
2793 contentType = n64;
2794 }
2795 aEntry->SetContentType(contentType);
2796
2797 aEntry->SetFileSize(static_cast<uint32_t>(std::min(
2798 static_cast<int64_t>(PR_UINT32_MAX4294967295U), (aFileSize + 0x3FF) >> 10)));
2799 return NS_OK;
2800}
2801
2802bool CacheIndex::IsUpdatePending() {
2803 sLock.AssertCurrentThreadOwns();
2804
2805 return mUpdateTimer || mUpdateEventPending;
2806}
2807
2808void CacheIndex::BuildIndex(const StaticMutexAutoLock& aProofOfLock) {
2809 sLock.AssertCurrentThreadOwns();
2810 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)
;
2811
2812 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"
, 2812); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mPendingUpdates.Count() == 0"
")"); do { MOZ_CrashSequence(__null, 2812); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2813
2814 nsresult rv;
2815
2816 if (!mDirEnumerator) {
2817 rv = SetupDirectoryEnumerator();
2818 if (mState == SHUTDOWN) {
2819 // The index was shut down while we released the lock. FinishUpdate() was
2820 // already called from Shutdown(), so just simply return here.
2821 return;
2822 }
2823
2824 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2825 FinishUpdate(false, aProofOfLock);
2826 return;
2827 }
2828 }
2829
2830 while (true) {
2831 if (CacheIOThread::YieldAndRerun()) {
2832 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)
2833 "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)
;
2834 mUpdateEventPending = true;
2835 return;
2836 }
2837
2838 bool fileExists = false;
2839 nsCOMPtr<nsIFile> file;
2840 {
2841 // Do not do IO under the lock.
2842 nsCOMPtr<nsIDirectoryEnumerator> dirEnumerator(mDirEnumerator);
2843 sLock.AssertCurrentThreadOwns();
2844 StaticMutexAutoUnlock unlock(sLock);
2845 rv = dirEnumerator->GetNextFile(getter_AddRefs(file));
2846
2847 if (file) {
2848 file->Exists(&fileExists);
2849 }
2850 }
2851 if (mState == SHUTDOWN) {
2852 return;
2853 }
2854 if (!file) {
2855 FinishUpdate(NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))), aProofOfLock);
2856 return;
2857 }
2858
2859 nsAutoCString leaf;
2860 rv = file->GetNativeLeafName(leaf);
2861 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2862 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)
2863 ("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)
2864 "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)
;
2865 mDontMarkIndexClean = true;
2866 continue;
2867 }
2868
2869 if (!fileExists) {
2870 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)
2871 ("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)
2872 "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)
2873 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)
;
2874 continue;
2875 }
2876
2877 SHA1Sum::Hash hash;
2878 rv = CacheFileIOManager::StrToHash(leaf, &hash);
2879 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2880 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)
2881 ("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)
2882 "[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)
2883 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)
;
2884 file->Remove(false);
2885 continue;
2886 }
2887
2888 CacheIndexEntry* entry = mIndex.GetEntry(hash);
2889 if (entry && entry->IsRemoved()) {
2890 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)
2891 ("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)
2892 "[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)
2893 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)
;
2894 entry->Log();
2895 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", 2895); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "entry->IsFresh()" ")"); do { MOZ_CrashSequence
(__null, 2895); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2896 entry = nullptr;
2897 }
2898
2899#ifdef DEBUG1
2900 RefPtr<CacheFileHandle> handle;
2901 CacheFileIOManager::gInstance->mHandles.GetHandle(&hash,
2902 getter_AddRefs(handle));
2903#endif
2904
2905 if (entry) {
2906 // the entry is up to date
2907 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)
2908 ("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)
2909 " 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)
2910 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)
;
2911 entry->Log();
2912 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", 2912); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "entry->IsFresh()" ")"); do { MOZ_CrashSequence
(__null, 2912); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
; // The entry must be from this session
2913 // there must be an active CacheFile if the entry is not initialized
2914 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"
, 2914); AnnotateMozCrashReason("MOZ_ASSERT" "(" "entry->IsInitialized() || handle"
")"); do { MOZ_CrashSequence(__null, 2914); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2915 continue;
2916 }
2917
2918 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"
, 2918); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!handle" ")"
); do { MOZ_CrashSequence(__null, 2918); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2919
2920 RefPtr<CacheFileMetadata> meta = new CacheFileMetadata();
2921 int64_t size = 0;
2922
2923 {
2924 // Do not do IO under the lock.
2925 StaticMutexAutoUnlock unlock(sLock);
2926 rv = meta->SyncReadMetadata(file);
2927
2928 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
2929 rv = file->GetFileSize(&size);
2930 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2931 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
)
2932 ("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
)
2933 " 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
)
2934 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
)
;
2935 }
2936 }
2937 }
2938 if (mState == SHUTDOWN) {
2939 return;
2940 }
2941
2942 // Nobody could add the entry while the lock was released since we modify
2943 // the index only on IO thread and this loop is executed on IO thread too.
2944 entry = mIndex.GetEntry(hash);
2945 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"
, 2945); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!entry || entry->IsRemoved()"
")"); do { MOZ_CrashSequence(__null, 2945); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2946
2947 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2948 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)
2949 ("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)
2950 "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)
2951 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)
;
2952 file->Remove(false);
2953 } else {
2954 CacheIndexEntryAutoManage entryMng(&hash, this, aProofOfLock);
2955 entry = mIndex.PutEntry(hash);
2956 if (NS_FAILED(InitEntryFromDiskData(entry, meta, size))((bool)(__builtin_expect(!!(NS_FAILED_impl(InitEntryFromDiskData
(entry, meta, size))), 0)))
) {
2957 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)
2958 ("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)
2959 "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)
2960 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)
;
2961 file->Remove(false);
2962 entry->MarkRemoved();
2963 } else {
2964 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)
2965 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)
;
2966 entry->Log();
2967 }
2968 }
2969 }
2970
2971 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"
, 2971); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "We should never get here" ")"); do
{ MOZ_CrashSequence(__null, 2971); __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
2972}
2973
2974bool CacheIndex::StartUpdatingIndexIfNeeded(
2975 const StaticMutexAutoLock& aProofOfLock, bool aSwitchingToReadyState) {
2976 sLock.AssertCurrentThreadOwns();
2977 // Start updating process when we are in or we are switching to READY state
2978 // and index needs update, but not during shutdown or when removing all
2979 // entries.
2980 if ((mState == READY || aSwitchingToReadyState) && mIndexNeedsUpdate &&
2981 !mShuttingDown && !mRemovingAll) {
2982 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)
;
2983 mIndexNeedsUpdate = false;
2984 StartUpdatingIndex(false, aProofOfLock);
2985 return true;
2986 }
2987
2988 return false;
2989}
2990
2991void CacheIndex::StartUpdatingIndex(bool aRebuild,
2992 const StaticMutexAutoLock& aProofOfLock) {
2993 sLock.AssertCurrentThreadOwns();
2994 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)
;
2995
2996 nsresult rv;
2997
2998 mIndexStats.Log();
2999
3000 ChangeState(aRebuild ? BUILDING : UPDATING, aProofOfLock);
3001 mDontMarkIndexClean = false;
3002
3003 if (mShuttingDown || mRemovingAll) {
3004 FinishUpdate(false, aProofOfLock);
3005 return;
3006 }
3007
3008 if (IsUpdatePending()) {
3009 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)
;
3010 return;
3011 }
3012
3013 uint32_t elapsed = (TimeStamp::NowLoRes() - mStartTime).ToMilliseconds();
3014 uint32_t startDelay =
3015 StaticPrefs::browser_cache_disk_index_update_start_delay_ms();
3016 if (elapsed < startDelay) {
3017 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)
3018 ("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)
3019 "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)
3020 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)
;
3021 rv = ScheduleUpdateTimer(startDelay - elapsed);
3022 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
3023 return;
3024 }
3025
3026 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)
3027 ("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)
3028 "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)
;
3029 } else {
3030 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)
3031 ("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)
3032 "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)
3033 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)
;
3034 }
3035
3036 RefPtr<CacheIOThread> ioThread = CacheFileIOManager::IOThread();
3037 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"
, 3037); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ioThread" ")"
); do { MOZ_CrashSequence(__null, 3037); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3038
3039 // We need to dispatch an event even if we are on IO thread since we need to
3040 // update the index with the correct priority.
3041 mUpdateEventPending = true;
3042 rv = ioThread->Dispatch(this, CacheIOThread::INDEX);
3043 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3044 mUpdateEventPending = false;
3045 NS_WARNING("CacheIndex::StartUpdatingIndex() - Can't dispatch event")NS_DebugBreak(NS_DEBUG_WARNING, "CacheIndex::StartUpdatingIndex() - Can't dispatch event"
, nullptr, "./../../../netwerk/cache2/CacheIndex.cpp", 3045)
;
3046 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)
;
3047 FinishUpdate(false, aProofOfLock);
3048 }
3049}
3050
3051void CacheIndex::UpdateIndex(const StaticMutexAutoLock& aProofOfLock) {
3052 sLock.AssertCurrentThreadOwns();
3053 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)
;
3054
3055 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"
, 3055); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mPendingUpdates.Count() == 0"
")"); do { MOZ_CrashSequence(__null, 3055); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3056 sLock.AssertCurrentThreadOwns();
3057
3058 nsresult rv;
3059
3060 if (!mDirEnumerator) {
3061 rv = SetupDirectoryEnumerator();
3062 if (mState == SHUTDOWN) {
3063 // The index was shut down while we released the lock. FinishUpdate() was
3064 // already called from Shutdown(), so just simply return here.
3065 return;
3066 }
3067
3068 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3069 FinishUpdate(false, aProofOfLock);
3070 return;
3071 }
3072 }
3073
3074 while (true) {
3075 if (CacheIOThread::YieldAndRerun()) {
3076 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)
3077 ("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)
3078 "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)
;
3079 mUpdateEventPending = true;
3080 return;
3081 }
3082
3083 bool fileExists = false;
3084 nsCOMPtr<nsIFile> file;
3085 {
3086 // Do not do IO under the lock.
3087 nsCOMPtr<nsIDirectoryEnumerator> dirEnumerator(mDirEnumerator);
3088 StaticMutexAutoUnlock unlock(sLock);
3089 rv = dirEnumerator->GetNextFile(getter_AddRefs(file));
3090
3091 if (file) {
3092 file->Exists(&fileExists);
3093 }
3094 }
3095 if (mState == SHUTDOWN) {
3096 return;
3097 }
3098 if (!file) {
3099 FinishUpdate(NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))), aProofOfLock);
3100 return;
3101 }
3102
3103 nsAutoCString leaf;
3104 rv = file->GetNativeLeafName(leaf);
3105 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3106 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)
3107 ("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)
3108 "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)
;
3109 mDontMarkIndexClean = true;
3110 continue;
3111 }
3112
3113 if (!fileExists) {
3114 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)
3115 ("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)
3116 "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)
3117 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)
;
3118 continue;
3119 }
3120
3121 SHA1Sum::Hash hash;
3122 rv = CacheFileIOManager::StrToHash(leaf, &hash);
3123 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3124 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)
3125 ("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)
3126 "[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)
3127 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)
;
3128 file->Remove(false);
3129 continue;
3130 }
3131
3132 CacheIndexEntry* entry = mIndex.GetEntry(hash);
3133 if (entry && entry->IsRemoved()) {
3134 if (entry->IsFresh()) {
3135 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)
3136 ("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)
3137 "[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)
3138 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)
;
3139 entry->Log();
3140 }
3141 entry = nullptr;
3142 }
3143
3144#ifdef DEBUG1
3145 RefPtr<CacheFileHandle> handle;
3146 CacheFileIOManager::gInstance->mHandles.GetHandle(&hash,
3147 getter_AddRefs(handle));
3148#endif
3149
3150 if (entry && entry->IsFresh()) {
3151 // the entry is up to date
3152 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)
3153 ("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)
3154 " 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)
3155 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)
;
3156 entry->Log();
3157 // there must be an active CacheFile if the entry is not initialized
3158 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"
, 3158); AnnotateMozCrashReason("MOZ_ASSERT" "(" "entry->IsInitialized() || handle"
")"); do { MOZ_CrashSequence(__null, 3158); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3159 continue;
3160 }
3161
3162 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"
, 3162); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!handle" ")"
); do { MOZ_CrashSequence(__null, 3162); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3163
3164 if (entry) {
3165 PRTime lastModifiedTime;
3166 {
3167 // Do not do IO under the lock.
3168 StaticMutexAutoUnlock unlock(sLock);
3169 rv = file->GetLastModifiedTime(&lastModifiedTime);
3170 }
3171 if (mState == SHUTDOWN) {
3172 return;
3173 }
3174 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3175 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)
3176 ("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)
3177 "[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)
3178 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)
;
3179 // Assume the file is newer than index
3180 } else {
3181 if (mIndexTimeStamp > (lastModifiedTime / PR_MSEC_PER_SEC1000L)) {
3182 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)
3183 ("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)
3184 "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)
3185 "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)
3186 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)
3187 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)
;
3188
3189 CacheIndexEntryAutoManage entryMng(&hash, this, aProofOfLock);
3190 entry->MarkFresh();
3191 continue;
3192 }
3193 }
3194 }
3195
3196 RefPtr<CacheFileMetadata> meta = new CacheFileMetadata();
3197 int64_t size = 0;
3198
3199 {
3200 // Do not do IO under the lock.
3201 StaticMutexAutoUnlock unlock(sLock);
3202 rv = meta->SyncReadMetadata(file);
3203
3204 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
3205 rv = file->GetFileSize(&size);
3206 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3207 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)
3208 ("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)
3209 "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)
3210 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)
;
3211 }
3212 }
3213 }
3214 if (mState == SHUTDOWN) {
3215 return;
3216 }
3217
3218 // Nobody could add the entry while the lock was released since we modify
3219 // the index only on IO thread and this loop is executed on IO thread too.
3220 entry = mIndex.GetEntry(hash);
3221 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"
, 3221); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!entry || !entry->IsFresh()"
")"); do { MOZ_CrashSequence(__null, 3221); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3222
3223 CacheIndexEntryAutoManage entryMng(&hash, this, aProofOfLock);
3224
3225 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3226 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)
3227 ("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)
3228 "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)
3229 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)
;
3230 } else {
3231 entry = mIndex.PutEntry(hash);
3232 rv = InitEntryFromDiskData(entry, meta, size);
3233 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3234 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)
3235 ("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)
3236 "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)
3237 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)
;
3238 }
3239 }
3240
3241 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3242 file->Remove(false);
3243 if (entry) {
3244 entry->MarkRemoved();
3245 entry->MarkFresh();
3246 entry->MarkDirty();
3247 }
3248 } else {
3249 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)
3250 ("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)
3251 "[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)
3252 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)
;
3253 entry->Log();
3254 }
3255 }
3256
3257 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"
, 3257); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "We should never get here" ")"); do
{ MOZ_CrashSequence(__null, 3257); __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
3258}
3259
3260void CacheIndex::FinishUpdate(bool aSucceeded,
3261 const StaticMutexAutoLock& aProofOfLock) {
3262 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)
;
3263
3264 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", 3265); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mState == UPDATING || mState == BUILDING || (!aSucceeded && mState == SHUTDOWN)"
")"); do { MOZ_CrashSequence(__null, 3265); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
3265 (!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", 3265); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mState == UPDATING || mState == BUILDING || (!aSucceeded && mState == SHUTDOWN)"
")"); do { MOZ_CrashSequence(__null, 3265); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3266
3267 if (mDirEnumerator) {
3268 if (NS_IsMainThread()) {
3269 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)
3270 ("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)
3271 " 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)
;
3272 NS_WARNING(("CacheIndex::FinishUpdate() - Leaking mDirEnumerator!"))NS_DebugBreak(NS_DEBUG_WARNING, ("CacheIndex::FinishUpdate() - Leaking mDirEnumerator!"
), nullptr, "./../../../netwerk/cache2/CacheIndex.cpp", 3272)
;
3273 // This can happen only in case dispatching event to IO thread failed in
3274 // CacheIndex::PreShutdown().
3275 mDirEnumerator.forget()
3276 .leak(); // Leak it since dir enumerator is not threadsafe
3277 } else {
3278 mDirEnumerator->Close();
3279 mDirEnumerator = nullptr;
3280 }
3281 }
3282
3283 if (!aSucceeded) {
3284 mDontMarkIndexClean = true;
3285 }
3286
3287 if (mState == SHUTDOWN) {
3288 return;
3289 }
3290
3291 if (mState == UPDATING && aSucceeded) {
3292 // If we've iterated over all entries successfully then all entries that
3293 // really exist on the disk are now marked as fresh. All non-fresh entries
3294 // don't exist anymore and must be removed from the index.
3295 RemoveNonFreshEntries(aProofOfLock);
3296 }
3297
3298 // Make sure we won't start update. If the build or update failed, there is no
3299 // reason to believe that it will succeed next time.
3300 mIndexNeedsUpdate = false;
3301
3302 ChangeState(READY, aProofOfLock);
3303 mLastDumpTime = TimeStamp::NowLoRes(); // Do not dump new index immediately
3304}
3305
3306void CacheIndex::RemoveNonFreshEntries(
3307 const StaticMutexAutoLock& aProofOfLock) {
3308 sLock.AssertCurrentThreadOwns();
3309 for (auto iter = mIndex.Iter(); !iter.Done(); iter.Next()) {
3310 CacheIndexEntry* entry = iter.Get();
3311 if (entry->IsFresh()) {
3312 continue;
3313 }
3314
3315 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
)
3316 ("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
)
3317 "[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
)
3318 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
)
;
3319
3320 {
3321 CacheIndexEntryAutoManage emng(entry->Hash(), this, aProofOfLock);
3322 emng.DoNotSearchInIndex();
3323 }
3324
3325 iter.Remove();
3326 }
3327}
3328
3329// static
3330char const* CacheIndex::StateString(EState aState) {
3331 switch (aState) {
3332 case INITIAL:
3333 return "INITIAL";
3334 case READING:
3335 return "READING";
3336 case WRITING:
3337 return "WRITING";
3338 case BUILDING:
3339 return "BUILDING";
3340 case UPDATING:
3341 return "UPDATING";
3342 case READY:
3343 return "READY";
3344 case SHUTDOWN:
3345 return "SHUTDOWN";
3346 }
3347
3348 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", 3348); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "false" ") (" "Unexpected state!" ")"); do {
MOZ_CrashSequence(__null, 3348); __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
3349 return "?";
3350}
3351
3352void CacheIndex::ChangeState(EState aNewState,
3353 const StaticMutexAutoLock& aProofOfLock) {
3354 sLock.AssertCurrentThreadOwns();
3355 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)
3356 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)
;
3357
3358 // All pending updates should be processed before changing state
3359 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"
, 3359); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mPendingUpdates.Count() == 0"
")"); do { MOZ_CrashSequence(__null, 3359); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3360
3361 // PreShutdownInternal() should change the state to READY from every state. It
3362 // may go through different states, but once we are in READY state the only
3363 // possible transition is to SHUTDOWN state.
3364 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", 3364); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!mShuttingDown || mState != READY || aNewState == SHUTDOWN"
")"); do { MOZ_CrashSequence(__null, 3364); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3365
3366 // Start updating process when switching to READY state if needed
3367 if (aNewState == READY && StartUpdatingIndexIfNeeded(aProofOfLock, true)) {
3368 return;
3369 }
3370
3371 // Try to evict entries over limit everytime we're leaving state READING,
3372 // BUILDING or UPDATING, but not during shutdown or when removing all
3373 // entries.
3374 if (!mShuttingDown && !mRemovingAll && aNewState != SHUTDOWN &&
3375 (mState == READING || mState == BUILDING || mState == UPDATING)) {
3376 CacheFileIOManager::EvictIfOverLimit();
3377 }
3378
3379 mState = aNewState;
3380
3381 if (mState != SHUTDOWN) {
3382 CacheFileIOManager::CacheIndexStateChanged();
3383 }
3384
3385 NotifyAsyncGetDiskConsumptionCallbacks();
3386}
3387
3388void CacheIndex::NotifyAsyncGetDiskConsumptionCallbacks() {
3389 if ((mState == READY || mState == WRITING) &&
3390 !mAsyncGetDiskConsumptionBlocked && mDiskConsumptionObservers.Length()) {
3391 for (uint32_t i = 0; i < mDiskConsumptionObservers.Length(); ++i) {
3392 DiskConsumptionObserver* o = mDiskConsumptionObservers[i];
3393 // Safe to call under the lock. We always post to the main thread.
3394 o->OnDiskConsumption(mIndexStats.Size() << 10);
3395 }
3396
3397 mDiskConsumptionObservers.Clear();
3398 }
3399}
3400
3401void CacheIndex::AllocBuffer() {
3402 switch (mState) {
3403 case WRITING:
3404 mRWBufSize = sizeof(CacheIndexHeader) + sizeof(CacheHash::Hash32_t) +
3405 mProcessEntries * sizeof(CacheIndexRecord);
3406 if (mRWBufSize > kMaxBufSize16384) {
3407 mRWBufSize = kMaxBufSize16384;
3408 }
3409 break;
3410 case READING:
3411 mRWBufSize = kMaxBufSize16384;
3412 break;
3413 default:
3414 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", 3414); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "false" ") (" "Unexpected state!" ")"); do {
MOZ_CrashSequence(__null, 3414); __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
3415 }
3416
3417 mRWBuf = static_cast<char*>(moz_xmalloc(mRWBufSize));
3418}
3419
3420void CacheIndex::ReleaseBuffer() {
3421 sLock.AssertCurrentThreadOwns();
3422
3423 if (!mRWBuf || mRWPending) {
3424 return;
3425 }
3426
3427 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)
;
3428
3429 free(mRWBuf);
3430 mRWBuf = nullptr;
3431 mRWBufSize = 0;
3432 mRWBufPos = 0;
3433 mRWEntries.Clear();
3434}
3435
3436void CacheIndex::FrecencyStorage::AppendRecord(
3437 CacheIndexRecordWrapper* aRecord, const StaticMutexAutoLock& aProofOfLock) {
3438 sLock.AssertCurrentThreadOwns();
3439 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)
3440 ("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)
3441 "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)
3442 "%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)
3443 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)
;
3444 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)"
" (" "Record is already in the frecency storage" ")", "./../../../netwerk/cache2/CacheIndex.cpp"
, 3445); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "!mRecs.Contains(aRecord)"
") (" "Record is already in the frecency storage" ")"); do {
MOZ_CrashSequence(__null, 3445); __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
3445 "Record is already in the frecency storage")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)"
" (" "Record is already in the frecency storage" ")", "./../../../netwerk/cache2/CacheIndex.cpp"
, 3445); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "!mRecs.Contains(aRecord)"
") (" "Record is already in the frecency storage" ")"); do {
MOZ_CrashSequence(__null, 3445); __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
3446 mRecs.PutEntry(aRecord);
3447}
3448
3449void CacheIndex::FrecencyStorage::RemoveRecord(
3450 CacheIndexRecordWrapper* aRecord, const StaticMutexAutoLock& aProofOfLock) {
3451 sLock.AssertCurrentThreadOwns();
3452 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)
;
3453 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", 3453); AnnotateMozCrashReason
("MOZ_RELEASE_ASSERT" "(" "mRecs.Contains(aRecord)" ")"); do {
MOZ_CrashSequence(__null, 3453); __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
3454 mRecs.RemoveEntry(aRecord);
3455}
3456
3457void CacheIndex::FrecencyStorage::ReplaceRecord(
3458 CacheIndexRecordWrapper* aOldRecord, CacheIndexRecordWrapper* aNewRecord,
3459 const StaticMutexAutoLock& aProofOfLock) {
3460 sLock.AssertCurrentThreadOwns();
3461 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)
3462 ("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)
3463 "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)
3464 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)
;
3465
3466 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"
, 3467); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "mRecs.Contains(aOldRecord)"
") (" "Tried to replace a record that doesn't exist" ")"); do
{ MOZ_CrashSequence(__null, 3467); __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
3467 "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"
, 3467); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "mRecs.Contains(aOldRecord)"
") (" "Tried to replace a record that doesn't exist" ")"); do
{ MOZ_CrashSequence(__null, 3467); __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
3468 mRecs.RemoveEntry(aOldRecord);
3469 mRecs.PutEntry(aNewRecord);
3470}
3471
3472// static
3473CacheIndex::EvictionSortedSnapshot CacheIndex::GetSortedSnapshotForEviction() {
3474 StaticMutexAutoLock lock(sLock);
3475 RefPtr<CacheIndex> index = gInstance;
3476 return index->mFrecencyStorage.GetSortedSnapshotForEviction();
3477}
3478
3479CacheIndex::EvictionSortedSnapshot
3480CacheIndex::FrecencyStorage::GetSortedSnapshotForEviction() {
3481 CacheIndex::EvictionSortedSnapshot snapshot;
3482 snapshot.SetCapacity(mRecs.Count());
3483 for (const auto& item : mRecs) {
3484 snapshot.AppendElement(item.GetKey());
3485 }
3486 snapshot.Sort(FrecencyComparator());
3487 return snapshot;
3488}
3489
3490bool CacheIndex::FrecencyStorage::RecordExistedUnlocked(
3491 CacheIndexRecordWrapper* aRecord) {
3492 return mRecs.Contains(aRecord);
3493}
3494
3495void CacheIndex::AddRecordToIterators(CacheIndexRecordWrapper* aRecord,
3496 const StaticMutexAutoLock& aProofOfLock) {
3497 sLock.AssertCurrentThreadOwns();
3498 for (uint32_t i = 0; i < mIterators.Length(); ++i) {
3499 // Add a new record only when iterator is supposed to be updated.
3500 if (mIterators[i]->ShouldBeNewAdded()) {
3501 mIterators[i]->AddRecord(aRecord, aProofOfLock);
3502 }
3503 }
3504}
3505
3506void CacheIndex::RemoveRecordFromIterators(
3507 CacheIndexRecordWrapper* aRecord, const StaticMutexAutoLock& aProofOfLock) {
3508 sLock.AssertCurrentThreadOwns();
3509 for (uint32_t i = 0; i < mIterators.Length(); ++i) {
3510 // Remove the record from iterator always, it makes no sence to return
3511 // non-existing entries. Also the pointer to the record is no longer valid
3512 // once the entry is removed from index.
3513 mIterators[i]->RemoveRecord(aRecord, aProofOfLock);
3514 }
3515}
3516
3517void CacheIndex::ReplaceRecordInIterators(
3518 CacheIndexRecordWrapper* aOldRecord, CacheIndexRecordWrapper* aNewRecord,
3519 const StaticMutexAutoLock& aProofOfLock) {
3520 sLock.AssertCurrentThreadOwns();
3521 for (uint32_t i = 0; i < mIterators.Length(); ++i) {
3522 // We have to replace the record always since the pointer is no longer
3523 // valid after this point. NOTE: Replacing the record doesn't mean that
3524 // a new entry was added, it just means that the data in the entry was
3525 // changed (e.g. a file size) and we had to track this change in
3526 // mPendingUpdates since mIndex was read-only.
3527 mIterators[i]->ReplaceRecord(aOldRecord, aNewRecord, aProofOfLock);
3528 }
3529}
3530
3531nsresult CacheIndex::Run() {
3532 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)
;
3533
3534 StaticMutexAutoLock lock(sLock);
3535
3536 if (!IsIndexUsable()) {
3537 return NS_ERROR_NOT_AVAILABLE;
3538 }
3539
3540 if (mState == READY && mShuttingDown) {
3541 return NS_OK;
3542 }
3543
3544 mUpdateEventPending = false;
3545
3546 switch (mState) {
3547 case BUILDING:
3548 BuildIndex(lock);
3549 break;
3550 case UPDATING:
3551 UpdateIndex(lock);
3552 break;
3553 default:
3554 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)
;
3555 }
3556
3557 return NS_OK;
3558}
3559
3560void CacheIndex::OnFileOpenedInternal(FileOpenHelper* aOpener,
3561 CacheFileHandle* aHandle,
3562 nsresult aResult,
3563 const StaticMutexAutoLock& aProofOfLock) {
3564 sLock.AssertCurrentThreadOwns();
3565 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)
3566 ("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)
3567 "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)
3568 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)
;
3569 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"
, 3569); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()"
")"); do { MOZ_CrashSequence(__null, 3569); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3570
3571 nsresult rv;
3572
3573 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", 3573); AnnotateMozCrashReason
("MOZ_RELEASE_ASSERT" "(" "IsIndexUsable()" ")"); do { MOZ_CrashSequence
(__null, 3573); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
3574
3575 if (mState == READY && mShuttingDown) {
3576 return;
3577 }
3578
3579 switch (mState) {
3580 case WRITING:
3581 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", 3581); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "aOpener == mIndexFileOpener" ")"); do { MOZ_CrashSequence
(__null, 3581); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
3582 mIndexFileOpener = nullptr;
3583
3584 if (NS_FAILED(aResult)((bool)(__builtin_expect(!!(NS_FAILED_impl(aResult)), 0)))) {
3585 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)
3586 ("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)
3587 "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)
3588 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)
;
3589 FinishWrite(false, aProofOfLock);
3590 } else {
3591 mIndexHandle = aHandle;
3592 WriteRecords(aProofOfLock);
3593 }
3594 break;
3595 case READING:
3596 if (aOpener == mIndexFileOpener) {
3597 mIndexFileOpener = nullptr;
3598
3599 if (NS_SUCCEEDED(aResult)((bool)(__builtin_expect(!!(!NS_FAILED_impl(aResult)), 1)))) {
3600 if (aHandle->FileSize() == 0) {
3601 FinishRead(false, aProofOfLock);
3602 CacheFileIOManager::DoomFile(aHandle, nullptr);
3603 break;
3604 }
3605 mIndexHandle = aHandle;
3606 } else {
3607 FinishRead(false, aProofOfLock);
3608 break;
3609 }
3610 } else if (aOpener == mJournalFileOpener) {
3611 mJournalFileOpener = nullptr;
3612 mJournalHandle = aHandle;
3613 } else if (aOpener == mTmpFileOpener) {
3614 mTmpFileOpener = nullptr;
3615 mTmpHandle = aHandle;
3616 } else {
3617 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", 3617); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "false" ") (" "Unexpected state!" ")"); do {
MOZ_CrashSequence(__null, 3617); __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
3618 }
3619
3620 if (mIndexFileOpener || mJournalFileOpener || mTmpFileOpener) {
3621 // Some opener still didn't finish
3622 break;
3623 }
3624
3625 // We fail and cancel all other openers when we opening index file fails.
3626 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"
, 3626); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIndexHandle"
")"); do { MOZ_CrashSequence(__null, 3626); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3627
3628 if (mTmpHandle) {
3629 CacheFileIOManager::DoomFile(mTmpHandle, nullptr);
3630 mTmpHandle = nullptr;
3631
3632 if (mJournalHandle) { // this shouldn't normally happen
3633 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)
3634 ("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)
3635 "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)
3636 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)
;
3637 FinishRead(false, aProofOfLock);
3638 break;
3639 }
3640 }
3641
3642 if (mJournalHandle) {
3643 // Rename journal to make sure we update index on next start in case
3644 // firefox crashes
3645 rv = CacheFileIOManager::RenameFile(
3646 mJournalHandle, nsLiteralCString(TEMP_INDEX_NAME"index.tmp"), this);
3647 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3648 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)
3649 ("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)
3650 "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)
3651 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)
;
3652 FinishRead(false, aProofOfLock);
3653 break;
3654 }
3655 } else {
3656 StartReadingIndex(aProofOfLock);
3657 }
3658
3659 break;
3660 default:
3661 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", 3661); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "false" ") (" "Unexpected state!" ")"); do {
MOZ_CrashSequence(__null, 3661); __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
3662 }
3663}
3664
3665nsresult CacheIndex::OnFileOpened(CacheFileHandle* aHandle, nsresult aResult) {
3666 MOZ_CRASH("CacheIndex::OnFileOpened should not be called!")do { do { } while (false); MOZ_ReportCrash("" "CacheIndex::OnFileOpened should not be called!"
, "./../../../netwerk/cache2/CacheIndex.cpp", 3666); AnnotateMozCrashReason
("MOZ_CRASH(" "CacheIndex::OnFileOpened should not be called!"
")"); do { MOZ_CrashSequence(__null, 3666); __attribute__((nomerge
)) ::abort(); } while (false); } while (false)
;
3667 return NS_ERROR_UNEXPECTED;
3668}
3669
3670nsresult CacheIndex::OnDataWritten(CacheFileHandle* aHandle, const char* aBuf,
3671 nsresult aResult) {
3672 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)
3673 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)
;
3674
3675 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"
, 3675); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()"
")"); do { MOZ_CrashSequence(__null, 3675); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3676
3677 nsresult rv;
3678
3679 StaticMutexAutoLock lock(sLock);
3680
3681 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", 3681); AnnotateMozCrashReason
("MOZ_RELEASE_ASSERT" "(" "IsIndexUsable()" ")"); do { MOZ_CrashSequence
(__null, 3681); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
3682 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"
, 3682); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "mRWPending"
")"); do { MOZ_CrashSequence(__null, 3682); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3683 mRWPending = false;
3684
3685 if (mState == READY && mShuttingDown) {
3686 return NS_OK;
3687 }
3688
3689 switch (mState) {
3690 case WRITING:
3691 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", 3691); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mIndexHandle == aHandle" ")"); do { MOZ_CrashSequence
(__null, 3691); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
3692
3693 if (NS_FAILED(aResult)((bool)(__builtin_expect(!!(NS_FAILED_impl(aResult)), 0)))) {
3694 FinishWrite(false, lock);
3695 } else {
3696 if (mSkipEntries == mProcessEntries) {
3697 rv = CacheFileIOManager::RenameFile(
3698 mIndexHandle, nsLiteralCString(INDEX_NAME"index"), this);
3699 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3700 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)
3701 ("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)
3702 "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)
3703 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)
;
3704 FinishWrite(false, lock);
3705 }
3706 } else {
3707 WriteRecords(lock);
3708 }
3709 }
3710 break;
3711 default:
3712 // Writing was canceled.
3713 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)
3714 ("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)
3715 "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)
3716 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)
;
3717 ReleaseBuffer();
3718 }
3719
3720 return NS_OK;
3721}
3722
3723nsresult CacheIndex::OnDataRead(CacheFileHandle* aHandle, char* aBuf,
3724 nsresult aResult) {
3725 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)
3726 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)
;
3727
3728 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"
, 3728); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()"
")"); do { MOZ_CrashSequence(__null, 3728); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3729
3730 StaticMutexAutoLock lock(sLock);
3731
3732 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", 3732); AnnotateMozCrashReason
("MOZ_RELEASE_ASSERT" "(" "IsIndexUsable()" ")"); do { MOZ_CrashSequence
(__null, 3732); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
3733 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"
, 3733); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "mRWPending"
")"); do { MOZ_CrashSequence(__null, 3733); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3734 mRWPending = false;
3735
3736 switch (mState) {
3737 case READING:
3738 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"
, 3738); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIndexHandle == aHandle || mJournalHandle == aHandle"
")"); do { MOZ_CrashSequence(__null, 3738); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3739
3740 if (NS_FAILED(aResult)((bool)(__builtin_expect(!!(NS_FAILED_impl(aResult)), 0)))) {
3741 FinishRead(false, lock);
3742 } else {
3743 if (!mIndexOnDiskIsValid) {
3744 ParseRecords(lock);
3745 } else {
3746 ParseJournal(lock);
3747 }
3748 }
3749 break;
3750 default:
3751 // Reading was canceled.
3752 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)
3753 ("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)
3754 "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)
3755 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)
;
3756 ReleaseBuffer();
3757 }
3758
3759 return NS_OK;
3760}
3761
3762nsresult CacheIndex::OnFileDoomed(CacheFileHandle* aHandle, nsresult aResult) {
3763 MOZ_CRASH("CacheIndex::OnFileDoomed should not be called!")do { do { } while (false); MOZ_ReportCrash("" "CacheIndex::OnFileDoomed should not be called!"
, "./../../../netwerk/cache2/CacheIndex.cpp", 3763); AnnotateMozCrashReason
("MOZ_CRASH(" "CacheIndex::OnFileDoomed should not be called!"
")"); do { MOZ_CrashSequence(__null, 3763); __attribute__((nomerge
)) ::abort(); } while (false); } while (false)
;
3764 return NS_ERROR_UNEXPECTED;
3765}
3766
3767nsresult CacheIndex::OnEOFSet(CacheFileHandle* aHandle, nsresult aResult) {
3768 MOZ_CRASH("CacheIndex::OnEOFSet should not be called!")do { do { } while (false); MOZ_ReportCrash("" "CacheIndex::OnEOFSet should not be called!"
, "./../../../netwerk/cache2/CacheIndex.cpp", 3768); AnnotateMozCrashReason
("MOZ_CRASH(" "CacheIndex::OnEOFSet should not be called!" ")"
); do { MOZ_CrashSequence(__null, 3768); __attribute__((nomerge
)) ::abort(); } while (false); } while (false)
;
3769 return NS_ERROR_UNEXPECTED;
3770}
3771
3772nsresult CacheIndex::OnFileRenamed(CacheFileHandle* aHandle, nsresult aResult) {
3773 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)
3774 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)
;
3775
3776 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"
, 3776); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()"
")"); do { MOZ_CrashSequence(__null, 3776); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3777
3778 StaticMutexAutoLock lock(sLock);
3779
3780 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", 3780); AnnotateMozCrashReason
("MOZ_RELEASE_ASSERT" "(" "IsIndexUsable()" ")"); do { MOZ_CrashSequence
(__null, 3780); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
3781
3782 if (mState == READY && mShuttingDown) {
3783 return NS_OK;
3784 }
3785
3786 switch (mState) {
3787 case WRITING:
3788 // This is a result of renaming the new index written to tmpfile to index
3789 // file. This is the last step when writing the index and the whole
3790 // writing process is successful iff renaming was successful.
3791
3792 if (mIndexHandle != aHandle) {
3793 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)
3794 ("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)
3795 "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)
3796 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)
;
3797 break;
3798 }
3799
3800 FinishWrite(NS_SUCCEEDED(aResult)((bool)(__builtin_expect(!!(!NS_FAILED_impl(aResult)), 1))), lock);
3801 break;
3802 case READING:
3803 // This is a result of renaming journal file to tmpfile. It is renamed
3804 // before we start reading index and journal file and it should normally
3805 // succeed. If it fails give up reading of index.
3806
3807 if (mJournalHandle != aHandle) {
3808 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)
3809 ("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)
3810 "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)
3811 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)
;
3812 break;
3813 }
3814
3815 if (NS_FAILED(aResult)((bool)(__builtin_expect(!!(NS_FAILED_impl(aResult)), 0)))) {
3816 FinishRead(false, lock);
3817 } else {
3818 StartReadingIndex(lock);
3819 }
3820 break;
3821 default:
3822 // Reading/writing was canceled.
3823 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)
3824 ("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)
3825 "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)
3826 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)
;
3827 }
3828
3829 return NS_OK;
3830}
3831
3832// Memory reporting
3833
3834size_t CacheIndex::SizeOfExcludingThisInternal(
3835 mozilla::MallocSizeOf mallocSizeOf) const {
3836 sLock.AssertCurrentThreadOwns();
3837
3838 size_t n = 0;
3839
3840 // mIndexHandle and mJournalHandle are reported via SizeOfHandlesRunnable
3841 // in CacheFileIOManager::SizeOfExcludingThisInternal as part of special
3842 // handles array.
3843
3844 // mCacheDirectory is an nsIFile which we don't have reporting for.
3845
3846 // mUpdateTimer is an nsITimer which we don't have reporting for.
3847
3848 n += mallocSizeOf(mRWBuf);
3849 n += mallocSizeOf(mRWHash);
3850
3851 n += mIndex.SizeOfExcludingThis(mallocSizeOf);
3852 n += mPendingUpdates.SizeOfExcludingThis(mallocSizeOf);
3853 n += mTmpJournal.SizeOfExcludingThis(mallocSizeOf);
3854
3855 // mFrecencyStorage items are reported by mIndex/mPendingUpdates
3856 n += mFrecencyStorage.mRecs.ShallowSizeOfExcludingThis(mallocSizeOf);
3857 n += mDiskConsumptionObservers.ShallowSizeOfExcludingThis(mallocSizeOf);
3858
3859 return n;
3860}
3861
3862// static
3863size_t CacheIndex::SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) {
3864 StaticMutexAutoLock lock(sLock);
3865
3866 if (!gInstance) return 0;
3867
3868 return gInstance->SizeOfExcludingThisInternal(mallocSizeOf);
3869}
3870
3871// static
3872size_t CacheIndex::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) {
3873 StaticMutexAutoLock lock(sLock);
3874
3875 return mallocSizeOf(gInstance) +
3876 (gInstance ? gInstance->SizeOfExcludingThisInternal(mallocSizeOf) : 0);
3877}
3878
3879// static
3880void CacheIndex::UpdateTotalBytesWritten(uint32_t aBytesWritten) {
3881 StaticMutexAutoLock lock(sLock);
3882
3883 RefPtr<CacheIndex> index = gInstance;
3884 if (!index) {
3885 return;
3886 }
3887
3888 index->mTotalBytesWritten += aBytesWritten;
3889
3890 // Do telemetry report if enough data has been written and the index is
3891 // in READY state. The data is available also in WRITING state, but we would
3892 // need to deal with pending updates.
3893 if (index->mTotalBytesWritten >= kTelemetryReportBytesLimit(2U * 1024U * 1024U * 1024U) &&
3894 index->mState == READY && !index->mIndexNeedsUpdate &&
3895 !index->mShuttingDown) {
3896 index->DoTelemetryReport();
3897 index->mTotalBytesWritten = 0;
3898 return;
3899 }
3900}
3901
3902void CacheIndex::DoTelemetryReport() {
3903 static const nsLiteralCString
3904 contentTypeNames[nsICacheEntry::CONTENT_TYPE_LAST] = {
3905 "UNKNOWN"_ns, "OTHER"_ns, "JAVASCRIPT"_ns, "IMAGE"_ns,
3906 "MEDIA"_ns, "STYLESHEET"_ns, "WASM"_ns, "DICTIONARY"_ns};
3907
3908 for (uint32_t i = 0; i < nsICacheEntry::CONTENT_TYPE_LAST; ++i) {
3909 if (mIndexStats.Size() > 0) {
3910 glean::network::cache_size_share.Get(contentTypeNames[i])
3911 .AccumulateSingleSample(
3912 round(static_cast<double>(mIndexStats.SizeByType(i)) * 100.0 /
3913 static_cast<double>(mIndexStats.Size())));
3914 }
3915
3916 if (mIndexStats.Count() > 0) {
3917 glean::network::cache_entry_count_share.Get(contentTypeNames[i])
3918 .AccumulateSingleSample(
3919 round(static_cast<double>(mIndexStats.CountByType(i)) * 100.0 /
3920 static_cast<double>(mIndexStats.Count())));
3921 }
3922 }
3923
3924 nsCString probeKey;
3925 if (CacheObserver::SmartCacheSizeEnabled()) {
3926 probeKey = "SMARTSIZE"_ns;
3927 } else {
3928 probeKey = "USERDEFINEDSIZE"_ns;
3929 }
3930 glean::network::cache_entry_count.Get(probeKey).AccumulateSingleSample(
3931 mIndexStats.Count());
3932 glean::network::cache_size.Get(probeKey).Accumulate(mIndexStats.Size() >> 10);
3933}
3934
3935// static
3936void CacheIndex::OnAsyncEviction(bool aEvicting) {
3937 StaticMutexAutoLock lock(sLock);
3938
3939 RefPtr<CacheIndex> index = gInstance;
3940 if (!index) {
3941 return;
3942 }
3943
3944 index->mAsyncGetDiskConsumptionBlocked = aEvicting;
3945 if (!aEvicting) {
3946 index->NotifyAsyncGetDiskConsumptionCallbacks();
3947 }
3948}
3949} // namespace mozilla::net