Bug Summary

File:root/firefox-clang/obj-x86_64-pc-linux-gnu/netwerk/cache2/./../../../netwerk/cache2/CacheFileIOManager.cpp
Warning:line 3811, column 5
Value stored to 'rv' 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/toolkit/components/telemetry -I /root/firefox-clang/xpcom/base -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-09-19-161322-621273-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 "CacheFileIOManager.h"
6
7#include <limits>
8
9#include "CacheFile.h"
10#include "CacheFileContextEvictor.h"
11#include "CacheFileUtils.h"
12#include "CacheHashUtils.h"
13#include "CacheIndex.h"
14#include "CacheLog.h"
15#include "CacheObserver.h"
16#include "CacheStorageService.h"
17#include "mozilla/DebugOnly.h"
18#include "mozilla/FileUtils.h"
19#include "mozilla/IOUtils.h"
20#include "mozilla/IntegerPrintfMacros.h"
21#include "mozilla/Preferences.h"
22#include "mozilla/Services.h"
23#include "mozilla/SpinEventLoopUntil.h"
24#include "mozilla/StaticPrefs_network.h"
25#include "mozilla/StoragePrincipalHelper.h"
26#include "mozilla/glean/NetwerkCache2Metrics.h"
27#include "mozilla/glean/NetwerkMetrics.h"
28#include "mozilla/net/MozURL.h"
29#include "nsAppDirectoryServiceDefs.h"
30#include "nsDirectoryServiceUtils.h"
31#include "nsEffectiveTLDService.h"
32#include "nsError.h"
33#include "nsIDirectoryEnumerator.h"
34#include "nsIFile.h"
35#include "nsIObserverService.h"
36#include "nsITimer.h"
37#include "nsNetUtil.h"
38#include "nsThreadUtils.h"
39#include "private/pprio.h"
40
41#ifdef MOZ_BACKGROUNDTASKS1
42# include "mozilla/BackgroundTasksRunner.h"
43# include "nsIBackgroundTasks.h"
44#endif
45
46// include files for ftruncate (or equivalent)
47#if defined(XP_UNIX1)
48# include <unistd.h>
49#elif defined(XP_WIN)
50# include <windows.h>
51# undef CreateFile
52# undef CREATE_NEW
53#else
54// XXX add necessary include file for ftruncate (or equivalent)
55#endif
56
57namespace mozilla::net {
58
59#define kOpenHandlesLimit128 128
60#define kMetadataWriteDelay5000 5000
61#define kRemoveTrashStartDelay60000 60000 // in milliseconds
62#define kSmartSizeUpdateInterval60000 60000 // in milliseconds
63
64#ifdef ANDROID
65const uint32_t kMaxCacheSizeKB = 512 * 1024; // 512 MB
66#else
67const uint32_t kMaxCacheSizeKB = 1024 * 1024; // 1 GB
68#endif
69const uint32_t kMaxClearOnShutdownCacheSizeKB = 150 * 1024; // 150 MB
70const auto kPurgeExtension = ".purge.bg_rm"_ns;
71
72bool CacheFileHandle::DispatchRelease() {
73 if (CacheFileIOManager::IsOnIOThreadOrCeased()) {
74 return false;
75 }
76
77 nsCOMPtr<nsIEventTarget> ioTarget = CacheFileIOManager::IOTarget();
78 if (!ioTarget) {
79 return false;
80 }
81
82 nsresult rv = ioTarget->Dispatch(
83 NewNonOwningRunnableMethod("net::CacheFileHandle::Release", this,
84 &CacheFileHandle::Release),
85 nsIEventTarget::DISPATCH_NORMAL);
86 return NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)));
87}
88
89#if defined(MOZ_CACHE_ASYNC_IO1)
90void CacheFileHandle::StartAsyncOperation() {
91 mAsyncRunning++;
92 CacheFileIOManager::gInstance->mAsyncRunning++;
93}
94
95bool CacheFileHandle::WaitForAsyncCompletion(nsIRunnable* aEvent,
96 uint32_t aLevel) {
97 if (mAsyncRunning) {
98 mPendingEvents.AppendElement(PendingItem(aEvent, aLevel));
99 return true;
100 }
101 return false;
102}
103
104# define GUARD_ASYNC_WRITE()if (mHandle->WaitForAsyncCompletion( this, mHandle->IsPriority
() ? CacheIOThread::WRITE_PRIORITY : CacheIOThread::WRITE)) {
return NS_OK; }
\
105 if (mHandle->WaitForAsyncCompletion( \
106 this, mHandle->IsPriority() ? CacheIOThread::WRITE_PRIORITY \
107 : CacheIOThread::WRITE)) { \
108 return NS_OK; \
109 }
110
111class PendingItemComparator {
112 public:
113 using PendingItem = CacheFileHandle::PendingItem;
114 bool LessThan(const PendingItem& a, const PendingItem& b) const {
115 return a.second < b.second;
116 }
117};
118
119void CacheFileHandle::EndAsyncOperation() {
120 MOZ_ASSERT(mAsyncRunning, "EndAsyncOperation called without async operation")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mAsyncRunning)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mAsyncRunning))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("mAsyncRunning" " ("
"EndAsyncOperation called without async operation" ")", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 120); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mAsyncRunning"
") (" "EndAsyncOperation called without async operation" ")"
); do { MOZ_CrashSequence(__null, 120); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
121 MOZ_ASSERT(CacheFileIOManager::gInstance->mIOThread->IsCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::gInstance->mIOThread->IsCurrentThread
())>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(CacheFileIOManager::gInstance->mIOThread->IsCurrentThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("CacheFileIOManager::gInstance->mIOThread->IsCurrentThread()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 121); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "CacheFileIOManager::gInstance->mIOThread->IsCurrentThread()"
")"); do { MOZ_CrashSequence(__null, 121); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
122
123 if (--mAsyncRunning == 0) {
124 // Notify all pending events
125 auto pendingEvents = std::move(mPendingEvents);
126 pendingEvents.StableSort(PendingItemComparator());
127 for (auto& event : pendingEvents) {
128 event.first->Run();
129 }
130 }
131 if (--CacheFileIOManager::gInstance->mAsyncRunning == 0) {
132 CacheFileIOManager::gInstance->DispatchPendingEvents();
133 }
134}
135#else
136# define GUARD_ASYNC_WRITE()if (mHandle->WaitForAsyncCompletion( this, mHandle->IsPriority
() ? CacheIOThread::WRITE_PRIORITY : CacheIOThread::WRITE)) {
return NS_OK; }
137#endif
138
139NS_IMPL_ADDREF(CacheFileHandle)MozExternalRefCountType CacheFileHandle::AddRef(void) { static_assert
(!std::is_destructible_v<CacheFileHandle>, "Reference-counted class "
"CacheFileHandle" " 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/CacheFileIOManager.cpp"
, 139); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { MOZ_CrashSequence(__null, 139
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("CacheFileHandle" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("CacheFileHandle" != nullptr
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"\"CacheFileHandle\" != nullptr" " (" "Must specify a name" ")"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 139); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "\"CacheFileHandle\" != nullptr" ") (" "Must specify a name"
")"); do { MOZ_CrashSequence(__null, 139); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); if (!mRefCnt
.isThreadSafe) _mOwningThread.AssertOwnership("CacheFileHandle"
" not thread-safe"); nsrefcnt count = ++mRefCnt; NS_LogAddRef
((this), (count), ("CacheFileHandle"), (uint32_t)(sizeof(*this
))); return count; }
140NS_IMETHODIMP_(MozExternalRefCountType)MozExternalRefCountType
141CacheFileHandle::Release() {
142 nsrefcnt count = mRefCnt - 1;
143 if (DispatchRelease()) {
144 // Redispatched to the IO thread.
145 return count;
146 }
147
148 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 148); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { MOZ_CrashSequence(__null, 148); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
149
150 LOG(("CacheFileHandle::Release() [this=%p, refcnt=%" PRIuPTR "]", 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, "CacheFileHandle::Release() [this=%p, refcnt=%"
"l" "u" "]", this, mRefCnt.get()); } } while (0)
151 mRefCnt.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, "CacheFileHandle::Release() [this=%p, refcnt=%"
"l" "u" "]", this, mRefCnt.get()); } } while (0)
;
152 MOZ_ASSERT(0 != mRefCnt, "dup release")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(0 != mRefCnt)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(0 != mRefCnt))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("0 != mRefCnt" " ("
"dup release" ")", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 152); AnnotateMozCrashReason("MOZ_ASSERT" "(" "0 != mRefCnt"
") (" "dup release" ")"); do { MOZ_CrashSequence(__null, 152
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
153 count = --mRefCnt;
154 NS_LOG_RELEASE(this, count, "CacheFileHandle")NS_LogRelease((this), (count), ("CacheFileHandle"));
155
156 if (0 == count) {
157 mRefCnt = 1;
158 delete (this);
159 return 0;
160 }
161
162 return count;
163}
164
165NS_INTERFACE_MAP_BEGIN(CacheFileHandle)nsresult CacheFileHandle::QueryInterface(const nsIID& aIID
, void** aInstancePtr) { do { if (!(aInstancePtr)) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!"
, "aInstancePtr", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 165); MOZ_PretendNoReturn(); } } while (0); nsISupports* foundInterface
;
166 NS_INTERFACE_MAP_ENTRY(nsISupports)if (aIID.Equals(mozilla::detail::kImplementedIID<std::remove_reference_t
<decltype(*this)>, nsISupports>)) foundInterface = static_cast
<nsISupports*>(this); else
167NS_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/CacheFileIOManager.cpp"
, 167); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aIID.Equals((nsISupports::kIID))"
")"); do { MOZ_CrashSequence(__null, 167); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); status = NS_NOINTERFACE
; } else { (foundInterface)->AddRef(); status = NS_OK; } *
aInstancePtr = foundInterface; return status; }
168
169CacheFileHandle::CacheFileHandle(const SHA1Sum::Hash* aHash, bool aPriority,
170 PinningStatus aPinning)
171 : mHash(aHash),
172 mIsDoomed(false),
173 mClosed(false),
174 mPriority(aPriority),
175 mSpecialFile(false),
176 mInvalid(false),
177 mFileExists(false),
178 mDoomWhenFoundPinned(false),
179 mDoomWhenFoundNonPinned(false),
180 mKilled(false),
181 mPinning(aPinning),
182 mFileSize(-1),
183 mFD(nullptr) {
184 // If we initialize mDoomed in the initialization list, that initialization is
185 // not guaranteeded to be atomic. Whereas this assignment here is guaranteed
186 // to be atomic. TSan will see this (atomic) assignment and be satisfied
187 // that cross-thread accesses to mIsDoomed are properly synchronized.
188 mIsDoomed = false;
189 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, "CacheFileHandle::CacheFileHandle() [this=%p, hash=%08x%08x%08x%08x%08x]"
, this, 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)
190 "CacheFileHandle::CacheFileHandle() [this=%p, 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, "CacheFileHandle::CacheFileHandle() [this=%p, hash=%08x%08x%08x%08x%08x]"
, this, 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)
191 this, 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, "CacheFileHandle::CacheFileHandle() [this=%p, hash=%08x%08x%08x%08x%08x]"
, this, 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)
;
192}
193
194CacheFileHandle::CacheFileHandle(const nsACString& aKey, bool aPriority,
195 PinningStatus aPinning)
196 : mHash(nullptr),
197 mIsDoomed(false),
198 mClosed(false),
199 mPriority(aPriority),
200 mSpecialFile(true),
201 mInvalid(false),
202 mFileExists(false),
203 mDoomWhenFoundPinned(false),
204 mDoomWhenFoundNonPinned(false),
205 mKilled(false),
206 mPinning(aPinning),
207 mFileSize(-1),
208 mFD(nullptr),
209 mKey(aKey) {
210 // See comment above about the initialization of mIsDoomed.
211 mIsDoomed = false;
212 LOG(("CacheFileHandle::CacheFileHandle() [this=%p, key=%s]", 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, "CacheFileHandle::CacheFileHandle() [this=%p, key=%s]"
, this, TPromiseFlatString<char>(aKey).get()); } } while
(0)
213 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, "CacheFileHandle::CacheFileHandle() [this=%p, key=%s]"
, this, TPromiseFlatString<char>(aKey).get()); } } while
(0)
;
214}
215
216CacheFileHandle::~CacheFileHandle() {
217 LOG(("CacheFileHandle::~CacheFileHandle() [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, "CacheFileHandle::~CacheFileHandle() [this=%p]"
, this); } } while (0)
;
218
219 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 219); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { MOZ_CrashSequence(__null, 219); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
220
221 RefPtr<CacheFileIOManager> ioMan = CacheFileIOManager::gInstance;
222 if (!IsClosed() && ioMan) {
223 ioMan->CloseHandleInternal(this);
224 }
225}
226
227void CacheFileHandle::Log() {
228 if (!LOG_ENABLED()(__builtin_expect(!!(mozilla::detail::log_test(gCache2Log, mozilla
::LogLevel::Debug)), 0))
) {
229 return;
230 }
231
232 nsAutoCString leafName;
233 if (mFile) {
234 mFile->GetNativeLeafName(leafName);
235 }
236
237 if (mSpecialFile) {
238 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, "CacheFileHandle::Log() - special file [this=%p, "
"isDoomed=%d, priority=%d, closed=%d, invalid=%d, " "pinning=%"
"u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
239 ("CacheFileHandle::Log() - special file [this=%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, "CacheFileHandle::Log() - special file [this=%p, "
"isDoomed=%d, priority=%d, closed=%d, invalid=%d, " "pinning=%"
"u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
240 "isDoomed=%d, priority=%d, closed=%d, invalid=%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, "CacheFileHandle::Log() - special file [this=%p, "
"isDoomed=%d, priority=%d, closed=%d, invalid=%d, " "pinning=%"
"u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
241 "pinning=%" PRIu32 ", fileExists=%d, fileSize=%" PRId64do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Log() - special file [this=%p, "
"isDoomed=%d, priority=%d, closed=%d, invalid=%d, " "pinning=%"
"u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
242 ", leafName=%s, 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, "CacheFileHandle::Log() - special file [this=%p, "
"isDoomed=%d, priority=%d, closed=%d, invalid=%d, " "pinning=%"
"u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
243 this, bool(mIsDoomed), bool(mPriority), bool(mClosed), bool(mInvalid),do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Log() - special file [this=%p, "
"isDoomed=%d, priority=%d, closed=%d, invalid=%d, " "pinning=%"
"u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
244 static_cast<uint32_t>(mPinning), bool(mFileExists), int64_t(mFileSize),do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Log() - special file [this=%p, "
"isDoomed=%d, priority=%d, closed=%d, invalid=%d, " "pinning=%"
"u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
245 leafName.get(), mKey.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, "CacheFileHandle::Log() - special file [this=%p, "
"isDoomed=%d, priority=%d, closed=%d, invalid=%d, " "pinning=%"
"u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
;
246 } else {
247 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, "CacheFileHandle::Log() - entry file [this=%p, "
"hash=%08x%08x%08x%08x%08x, " "isDoomed=%d, priority=%d, closed=%d, invalid=%d, "
"pinning=%" "u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[4]), bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
248 ("CacheFileHandle::Log() - entry file [this=%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, "CacheFileHandle::Log() - entry file [this=%p, "
"hash=%08x%08x%08x%08x%08x, " "isDoomed=%d, priority=%d, closed=%d, invalid=%d, "
"pinning=%" "u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[4]), bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
249 "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, "CacheFileHandle::Log() - entry file [this=%p, "
"hash=%08x%08x%08x%08x%08x, " "isDoomed=%d, priority=%d, closed=%d, invalid=%d, "
"pinning=%" "u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[4]), bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
250 "isDoomed=%d, priority=%d, closed=%d, invalid=%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, "CacheFileHandle::Log() - entry file [this=%p, "
"hash=%08x%08x%08x%08x%08x, " "isDoomed=%d, priority=%d, closed=%d, invalid=%d, "
"pinning=%" "u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[4]), bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
251 "pinning=%" PRIu32 ", fileExists=%d, fileSize=%" PRId64do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Log() - entry file [this=%p, "
"hash=%08x%08x%08x%08x%08x, " "isDoomed=%d, priority=%d, closed=%d, invalid=%d, "
"pinning=%" "u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[4]), bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
252 ", leafName=%s, 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, "CacheFileHandle::Log() - entry file [this=%p, "
"hash=%08x%08x%08x%08x%08x, " "isDoomed=%d, priority=%d, closed=%d, invalid=%d, "
"pinning=%" "u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[4]), bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
253 this, LOGSHA1(mHash), bool(mIsDoomed), bool(mPriority), bool(mClosed),do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Log() - entry file [this=%p, "
"hash=%08x%08x%08x%08x%08x, " "isDoomed=%d, priority=%d, closed=%d, invalid=%d, "
"pinning=%" "u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[4]), bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
254 bool(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists),do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandle::Log() - entry file [this=%p, "
"hash=%08x%08x%08x%08x%08x, " "isDoomed=%d, priority=%d, closed=%d, invalid=%d, "
"pinning=%" "u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[4]), bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
255 int64_t(mFileSize), leafName.get(), mKey.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, "CacheFileHandle::Log() - entry file [this=%p, "
"hash=%08x%08x%08x%08x%08x, " "isDoomed=%d, priority=%d, closed=%d, invalid=%d, "
"pinning=%" "u" ", fileExists=%d, fileSize=%" "l" "d" ", leafName=%s, key=%s]"
, this, PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[0]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[1]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[2]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[3]), PR_htonl((reinterpret_cast<const uint32_t*>(mHash
))[4]), bool(mIsDoomed), bool(mPriority), bool(mClosed), bool
(mInvalid), static_cast<uint32_t>(mPinning), bool(mFileExists
), int64_t(mFileSize), leafName.get(), mKey.get()); } } while
(0)
;
256 }
257}
258
259uint32_t CacheFileHandle::FileSizeInK() const {
260 MOZ_ASSERT(mFileSize != -1)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mFileSize != -1)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mFileSize != -1))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("mFileSize != -1"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 260); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mFileSize != -1" ")"); do { MOZ_CrashSequence
(__null, 260); __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
261 uint64_t size64 = mFileSize;
262
263 size64 += 0x3FF;
264 size64 >>= 10;
265
266 uint32_t size;
267 if (size64 >> 32) {
268 NS_WARNING(NS_DebugBreak(NS_DEBUG_WARNING, "CacheFileHandle::FileSizeInK() - FileSize is too large, "
"truncating to PR_UINT32_MAX", nullptr, "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 270)
269 "CacheFileHandle::FileSizeInK() - FileSize is too large, "NS_DebugBreak(NS_DEBUG_WARNING, "CacheFileHandle::FileSizeInK() - FileSize is too large, "
"truncating to PR_UINT32_MAX", nullptr, "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 270)
270 "truncating to PR_UINT32_MAX")NS_DebugBreak(NS_DEBUG_WARNING, "CacheFileHandle::FileSizeInK() - FileSize is too large, "
"truncating to PR_UINT32_MAX", nullptr, "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 270)
;
271 size = PR_UINT32_MAX4294967295U;
272 } else {
273 size = static_cast<uint32_t>(size64);
274 }
275
276 return size;
277}
278
279bool CacheFileHandle::SetPinned(bool aPinned) {
280 LOG(("CacheFileHandle::SetPinned [this=%p, pinned=%d]", this, 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, "CacheFileHandle::SetPinned [this=%p, pinned=%d]"
, this, aPinned); } } while (0)
;
281
282 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 282); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { MOZ_CrashSequence(__null, 282); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
283
284 mPinning = aPinned ? PinningStatus::PINNED : PinningStatus::NON_PINNED;
285
286 if ((MOZ_UNLIKELY(mDoomWhenFoundPinned)(__builtin_expect(!!(mDoomWhenFoundPinned), 0)) && aPinned) ||
287 (MOZ_UNLIKELY(mDoomWhenFoundNonPinned)(__builtin_expect(!!(mDoomWhenFoundNonPinned), 0)) && !aPinned)) {
288 LOG((" dooming, when: pinned=%d, non-pinned=%d, found: 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, " dooming, when: pinned=%d, non-pinned=%d, found: pinned=%d"
, bool(mDoomWhenFoundPinned), bool(mDoomWhenFoundNonPinned), aPinned
); } } while (0)
289 bool(mDoomWhenFoundPinned), bool(mDoomWhenFoundNonPinned), 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, " dooming, when: pinned=%d, non-pinned=%d, found: pinned=%d"
, bool(mDoomWhenFoundPinned), bool(mDoomWhenFoundNonPinned), aPinned
); } } while (0)
;
290
291 mDoomWhenFoundPinned = false;
292 mDoomWhenFoundNonPinned = false;
293
294 return false;
295 }
296
297 return true;
298}
299
300// Memory reporting
301
302size_t CacheFileHandle::SizeOfExcludingThis(
303 mozilla::MallocSizeOf mallocSizeOf) const {
304 size_t n = 0;
305 n += mallocSizeOf(mFD);
306 n += mKey.SizeOfExcludingThisIfUnshared(mallocSizeOf);
307 return n;
308}
309
310size_t CacheFileHandle::SizeOfIncludingThis(
311 mozilla::MallocSizeOf mallocSizeOf) const {
312 return mallocSizeOf(this) + SizeOfExcludingThis(mallocSizeOf);
313}
314
315/******************************************************************************
316 * CacheFileHandles::HandleHashKey
317 *****************************************************************************/
318
319void CacheFileHandles::HandleHashKey::AddHandle(CacheFileHandle* aHandle) {
320 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 320); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { MOZ_CrashSequence(__null, 320); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
321
322 mHandles.InsertElementAt(0, aHandle);
323}
324
325void CacheFileHandles::HandleHashKey::RemoveHandle(CacheFileHandle* aHandle) {
326 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 326); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { MOZ_CrashSequence(__null, 326); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
327
328 DebugOnly<bool> found{};
329 found = mHandles.RemoveElement(aHandle);
330 MOZ_ASSERT(found)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(found)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(found))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("found", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 330); AnnotateMozCrashReason("MOZ_ASSERT" "(" "found" ")");
do { MOZ_CrashSequence(__null, 330); __attribute__((nomerge)
) ::abort(); } while (false); } } while (false)
;
331}
332
333already_AddRefed<CacheFileHandle>
334CacheFileHandles::HandleHashKey::GetNewestHandle() {
335 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 335); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { MOZ_CrashSequence(__null, 335); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
336
337 RefPtr<CacheFileHandle> handle;
338 if (mHandles.Length()) {
339 handle = mHandles[0];
340 }
341
342 return handle.forget();
343}
344
345void CacheFileHandles::HandleHashKey::GetHandles(
346 nsTArray<RefPtr<CacheFileHandle>>& aResult) {
347 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 347); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { MOZ_CrashSequence(__null, 347); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
348
349 for (uint32_t i = 0; i < mHandles.Length(); ++i) {
350 CacheFileHandle* handle = mHandles[i];
351 aResult.AppendElement(handle);
352 }
353}
354
355#ifdef DEBUG1
356
357void CacheFileHandles::HandleHashKey::AssertHandlesState() {
358 for (uint32_t i = 0; i < mHandles.Length(); ++i) {
359 CacheFileHandle* handle = mHandles[i];
360 MOZ_ASSERT(handle->IsDoomed())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(handle->IsDoomed())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(handle->IsDoomed()))), 0)
)) { do { } while (false); MOZ_ReportAssertionFailure("handle->IsDoomed()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 360); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "handle->IsDoomed()" ")"); do { MOZ_CrashSequence
(__null, 360); __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
361 }
362}
363
364#endif
365
366size_t CacheFileHandles::HandleHashKey::SizeOfExcludingThis(
367 mozilla::MallocSizeOf mallocSizeOf) const {
368 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/CacheFileIOManager.cpp"
, 368); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()"
")"); do { MOZ_CrashSequence(__null, 368); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
369
370 size_t n = 0;
371 n += mallocSizeOf(mHash.get());
372 for (uint32_t i = 0; i < mHandles.Length(); ++i) {
373 n += mHandles[i]->SizeOfIncludingThis(mallocSizeOf);
374 }
375
376 return n;
377}
378
379/******************************************************************************
380 * CacheFileHandles
381 *****************************************************************************/
382
383CacheFileHandles::CacheFileHandles() {
384 LOG(("CacheFileHandles::CacheFileHandles() [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, "CacheFileHandles::CacheFileHandles() [this=%p]"
, this); } } while (0)
;
385 MOZ_COUNT_CTOR(CacheFileHandles)do { static_assert(std::is_class_v<CacheFileHandles>, "Token '"
"CacheFileHandles" "' is not a class type."); static_assert(
!std::is_base_of_v<nsISupports, CacheFileHandles>, "nsISupports classes don't need to call MOZ_COUNT_CTOR or "
"MOZ_COUNT_DTOR");; NS_LogCtor((void*)this, "CacheFileHandles"
, sizeof(*this)); } while (0)
;
386}
387
388CacheFileHandles::~CacheFileHandles() {
389 LOG(("CacheFileHandles::~CacheFileHandles() [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, "CacheFileHandles::~CacheFileHandles() [this=%p]"
, this); } } while (0)
;
390 MOZ_COUNT_DTOR(CacheFileHandles)do { static_assert(std::is_class_v<CacheFileHandles>, "Token '"
"CacheFileHandles" "' is not a class type."); static_assert(
!std::is_base_of_v<nsISupports, CacheFileHandles>, "nsISupports classes don't need to call MOZ_COUNT_CTOR or "
"MOZ_COUNT_DTOR");; NS_LogDtor((void*)this, "CacheFileHandles"
, sizeof(*this)); } while (0)
;
391}
392
393nsresult CacheFileHandles::GetHandle(const SHA1Sum::Hash* aHash,
394 CacheFileHandle** _retval) {
395 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 395); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { MOZ_CrashSequence(__null, 395); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
396 MOZ_ASSERT(aHash)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aHash)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(aHash))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("aHash", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 396); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aHash" ")");
do { MOZ_CrashSequence(__null, 396); __attribute__((nomerge)
) ::abort(); } while (false); } } while (false)
;
397
398#ifdef DEBUG_HANDLES
399 LOG(("CacheFileHandles::GetHandle() [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, "CacheFileHandles::GetHandle() [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)
400 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, "CacheFileHandles::GetHandle() [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)
;
401#endif
402
403 // find hash entry for key
404 HandleHashKey* entry = mTable.GetEntry(*aHash);
405 if (!entry) {
406 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, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"no handle entries found", 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)
407 ("CacheFileHandles::GetHandle() 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, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"no handle entries found", 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)
408 "no handle entries found",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"no handle entries found", 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)
409 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, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"no handle entries found", 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)
;
410 return NS_ERROR_NOT_AVAILABLE;
411 }
412
413#ifdef DEBUG_HANDLES
414 Log(entry);
415#endif
416
417 // Check if the entry is doomed
418 RefPtr<CacheFileHandle> handle = entry->GetNewestHandle();
419 if (!handle) {
420 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, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"no handle found %p, entry %p", 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]), handle.get(), entry); } } while
(0)
421 ("CacheFileHandles::GetHandle() 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, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"no handle found %p, entry %p", 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]), handle.get(), entry); } } while
(0)
422 "no handle found %p, entry %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, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"no handle found %p, entry %p", 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]), handle.get(), entry); } } while
(0)
423 LOGSHA1(aHash), handle.get(), 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, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"no handle found %p, entry %p", 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]), handle.get(), entry); } } while
(0)
;
424 return NS_ERROR_NOT_AVAILABLE;
425 }
426
427 if (handle->IsDoomed()) {
428 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, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"found doomed handle %p, entry %p", 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]), handle.get(), entry); } }
while (0)
429 ("CacheFileHandles::GetHandle() 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, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"found doomed handle %p, entry %p", 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]), handle.get(), entry); } }
while (0)
430 "found doomed handle %p, entry %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, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"found doomed handle %p, entry %p", 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]), handle.get(), entry); } }
while (0)
431 LOGSHA1(aHash), handle.get(), 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, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"found doomed handle %p, entry %p", 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]), handle.get(), entry); } }
while (0)
;
432 return NS_ERROR_NOT_AVAILABLE;
433 }
434
435 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, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"found handle %p, entry %p", 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]), handle.get(), entry); } } while (
0)
436 ("CacheFileHandles::GetHandle() 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, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"found handle %p, entry %p", 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]), handle.get(), entry); } } while (
0)
437 "found handle %p, entry %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, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"found handle %p, entry %p", 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]), handle.get(), entry); } } while (
0)
438 LOGSHA1(aHash), handle.get(), 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, "CacheFileHandles::GetHandle() hash=%08x%08x%08x%08x%08x "
"found handle %p, entry %p", 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]), handle.get(), entry); } } while (
0)
;
439
440 handle.forget(_retval);
441 return NS_OK;
442}
443
444already_AddRefed<CacheFileHandle> CacheFileHandles::NewHandle(
445 const SHA1Sum::Hash* aHash, bool aPriority,
446 CacheFileHandle::PinningStatus aPinning) {
447 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 447); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { MOZ_CrashSequence(__null, 447); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
448 MOZ_ASSERT(aHash)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aHash)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(aHash))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("aHash", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 448); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aHash" ")");
do { MOZ_CrashSequence(__null, 448); __attribute__((nomerge)
) ::abort(); } while (false); } } while (false)
;
449
450#ifdef DEBUG_HANDLES
451 LOG(("CacheFileHandles::NewHandle() [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, "CacheFileHandles::NewHandle() [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)
452 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, "CacheFileHandles::NewHandle() [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)
;
453#endif
454
455 // find hash entry for key
456 HandleHashKey* entry = mTable.PutEntry(*aHash);
457
458#ifdef DEBUG_HANDLES
459 Log(entry);
460#endif
461
462#ifdef DEBUG1
463 entry->AssertHandlesState();
464#endif
465
466 RefPtr<CacheFileHandle> handle =
467 new CacheFileHandle(entry->Hash(), aPriority, aPinning);
468 entry->AddHandle(handle);
469
470 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, "CacheFileHandles::NewHandle() hash=%08x%08x%08x%08x%08x "
"created new handle %p, entry=%p", 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]), handle.get(), entry); } }
while (0)
471 ("CacheFileHandles::NewHandle() 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, "CacheFileHandles::NewHandle() hash=%08x%08x%08x%08x%08x "
"created new handle %p, entry=%p", 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]), handle.get(), entry); } }
while (0)
472 "created new handle %p, entry=%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, "CacheFileHandles::NewHandle() hash=%08x%08x%08x%08x%08x "
"created new handle %p, entry=%p", 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]), handle.get(), entry); } }
while (0)
473 LOGSHA1(aHash), handle.get(), 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, "CacheFileHandles::NewHandle() hash=%08x%08x%08x%08x%08x "
"created new handle %p, entry=%p", 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]), handle.get(), entry); } }
while (0)
;
474 return handle.forget();
475}
476
477void CacheFileHandles::RemoveHandle(CacheFileHandle* aHandle) {
478 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 478); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { MOZ_CrashSequence(__null, 478); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
479 MOZ_ASSERT(aHandle)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aHandle)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aHandle))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aHandle", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 479); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aHandle" ")"
); do { MOZ_CrashSequence(__null, 479); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
480
481 if (!aHandle) {
482 return;
483 }
484
485#ifdef DEBUG_HANDLES
486 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, "CacheFileHandles::RemoveHandle() [handle=%p, hash=%08x%08x%08x%08x%08x]"
, aHandle, PR_htonl((reinterpret_cast<const uint32_t*>(
aHandle->Hash()))[0]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHandle->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[4])); } } while (
0)
487 "CacheFileHandles::RemoveHandle() [handle=%p, 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, "CacheFileHandles::RemoveHandle() [handle=%p, hash=%08x%08x%08x%08x%08x]"
, aHandle, PR_htonl((reinterpret_cast<const uint32_t*>(
aHandle->Hash()))[0]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHandle->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[4])); } } while (
0)
488 aHandle, LOGSHA1(aHandle->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, "CacheFileHandles::RemoveHandle() [handle=%p, hash=%08x%08x%08x%08x%08x]"
, aHandle, PR_htonl((reinterpret_cast<const uint32_t*>(
aHandle->Hash()))[0]), PR_htonl((reinterpret_cast<const
uint32_t*>(aHandle->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[4])); } } while (
0)
;
489#endif
490
491 // find hash entry for key
492 HandleHashKey* entry = mTable.GetEntry(*aHandle->Hash());
493 if (!entry) {
494 MOZ_ASSERT(CacheFileIOManager::IsShutdown(),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsShutdown())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(CacheFileIOManager::IsShutdown
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("CacheFileIOManager::IsShutdown()" " (" "Should find entry when removing a handle before shutdown"
")", "./../../../netwerk/cache2/CacheFileIOManager.cpp", 495
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsShutdown()"
") (" "Should find entry when removing a handle before shutdown"
")"); do { MOZ_CrashSequence(__null, 495); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
495 "Should find entry when removing a handle before shutdown")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsShutdown())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(CacheFileIOManager::IsShutdown
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("CacheFileIOManager::IsShutdown()" " (" "Should find entry when removing a handle before shutdown"
")", "./../../../netwerk/cache2/CacheFileIOManager.cpp", 495
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsShutdown()"
") (" "Should find entry when removing a handle before shutdown"
")"); do { MOZ_CrashSequence(__null, 495); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
496
497 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, "CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "
"no entries found", PR_htonl((reinterpret_cast<const uint32_t
*>(aHandle->Hash()))[0]), PR_htonl((reinterpret_cast<
const uint32_t*>(aHandle->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[4])); } } while (
0)
498 ("CacheFileHandles::RemoveHandle() 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, "CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "
"no entries found", PR_htonl((reinterpret_cast<const uint32_t
*>(aHandle->Hash()))[0]), PR_htonl((reinterpret_cast<
const uint32_t*>(aHandle->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[4])); } } while (
0)
499 "no entries found",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "
"no entries found", PR_htonl((reinterpret_cast<const uint32_t
*>(aHandle->Hash()))[0]), PR_htonl((reinterpret_cast<
const uint32_t*>(aHandle->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[4])); } } while (
0)
500 LOGSHA1(aHandle->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, "CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "
"no entries found", PR_htonl((reinterpret_cast<const uint32_t
*>(aHandle->Hash()))[0]), PR_htonl((reinterpret_cast<
const uint32_t*>(aHandle->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[4])); } } while (
0)
;
501 return;
502 }
503
504#ifdef DEBUG_HANDLES
505 Log(entry);
506#endif
507
508 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, "CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "
"removing handle %p", 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]), aHandle); } }
while (0)
509 ("CacheFileHandles::RemoveHandle() 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, "CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "
"removing handle %p", 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]), aHandle); } }
while (0)
510 "removing 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, "CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "
"removing handle %p", 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]), aHandle); } }
while (0)
511 LOGSHA1(entry->Hash()), 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, "CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "
"removing handle %p", 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]), aHandle); } }
while (0)
;
512 entry->RemoveHandle(aHandle);
513
514 if (entry->IsEmpty()) {
515 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, "CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "
"list is empty, removing entry %p", 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]), entry); } } while
(0)
516 ("CacheFileHandles::RemoveHandle() 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, "CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "
"list is empty, removing entry %p", 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]), entry); } } while
(0)
517 "list is empty, removing entry %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, "CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "
"list is empty, removing entry %p", 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]), entry); } } while
(0)
518 LOGSHA1(entry->Hash()), 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, "CacheFileHandles::RemoveHandle() hash=%08x%08x%08x%08x%08x "
"list is empty, removing entry %p", 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]), entry); } } while
(0)
;
519 mTable.RemoveEntry(entry);
520 }
521}
522
523void CacheFileHandles::GetAllHandles(
524 nsTArray<RefPtr<CacheFileHandle>>* _retval) {
525 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 525); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { MOZ_CrashSequence(__null, 525); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
526 for (auto iter = mTable.Iter(); !iter.Done(); iter.Next()) {
527 iter.Get()->GetHandles(*_retval);
528 }
529}
530
531void CacheFileHandles::GetActiveHandles(
532 nsTArray<RefPtr<CacheFileHandle>>* _retval) {
533 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 533); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { MOZ_CrashSequence(__null, 533); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
534 for (auto iter = mTable.Iter(); !iter.Done(); iter.Next()) {
535 RefPtr<CacheFileHandle> handle = iter.Get()->GetNewestHandle();
536 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/CacheFileIOManager.cpp"
, 536); AnnotateMozCrashReason("MOZ_ASSERT" "(" "handle" ")")
; do { MOZ_CrashSequence(__null, 536); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
537
538 if (!handle->IsDoomed()) {
539 _retval->AppendElement(handle);
540 }
541 }
542}
543
544void CacheFileHandles::ClearAll() {
545 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 545); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { MOZ_CrashSequence(__null, 545); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
546 mTable.Clear();
547}
548
549uint32_t CacheFileHandles::HandleCount() { return mTable.Count(); }
550
551#ifdef DEBUG_HANDLES
552void CacheFileHandles::Log(CacheFileHandlesEntry* entry) {
553 LOG(("CacheFileHandles::Log() BEGIN [entry=%p]", 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, "CacheFileHandles::Log() BEGIN [entry=%p]"
, entry); } } while (0)
;
554
555 nsTArray<RefPtr<CacheFileHandle>> array;
556 aEntry->GetHandles(array);
557
558 for (uint32_t i = 0; i < array.Length(); ++i) {
559 CacheFileHandle* handle = array[i];
560 handle->Log();
561 }
562
563 LOG(("CacheFileHandles::Log() END [entry=%p]", 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, "CacheFileHandles::Log() END [entry=%p]"
, entry); } } while (0)
;
564}
565#endif
566
567// Memory reporting
568
569size_t CacheFileHandles::SizeOfExcludingThis(
570 mozilla::MallocSizeOf mallocSizeOf) const {
571 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/CacheFileIOManager.cpp"
, 571); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()"
")"); do { MOZ_CrashSequence(__null, 571); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
572
573 return mTable.SizeOfExcludingThis(mallocSizeOf);
574}
575
576// Events
577
578class ShutdownEvent : public Runnable, nsITimerCallback {
579 NS_DECL_ISUPPORTS_INHERITEDpublic: virtual nsresult QueryInterface(const nsIID& aIID
, void** aInstancePtr) override; virtual MozExternalRefCountType
AddRef(void) override; virtual MozExternalRefCountType Release
(void) override;
580 public:
581 ShutdownEvent() : Runnable("net::ShutdownEvent") {}
582
583 protected:
584 ~ShutdownEvent() = default;
585
586 public:
587 NS_IMETHODvirtual nsresult Run() override {
588#if defined(MOZ_CACHE_ASYNC_IO1)
589 if (CacheFileIOManager::gInstance->mAsyncRunning > 0) {
590 // If there are any async operations running, we will wait for them to
591 // finish before shutting down the IO thread.
592 LOG(("CacheFileIOManager::ShutdownEvent - waiting for async operations"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::ShutdownEvent - waiting for async operations"
); } } while (0)
;
593 CacheFileIOManager::gInstance->mPendingEvents.AppendElement(
594 CacheFileIOManager::PendingItem(this, CacheIOThread::WRITE));
595 return NS_OK;
596 }
597#endif
598 CacheFileIOManager::gInstance->ShutdownInternal();
599
600 mNotified = true;
601
602 NS_DispatchToMainThread(
603 NS_NewRunnableFunction("CacheFileIOManager::ShutdownEvent::Run", []() {
604 // This empty runnable is dispatched just in case the MT event loop
605 // becomes empty - we need to process a task to break out of
606 // SpinEventLoopUntil.
607 }));
608
609 return NS_OK;
610 }
611
612 NS_IMETHODvirtual nsresult Notify(nsITimer* timer) override {
613 if (mNotified) {
614 return NS_OK;
615 }
616
617 // If there is any IO blocking on the IO thread, this will
618 // try to cancel it.
619 CacheFileIOManager::gInstance->mIOThread->CancelBlockingIO();
620
621 // After this runs the first time, the browser_cache_max_shutdown_io_lag
622 // time has elapsed. The CacheIO thread may pick up more blocking IO tasks
623 // so we want to block those too if necessary.
624 mTimer->SetDelay(
625 StaticPrefs::browser_cache_shutdown_io_time_between_cancellations_ms());
626 return NS_OK;
627 }
628
629 void PostAndWait() {
630 nsresult rv = CacheFileIOManager::gInstance->mIOThread->Dispatch(
631 this,
632 CacheIOThread::WRITE); // When writes and closing of handles is done
633 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 633); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { MOZ_CrashSequence(__null, 633); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
634
635 // If we failed to post the even there's no reason to go into the loop
636 // because mNotified will never be set to true.
637 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
638 NS_WARNING("Posting ShutdownEvent task failed")NS_DebugBreak(NS_DEBUG_WARNING, "Posting ShutdownEvent task failed"
, nullptr, "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 638)
;
639 return;
640 }
641
642 rv = NS_NewTimerWithCallback(
643 getter_AddRefs(mTimer), this,
644 StaticPrefs::browser_cache_max_shutdown_io_lag() * 1000,
645 nsITimer::TYPE_REPEATING_SLACK);
646 MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 646); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { MOZ_CrashSequence(__null, 646); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
647
648 mozilla::SpinEventLoopUntil("CacheFileIOManager::ShutdownEvent"_ns,
649 [&]() { return bool(mNotified); });
650
651 if (mTimer) {
652 mTimer->Cancel();
653 mTimer = nullptr;
654 }
655 }
656
657 protected:
658 Atomic<bool> mNotified{false};
659 nsCOMPtr<nsITimer> mTimer;
660};
661
662NS_IMPL_ISUPPORTS_INHERITED(ShutdownEvent, Runnable, nsITimerCallback)nsresult ShutdownEvent::QueryInterface(const nsIID& aIID,
void** aInstancePtr) { do { if (!(aInstancePtr)) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!"
, "aInstancePtr", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 662); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(1 > 0, "Need more arguments to NS_INTERFACE_TABLE_INHERITED"
); static const QITableEntry table[] = { {&mozilla::detail
::kImplementedIID<ShutdownEvent, nsITimerCallback>, int32_t
( reinterpret_cast<char*>(static_cast<nsITimerCallback
*>((ShutdownEvent*)0x1000)) - reinterpret_cast<char*>
((ShutdownEvent*)0x1000))}, { nullptr, 0 } } ; static_assert(
std::size(table) > 1, "need at least 1 interface"); rv = NS_TableDrivenQI
(static_cast<void*>(this), aIID, aInstancePtr, table); if
(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) return
rv; return Runnable::QueryInterface(aIID, aInstancePtr); } MozExternalRefCountType
ShutdownEvent::AddRef(void) { static_assert(!std::is_destructible_v
<ShutdownEvent>, "Reference-counted class " "ShutdownEvent"
" should not have a public destructor. " "Make this class's destructor non-public"
); nsrefcnt r = Runnable::AddRef(); if constexpr (::mozilla::
detail::ShouldLogInheritedRefcnt<ShutdownEvent>) { NS_LogAddRef
((this), (r), ("ShutdownEvent"), (uint32_t)(sizeof(*this))); }
return r; } MozExternalRefCountType ShutdownEvent::Release(void
) { nsrefcnt r = Runnable::Release(); if constexpr (::mozilla
::detail::ShouldLogInheritedRefcnt<ShutdownEvent>) { NS_LogRelease
((this), (r), ("ShutdownEvent")); } return r; }
663
664class OpenFileEvent : public Runnable {
665 public:
666 OpenFileEvent(const nsACString& aKey, uint32_t aFlags,
667 CacheFileIOListener* aCallback)
668 : Runnable("net::OpenFileEvent"),
669 mFlags(aFlags),
670 mCallback(aCallback),
671 mKey(aKey) {
672 mIOMan = CacheFileIOManager::gInstance;
673 }
674
675 protected:
676 ~OpenFileEvent() = default;
677
678 public:
679 NS_IMETHODvirtual nsresult Run() override {
680 nsresult rv = NS_OK;
681
682 if (!(mFlags & CacheFileIOManager::SPECIAL_FILE)) {
683 SHA1Sum sum;
684 sum.update(mKey.BeginReading(), mKey.Length());
685 sum.finish(mHash);
686 }
687
688 if (!mIOMan) {
689 rv = NS_ERROR_NOT_INITIALIZED;
690 } else {
691 if (mFlags & CacheFileIOManager::SPECIAL_FILE) {
692 rv = mIOMan->OpenSpecialFileInternal(mKey, mFlags,
693 getter_AddRefs(mHandle));
694 } else {
695 rv = mIOMan->OpenFileInternal(&mHash, mKey, mFlags,
696 getter_AddRefs(mHandle));
697 }
698 mIOMan = nullptr;
699 if (mHandle) {
700 if (mHandle->Key().IsEmpty()) {
701 mHandle->Key() = mKey;
702 }
703 }
704 }
705
706 mCallback->OnFileOpened(mHandle, rv);
707 return NS_OK;
708 }
709
710 protected:
711 SHA1Sum::Hash mHash{};
712 uint32_t mFlags;
713 nsCOMPtr<CacheFileIOListener> mCallback;
714 RefPtr<CacheFileIOManager> mIOMan;
715 RefPtr<CacheFileHandle> mHandle;
716 nsCString mKey;
717};
718
719class ReadEvent : public Runnable {
720 public:
721 ReadEvent(CacheFileHandle* aHandle, int64_t aOffset, char* aBuf,
722 int32_t aCount, CacheFileIOListener* aCallback)
723 : Runnable("net::ReadEvent"),
724 mHandle(aHandle),
725 mOffset(aOffset),
726 mBuf(aBuf),
727 mCount(aCount),
728 mCallback(aCallback) {}
729
730 protected:
731 ~ReadEvent() = default;
732
733 public:
734 nsresult InlineRun(bool aAsyncDataRead) {
735 nsresult rv;
736
737 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/CacheFileIOManager.cpp"
, 737); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()"
")"); do { MOZ_CrashSequence(__null, 737); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
738
739 if (mHandle->IsClosed() || (mCallback && mCallback->IsKilled())) {
740 rv = NS_ERROR_NOT_INITIALIZED;
741 } else {
742 rv = CacheFileIOManager::gInstance->ReadInternal(mHandle, mOffset, mBuf,
743 mCount, this);
744#if defined(MOZ_CACHE_ASYNC_IO1)
745 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
746 /* The request has been performed asynchronously. It should
747 * complete later.
748 */
749 return NS_OK;
750 }
751#endif
752 }
753
754#if defined(MOZ_CACHE_ASYNC_IO1)
755 if (aAsyncDataRead) {
756 nsCOMPtr<nsIEventTarget> ioTarget = CacheFileIOManager::IOTarget();
757 ioTarget->Dispatch(NS_NewRunnableFunction(
758 "net::ReadEvent::Callback", [self = RefPtr(this), rv]() {
759 // Prevent calling back twice
760 nsCOMPtr<CacheFileIOListener> cb = std::move(self->mCallback);
761 cb->OnDataRead(self->mHandle, self->mBuf, rv);
762 }));
763 return NS_OK;
764 }
765#endif
766
767 // Prevent calling back twice
768 nsCOMPtr<CacheFileIOListener> cb = std::move(mCallback);
769 cb->OnDataRead(mHandle, mBuf, rv);
770 return NS_OK;
771 }
772
773 NS_IMETHODvirtual nsresult Run() override { return InlineRun(false); }
774
775#if defined(MOZ_CACHE_ASYNC_IO1)
776 nsresult OnComplete(nsresult aStatus) {
777 // Prevent calling back twice
778 nsCOMPtr<CacheFileIOListener> cb = std::move(mCallback);
779 cb->OnDataRead(mHandle, mBuf, aStatus);
780 mHandle->EndAsyncOperation();
781 return NS_OK;
782 }
783#endif
784
785 protected:
786 RefPtr<CacheFileHandle> mHandle;
787 int64_t mOffset;
788 char* mBuf;
789 int32_t mCount;
790 nsCOMPtr<CacheFileIOListener> mCallback;
791};
792
793class WriteEvent : public Runnable {
794 public:
795 WriteEvent(CacheFileHandle* aHandle, int64_t aOffset, const char* aBuf,
796 int32_t aCount, bool aValidate, bool aTruncate,
797 CacheFileIOListener* aCallback)
798 : Runnable("net::WriteEvent"),
799 mHandle(aHandle),
800 mOffset(aOffset),
801 mBuf(aBuf),
802 mCount(aCount),
803 mValidate(aValidate),
804 mTruncate(aTruncate),
805 mCallback(aCallback) {}
806
807 protected:
808 ~WriteEvent() {
809 if (!mCallback && mBuf) {
810 free(const_cast<char*>(mBuf));
811 }
812 }
813
814 public:
815 NS_IMETHODvirtual nsresult Run() override {
816 GUARD_ASYNC_WRITE()if (mHandle->WaitForAsyncCompletion( this, mHandle->IsPriority
() ? CacheIOThread::WRITE_PRIORITY : CacheIOThread::WRITE)) {
return NS_OK; }
;
817 nsresult rv;
818
819 if (mHandle->IsClosed() || (mCallback && mCallback->IsKilled())) {
820 // We usually get here only after the internal shutdown
821 // (i.e. mShuttingDown == true). Pretend write has succeeded
822 // to avoid any past-shutdown file dooming.
823 rv = (CacheObserver::IsPastShutdownIOLag() ||
824 CacheFileIOManager::gInstance->mShuttingDown)
825 ? NS_OK
826 : NS_ERROR_NOT_INITIALIZED;
827 } else {
828 rv = CacheFileIOManager::gInstance->WriteInternal(
829 mHandle, mOffset, mBuf, mCount, mValidate, mTruncate);
830 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0))) && !mCallback) {
831 // No listener is going to handle the error, doom the file
832 CacheFileIOManager::gInstance->DoomFileInternal(mHandle);
833 }
834 }
835 if (mCallback) {
836 mCallback->OnDataWritten(mHandle, mBuf, rv);
837 } else {
838 free(const_cast<char*>(mBuf));
839 mBuf = nullptr;
840 }
841
842 return NS_OK;
843 }
844
845 protected:
846 RefPtr<CacheFileHandle> mHandle;
847 int64_t mOffset;
848 const char* mBuf;
849 int32_t mCount;
850 bool mValidate : 1;
851 bool mTruncate : 1;
852 nsCOMPtr<CacheFileIOListener> mCallback;
853};
854
855class DoomFileEvent : public Runnable {
856 public:
857 DoomFileEvent(CacheFileHandle* aHandle, CacheFileIOListener* aCallback)
858 : Runnable("net::DoomFileEvent"),
859 mCallback(aCallback),
860 mHandle(aHandle) {}
861
862 protected:
863 ~DoomFileEvent() = default;
864
865 public:
866 NS_IMETHODvirtual nsresult Run() override {
867 nsresult rv;
868
869 if (mHandle->IsClosed()) {
870 rv = NS_ERROR_NOT_INITIALIZED;
871 } else {
872 rv = CacheFileIOManager::gInstance->DoomFileInternal(mHandle);
873 }
874
875 if (mCallback) {
876 mCallback->OnFileDoomed(mHandle, rv);
877 }
878
879 return NS_OK;
880 }
881
882 protected:
883 nsCOMPtr<CacheFileIOListener> mCallback;
884 nsCOMPtr<nsIEventTarget> mTarget;
885 RefPtr<CacheFileHandle> mHandle;
886};
887
888class DoomFileByKeyEvent : public Runnable {
889 public:
890 DoomFileByKeyEvent(const nsACString& aKey, CacheFileIOListener* aCallback)
891 : Runnable("net::DoomFileByKeyEvent"), mCallback(aCallback) {
892 SHA1Sum sum;
893 sum.update(aKey.BeginReading(), aKey.Length());
894 sum.finish(mHash);
895
896 mIOMan = CacheFileIOManager::gInstance;
897 }
898
899 protected:
900 ~DoomFileByKeyEvent() = default;
901
902 public:
903 NS_IMETHODvirtual nsresult Run() override {
904 nsresult rv;
905
906 if (!mIOMan) {
907 rv = NS_ERROR_NOT_INITIALIZED;
908 } else {
909 rv = mIOMan->DoomFileByKeyInternal(&mHash);
910 mIOMan = nullptr;
911 }
912
913 if (mCallback) {
914 mCallback->OnFileDoomed(nullptr, rv);
915 }
916
917 return NS_OK;
918 }
919
920 protected:
921 SHA1Sum::Hash mHash{};
922 nsCOMPtr<CacheFileIOListener> mCallback;
923 RefPtr<CacheFileIOManager> mIOMan;
924};
925
926class ReleaseNSPRHandleEvent : public Runnable {
927 public:
928 explicit ReleaseNSPRHandleEvent(CacheFileHandle* aHandle)
929 : Runnable("net::ReleaseNSPRHandleEvent"), mHandle(aHandle) {}
930
931 protected:
932 ~ReleaseNSPRHandleEvent() = default;
933
934 public:
935 NS_IMETHODvirtual nsresult Run() override {
936 if (!mHandle->IsClosed()) {
937 CacheFileIOManager::gInstance->MaybeReleaseNSPRHandleInternal(mHandle);
938 }
939
940 return NS_OK;
941 }
942
943 protected:
944 RefPtr<CacheFileHandle> mHandle;
945};
946
947class TruncateSeekSetEOFEvent : public Runnable {
948 public:
949 TruncateSeekSetEOFEvent(CacheFileHandle* aHandle, int64_t aTruncatePos,
950 int64_t aEOFPos, CacheFileIOListener* aCallback)
951 : Runnable("net::TruncateSeekSetEOFEvent"),
952 mHandle(aHandle),
953 mTruncatePos(aTruncatePos),
954 mEOFPos(aEOFPos),
955 mCallback(aCallback) {}
956
957 protected:
958 ~TruncateSeekSetEOFEvent() = default;
959
960 public:
961 NS_IMETHODvirtual nsresult Run() override {
962 GUARD_ASYNC_WRITE()if (mHandle->WaitForAsyncCompletion( this, mHandle->IsPriority
() ? CacheIOThread::WRITE_PRIORITY : CacheIOThread::WRITE)) {
return NS_OK; }
;
963 nsresult rv;
964
965 if (mHandle->IsClosed() || (mCallback && mCallback->IsKilled())) {
966 rv = NS_ERROR_NOT_INITIALIZED;
967 } else {
968 rv = CacheFileIOManager::gInstance->TruncateSeekSetEOFInternal(
969 mHandle, mTruncatePos, mEOFPos);
970 }
971
972 if (mCallback) {
973 mCallback->OnEOFSet(mHandle, rv);
974 }
975
976 return NS_OK;
977 }
978
979 protected:
980 RefPtr<CacheFileHandle> mHandle;
981 int64_t mTruncatePos;
982 int64_t mEOFPos;
983 nsCOMPtr<CacheFileIOListener> mCallback;
984};
985
986class RenameFileEvent : public Runnable {
987 public:
988 RenameFileEvent(CacheFileHandle* aHandle, const nsACString& aNewName,
989 CacheFileIOListener* aCallback)
990 : Runnable("net::RenameFileEvent"),
991 mHandle(aHandle),
992 mNewName(aNewName),
993 mCallback(aCallback) {}
994
995 protected:
996 ~RenameFileEvent() = default;
997
998 public:
999 NS_IMETHODvirtual nsresult Run() override {
1000 GUARD_ASYNC_WRITE()if (mHandle->WaitForAsyncCompletion( this, mHandle->IsPriority
() ? CacheIOThread::WRITE_PRIORITY : CacheIOThread::WRITE)) {
return NS_OK; }
;
1001 nsresult rv;
1002
1003 if (mHandle->IsClosed()) {
1004 rv = NS_ERROR_NOT_INITIALIZED;
1005 } else {
1006 rv = CacheFileIOManager::gInstance->RenameFileInternal(mHandle, mNewName);
1007 }
1008
1009 if (mCallback) {
1010 mCallback->OnFileRenamed(mHandle, rv);
1011 }
1012
1013 return NS_OK;
1014 }
1015
1016 protected:
1017 RefPtr<CacheFileHandle> mHandle;
1018 nsCString mNewName;
1019 nsCOMPtr<CacheFileIOListener> mCallback;
1020};
1021
1022class InitIndexEntryEvent : public Runnable {
1023 public:
1024 InitIndexEntryEvent(CacheFileHandle* aHandle,
1025 OriginAttrsHash aOriginAttrsHash, bool aAnonymous,
1026 bool aPinning)
1027 : Runnable("net::InitIndexEntryEvent"),
1028 mHandle(aHandle),
1029 mOriginAttrsHash(aOriginAttrsHash),
1030 mAnonymous(aAnonymous),
1031 mPinning(aPinning) {}
1032
1033 protected:
1034 ~InitIndexEntryEvent() = default;
1035
1036 public:
1037 NS_IMETHODvirtual nsresult Run() override {
1038 if (mHandle->IsClosed() || mHandle->IsDoomed()) {
1039 return NS_OK;
1040 }
1041
1042 CacheIndex::InitEntry(mHandle->Hash(), mOriginAttrsHash, mAnonymous,
1043 mPinning);
1044
1045 // We cannot set the filesize before we init the entry. If we're opening
1046 // an existing entry file, frecency will be set after parsing the entry
1047 // file, but we must set the filesize here since nobody is going to set it
1048 // if there is no write to the file.
1049 uint32_t sizeInK = mHandle->FileSizeInK();
1050 CacheIndex::UpdateEntry(mHandle->Hash(), nullptr, nullptr, nullptr, nullptr,
1051 nullptr, &sizeInK);
1052
1053 return NS_OK;
1054 }
1055
1056 protected:
1057 RefPtr<CacheFileHandle> mHandle;
1058 OriginAttrsHash mOriginAttrsHash;
1059 bool mAnonymous;
1060 bool mPinning;
1061};
1062
1063class UpdateIndexEntryEvent : public Runnable {
1064 public:
1065 UpdateIndexEntryEvent(CacheFileHandle* aHandle, const uint32_t* aFrecency,
1066 const bool* aHasAltData, const uint32_t* aLastFetched,
1067 const uint32_t* aFetchCount,
1068 const uint8_t* aContentType)
1069 : Runnable("net::UpdateIndexEntryEvent"),
1070 mHandle(aHandle),
1071 mHasFrecency(false),
1072 mHasHasAltData(false),
1073 mHasLastFetched(false),
1074 mHasFetchCount(false),
1075 mHasContentType(false),
1076 mFrecency(0),
1077 mHasAltData(false),
1078 mLastFetched(0),
1079 mFetchCount(0),
1080 mContentType(nsICacheEntry::CONTENT_TYPE_UNKNOWN) {
1081 if (aFrecency) {
1082 mHasFrecency = true;
1083 mFrecency = *aFrecency;
1084 }
1085 if (aHasAltData) {
1086 mHasHasAltData = true;
1087 mHasAltData = *aHasAltData;
1088 }
1089 if (aLastFetched) {
1090 mHasLastFetched = true;
1091 mLastFetched = *aLastFetched;
1092 }
1093 if (aFetchCount) {
1094 mHasFetchCount = true;
1095 mFetchCount = *aFetchCount;
1096 }
1097 if (aContentType) {
1098 mHasContentType = true;
1099 mContentType = *aContentType;
1100 }
1101 }
1102
1103 protected:
1104 ~UpdateIndexEntryEvent() = default;
1105
1106 public:
1107 NS_IMETHODvirtual nsresult Run() override {
1108 if (mHandle->IsClosed() || mHandle->IsDoomed()) {
1109 return NS_OK;
1110 }
1111
1112 CacheIndex::UpdateEntry(mHandle->Hash(),
1113 mHasFrecency ? &mFrecency : nullptr,
1114 mHasHasAltData ? &mHasAltData : nullptr,
1115 mHasLastFetched ? &mLastFetched : nullptr,
1116 mHasFetchCount ? &mFetchCount : nullptr,
1117 mHasContentType ? &mContentType : nullptr, nullptr);
1118 return NS_OK;
1119 }
1120
1121 protected:
1122 RefPtr<CacheFileHandle> mHandle;
1123
1124 bool mHasFrecency;
1125 bool mHasHasAltData;
1126 bool mHasLastFetched;
1127 bool mHasFetchCount;
1128 bool mHasContentType;
1129
1130 uint32_t mFrecency;
1131 bool mHasAltData;
1132 uint32_t mLastFetched;
1133 uint32_t mFetchCount;
1134 uint8_t mContentType;
1135};
1136
1137class MetadataWriteScheduleEvent : public Runnable {
1138 public:
1139 enum EMode { SCHEDULE, UNSCHEDULE, SHUTDOWN } mMode;
1140
1141 RefPtr<CacheFile> mFile;
1142 RefPtr<CacheFileIOManager> mIOMan;
1143
1144 MetadataWriteScheduleEvent(CacheFileIOManager* aManager, CacheFile* aFile,
1145 EMode aMode)
1146 : Runnable("net::MetadataWriteScheduleEvent"),
1147 mMode(aMode),
1148 mFile(aFile),
1149 mIOMan(aManager) {}
1150
1151 virtual ~MetadataWriteScheduleEvent() = default;
1152
1153 NS_IMETHODvirtual nsresult Run() override {
1154 RefPtr<CacheFileIOManager> ioMan = CacheFileIOManager::gInstance;
1155 if (!ioMan) {
1156 NS_WARNING(NS_DebugBreak(NS_DEBUG_WARNING, "CacheFileIOManager already gone in "
"MetadataWriteScheduleEvent::Run()", nullptr, "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 1158)
1157 "CacheFileIOManager already gone in "NS_DebugBreak(NS_DEBUG_WARNING, "CacheFileIOManager already gone in "
"MetadataWriteScheduleEvent::Run()", nullptr, "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 1158)
1158 "MetadataWriteScheduleEvent::Run()")NS_DebugBreak(NS_DEBUG_WARNING, "CacheFileIOManager already gone in "
"MetadataWriteScheduleEvent::Run()", nullptr, "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 1158)
;
1159 return NS_OK;
1160 }
1161
1162 switch (mMode) {
1163 case SCHEDULE:
1164 ioMan->ScheduleMetadataWriteInternal(mFile);
1165 break;
1166 case UNSCHEDULE:
1167 ioMan->UnscheduleMetadataWriteInternal(mFile);
1168 break;
1169 case SHUTDOWN:
1170 ioMan->ShutdownMetadataWriteSchedulingInternal();
1171 break;
1172 }
1173 return NS_OK;
1174 }
1175};
1176
1177StaticRefPtr<CacheFileIOManager> CacheFileIOManager::gInstance;
1178
1179NS_IMPL_ISUPPORTS(CacheFileIOManager, nsITimerCallback, nsINamed)MozExternalRefCountType CacheFileIOManager::AddRef(void) { static_assert
(!std::is_destructible_v<CacheFileIOManager>, "Reference-counted class "
"CacheFileIOManager" " 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/CacheFileIOManager.cpp"
, 1179); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { MOZ_CrashSequence(__null, 1179
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("CacheFileIOManager" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("CacheFileIOManager" != nullptr
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"\"CacheFileIOManager\" != nullptr" " (" "Must specify a name"
")", "./../../../netwerk/cache2/CacheFileIOManager.cpp", 1179
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"CacheFileIOManager\" != nullptr"
") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null
, 1179); __attribute__((nomerge)) ::abort(); } while (false);
} } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread
.AssertOwnership("CacheFileIOManager" " not thread-safe"); nsrefcnt
count = ++mRefCnt; NS_LogAddRef((this), (count), ("CacheFileIOManager"
), (uint32_t)(sizeof(*this))); return count; } MozExternalRefCountType
CacheFileIOManager::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/CacheFileIOManager.cpp", 1179
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { MOZ_CrashSequence(__null, 1179
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("CacheFileIOManager" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("CacheFileIOManager" != nullptr
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"\"CacheFileIOManager\" != nullptr" " (" "Must specify a name"
")", "./../../../netwerk/cache2/CacheFileIOManager.cpp", 1179
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"CacheFileIOManager\" != nullptr"
") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null
, 1179); __attribute__((nomerge)) ::abort(); } while (false);
} } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread
.AssertOwnership("CacheFileIOManager" " not thread-safe"); const
char* const nametmp = "CacheFileIOManager"; nsrefcnt count =
--mRefCnt; NS_LogRelease((this), (count), (nametmp)); if (count
== 0) { mRefCnt = 1; delete (this); return 0; } return count
; } nsresult CacheFileIOManager::QueryInterface(const nsIID&
aIID, void** aInstancePtr) { do { if (!(aInstancePtr)) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!"
, "aInstancePtr", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 1179); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(2 > 0, "Need more arguments to NS_INTERFACE_TABLE"
); static const QITableEntry table[] = { {&mozilla::detail
::kImplementedIID<CacheFileIOManager, nsITimerCallback>
, int32_t( reinterpret_cast<char*>(static_cast<nsITimerCallback
*>((CacheFileIOManager*)0x1000)) - reinterpret_cast<char
*>((CacheFileIOManager*)0x1000))}, {&mozilla::detail::
kImplementedIID<CacheFileIOManager, nsINamed>, int32_t(
reinterpret_cast<char*>(static_cast<nsINamed*>((
CacheFileIOManager*)0x1000)) - reinterpret_cast<char*>(
(CacheFileIOManager*)0x1000))}, {&mozilla::detail::kImplementedIID
<CacheFileIOManager, nsISupports>, int32_t(reinterpret_cast
<char*>(static_cast<nsISupports*>( static_cast<
nsITimerCallback*>((CacheFileIOManager*)0x1000))) - reinterpret_cast
<char*>((CacheFileIOManager*)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; }
1180
1181CacheFileIOManager::CacheFileIOManager()
1182
1183{
1184 LOG(("CacheFileIOManager::CacheFileIOManager [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, "CacheFileIOManager::CacheFileIOManager [this=%p]"
, this); } } while (0)
;
1185 MOZ_ASSERT(!gInstance, "multiple CacheFileIOManager 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 CacheFileIOManager instances!"
")", "./../../../netwerk/cache2/CacheFileIOManager.cpp", 1185
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!gInstance" ") ("
"multiple CacheFileIOManager instances!" ")"); do { MOZ_CrashSequence
(__null, 1185); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1186}
1187
1188CacheFileIOManager::~CacheFileIOManager() {
1189 LOG(("CacheFileIOManager::~CacheFileIOManager [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, "CacheFileIOManager::~CacheFileIOManager [this=%p]"
, this); } } while (0)
;
1190}
1191
1192// static
1193nsresult CacheFileIOManager::Init() {
1194 LOG(("CacheFileIOManager::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, "CacheFileIOManager::Init()"
); } } while (0)
;
1195
1196 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/CacheFileIOManager.cpp", 1196); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "NS_IsMainThread()" ")"); do { MOZ_CrashSequence
(__null, 1196); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1197
1198 if (gInstance) {
1199 return NS_ERROR_ALREADY_INITIALIZED;
1200 }
1201
1202 RefPtr<CacheFileIOManager> ioMan = new CacheFileIOManager();
1203
1204 nsresult rv = ioMan->InitInternal();
1205 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/CacheFileIOManager.cpp"
, 1205); return rv; } } while (false)
;
1206
1207 gInstance = std::move(ioMan);
1208
1209 // Ensure that transport service is initialized on the main thread.
1210 nsCOMPtr<nsIEventTarget> target =
1211 do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID"@mozilla.org/network/stream-transport-service;1", &rv);
1212 (void)target;
1213
1214 return NS_OK;
1215}
1216
1217nsresult CacheFileIOManager::InitInternal() {
1218 nsresult rv;
1219
1220 mIOThread = new CacheIOThread();
1221
1222 rv = mIOThread->Init();
1223 MOZ_ASSERT(NS_SUCCEEDED(rv), "Can't create background thread")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)))>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" " ("
"Can't create background thread" ")", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 1223); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
") (" "Can't create background thread" ")"); do { MOZ_CrashSequence
(__null, 1223); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1224 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/CacheFileIOManager.cpp"
, 1224); return rv; } } while (false)
;
1225
1226 mStartTime = TimeStamp::NowLoRes();
1227
1228 return NS_OK;
1229}
1230
1231// static
1232nsresult CacheFileIOManager::Shutdown() {
1233 LOG(("CacheFileIOManager::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, "CacheFileIOManager::Shutdown() [gInstance=%p]"
, gInstance.get()); } } while (0)
;
1234
1235 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/CacheFileIOManager.cpp", 1235); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "NS_IsMainThread()" ")"); do { MOZ_CrashSequence
(__null, 1235); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1236
1237 if (!gInstance) {
1238 return NS_ERROR_NOT_INITIALIZED;
1239 }
1240
1241 CacheIndex::PreShutdown();
1242
1243 ShutdownMetadataWriteScheduling();
1244
1245 RefPtr<ShutdownEvent> ev = new ShutdownEvent();
1246 ev->PostAndWait();
1247
1248 MOZ_ASSERT(gInstance->mHandles.HandleCount() == 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(gInstance->mHandles.HandleCount() == 0)>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(gInstance->mHandles.HandleCount() == 0))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("gInstance->mHandles.HandleCount() == 0"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 1248); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "gInstance->mHandles.HandleCount() == 0"
")"); do { MOZ_CrashSequence(__null, 1248); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1249 MOZ_ASSERT(gInstance->mHandlesByLastUsed.Length() == 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(gInstance->mHandlesByLastUsed.Length() == 0)>::
isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(gInstance->mHandlesByLastUsed.Length() == 0))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("gInstance->mHandlesByLastUsed.Length() == 0"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 1249); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "gInstance->mHandlesByLastUsed.Length() == 0"
")"); do { MOZ_CrashSequence(__null, 1249); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1250
1251 if (gInstance->mIOThread) {
1252 gInstance->mIOThread->Shutdown();
1253 }
1254
1255 CacheIndex::Shutdown();
1256 DictionaryCache::Shutdown();
1257
1258 if (CacheObserver::ClearCacheOnShutdown()) {
1259 auto totalTimer =
1260 glean::network::disk_cache2_shutdown_clear_private.Measure();
1261 gInstance->SyncRemoveAllCacheFiles();
1262 }
1263
1264 gInstance = nullptr;
1265
1266 return NS_OK;
1267}
1268
1269void CacheFileIOManager::ShutdownInternal() {
1270 LOG(("CacheFileIOManager::ShutdownInternal() [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, "CacheFileIOManager::ShutdownInternal() [this=%p]"
, this); } } while (0)
;
1271
1272 MOZ_ASSERT(mIOThread->IsCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIOThread->IsCurrentThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mIOThread->IsCurrentThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mIOThread->IsCurrentThread()", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 1272); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { MOZ_CrashSequence(__null, 1272); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1273
1274 // No new handles can be created after this flag is set
1275 mShuttingDown = true;
1276
1277 if (mTrashTimer) {
1278 mTrashTimer->Cancel();
1279 mTrashTimer = nullptr;
1280 }
1281
1282 // close all handles and delete all associated files
1283 nsTArray<RefPtr<CacheFileHandle>> handles;
1284 mHandles.GetAllHandles(&handles);
1285 handles.AppendElements(mSpecialHandles);
1286
1287 for (uint32_t i = 0; i < handles.Length(); i++) {
1288 CacheFileHandle* h = handles[i];
1289 h->mClosed = true;
1290
1291 h->Log();
1292
1293 // Close completely written files.
1294 MaybeReleaseNSPRHandleInternal(h);
1295 // Don't bother removing invalid and/or doomed files to improve
1296 // shutdown perfomrance.
1297 // Doomed files are already in the doomed directory from which
1298 // we never reuse files and delete the dir on next session startup.
1299 // Invalid files don't have metadata and thus won't load anyway
1300 // (hashes won't match).
1301
1302 // Past the shutdown I/O lag the index is no longer written to disk, so
1303 // this bookkeeping would be thrown away. The next startup rescans the
1304 // entries directory and drops the stale entries anyway.
1305 if (!h->IsSpecialFile() && !h->mIsDoomed && !h->mFileExists &&
1306 !CacheObserver::IsPastShutdownIOLag()) {
1307 CacheIndex::RemoveEntry(h->Hash(), h->Key());
1308 }
1309
1310 // Remove the handle from mHandles/mSpecialHandles
1311 if (h->IsSpecialFile()) {
1312 mSpecialHandles.RemoveElement(h);
1313 } else {
1314 mHandles.RemoveHandle(h);
1315 }
1316
1317 // Pointer to the hash is no longer valid once the last handle with the
1318 // given hash is released. Null out the pointer so that we crash if there
1319 // is a bug in this code and we dereference the pointer after this point.
1320 if (!h->IsSpecialFile()) {
1321 h->mHash = nullptr;
1322 }
1323 }
1324
1325 // Assert the table is empty. When we are here, no new handles can be added
1326 // and handles will no longer remove them self from this table and we don't
1327 // want to keep invalid handles here. Also, there is no lookup after this
1328 // point to happen.
1329 MOZ_ASSERT(mHandles.HandleCount() == 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mHandles.HandleCount() == 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mHandles.HandleCount() == 0)
)), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mHandles.HandleCount() == 0"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 1329); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mHandles.HandleCount() == 0" ")"); do { MOZ_CrashSequence
(__null, 1329); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1330
1331 // Release trash directory enumerator
1332 if (mTrashDirEnumerator) {
1333 mTrashDirEnumerator->Close();
1334 mTrashDirEnumerator = nullptr;
1335 }
1336
1337 if (mContextEvictor) {
1338 mContextEvictor->Shutdown();
1339 mContextEvictor = nullptr;
1340 }
1341}
1342
1343// static
1344nsresult CacheFileIOManager::OnProfile() {
1345 LOG(("CacheFileIOManager::OnProfile() [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, "CacheFileIOManager::OnProfile() [gInstance=%p]"
, gInstance.get()); } } while (0)
;
1346
1347 RefPtr<CacheFileIOManager> ioMan = gInstance;
1348 if (!ioMan) {
1349 // CacheFileIOManager::Init() failed, probably could not create the IO
1350 // thread, just go with it...
1351 return NS_ERROR_NOT_INITIALIZED;
1352 }
1353
1354 nsresult rv;
1355
1356 nsCOMPtr<nsIFile> directory;
1357
1358 CacheObserver::ParentDirOverride(getter_AddRefs(directory));
1359
1360#if defined(MOZ_WIDGET_ANDROID)
1361 nsCOMPtr<nsIFile> profilelessDirectory;
1362 char* cachePath = getenv("CACHE_DIRECTORY");
1363 if (!directory && cachePath && *cachePath) {
1364 rv = NS_NewNativeLocalFile(nsDependentCString(cachePath),
1365 getter_AddRefs(directory));
1366 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
1367 // Save this directory as the profileless path.
1368 rv = directory->Clone(getter_AddRefs(profilelessDirectory));
1369 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/CacheFileIOManager.cpp"
, 1369); return rv; } } while (false)
;
1370
1371 // Add profile leaf name to the directory name to distinguish
1372 // multiple profiles Fennec supports.
1373 nsCOMPtr<nsIFile> profD;
1374 rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR"ProfD",
1375 getter_AddRefs(profD));
1376
1377 nsAutoCString leafName;
1378 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
1379 rv = profD->GetNativeLeafName(leafName);
1380 }
1381 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
1382 rv = directory->AppendNative(leafName);
1383 }
1384 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1385 directory = nullptr;
1386 }
1387 }
1388 }
1389#endif
1390
1391 if (!directory) {
1392 rv = NS_GetSpecialDirectory(NS_APP_CACHE_PARENT_DIR"cachePDir",
1393 getter_AddRefs(directory));
1394 }
1395
1396 if (!directory) {
1397 rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_LOCAL_50_DIR"ProfLD",
1398 getter_AddRefs(directory));
1399 }
1400
1401 if (directory) {
1402 rv = directory->Append(u"cache2"_ns);
1403 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/CacheFileIOManager.cpp"
, 1403); return rv; } } while (false)
;
1404 }
1405
1406 // All functions return a clone.
1407 ioMan->mCacheDirectory.swap(directory);
1408
1409#if defined(MOZ_WIDGET_ANDROID)
1410 if (profilelessDirectory) {
1411 rv = profilelessDirectory->Append(u"cache2"_ns);
1412 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/CacheFileIOManager.cpp"
, 1412); return rv; } } while (false)
;
1413 }
1414
1415 ioMan->mCacheProfilelessDirectory.swap(profilelessDirectory);
1416#endif
1417
1418 if (ioMan->mCacheDirectory) {
1419 CacheIndex::Init(ioMan->mCacheDirectory);
1420 }
1421
1422 return NS_OK;
1423}
1424
1425static bool inBackgroundTask() {
1426 MOZ_ASSERT(NS_IsMainThread(), "backgroundtasks are main thread only")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()"
" (" "backgroundtasks are main thread only" ")", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 1426); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
") (" "backgroundtasks are main thread only" ")"); do { MOZ_CrashSequence
(__null, 1426); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1427#if defined(MOZ_BACKGROUNDTASKS1)
1428 nsCOMPtr<nsIBackgroundTasks> backgroundTaskService =
1429 do_GetService("@mozilla.org/backgroundtasks;1");
1430 if (!backgroundTaskService) {
1431 return false;
1432 }
1433 bool isBackgroundTask = false;
1434 backgroundTaskService->GetIsBackgroundTaskMode(&isBackgroundTask);
1435 return isBackgroundTask;
1436#else
1437 return false;
1438#endif
1439}
1440
1441// static
1442nsresult CacheFileIOManager::OnDelayedStartupFinished() {
1443 // If we don't clear the cache at shutdown, or we don't use a
1444 // background task then there's no need to dispatch a cleanup task
1445 // at startup
1446 if (!CacheObserver::ClearCacheOnShutdown()) {
1447 return NS_OK;
1448 }
1449 if (!StaticPrefs::network_cache_shutdown_purge_in_background_task()) {
1450 return NS_OK;
1451 }
1452
1453 // If this is a background task already, there's no need to
1454 // dispatch another one.
1455 if (inBackgroundTask()) {
1456 return NS_OK;
1457 }
1458
1459 RefPtr<CacheFileIOManager> ioMan = gInstance;
1460 nsCOMPtr<nsIEventTarget> target = IOTarget();
1461 if (NS_WARN_IF(!ioMan || !target)NS_warn_if_impl(!ioMan || !target, "!ioMan || !target", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 1461)
) {
1462 return NS_ERROR_NOT_AVAILABLE;
1463 }
1464
1465 return target->Dispatch(
1466 NS_NewRunnableFunction("CacheFileIOManager::OnDelayedStartupFinished",
1467 [ioMan = std::move(ioMan)] {
1468 ioMan->DispatchPurgeTask(""_ns, "0"_ns,
1469 kPurgeExtension);
1470 }),
1471 nsIEventTarget::DISPATCH_NORMAL);
1472}
1473
1474// static
1475nsresult CacheFileIOManager::OnIdleDaily() {
1476 // In case the background task process fails for some reason (bug 1848542)
1477 // We will remove the directories in the main process on a daily idle.
1478 if (!CacheObserver::ClearCacheOnShutdown()) {
1479 return NS_OK;
1480 }
1481 if (!StaticPrefs::network_cache_shutdown_purge_in_background_task()) {
1482 return NS_OK;
1483 }
1484
1485 RefPtr<CacheFileIOManager> ioMan = gInstance;
1486 nsCOMPtr<nsIFile> parentDir;
1487 nsresult rv = ioMan->mCacheDirectory->GetParent(getter_AddRefs(parentDir));
1488 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0))) || !parentDir) {
1489 return NS_OK;
1490 }
1491
1492 NS_DispatchBackgroundTask(
1493 NS_NewRunnableFunction(
1494 "CacheFileIOManager::CheckLeftoverFolders",
1495 [dir = std::move(parentDir)] {
1496 nsCOMPtr<nsIDirectoryEnumerator> directories;
1497 nsresult rv = dir->GetDirectoryEntries(getter_AddRefs(directories));
1498 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1499 return;
1500 }
1501 bool hasMoreElements = false;
1502 while (
1503 NS_SUCCEEDED(directories->HasMoreElements(&hasMoreElements))((bool)(__builtin_expect(!!(!NS_FAILED_impl(directories->HasMoreElements
(&hasMoreElements))), 1)))
&&
1504 hasMoreElements) {
1505 nsCOMPtr<nsIFile> subdir;
1506 rv = directories->GetNextFile(getter_AddRefs(subdir));
1507 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0))) || !subdir) {
1508 break;
1509 }
1510 nsAutoCString leafName;
1511 rv = subdir->GetNativeLeafName(leafName);
1512 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1513 continue;
1514 }
1515 if (leafName.Find(kPurgeExtension) != kNotFound) {
1516 mozilla::glean::networking::residual_cache_folder_count.Add(1);
1517 // A read-only entry anywhere in the folder makes both
1518 // DeleteFileW and RemoveDirectoryW fail with ACCESS_DENIED, so
1519 // clear the attribute and retry rather than leaving the folder
1520 // behind forever (bug 1882163).
1521 if (IOUtils::RemoveSync(subdir, /* aIgnoreAbsent */ true,
1522 /* aRecursive */ true,
1523 /* aRetryReadonly */ true)
1524 .isOk()) {
1525 mozilla::glean::networking::residual_cache_folder_removal
1526 .Get("success"_ns)
1527 .Add(1);
1528 } else {
1529 mozilla::glean::networking::residual_cache_folder_removal
1530 .Get("failure"_ns)
1531 .Add(1);
1532 }
1533 }
1534 }
1535
1536 return;
1537 }),
1538 NS_DISPATCH_EVENT_MAY_BLOCKnsIEventTarget::DISPATCH_EVENT_MAY_BLOCK);
1539
1540 return NS_OK;
1541}
1542
1543// static
1544already_AddRefed<nsIEventTarget> CacheFileIOManager::IOTarget() {
1545 nsCOMPtr<nsIEventTarget> target;
1546 if (gInstance && gInstance->mIOThread) {
1547 target = gInstance->mIOThread->Target();
1548 }
1549
1550 return target.forget();
1551}
1552
1553// static
1554already_AddRefed<CacheIOThread> CacheFileIOManager::IOThread() {
1555 RefPtr<CacheIOThread> thread;
1556 if (gInstance) {
1557 thread = gInstance->mIOThread;
1558 }
1559
1560 return thread.forget();
1561}
1562
1563// static
1564bool CacheFileIOManager::IsOnIOThread() {
1565 RefPtr<CacheFileIOManager> ioMan = gInstance;
1566 if (ioMan && ioMan->mIOThread) {
1567 return ioMan->mIOThread->IsCurrentThread();
1568 }
1569
1570 return false;
1571}
1572
1573// static
1574bool CacheFileIOManager::IsOnIOThreadOrCeased() {
1575 RefPtr<CacheFileIOManager> ioMan = gInstance;
1576 if (ioMan && ioMan->mIOThread) {
1577 return ioMan->mIOThread->IsCurrentThread();
1578 }
1579
1580 // Ceased...
1581 return true;
1582}
1583
1584// static
1585bool CacheFileIOManager::IsShutdown() {
1586 if (!gInstance) {
1587 return true;
1588 }
1589 return gInstance->mShuttingDown;
1590}
1591
1592// static
1593nsresult CacheFileIOManager::ScheduleMetadataWrite(CacheFile* aFile) {
1594 RefPtr<CacheFileIOManager> ioMan = gInstance;
1595 NS_ENSURE_TRUE(ioMan, NS_ERROR_NOT_INITIALIZED)do { if ((__builtin_expect(!!(!(ioMan)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "ioMan" ") failed", nullptr
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 1595); return
NS_ERROR_NOT_INITIALIZED; } } while (false)
;
1596
1597 NS_ENSURE_TRUE(!ioMan->mShuttingDown, NS_ERROR_NOT_INITIALIZED)do { if ((__builtin_expect(!!(!(!ioMan->mShuttingDown)), 0
))) { NS_DebugBreak(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "!ioMan->mShuttingDown"
") failed", nullptr, "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 1597); return NS_ERROR_NOT_INITIALIZED; } } while (false)
;
1598
1599 RefPtr<MetadataWriteScheduleEvent> event = new MetadataWriteScheduleEvent(
1600 ioMan, aFile, MetadataWriteScheduleEvent::SCHEDULE);
1601 nsCOMPtr<nsIEventTarget> target = ioMan->IOTarget();
1602 NS_ENSURE_TRUE(target, NS_ERROR_UNEXPECTED)do { if ((__builtin_expect(!!(!(target)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "target" ") failed", nullptr
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 1602); return
NS_ERROR_UNEXPECTED; } } while (false)
;
1603 return target->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL);
1604}
1605
1606nsresult CacheFileIOManager::ScheduleMetadataWriteInternal(CacheFile* aFile) {
1607 MOZ_ASSERT(IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(IsOnIOThreadOrCeased())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(IsOnIOThreadOrCeased()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("IsOnIOThreadOrCeased()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 1607); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "IsOnIOThreadOrCeased()" ")"); do { MOZ_CrashSequence
(__null, 1607); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1608
1609 nsresult rv;
1610
1611 if (!mMetadataWritesTimer) {
1612 rv = NS_NewTimerWithCallback(getter_AddRefs(mMetadataWritesTimer), this,
1613 kMetadataWriteDelay5000, nsITimer::TYPE_ONE_SHOT);
1614 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/CacheFileIOManager.cpp"
, 1614); return rv; } } while (false)
;
1615 }
1616
1617 if (mScheduledMetadataWrites.IndexOf(aFile) !=
1618 nsTArray<RefPtr<mozilla::net::CacheFile>>::NoIndex) {
1619 return NS_OK;
1620 }
1621
1622 mScheduledMetadataWrites.AppendElement(aFile);
1623
1624 return NS_OK;
1625}
1626
1627// static
1628nsresult CacheFileIOManager::UnscheduleMetadataWrite(CacheFile* aFile) {
1629 RefPtr<CacheFileIOManager> ioMan = gInstance;
1630 NS_ENSURE_TRUE(ioMan, NS_ERROR_NOT_INITIALIZED)do { if ((__builtin_expect(!!(!(ioMan)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "ioMan" ") failed", nullptr
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 1630); return
NS_ERROR_NOT_INITIALIZED; } } while (false)
;
1631
1632 NS_ENSURE_TRUE(!ioMan->mShuttingDown, NS_ERROR_NOT_INITIALIZED)do { if ((__builtin_expect(!!(!(!ioMan->mShuttingDown)), 0
))) { NS_DebugBreak(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "!ioMan->mShuttingDown"
") failed", nullptr, "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 1632); return NS_ERROR_NOT_INITIALIZED; } } while (false)
;
1633
1634 RefPtr<MetadataWriteScheduleEvent> event = new MetadataWriteScheduleEvent(
1635 ioMan, aFile, MetadataWriteScheduleEvent::UNSCHEDULE);
1636 nsCOMPtr<nsIEventTarget> target = ioMan->IOTarget();
1637 NS_ENSURE_TRUE(target, NS_ERROR_UNEXPECTED)do { if ((__builtin_expect(!!(!(target)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "target" ") failed", nullptr
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 1637); return
NS_ERROR_UNEXPECTED; } } while (false)
;
1638 return target->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL);
1639}
1640
1641void CacheFileIOManager::UnscheduleMetadataWriteInternal(CacheFile* aFile) {
1642 MOZ_ASSERT(IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(IsOnIOThreadOrCeased())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(IsOnIOThreadOrCeased()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("IsOnIOThreadOrCeased()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 1642); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "IsOnIOThreadOrCeased()" ")"); do { MOZ_CrashSequence
(__null, 1642); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1643
1644 mScheduledMetadataWrites.RemoveElement(aFile);
1645
1646 if (mScheduledMetadataWrites.Length() == 0 && mMetadataWritesTimer) {
1647 mMetadataWritesTimer->Cancel();
1648 mMetadataWritesTimer = nullptr;
1649 }
1650}
1651
1652// static
1653nsresult CacheFileIOManager::ShutdownMetadataWriteScheduling() {
1654 RefPtr<CacheFileIOManager> ioMan = gInstance;
1655 NS_ENSURE_TRUE(ioMan, NS_ERROR_NOT_INITIALIZED)do { if ((__builtin_expect(!!(!(ioMan)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "ioMan" ") failed", nullptr
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 1655); return
NS_ERROR_NOT_INITIALIZED; } } while (false)
;
1656
1657 RefPtr<MetadataWriteScheduleEvent> event = new MetadataWriteScheduleEvent(
1658 ioMan, nullptr, MetadataWriteScheduleEvent::SHUTDOWN);
1659 nsCOMPtr<nsIEventTarget> target = ioMan->IOTarget();
1660 NS_ENSURE_TRUE(target, NS_ERROR_UNEXPECTED)do { if ((__builtin_expect(!!(!(target)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "target" ") failed", nullptr
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 1660); return
NS_ERROR_UNEXPECTED; } } while (false)
;
1661 return target->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL);
1662}
1663
1664void CacheFileIOManager::ShutdownMetadataWriteSchedulingInternal() {
1665 MOZ_ASSERT(IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(IsOnIOThreadOrCeased())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(IsOnIOThreadOrCeased()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("IsOnIOThreadOrCeased()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 1665); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "IsOnIOThreadOrCeased()" ")"); do { MOZ_CrashSequence
(__null, 1665); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1666
1667 nsTArray<RefPtr<CacheFile>> files = std::move(mScheduledMetadataWrites);
1668 for (uint32_t i = 0; i < files.Length(); ++i) {
1669 CacheFile* file = files[i];
1670 file->WriteMetadataIfNeeded();
1671 }
1672
1673 if (mMetadataWritesTimer) {
1674 mMetadataWritesTimer->Cancel();
1675 mMetadataWritesTimer = nullptr;
1676 }
1677}
1678
1679NS_IMETHODIMPnsresult
1680CacheFileIOManager::Notify(nsITimer* aTimer) {
1681 MOZ_ASSERT(IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(IsOnIOThreadOrCeased())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(IsOnIOThreadOrCeased()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("IsOnIOThreadOrCeased()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 1681); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "IsOnIOThreadOrCeased()" ")"); do { MOZ_CrashSequence
(__null, 1681); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1682 MOZ_ASSERT(mMetadataWritesTimer == aTimer)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mMetadataWritesTimer == aTimer)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mMetadataWritesTimer == aTimer
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"mMetadataWritesTimer == aTimer", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 1682); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mMetadataWritesTimer == aTimer"
")"); do { MOZ_CrashSequence(__null, 1682); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1683
1684 mMetadataWritesTimer = nullptr;
1685
1686 nsTArray<RefPtr<CacheFile>> files = std::move(mScheduledMetadataWrites);
1687 for (uint32_t i = 0; i < files.Length(); ++i) {
1688 CacheFile* file = files[i];
1689 file->WriteMetadataIfNeeded();
1690 }
1691
1692 return NS_OK;
1693}
1694
1695NS_IMETHODIMPnsresult
1696CacheFileIOManager::GetName(nsACString& aName) {
1697 aName.AssignLiteral("CacheFileIOManager");
1698 return NS_OK;
1699}
1700
1701// static
1702nsresult CacheFileIOManager::OpenFile(const nsACString& aKey, uint32_t aFlags,
1703 CacheFileIOListener* aCallback) {
1704 LOG(("CacheFileIOManager::OpenFile() [key=%s, flags=%d, listener=%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, "CacheFileIOManager::OpenFile() [key=%s, flags=%d, listener=%p]"
, TPromiseFlatString<char>(aKey).get(), aFlags, aCallback
); } } while (0)
1705 PromiseFlatCString(aKey).get(), aFlags, aCallback))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenFile() [key=%s, flags=%d, listener=%p]"
, TPromiseFlatString<char>(aKey).get(), aFlags, aCallback
); } } while (0)
;
1706
1707 nsresult rv;
1708 RefPtr<CacheFileIOManager> ioMan = gInstance;
1709
1710 if (!ioMan) {
1711 return NS_ERROR_NOT_INITIALIZED;
1712 }
1713
1714 bool priority = aFlags & CacheFileIOManager::PRIORITY;
1715 RefPtr<OpenFileEvent> ev = new OpenFileEvent(aKey, aFlags, aCallback);
1716 rv = ioMan->mIOThread->Dispatch(
1717 ev, priority ? CacheIOThread::OPEN_PRIORITY : CacheIOThread::OPEN);
1718 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/CacheFileIOManager.cpp"
, 1718); return rv; } } while (false)
;
1719
1720 return NS_OK;
1721}
1722
1723nsresult CacheFileIOManager::OpenFileInternal(const SHA1Sum::Hash* aHash,
1724 const nsACString& aKey,
1725 uint32_t aFlags,
1726 CacheFileHandle** _retval) {
1727 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, "CacheFileIOManager::OpenFileInternal() [hash=%08x%08x%08x%08x%08x, "
"key=%s, flags=%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()
, aFlags); } } while (0)
1728 ("CacheFileIOManager::OpenFileInternal() [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, "CacheFileIOManager::OpenFileInternal() [hash=%08x%08x%08x%08x%08x, "
"key=%s, flags=%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()
, aFlags); } } while (0)
1729 "key=%s, flags=%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, "CacheFileIOManager::OpenFileInternal() [hash=%08x%08x%08x%08x%08x, "
"key=%s, flags=%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()
, aFlags); } } while (0)
1730 LOGSHA1(aHash), PromiseFlatCString(aKey).get(), aFlags))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenFileInternal() [hash=%08x%08x%08x%08x%08x, "
"key=%s, flags=%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()
, aFlags); } } while (0)
;
1731
1732 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/CacheFileIOManager.cpp"
, 1732); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()"
")"); do { MOZ_CrashSequence(__null, 1732); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1733
1734 nsresult rv;
1735
1736 if (mShuttingDown) {
1737 return NS_ERROR_NOT_INITIALIZED;
1738 }
1739
1740 CacheIOThread::Cancelable cancelable(
1741 true /* never called for special handles */);
1742
1743 if (!mTreeCreated) {
1744 rv = CreateCacheTree();
1745 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
1746 }
1747
1748 CacheFileHandle::PinningStatus pinning =
1749 aFlags & PINNED ? CacheFileHandle::PinningStatus::PINNED
1750 : CacheFileHandle::PinningStatus::NON_PINNED;
1751
1752 nsCOMPtr<nsIFile> file;
1753 rv = GetFile(aHash, getter_AddRefs(file));
1754 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/CacheFileIOManager.cpp"
, 1754); return rv; } } while (false)
;
1755
1756 RefPtr<CacheFileHandle> handle;
1757 mHandles.GetHandle(aHash, getter_AddRefs(handle));
1758
1759 if ((aFlags & (OPEN | CREATE | CREATE_NEW)) == CREATE_NEW) {
1760 if (handle) {
1761 rv = DoomFileInternal(handle);
1762 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/CacheFileIOManager.cpp"
, 1762); return rv; } } while (false)
;
1763 handle = nullptr;
1764 }
1765
1766 handle = mHandles.NewHandle(aHash, aFlags & PRIORITY, pinning);
1767
1768 bool exists;
1769 rv = file->Exists(&exists);
1770 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/CacheFileIOManager.cpp"
, 1770); return rv; } } while (false)
;
1771
1772 if (exists) {
1773 CacheIndex::RemoveEntry(aHash, handle->Key());
1774
1775 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, "CacheFileIOManager::OpenFileInternal() - Removing old file from "
"disk"); } } while (0)
1776 ("CacheFileIOManager::OpenFileInternal() - Removing old file from "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenFileInternal() - Removing old file from "
"disk"); } } while (0)
1777 "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, "CacheFileIOManager::OpenFileInternal() - Removing old file from "
"disk"); } } while (0)
;
1778 rv = file->Remove(false);
1779 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1780 NS_WARNING("Cannot remove old entry from the disk")NS_DebugBreak(NS_DEBUG_WARNING, "Cannot remove old entry from the disk"
, nullptr, "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 1780)
;
1781 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, "CacheFileIOManager::OpenFileInternal() - Removing old file failed"
". [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } }
while (0)
1782 ("CacheFileIOManager::OpenFileInternal() - Removing old file 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, "CacheFileIOManager::OpenFileInternal() - Removing old file failed"
". [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } }
while (0)
1783 ". [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, "CacheFileIOManager::OpenFileInternal() - Removing old file failed"
". [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } }
while (0)
1784 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, "CacheFileIOManager::OpenFileInternal() - Removing old file failed"
". [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } }
while (0)
;
1785 }
1786 }
1787
1788 CacheIndex::AddEntry(aHash);
1789 handle->mFile.swap(file);
1790 handle->mFileSize = 0;
1791 }
1792
1793 if (handle) {
1794 handle.swap(*_retval);
1795 return NS_OK;
1796 }
1797
1798 bool exists, evictedAsPinned = false, evictedAsNonPinned = false;
1799 rv = file->Exists(&exists);
1800 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/CacheFileIOManager.cpp"
, 1800); return rv; } } while (false)
;
1801
1802 if (exists && mContextEvictor) {
1803 if (mContextEvictor->ContextsCount() == 0) {
1804 mContextEvictor = nullptr;
1805 } else {
1806 mContextEvictor->WasEvicted(aKey, file, &evictedAsPinned,
1807 &evictedAsNonPinned);
1808 }
1809 }
1810
1811 if (!exists && (aFlags & (OPEN | CREATE | CREATE_NEW)) == OPEN) {
1812 return NS_ERROR_NOT_AVAILABLE;
1813 }
1814
1815 if (exists) {
1816 // For existing files we determine the pinning status later, after the
1817 // metadata gets parsed.
1818 pinning = CacheFileHandle::PinningStatus::UNKNOWN;
1819 }
1820
1821 handle = mHandles.NewHandle(aHash, aFlags & PRIORITY, pinning);
1822 if (exists) {
1823 // If this file has been found evicted through the context file evictor
1824 // above for any of pinned or non-pinned state, these calls ensure we doom
1825 // the handle ASAP we know the real pinning state after metadata has been
1826 // parsed. DoomFileInternal on the |handle| doesn't doom right now, since
1827 // the pinning state is unknown and we pass down a pinning restriction.
1828 if (evictedAsPinned) {
1829 rv = DoomFileInternal(handle, DOOM_WHEN_PINNED);
1830 MOZ_ASSERT(!handle->IsDoomed() && NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!handle->IsDoomed() && ((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!handle->IsDoomed() &&
((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("!handle->IsDoomed() && ((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 1830); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!handle->IsDoomed() && ((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { MOZ_CrashSequence(__null, 1830); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1831 }
1832 if (evictedAsNonPinned) {
1833 rv = DoomFileInternal(handle, DOOM_WHEN_NON_PINNED);
1834 MOZ_ASSERT(!handle->IsDoomed() && NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!handle->IsDoomed() && ((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!handle->IsDoomed() &&
((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("!handle->IsDoomed() && ((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 1834); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!handle->IsDoomed() && ((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { MOZ_CrashSequence(__null, 1834); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1835 }
1836
1837 int64_t fileSize = -1;
1838 rv = file->GetFileSize(&fileSize);
1839 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/CacheFileIOManager.cpp"
, 1839); return rv; } } while (false)
;
1840
1841 handle->mFileSize = fileSize;
1842 handle->mFileExists = true;
1843
1844 CacheIndex::EnsureEntryExists(aHash);
1845 } else {
1846 handle->mFileSize = 0;
1847
1848 CacheIndex::AddEntry(aHash);
1849 }
1850
1851 handle->mFile.swap(file);
1852 handle.swap(*_retval);
1853 return NS_OK;
1854}
1855
1856nsresult CacheFileIOManager::OpenSpecialFileInternal(
1857 const nsACString& aKey, uint32_t aFlags, CacheFileHandle** _retval) {
1858 LOG(("CacheFileIOManager::OpenSpecialFileInternal() [key=%s, flags=%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, "CacheFileIOManager::OpenSpecialFileInternal() [key=%s, flags=%d]"
, TPromiseFlatString<char>(aKey).get(), aFlags); } } while
(0)
1859 PromiseFlatCString(aKey).get(), aFlags))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenSpecialFileInternal() [key=%s, flags=%d]"
, TPromiseFlatString<char>(aKey).get(), aFlags); } } while
(0)
;
1860
1861 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/CacheFileIOManager.cpp"
, 1861); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()"
")"); do { MOZ_CrashSequence(__null, 1861); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1862
1863 nsresult rv;
1864
1865 if (mShuttingDown) {
1866 return NS_ERROR_NOT_INITIALIZED;
1867 }
1868
1869 if (!mTreeCreated) {
1870 rv = CreateCacheTree();
1871 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) return rv;
1872 }
1873
1874 nsCOMPtr<nsIFile> file;
1875 rv = GetSpecialFile(aKey, getter_AddRefs(file));
1876 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/CacheFileIOManager.cpp"
, 1876); return rv; } } while (false)
;
1877
1878 RefPtr<CacheFileHandle> handle;
1879 for (uint32_t i = 0; i < mSpecialHandles.Length(); i++) {
1880 if (!mSpecialHandles[i]->IsDoomed() && mSpecialHandles[i]->Key() == aKey) {
1881 handle = mSpecialHandles[i];
1882 break;
1883 }
1884 }
1885
1886 if ((aFlags & (OPEN | CREATE | CREATE_NEW)) == CREATE_NEW) {
1887 if (handle) {
1888 rv = DoomFileInternal(handle);
1889 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/CacheFileIOManager.cpp"
, 1889); return rv; } } while (false)
;
1890 handle = nullptr;
1891 }
1892
1893 handle = new CacheFileHandle(aKey, aFlags & PRIORITY,
1894 CacheFileHandle::PinningStatus::NON_PINNED);
1895 mSpecialHandles.AppendElement(handle);
1896
1897 bool exists;
1898 rv = file->Exists(&exists);
1899 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/CacheFileIOManager.cpp"
, 1899); return rv; } } while (false)
;
1900
1901 if (exists) {
1902 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, "CacheFileIOManager::OpenSpecialFileInternal() - Removing file from "
"disk"); } } while (0)
1903 ("CacheFileIOManager::OpenSpecialFileInternal() - Removing file from "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenSpecialFileInternal() - Removing file from "
"disk"); } } while (0)
1904 "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, "CacheFileIOManager::OpenSpecialFileInternal() - Removing file from "
"disk"); } } while (0)
;
1905 rv = file->Remove(false);
1906 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1907 NS_WARNING("Cannot remove old entry from the disk")NS_DebugBreak(NS_DEBUG_WARNING, "Cannot remove old entry from the disk"
, nullptr, "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 1907)
;
1908 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, "CacheFileIOManager::OpenSpecialFileInternal() - Removing file "
"failed. [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)
); } } while (0)
1909 ("CacheFileIOManager::OpenSpecialFileInternal() - 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, "CacheFileIOManager::OpenSpecialFileInternal() - Removing file "
"failed. [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)
); } } while (0)
1910 "failed. [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, "CacheFileIOManager::OpenSpecialFileInternal() - Removing file "
"failed. [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)
); } } while (0)
1911 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, "CacheFileIOManager::OpenSpecialFileInternal() - Removing file "
"failed. [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)
); } } while (0)
;
1912 }
1913 }
1914
1915 handle->mFile.swap(file);
1916 handle->mFileSize = 0;
1917 }
1918
1919 if (handle) {
1920 handle.swap(*_retval);
1921 return NS_OK;
1922 }
1923
1924 bool exists;
1925 rv = file->Exists(&exists);
1926 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/CacheFileIOManager.cpp"
, 1926); return rv; } } while (false)
;
1927
1928 if (!exists && (aFlags & (OPEN | CREATE | CREATE_NEW)) == OPEN) {
1929 return NS_ERROR_NOT_AVAILABLE;
1930 }
1931
1932 handle = new CacheFileHandle(aKey, aFlags & PRIORITY,
1933 CacheFileHandle::PinningStatus::NON_PINNED);
1934 mSpecialHandles.AppendElement(handle);
1935
1936 if (exists) {
1937 int64_t fileSize = -1;
1938 rv = file->GetFileSize(&fileSize);
1939 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/CacheFileIOManager.cpp"
, 1939); return rv; } } while (false)
;
1940
1941 handle->mFileSize = fileSize;
1942 handle->mFileExists = true;
1943 } else {
1944 handle->mFileSize = 0;
1945 }
1946
1947 handle->mFile.swap(file);
1948 handle.swap(*_retval);
1949 return NS_OK;
1950}
1951
1952void CacheFileIOManager::CloseHandleInternal(CacheFileHandle* aHandle) {
1953 nsresult rv;
1954 LOG(("CacheFileIOManager::CloseHandleInternal() [handle=%p]", 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, "CacheFileIOManager::CloseHandleInternal() [handle=%p]"
, aHandle); } } while (0)
;
1955
1956 MOZ_ASSERT(!aHandle->IsClosed())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!aHandle->IsClosed())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!aHandle->IsClosed()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("!aHandle->IsClosed()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 1956); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!aHandle->IsClosed()" ")"); do { MOZ_CrashSequence
(__null, 1956); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1957
1958 aHandle->Log();
1959
1960 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 1960); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { MOZ_CrashSequence(__null, 1960); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1961
1962 CacheIOThread::Cancelable cancelable(!aHandle->IsSpecialFile());
1963
1964 // Maybe close file handle (can be legally bypassed after shutdown)
1965 rv = MaybeReleaseNSPRHandleInternal(aHandle);
1966
1967 // Delete the file if the entry was doomed or invalid and
1968 // filedesc properly closed
1969 if ((aHandle->mIsDoomed || aHandle->mInvalid) && aHandle->mFileExists &&
1970 NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
1971 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, "CacheFileIOManager::CloseHandleInternal() - Removing file from "
"disk"); } } while (0)
1972 ("CacheFileIOManager::CloseHandleInternal() - Removing file from "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::CloseHandleInternal() - Removing file from "
"disk"); } } while (0)
1973 "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, "CacheFileIOManager::CloseHandleInternal() - Removing file from "
"disk"); } } while (0)
;
1974
1975 rv = aHandle->mFile->Remove(false);
1976 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
1977 aHandle->mFileExists = false;
1978 } else {
1979 LOG((" failed to remove the file [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, " failed to remove the file [rv=0x%08"
"x" "]", static_cast<uint32_t>(rv)); } } while (0)
1980 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, " failed to remove the file [rv=0x%08"
"x" "]", static_cast<uint32_t>(rv)); } } while (0)
;
1981 }
1982 }
1983
1984 if (!aHandle->IsSpecialFile() && !aHandle->mIsDoomed &&
1985 (aHandle->mInvalid || !aHandle->mFileExists)) {
1986 CacheIndex::RemoveEntry(aHandle->Hash(), aHandle->Key());
1987 }
1988
1989 // Don't remove handles after shutdown
1990 if (!mShuttingDown) {
1991 if (aHandle->IsSpecialFile()) {
1992 mSpecialHandles.RemoveElement(aHandle);
1993 } else {
1994 mHandles.RemoveHandle(aHandle);
1995 }
1996 }
1997}
1998
1999// static
2000nsresult CacheFileIOManager::Read(CacheFileHandle* aHandle, int64_t aOffset,
2001 char* aBuf, int32_t aCount,
2002 CacheFileIOListener* aCallback) {
2003 LOG(("CacheFileIOManager::Read() [handle=%p, offset=%" PRId64 ", count=%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, "CacheFileIOManager::Read() [handle=%p, offset=%"
"l" "d" ", count=%d, " "listener=%p]", aHandle, aOffset, aCount
, aCallback); } } while (0)
2004 "listener=%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, "CacheFileIOManager::Read() [handle=%p, offset=%"
"l" "d" ", count=%d, " "listener=%p]", aHandle, aOffset, aCount
, aCallback); } } while (0)
2005 aHandle, aOffset, aCount, aCallback))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::Read() [handle=%p, offset=%"
"l" "d" ", count=%d, " "listener=%p]", aHandle, aOffset, aCount
, aCallback); } } while (0)
;
2006
2007 if (CacheObserver::ShuttingDown()) {
2008 LOG((" no reads after shutdown"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " no reads after shutdown"
); } } while (0)
;
2009 return NS_ERROR_NOT_INITIALIZED;
2010 }
2011
2012 if (!aHandle) {
2013 return NS_ERROR_NULL_POINTER;
2014 }
2015
2016 nsresult rv;
2017 RefPtr<CacheFileIOManager> ioMan = gInstance;
2018
2019 if (aHandle->IsClosed() || !ioMan) {
2020 return NS_ERROR_NOT_INITIALIZED;
2021 }
2022
2023 RefPtr<ReadEvent> ev =
2024 new ReadEvent(aHandle, aOffset, aBuf, aCount, aCallback);
2025#if defined(MOZ_CACHE_ASYNC_IO1)
2026 if (IsOnIOThread()) {
2027 // If we are already on the IO thread, we can run the event
2028 // inline. However, preserve the behavior that OnDataRead will be
2029 // called async when read operation is unsucessful in case the
2030 // caller relies this assumption.
2031 ev->InlineRun(true);
2032 return NS_OK;
2033 }
2034#endif
2035
2036 rv = ioMan->mIOThread->Dispatch(ev, aHandle->IsPriority()
2037 ? CacheIOThread::READ_PRIORITY
2038 : CacheIOThread::READ);
2039 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/CacheFileIOManager.cpp"
, 2039); return rv; } } while (false)
;
2040
2041 return NS_OK;
2042}
2043
2044nsresult CacheFileIOManager::ReadInternal(CacheFileHandle* aHandle,
2045 int64_t aOffset, char* aBuf,
2046 int32_t aCount,
2047 ReadEvent* aReadEvent) {
2048 LOG(("CacheFileIOManager::ReadInternal() [handle=%p, offset=%" PRId64do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::ReadInternal() [handle=%p, offset=%"
"l" "d" ", count=%d]", aHandle, aOffset, aCount); } } while (
0)
2049 ", count=%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, "CacheFileIOManager::ReadInternal() [handle=%p, offset=%"
"l" "d" ", count=%d]", aHandle, aOffset, aCount); } } while (
0)
2050 aHandle, aOffset, aCount))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::ReadInternal() [handle=%p, offset=%"
"l" "d" ", count=%d]", aHandle, aOffset, aCount); } } while (
0)
;
2051
2052 nsresult rv;
2053
2054 if (CacheObserver::ShuttingDown()) {
2055 LOG((" no reads after shutdown"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " no reads after shutdown"
); } } while (0)
;
2056 return NS_ERROR_NOT_INITIALIZED;
2057 }
2058
2059 if (!aHandle->mFileExists) {
2060 NS_WARNING("Trying to read from non-existent file")NS_DebugBreak(NS_DEBUG_WARNING, "Trying to read from non-existent file"
, nullptr, "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 2060)
;
2061 return NS_ERROR_NOT_AVAILABLE;
2062 }
2063
2064 CacheIOThread::Cancelable cancelable(!aHandle->IsSpecialFile());
2065
2066 if (!aHandle->mFD) {
2067 rv = OpenNSPRHandle(aHandle);
2068 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/CacheFileIOManager.cpp"
, 2068); return rv; } } while (false)
;
2069 } else {
2070 NSPRHandleUsed(aHandle);
2071 }
2072
2073 // Check again, OpenNSPRHandle could figure out the file was gone.
2074 if (!aHandle->mFileExists) {
2075 NS_WARNING("Trying to read from non-existent file")NS_DebugBreak(NS_DEBUG_WARNING, "Trying to read from non-existent file"
, nullptr, "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 2075)
;
2076 return NS_ERROR_NOT_AVAILABLE;
2077 }
2078
2079 MOZ_ASSERT(aOffset + aCount <= aHandle->mFileSize)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aOffset + aCount <= aHandle->mFileSize)>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(aOffset + aCount <= aHandle->mFileSize))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("aOffset + aCount <= aHandle->mFileSize"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 2079); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "aOffset + aCount <= aHandle->mFileSize"
")"); do { MOZ_CrashSequence(__null, 2079); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2080
2081#if !defined(MOZ_CACHE_ASYNC_IO1)
2082 int64_t offset = PR_Seek64(aHandle->mFD, aOffset, PR_SEEK_SET);
2083 if (offset == -1) {
2084 return NS_ERROR_FAILURE;
2085 }
2086
2087 int32_t bytesRead = PR_Read(aHandle->mFD, aBuf, aCount);
2088 if (bytesRead != aCount) {
2089 return NS_ERROR_FAILURE;
2090 }
2091#else
2092 PRFileDesc* fd;
2093 AutoFDClose autoFd;
2094
2095 if (!aHandle->IsAsyncOperationRunning()) {
2096 // If the handle is not running an async operation, we can use the
2097 // file descriptor directly without extra file open operation.
2098 fd = aHandle->mFD;
2099 } else {
2100 PRFileDesc* rawFd = nullptr;
2101 rv = aHandle->mFile->OpenNSPRFileDesc(PR_RDONLY0x01, 0600, &rawFd);
2102 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2103 return NS_ERROR_FAILURE;
2104 }
2105
2106 // Assign the raw pointer to AutoFDClose
2107 autoFd.reset(rawFd);
2108 fd = autoFd.get();
2109 }
2110
2111 nsCOMPtr<nsIEventTarget> target =
2112 do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID"@mozilla.org/network/stream-transport-service;1", &rv);
2113 MOZ_ASSERT(target)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(target)>::isValid, "invalid assertion condition")
; if ((__builtin_expect(!!(!(!!(target))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("target", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 2113); AnnotateMozCrashReason("MOZ_ASSERT" "(" "target" ")"
); do { MOZ_CrashSequence(__null, 2113); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2114 const bool isPriority = aHandle->IsPriority();
2115 rv = target->Dispatch(
2116 NS_NewRunnableFunction(
2117 "CacheFileIOManager::ReadInternal",
2118 [fd, autoFd = std::move(autoFd), aBuf, aCount, aOffset,
2119 readevent = RefPtr(aReadEvent), isPriority]() mutable {
2120 nsresult rv = NS_OK;
2121 int64_t offset = PR_Seek64(fd, aOffset, PR_SEEK_SET);
2122 if (offset == -1) {
2123 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, "CacheFileIOManager::ReadInternal() - PR_Seek64 failed "
"[offset=%d]\n", static_cast<int32_t>(aOffset)); } } while
(0)
2124 ("CacheFileIOManager::ReadInternal() - PR_Seek64 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, "CacheFileIOManager::ReadInternal() - PR_Seek64 failed "
"[offset=%d]\n", static_cast<int32_t>(aOffset)); } } while
(0)
2125 "[offset=%d]\n",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::ReadInternal() - PR_Seek64 failed "
"[offset=%d]\n", static_cast<int32_t>(aOffset)); } } while
(0)
2126 static_cast<int32_t>(aOffset)))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::ReadInternal() - PR_Seek64 failed "
"[offset=%d]\n", static_cast<int32_t>(aOffset)); } } while
(0)
;
2127 rv = NS_ERROR_FAILURE;
2128 }
2129
2130 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
2131 int32_t bytesRead = PR_Read(fd, aBuf, aCount);
2132 if (bytesRead != aCount) {
2133 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, "CacheFileIOManager::ReadInternal() - PR_Read failed "
"[bytesRead=%d]\n", bytesRead); } } while (0)
2134 ("CacheFileIOManager::ReadInternal() - PR_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, "CacheFileIOManager::ReadInternal() - PR_Read failed "
"[bytesRead=%d]\n", bytesRead); } } while (0)
2135 "[bytesRead=%d]\n",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::ReadInternal() - PR_Read failed "
"[bytesRead=%d]\n", bytesRead); } } while (0)
2136 bytesRead))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::ReadInternal() - PR_Read failed "
"[bytesRead=%d]\n", bytesRead); } } while (0)
;
2137 rv = NS_ERROR_FAILURE;
2138 }
2139 }
2140
2141 // Post completion back to the cache IO thread at the READ level,
2142 // so that test suspensions at READ properly block completion.
2143 DebugOnly<nsresult> rv_dispatch = gInstance->mIOThread->Dispatch(
2144 NewRunnableMethod<nsresult>(
2145 "CacheFileIOManager::ReadEvent::OnComplete", readevent,
2146 &ReadEvent::OnComplete, rv),
2147 isPriority ? CacheIOThread::READ_PRIORITY
2148 : CacheIOThread::READ);
2149
2150 MOZ_ASSERT(NS_SUCCEEDED(rv_dispatch))do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv_dispatch
)), 1))))>::isValid, "invalid assertion condition"); if ((
__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl
(rv_dispatch)), 1)))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv_dispatch)), 1)))"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 2150); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv_dispatch)), 1)))"
")"); do { MOZ_CrashSequence(__null, 2150); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2151 }),
2152 NS_DISPATCH_NORMALnsIEventTarget::DISPATCH_NORMAL);
2153 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/CacheFileIOManager.cpp"
, 2153); return rv; } } while (false)
;
2154
2155 aHandle->StartAsyncOperation();
2156#endif
2157
2158 return NS_OK;
2159}
2160
2161// static
2162nsresult CacheFileIOManager::Write(CacheFileHandle* aHandle, int64_t aOffset,
2163 const char* aBuf, int32_t aCount,
2164 bool aValidate, bool aTruncate,
2165 CacheFileIOListener* aCallback) {
2166 LOG(("CacheFileIOManager::Write() [handle=%p, offset=%" PRId64 ", count=%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, "CacheFileIOManager::Write() [handle=%p, offset=%"
"l" "d" ", count=%d, " "validate=%d, truncate=%d, listener=%p]"
, aHandle, aOffset, aCount, aValidate, aTruncate, aCallback);
} } while (0)
2167 "validate=%d, truncate=%d, listener=%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, "CacheFileIOManager::Write() [handle=%p, offset=%"
"l" "d" ", count=%d, " "validate=%d, truncate=%d, listener=%p]"
, aHandle, aOffset, aCount, aValidate, aTruncate, aCallback);
} } while (0)
2168 aHandle, aOffset, aCount, aValidate, aTruncate, aCallback))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::Write() [handle=%p, offset=%"
"l" "d" ", count=%d, " "validate=%d, truncate=%d, listener=%p]"
, aHandle, aOffset, aCount, aValidate, aTruncate, aCallback);
} } while (0)
;
2169
2170 MOZ_ASSERT(aCallback)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aCallback)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aCallback))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aCallback", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 2170); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aCallback" ")"
); do { MOZ_CrashSequence(__null, 2170); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2171
2172 RefPtr<CacheFileIOManager> ioMan = gInstance;
2173
2174 if (aHandle->IsClosed() || aCallback->IsKilled() || !ioMan) {
2175 return NS_ERROR_NOT_INITIALIZED;
2176 }
2177
2178 RefPtr<WriteEvent> ev = new WriteEvent(aHandle, aOffset, aBuf, aCount,
2179 aValidate, aTruncate, aCallback);
2180 return ioMan->mIOThread->Dispatch(ev, aHandle->mPriority
2181 ? CacheIOThread::WRITE_PRIORITY
2182 : CacheIOThread::WRITE);
2183}
2184
2185// static
2186nsresult CacheFileIOManager::WriteWithoutCallback(CacheFileHandle* aHandle,
2187 int64_t aOffset, char* aBuf,
2188 int32_t aCount,
2189 bool aValidate,
2190 bool aTruncate) {
2191 LOG(("CacheFileIOManager::WriteWithoutCallback() [handle=%p, offset=%" PRId64do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteWithoutCallback() [handle=%p, offset=%"
"l" "d" ", count=%d, " "validate=%d, truncate=%d]", aHandle,
aOffset, aCount, aValidate, aTruncate); } } while (0)
2192 ", count=%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, "CacheFileIOManager::WriteWithoutCallback() [handle=%p, offset=%"
"l" "d" ", count=%d, " "validate=%d, truncate=%d]", aHandle,
aOffset, aCount, aValidate, aTruncate); } } while (0)
2193 "validate=%d, truncate=%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, "CacheFileIOManager::WriteWithoutCallback() [handle=%p, offset=%"
"l" "d" ", count=%d, " "validate=%d, truncate=%d]", aHandle,
aOffset, aCount, aValidate, aTruncate); } } while (0)
2194 aHandle, aOffset, aCount, aValidate, aTruncate))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteWithoutCallback() [handle=%p, offset=%"
"l" "d" ", count=%d, " "validate=%d, truncate=%d]", aHandle,
aOffset, aCount, aValidate, aTruncate); } } while (0)
;
2195
2196 RefPtr<CacheFileIOManager> ioMan = gInstance;
2197
2198 if (aHandle->IsClosed() || !ioMan) {
2199 // When no callback is provided, CacheFileIOManager is responsible for
2200 // releasing the buffer. We must release it even in case of failure.
2201 free(aBuf);
2202 return NS_ERROR_NOT_INITIALIZED;
2203 }
2204
2205 RefPtr<WriteEvent> ev = new WriteEvent(aHandle, aOffset, aBuf, aCount,
2206 aValidate, aTruncate, nullptr);
2207 return ioMan->mIOThread->Dispatch(ev, aHandle->mPriority
2208 ? CacheIOThread::WRITE_PRIORITY
2209 : CacheIOThread::WRITE);
2210}
2211
2212static nsresult TruncFile(PRFileDesc* aFD, int64_t aEOF) {
2213#if defined(XP_UNIX1)
2214 if (ftruncate(PR_FileDesc2NativeHandle(aFD), aEOF) != 0) {
2215 NS_ERROR("ftruncate failed")do { NS_DebugBreak(NS_DEBUG_ASSERTION, "ftruncate failed", "Error"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 2215); MOZ_PretendNoReturn
(); } while (0)
;
2216 return NS_ERROR_FAILURE;
2217 }
2218#elif defined(XP_WIN)
2219 int64_t cnt = PR_Seek64(aFD, aEOF, PR_SEEK_SET);
2220 if (cnt == -1) {
2221 return NS_ERROR_FAILURE;
2222 }
2223 if (!SetEndOfFile((HANDLE)PR_FileDesc2NativeHandle(aFD))) {
2224 NS_ERROR("SetEndOfFile failed")do { NS_DebugBreak(NS_DEBUG_ASSERTION, "SetEndOfFile failed",
"Error", "./../../../netwerk/cache2/CacheFileIOManager.cpp",
2224); MOZ_PretendNoReturn(); } while (0)
;
2225 return NS_ERROR_FAILURE;
2226 }
2227#else
2228 MOZ_ASSERT(false, "Not implemented!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false" " (" "Not implemented!"
")", "./../../../netwerk/cache2/CacheFileIOManager.cpp", 2228
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "Not implemented!"
")"); do { MOZ_CrashSequence(__null, 2228); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2229 return NS_ERROR_NOT_IMPLEMENTED;
2230#endif
2231
2232 return NS_OK;
2233}
2234
2235nsresult CacheFileIOManager::WriteInternal(CacheFileHandle* aHandle,
2236 int64_t aOffset, const char* aBuf,
2237 int32_t aCount, bool aValidate,
2238 bool aTruncate) {
2239 LOG(("CacheFileIOManager::WriteInternal() [handle=%p, offset=%" PRId64do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteInternal() [handle=%p, offset=%"
"l" "d" ", count=%d, " "validate=%d, truncate=%d]", aHandle,
aOffset, aCount, aValidate, aTruncate); } } while (0)
2240 ", count=%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, "CacheFileIOManager::WriteInternal() [handle=%p, offset=%"
"l" "d" ", count=%d, " "validate=%d, truncate=%d]", aHandle,
aOffset, aCount, aValidate, aTruncate); } } while (0)
2241 "validate=%d, truncate=%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, "CacheFileIOManager::WriteInternal() [handle=%p, offset=%"
"l" "d" ", count=%d, " "validate=%d, truncate=%d]", aHandle,
aOffset, aCount, aValidate, aTruncate); } } while (0)
2242 aHandle, aOffset, aCount, aValidate, aTruncate))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteInternal() [handle=%p, offset=%"
"l" "d" ", count=%d, " "validate=%d, truncate=%d]", aHandle,
aOffset, aCount, aValidate, aTruncate); } } while (0)
;
2243
2244 nsresult rv;
2245
2246 if (aHandle->mKilled) {
2247 LOG((" handle already killed, nothing written"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " handle already killed, nothing written"
); } } while (0)
;
2248 return NS_OK;
2249 }
2250
2251 if (CacheObserver::ShuttingDown() && (!aValidate || !aHandle->mFD)) {
2252 aHandle->mKilled = true;
2253 LOG((" killing the handle, nothing written"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " killing the handle, nothing written"
); } } while (0)
;
2254 return NS_OK;
2255 }
2256
2257 if (CacheObserver::IsPastShutdownIOLag()) {
2258 LOG((" past the shutdown I/O lag, nothing written"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " past the shutdown I/O lag, nothing written"
); } } while (0)
;
2259 // Pretend the write has succeeded, otherwise upper layers will doom
2260 // the file and we end up with I/O anyway.
2261 return NS_OK;
2262 }
2263
2264 CacheIOThread::Cancelable cancelable(!aHandle->IsSpecialFile());
2265
2266 if (!aHandle->mFileExists) {
2267 rv = CreateFile(aHandle);
2268 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/CacheFileIOManager.cpp"
, 2268); return rv; } } while (false)
;
2269 }
2270
2271 if (!aHandle->mFD) {
2272 rv = OpenNSPRHandle(aHandle);
2273 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/CacheFileIOManager.cpp"
, 2273); return rv; } } while (false)
;
2274 } else {
2275 NSPRHandleUsed(aHandle);
2276 }
2277
2278 // Check again, OpenNSPRHandle could figure out the file was gone.
2279 if (!aHandle->mFileExists) {
2280 return NS_ERROR_NOT_AVAILABLE;
2281 }
2282
2283 // When this operation would increase cache size, check whether the cache size
2284 // reached the hard limit and whether it would cause critical low disk space.
2285 if (aHandle->mFileSize < aOffset + aCount) {
2286 if (mOverLimitEvicting && mCacheSizeOnHardLimit) {
2287 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, "CacheFileIOManager::WriteInternal() - failing because cache size "
"reached hard limit!"); } } while (0)
2288 ("CacheFileIOManager::WriteInternal() - failing because cache size "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteInternal() - failing because cache size "
"reached hard limit!"); } } while (0)
2289 "reached hard limit!"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteInternal() - failing because cache size "
"reached hard limit!"); } } while (0)
;
2290 return NS_ERROR_FILE_NO_DEVICE_SPACE;
2291 }
2292
2293 int64_t freeSpace;
2294 rv = mCacheDirectory->GetDiskSpaceAvailable(&freeSpace);
2295 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 2295)
) {
2296 freeSpace = -1;
2297 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, "CacheFileIOManager::WriteInternal() - GetDiskSpaceAvailable() "
"failed! [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)
); } } while (0)
2298 ("CacheFileIOManager::WriteInternal() - GetDiskSpaceAvailable() "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteInternal() - GetDiskSpaceAvailable() "
"failed! [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)
); } } while (0)
2299 "failed! [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, "CacheFileIOManager::WriteInternal() - GetDiskSpaceAvailable() "
"failed! [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)
); } } while (0)
2300 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, "CacheFileIOManager::WriteInternal() - GetDiskSpaceAvailable() "
"failed! [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)
); } } while (0)
;
2301 } else {
2302 freeSpace >>= 10; // bytes to kilobytes
2303 uint32_t limit = CacheObserver::DiskFreeSpaceHardLimit();
2304 // Convert to KiB for comparison
2305 if (freeSpace - ((aOffset + aCount - aHandle->mFileSize) >> 10) < limit) {
2306 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, "CacheFileIOManager::WriteInternal() - Low free space, refusing "
"to write! [freeSpace=%" "l" "d" "kB, limit=%ukB]", freeSpace
, limit); } } while (0)
2307 ("CacheFileIOManager::WriteInternal() - Low free space, refusing "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteInternal() - Low free space, refusing "
"to write! [freeSpace=%" "l" "d" "kB, limit=%ukB]", freeSpace
, limit); } } while (0)
2308 "to write! [freeSpace=%" PRId64 "kB, limit=%ukB]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteInternal() - Low free space, refusing "
"to write! [freeSpace=%" "l" "d" "kB, limit=%ukB]", freeSpace
, limit); } } while (0)
2309 freeSpace, limit))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::WriteInternal() - Low free space, refusing "
"to write! [freeSpace=%" "l" "d" "kB, limit=%ukB]", freeSpace
, limit); } } while (0)
;
2310 return NS_ERROR_FILE_NO_DEVICE_SPACE;
2311 }
2312 }
2313 }
2314
2315 // Write invalidates the entry by default
2316 aHandle->mInvalid = true;
2317
2318 int64_t offset = PR_Seek64(aHandle->mFD, aOffset, PR_SEEK_SET);
2319 if (offset == -1) {
2320 return NS_ERROR_FAILURE;
2321 }
2322
2323 int32_t bytesWritten = PR_Write(aHandle->mFD, aBuf, aCount);
2324
2325 if (bytesWritten != -1) {
2326 uint32_t oldSizeInK = aHandle->FileSizeInK();
2327 int64_t writeEnd = aOffset + bytesWritten;
2328
2329 if (aTruncate) {
2330 rv = TruncFile(aHandle->mFD, writeEnd);
2331 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/CacheFileIOManager.cpp"
, 2331); return rv; } } while (false)
;
2332
2333 aHandle->mFileSize = writeEnd;
2334 } else {
2335 if (aHandle->mFileSize < writeEnd) {
2336 aHandle->mFileSize = writeEnd;
2337 }
2338 }
2339
2340 uint32_t newSizeInK = aHandle->FileSizeInK();
2341
2342 if (oldSizeInK != newSizeInK && !aHandle->IsDoomed() &&
2343 !aHandle->IsSpecialFile()) {
2344 CacheIndex::UpdateEntry(aHandle->Hash(), nullptr, nullptr, nullptr,
2345 nullptr, nullptr, &newSizeInK);
2346
2347 if (oldSizeInK < newSizeInK) {
2348 EvictIfOverLimitInternal();
2349 }
2350 }
2351
2352 CacheIndex::UpdateTotalBytesWritten(bytesWritten);
2353 }
2354
2355 if (bytesWritten != aCount) {
2356 return NS_ERROR_FAILURE;
2357 }
2358
2359 // Write was successful and this write validates the entry (i.e. metadata)
2360 if (aValidate) {
2361 aHandle->mInvalid = false;
2362 }
2363
2364 return NS_OK;
2365}
2366
2367// static
2368nsresult CacheFileIOManager::DoomFile(CacheFileHandle* aHandle,
2369 CacheFileIOListener* aCallback) {
2370 LOG(("CacheFileIOManager::DoomFile() [handle=%p, listener=%p]", 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, "CacheFileIOManager::DoomFile() [handle=%p, listener=%p]"
, aHandle, aCallback); } } while (0)
2371 aCallback))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::DoomFile() [handle=%p, listener=%p]"
, aHandle, aCallback); } } while (0)
;
2372
2373 nsresult rv;
2374 RefPtr<CacheFileIOManager> ioMan = gInstance;
2375
2376 if (aHandle->IsClosed() || !ioMan) {
2377 return NS_ERROR_NOT_INITIALIZED;
2378 }
2379
2380 RefPtr<DoomFileEvent> ev = new DoomFileEvent(aHandle, aCallback);
2381 rv = ioMan->mIOThread->Dispatch(ev, aHandle->IsPriority()
2382 ? CacheIOThread::OPEN_PRIORITY
2383 : CacheIOThread::OPEN);
2384 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/CacheFileIOManager.cpp"
, 2384); return rv; } } while (false)
;
2385
2386 return NS_OK;
2387}
2388
2389nsresult CacheFileIOManager::DoomFileInternal(
2390 CacheFileHandle* aHandle, PinningDoomRestriction aPinningDoomRestriction,
2391 bool aClearDictionary) {
2392 LOG(("CacheFileIOManager::DoomFileInternal() [handle=%p]", 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, "CacheFileIOManager::DoomFileInternal() [handle=%p]"
, aHandle); } } while (0)
;
2393 aHandle->Log();
2394
2395 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 2395); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { MOZ_CrashSequence(__null, 2395); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2396
2397 nsresult rv;
2398
2399 if (aHandle->IsDoomed()) {
2400 return NS_OK;
2401 }
2402
2403 CacheIOThread::Cancelable cancelable(!aHandle->IsSpecialFile());
2404
2405 if (aPinningDoomRestriction > NO_RESTRICTION) {
2406 switch (aHandle->mPinning) {
2407 case CacheFileHandle::PinningStatus::NON_PINNED:
2408 if (MOZ_LIKELY(aPinningDoomRestriction != DOOM_WHEN_NON_PINNED)(__builtin_expect(!!(aPinningDoomRestriction != DOOM_WHEN_NON_PINNED
), 1))
) {
2409 LOG((" not dooming, it's a non-pinned handle"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " not dooming, it's a non-pinned handle"
); } } while (0)
;
2410 return NS_OK;
2411 }
2412 // Doom now
2413 break;
2414
2415 case CacheFileHandle::PinningStatus::PINNED:
2416 if (MOZ_UNLIKELY(aPinningDoomRestriction != DOOM_WHEN_PINNED)(__builtin_expect(!!(aPinningDoomRestriction != DOOM_WHEN_PINNED
), 0))
) {
2417 LOG((" not dooming, it's a pinned handle"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " not dooming, it's a pinned handle"
); } } while (0)
;
2418 return NS_OK;
2419 }
2420 // Doom now
2421 break;
2422
2423 case CacheFileHandle::PinningStatus::UNKNOWN:
2424 if (MOZ_LIKELY(aPinningDoomRestriction == DOOM_WHEN_NON_PINNED)(__builtin_expect(!!(aPinningDoomRestriction == DOOM_WHEN_NON_PINNED
), 1))
) {
2425 LOG((" doom when non-pinned set"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " doom when non-pinned set"
); } } while (0)
;
2426 aHandle->mDoomWhenFoundNonPinned = true;
2427 } else if (MOZ_UNLIKELY(aPinningDoomRestriction == DOOM_WHEN_PINNED)(__builtin_expect(!!(aPinningDoomRestriction == DOOM_WHEN_PINNED
), 0))
) {
2428 LOG((" doom when pinned set"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " doom when pinned set"
); } } while (0)
;
2429 aHandle->mDoomWhenFoundPinned = true;
2430 }
2431
2432 LOG((" pinning status not known, deferring doom decision"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " pinning status not known, deferring doom decision"
); } } while (0)
;
2433 return NS_OK;
2434 }
2435 }
2436
2437 if (aHandle->mFileExists) {
2438 // we need to move the current file to the doomed directory
2439 rv = MaybeReleaseNSPRHandleInternal(aHandle, true);
2440 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/CacheFileIOManager.cpp"
, 2440); return rv; } } while (false)
;
2441
2442 // find unused filename
2443 nsCOMPtr<nsIFile> file;
2444 rv = GetDoomedFile(getter_AddRefs(file));
2445 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/CacheFileIOManager.cpp"
, 2445); return rv; } } while (false)
;
2446
2447 nsCOMPtr<nsIFile> parentDir;
2448 rv = file->GetParent(getter_AddRefs(parentDir));
2449 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/CacheFileIOManager.cpp"
, 2449); return rv; } } while (false)
;
2450
2451 nsAutoCString leafName;
2452 rv = file->GetNativeLeafName(leafName);
2453 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/CacheFileIOManager.cpp"
, 2453); return rv; } } while (false)
;
2454
2455 rv = aHandle->mFile->MoveToNative(parentDir, leafName);
2456 if (NS_ERROR_FILE_NOT_FOUND == rv) {
2457 LOG((" file already removed under our hands"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " file already removed under our hands"
); } } while (0)
;
2458 aHandle->mFileExists = false;
2459 rv = NS_OK;
2460 } else {
2461 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/CacheFileIOManager.cpp"
, 2461); return rv; } } while (false)
;
2462 aHandle->mFile.swap(file);
2463 }
2464 }
2465
2466 if (!aHandle->IsSpecialFile()) {
2467 // Ensure the string doesn't disappear with the handle
2468 RefPtr<CacheFileHandle> handle(aHandle);
2469 CacheIndex::RemoveEntry(aHandle->Hash(), aHandle->Key(), aClearDictionary);
2470 }
2471
2472 aHandle->mIsDoomed = true;
2473
2474 if (!aHandle->IsSpecialFile()) {
2475 RefPtr<CacheStorageService> storageService = CacheStorageService::Self();
2476 if (storageService) {
2477 nsAutoCString idExtension, url;
2478 nsCOMPtr<nsILoadContextInfo> info =
2479 CacheFileUtils::ParseKey(aHandle->Key(), &idExtension, &url);
2480 MOZ_ASSERT(info)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(info)>::isValid, "invalid assertion condition"); if
((__builtin_expect(!!(!(!!(info))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("info", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 2480); AnnotateMozCrashReason("MOZ_ASSERT" "(" "info" ")");
do { MOZ_CrashSequence(__null, 2480); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2481 if (info) {
2482 storageService->CacheFileDoomed(aHandle->mKey, info, idExtension, url);
2483 }
2484 }
2485 }
2486
2487 return NS_OK;
2488}
2489
2490// static
2491nsresult CacheFileIOManager::DoomFileByKey(const nsACString& aKey,
2492 CacheFileIOListener* aCallback) {
2493 LOG(("CacheFileIOManager::DoomFileByKey() [key=%s, listener=%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, "CacheFileIOManager::DoomFileByKey() [key=%s, listener=%p]"
, TPromiseFlatString<char>(aKey).get(), aCallback); } }
while (0)
2494 PromiseFlatCString(aKey).get(), aCallback))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::DoomFileByKey() [key=%s, listener=%p]"
, TPromiseFlatString<char>(aKey).get(), aCallback); } }
while (0)
;
2495
2496 nsresult rv;
2497 RefPtr<CacheFileIOManager> ioMan = gInstance;
2498
2499 if (!ioMan) {
2500 return NS_ERROR_NOT_INITIALIZED;
2501 }
2502
2503 RefPtr<DoomFileByKeyEvent> ev = new DoomFileByKeyEvent(aKey, aCallback);
2504 rv = ioMan->mIOThread->DispatchAfterPendingOpens(ev);
2505 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/CacheFileIOManager.cpp"
, 2505); return rv; } } while (false)
;
2506
2507 return NS_OK;
2508}
2509
2510nsresult CacheFileIOManager::DoomFileByKeyInternal(const SHA1Sum::Hash* aHash) {
2511 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, "CacheFileIOManager::DoomFileByKeyInternal() [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)
2512 "CacheFileIOManager::DoomFileByKeyInternal() [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, "CacheFileIOManager::DoomFileByKeyInternal() [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)
2513 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, "CacheFileIOManager::DoomFileByKeyInternal() [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)
;
2514
2515 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 2515); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { MOZ_CrashSequence(__null, 2515); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2516
2517 nsresult rv;
2518
2519 if (mShuttingDown) {
2520 return NS_ERROR_NOT_INITIALIZED;
2521 }
2522
2523 if (!mCacheDirectory) {
2524 return NS_ERROR_FILE_INVALID_PATH;
2525 }
2526
2527 // Find active handle
2528 RefPtr<CacheFileHandle> handle;
2529 mHandles.GetHandle(aHash, getter_AddRefs(handle));
2530
2531 if (handle) {
2532 handle->Log();
2533
2534 return DoomFileInternal(handle);
2535 }
2536
2537 CacheIOThread::Cancelable cancelable(true);
2538
2539 // There is no handle for this file, delete the file if exists
2540 nsCOMPtr<nsIFile> file;
2541 rv = GetFile(aHash, getter_AddRefs(file));
2542 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/CacheFileIOManager.cpp"
, 2542); return rv; } } while (false)
;
2543
2544 bool exists;
2545 rv = file->Exists(&exists);
2546 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/CacheFileIOManager.cpp"
, 2546); return rv; } } while (false)
;
2547
2548 if (!exists) {
2549 return NS_ERROR_NOT_AVAILABLE;
2550 }
2551
2552 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, "CacheFileIOManager::DoomFileByKeyInternal() - Removing file from "
"disk"); } } while (0)
2553 ("CacheFileIOManager::DoomFileByKeyInternal() - Removing file from "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::DoomFileByKeyInternal() - Removing file from "
"disk"); } } while (0)
2554 "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, "CacheFileIOManager::DoomFileByKeyInternal() - Removing file from "
"disk"); } } while (0)
;
2555 rv = file->Remove(false);
2556 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2557 NS_WARNING("Cannot remove old entry from the disk")NS_DebugBreak(NS_DEBUG_WARNING, "Cannot remove old entry from the disk"
, nullptr, "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 2557)
;
2558 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, "CacheFileIOManager::DoomFileByKeyInternal() - Removing file failed. "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
2559 ("CacheFileIOManager::DoomFileByKeyInternal() - Removing file 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, "CacheFileIOManager::DoomFileByKeyInternal() - Removing file failed. "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
2560 "[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, "CacheFileIOManager::DoomFileByKeyInternal() - Removing file failed. "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
2561 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, "CacheFileIOManager::DoomFileByKeyInternal() - Removing file failed. "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
;
2562 }
2563
2564 // Find the key for the hash
2565 // Read metadata from the file synchronously
2566 RefPtr<CacheFileMetadata> metadata = new CacheFileMetadata();
2567 rv = metadata->SyncReadMetadata(file);
2568 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 2568)
) {
2569 CacheIndex::RemoveEntry(aHash, ""_ns);
2570 } else {
2571 CacheIndex::RemoveEntry(aHash, metadata->GetKey());
2572 }
2573
2574 return NS_OK;
2575}
2576
2577// static
2578nsresult CacheFileIOManager::ReleaseNSPRHandle(CacheFileHandle* aHandle) {
2579 LOG(("CacheFileIOManager::ReleaseNSPRHandle() [handle=%p]", 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, "CacheFileIOManager::ReleaseNSPRHandle() [handle=%p]"
, aHandle); } } while (0)
;
2580
2581 nsresult rv;
2582 RefPtr<CacheFileIOManager> ioMan = gInstance;
2583
2584 if (aHandle->IsClosed() || !ioMan) {
2585 return NS_ERROR_NOT_INITIALIZED;
2586 }
2587
2588 RefPtr<ReleaseNSPRHandleEvent> ev = new ReleaseNSPRHandleEvent(aHandle);
2589 rv = ioMan->mIOThread->Dispatch(ev, aHandle->mPriority
2590 ? CacheIOThread::WRITE_PRIORITY
2591 : CacheIOThread::WRITE);
2592 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/CacheFileIOManager.cpp"
, 2592); return rv; } } while (false)
;
2593
2594 return NS_OK;
2595}
2596
2597nsresult CacheFileIOManager::MaybeReleaseNSPRHandleInternal(
2598 CacheFileHandle* aHandle, bool aIgnoreShutdownLag) {
2599 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, "CacheFileIOManager::MaybeReleaseNSPRHandleInternal() [handle=%p, "
"ignore shutdown=%d]", aHandle, aIgnoreShutdownLag); } } while
(0)
2600 ("CacheFileIOManager::MaybeReleaseNSPRHandleInternal() [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, "CacheFileIOManager::MaybeReleaseNSPRHandleInternal() [handle=%p, "
"ignore shutdown=%d]", aHandle, aIgnoreShutdownLag); } } while
(0)
2601 "ignore shutdown=%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, "CacheFileIOManager::MaybeReleaseNSPRHandleInternal() [handle=%p, "
"ignore shutdown=%d]", aHandle, aIgnoreShutdownLag); } } while
(0)
2602 aHandle, aIgnoreShutdownLag))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::MaybeReleaseNSPRHandleInternal() [handle=%p, "
"ignore shutdown=%d]", aHandle, aIgnoreShutdownLag); } } while
(0)
;
2603
2604 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 2604); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { MOZ_CrashSequence(__null, 2604); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2605
2606 if (aHandle->mFD) {
2607 DebugOnly<bool> found{};
2608 found = mHandlesByLastUsed.RemoveElement(aHandle);
2609 MOZ_ASSERT(found)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(found)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(found))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("found", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 2609); AnnotateMozCrashReason("MOZ_ASSERT" "(" "found" ")")
; do { MOZ_CrashSequence(__null, 2609); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2610 }
2611
2612 PRFileDesc* fd = aHandle->mFD;
2613 aHandle->mFD = nullptr;
2614
2615 // Leak invalid (w/o metadata) and doomed handles immediately after shutdown.
2616 // Leak other handles when past the shutdown time maximum lag.
2617 if (
2618#ifndef DEBUG1
2619 ((aHandle->mInvalid || aHandle->mIsDoomed) &&
2620 MOZ_UNLIKELY(CacheObserver::ShuttingDown())(__builtin_expect(!!(CacheObserver::ShuttingDown()), 0))) ||
2621#endif
2622 MOZ_UNLIKELY(!aIgnoreShutdownLag &&(__builtin_expect(!!(!aIgnoreShutdownLag && CacheObserver
::IsPastShutdownIOLag()), 0))
2623 CacheObserver::IsPastShutdownIOLag())(__builtin_expect(!!(!aIgnoreShutdownLag && CacheObserver
::IsPastShutdownIOLag()), 0))
) {
2624 // Don't bother closing this file. Return a failure code from here will
2625 // cause any following IO operation on the file (mainly removal) to be
2626 // bypassed, which is what we want.
2627 // For mInvalid == true the entry will never be used, since it doesn't
2628 // have correct metadata, thus we don't need to worry about removing it.
2629 // For mIsDoomed == true the file is already in the doomed sub-dir and
2630 // will be removed on next session start.
2631 LOG((" past the shutdown I/O lag, leaking file handle"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " past the shutdown I/O lag, leaking file handle"
); } } while (0)
;
2632 return NS_ERROR_ILLEGAL_DURING_SHUTDOWN;
2633 }
2634
2635 if (!fd) {
2636 // The filedesc has already been closed before, just let go.
2637 return NS_OK;
2638 }
2639
2640 bool cancelable = !aHandle->IsSpecialFile();
2641#if defined(MOZ_CACHE_ASYNC_IO1)
2642 if (aHandle->mAsyncRunning) {
2643 // Need to wait for async operation to finish before closing the
2644 // file descriptor.
2645 RefPtr<nsIRunnable> closeFunc = NS_NewRunnableFunction(
2646 "CacheFileIOManager::MaybeReleaseNSPRHandleInternal",
2647 [fd, cancelable]() {
2648 CacheIOThread::Cancelable _cancelable(cancelable);
2649
2650 PR_Close(fd);
2651 });
2652
2653 if (aHandle->WaitForAsyncCompletion(closeFunc, CacheIOThread::OPEN)) {
2654 return NS_OK;
2655 }
2656 }
2657#endif
2658
2659 CacheIOThread::Cancelable _cancelable(cancelable);
2660
2661 PRStatus status = PR_Close(fd);
2662 if (status != PR_SUCCESS) {
2663 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, "CacheFileIOManager::MaybeReleaseNSPRHandleInternal() "
"failed to close [handle=%p, status=%u]", aHandle, status); }
} while (0)
2664 ("CacheFileIOManager::MaybeReleaseNSPRHandleInternal() "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::MaybeReleaseNSPRHandleInternal() "
"failed to close [handle=%p, status=%u]", aHandle, status); }
} while (0)
2665 "failed to close [handle=%p, status=%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, "CacheFileIOManager::MaybeReleaseNSPRHandleInternal() "
"failed to close [handle=%p, status=%u]", aHandle, status); }
} while (0)
2666 aHandle, status))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::MaybeReleaseNSPRHandleInternal() "
"failed to close [handle=%p, status=%u]", aHandle, status); }
} while (0)
;
2667 return NS_ERROR_FAILURE;
2668 }
2669
2670 LOG(("CacheFileIOManager::MaybeReleaseNSPRHandleInternal() DONE"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::MaybeReleaseNSPRHandleInternal() DONE"
); } } while (0)
;
2671
2672 return NS_OK;
2673}
2674
2675// static
2676nsresult CacheFileIOManager::TruncateSeekSetEOF(
2677 CacheFileHandle* aHandle, int64_t aTruncatePos, int64_t aEOFPos,
2678 CacheFileIOListener* aCallback) {
2679 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, "CacheFileIOManager::TruncateSeekSetEOF() [handle=%p, "
"truncatePos=%" "l" "d" ", " "EOFPos=%" "l" "d" ", listener=%p]"
, aHandle, aTruncatePos, aEOFPos, aCallback); } } while (0)
2680 ("CacheFileIOManager::TruncateSeekSetEOF() [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, "CacheFileIOManager::TruncateSeekSetEOF() [handle=%p, "
"truncatePos=%" "l" "d" ", " "EOFPos=%" "l" "d" ", listener=%p]"
, aHandle, aTruncatePos, aEOFPos, aCallback); } } while (0)
2681 "truncatePos=%" 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, "CacheFileIOManager::TruncateSeekSetEOF() [handle=%p, "
"truncatePos=%" "l" "d" ", " "EOFPos=%" "l" "d" ", listener=%p]"
, aHandle, aTruncatePos, aEOFPos, aCallback); } } while (0)
2682 "EOFPos=%" PRId64 ", listener=%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, "CacheFileIOManager::TruncateSeekSetEOF() [handle=%p, "
"truncatePos=%" "l" "d" ", " "EOFPos=%" "l" "d" ", listener=%p]"
, aHandle, aTruncatePos, aEOFPos, aCallback); } } while (0)
2683 aHandle, aTruncatePos, aEOFPos, aCallback))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOF() [handle=%p, "
"truncatePos=%" "l" "d" ", " "EOFPos=%" "l" "d" ", listener=%p]"
, aHandle, aTruncatePos, aEOFPos, aCallback); } } while (0)
;
2684
2685 nsresult rv;
2686 RefPtr<CacheFileIOManager> ioMan = gInstance;
2687
2688 if (aHandle->IsClosed() || (aCallback && aCallback->IsKilled()) || !ioMan) {
2689 return NS_ERROR_NOT_INITIALIZED;
2690 }
2691
2692 RefPtr<TruncateSeekSetEOFEvent> ev =
2693 new TruncateSeekSetEOFEvent(aHandle, aTruncatePos, aEOFPos, aCallback);
2694 rv = ioMan->mIOThread->Dispatch(ev, aHandle->mPriority
2695 ? CacheIOThread::WRITE_PRIORITY
2696 : CacheIOThread::WRITE);
2697 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/CacheFileIOManager.cpp"
, 2697); return rv; } } while (false)
;
2698
2699 return NS_OK;
2700}
2701
2702// static
2703void CacheFileIOManager::GetCacheDirectory(nsIFile** result) {
2704 *result = nullptr;
2705
2706 RefPtr<CacheFileIOManager> ioMan = gInstance;
2707 if (!ioMan || !ioMan->mCacheDirectory) {
2708 return;
2709 }
2710
2711 ioMan->mCacheDirectory->Clone(result);
2712}
2713
2714#if defined(MOZ_WIDGET_ANDROID)
2715
2716// static
2717void CacheFileIOManager::GetProfilelessCacheDirectory(nsIFile** result) {
2718 *result = nullptr;
2719
2720 RefPtr<CacheFileIOManager> ioMan = gInstance;
2721 if (!ioMan || !ioMan->mCacheProfilelessDirectory) {
2722 return;
2723 }
2724
2725 ioMan->mCacheProfilelessDirectory->Clone(result);
2726}
2727
2728#endif
2729
2730// static
2731nsresult CacheFileIOManager::GetEntryInfo(
2732 const SHA1Sum::Hash* aHash,
2733 CacheStorageService::EntryInfoCallback* aCallback) {
2734 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/CacheFileIOManager.cpp"
, 2734); AnnotateMozCrashReason("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThread()"
")"); do { MOZ_CrashSequence(__null, 2734); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2735
2736 nsresult rv;
2737
2738 RefPtr<CacheFileIOManager> ioMan = gInstance;
2739 if (!ioMan) {
2740 return NS_ERROR_NOT_INITIALIZED;
2741 }
2742
2743 nsAutoCString enhanceId;
2744 nsAutoCString uriSpec;
2745
2746 RefPtr<CacheFileHandle> handle;
2747 ioMan->mHandles.GetHandle(aHash, getter_AddRefs(handle));
2748 if (handle) {
2749 RefPtr<nsILoadContextInfo> info =
2750 CacheFileUtils::ParseKey(handle->Key(), &enhanceId, &uriSpec);
2751
2752 MOZ_ASSERT(info)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(info)>::isValid, "invalid assertion condition"); if
((__builtin_expect(!!(!(!!(info))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("info", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 2752); AnnotateMozCrashReason("MOZ_ASSERT" "(" "info" ")");
do { MOZ_CrashSequence(__null, 2752); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2753 if (!info) {
2754 return NS_OK; // ignore
2755 }
2756
2757 RefPtr<CacheStorageService> service = CacheStorageService::Self();
2758 if (!service) {
2759 return NS_ERROR_NOT_INITIALIZED;
2760 }
2761
2762 // Invokes OnCacheEntryInfo when an existing entry is found
2763 if (service->GetCacheEntryInfo(info, enhanceId, uriSpec, aCallback)) {
2764 return NS_OK;
2765 }
2766
2767 // When we are here, there is no existing entry and we need
2768 // to synchrnously load metadata from a disk file.
2769 }
2770
2771 // Locate the actual file
2772 nsCOMPtr<nsIFile> file;
2773 ioMan->GetFile(aHash, getter_AddRefs(file));
2774
2775 // Read metadata from the file synchronously
2776 RefPtr<CacheFileMetadata> metadata = new CacheFileMetadata();
2777 rv = metadata->SyncReadMetadata(file);
2778 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2779 return NS_OK;
2780 }
2781
2782 // Now get the context + enhance id + URL from the key.
2783 RefPtr<nsILoadContextInfo> info =
2784 CacheFileUtils::ParseKey(metadata->GetKey(), &enhanceId, &uriSpec);
2785 MOZ_ASSERT(info)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(info)>::isValid, "invalid assertion condition"); if
((__builtin_expect(!!(!(!!(info))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("info", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 2785); AnnotateMozCrashReason("MOZ_ASSERT" "(" "info" ")");
do { MOZ_CrashSequence(__null, 2785); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2786 if (!info) {
2787 return NS_OK;
2788 }
2789
2790 // Pick all data to pass to the callback.
2791 int64_t dataSize = metadata->Offset();
2792 int64_t altDataSize = 0;
2793 uint32_t fetchCount = metadata->GetFetchCount();
2794 uint32_t expirationTime = metadata->GetExpirationTime();
2795 uint32_t lastModified = metadata->GetLastModified();
2796
2797 const char* altDataElement =
2798 metadata->GetElement(CacheFileUtils::kAltDataKey);
2799 if (altDataElement) {
2800 int64_t altDataOffset = std::numeric_limits<int64_t>::max();
2801 if (NS_SUCCEEDED(CacheFileUtils::ParseAlternativeDataInfo(((bool)(__builtin_expect(!!(!NS_FAILED_impl(CacheFileUtils::ParseAlternativeDataInfo
( altDataElement, &altDataOffset, nullptr))), 1)))
2802 altDataElement, &altDataOffset, nullptr))((bool)(__builtin_expect(!!(!NS_FAILED_impl(CacheFileUtils::ParseAlternativeDataInfo
( altDataElement, &altDataOffset, nullptr))), 1)))
&&
2803 altDataOffset < dataSize) {
2804 dataSize = altDataOffset;
2805 altDataSize = metadata->Offset() - altDataOffset;
2806 } else {
2807 LOG(("CacheFileIOManager::GetEntryInfo() invalid alternative data info"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::GetEntryInfo() invalid alternative data info"
); } } while (0)
;
2808 return NS_OK;
2809 }
2810 }
2811
2812 // Call directly on the callback.
2813 aCallback->OnEntryInfo(uriSpec, enhanceId, dataSize, altDataSize, fetchCount,
2814 lastModified, expirationTime, metadata->Pinned(),
2815 info);
2816
2817 return NS_OK;
2818}
2819
2820nsresult CacheFileIOManager::TruncateSeekSetEOFInternal(
2821 CacheFileHandle* aHandle, int64_t aTruncatePos, int64_t aEOFPos) {
2822 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, "CacheFileIOManager::TruncateSeekSetEOFInternal() [handle=%p, "
"truncatePos=%" "l" "d" ", EOFPos=%" "l" "d" "]", aHandle, aTruncatePos
, aEOFPos); } } while (0)
2823 ("CacheFileIOManager::TruncateSeekSetEOFInternal() [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, "CacheFileIOManager::TruncateSeekSetEOFInternal() [handle=%p, "
"truncatePos=%" "l" "d" ", EOFPos=%" "l" "d" "]", aHandle, aTruncatePos
, aEOFPos); } } while (0)
2824 "truncatePos=%" PRId64 ", EOFPos=%" 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, "CacheFileIOManager::TruncateSeekSetEOFInternal() [handle=%p, "
"truncatePos=%" "l" "d" ", EOFPos=%" "l" "d" "]", aHandle, aTruncatePos
, aEOFPos); } } while (0)
2825 aHandle, aTruncatePos, aEOFPos))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOFInternal() [handle=%p, "
"truncatePos=%" "l" "d" ", EOFPos=%" "l" "d" "]", aHandle, aTruncatePos
, aEOFPos); } } while (0)
;
2826
2827 nsresult rv;
2828
2829 if (aHandle->mKilled) {
2830 LOG((" handle already killed, file not truncated"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " handle already killed, file not truncated"
); } } while (0)
;
2831 return NS_OK;
2832 }
2833
2834 if (CacheObserver::ShuttingDown() && !aHandle->mFD) {
2835 aHandle->mKilled = true;
2836 LOG((" killing the handle, file not truncated"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " killing the handle, file not truncated"
); } } while (0)
;
2837 return NS_OK;
2838 }
2839
2840 CacheIOThread::Cancelable cancelable(!aHandle->IsSpecialFile());
2841
2842 if (!aHandle->mFileExists) {
2843 rv = CreateFile(aHandle);
2844 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/CacheFileIOManager.cpp"
, 2844); return rv; } } while (false)
;
2845 }
2846
2847 if (!aHandle->mFD) {
2848 rv = OpenNSPRHandle(aHandle);
2849 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/CacheFileIOManager.cpp"
, 2849); return rv; } } while (false)
;
2850 } else {
2851 NSPRHandleUsed(aHandle);
2852 }
2853
2854 // Check again, OpenNSPRHandle could figure out the file was gone.
2855 if (!aHandle->mFileExists) {
2856 return NS_ERROR_NOT_AVAILABLE;
2857 }
2858
2859 // When this operation would increase cache size, check whether the cache size
2860 // reached the hard limit and whether it would cause critical low disk space.
2861 if (aHandle->mFileSize < aEOFPos) {
2862 if (mOverLimitEvicting && mCacheSizeOnHardLimit) {
2863 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, "CacheFileIOManager::TruncateSeekSetEOFInternal() - failing because "
"cache size reached hard limit!"); } } while (0)
2864 ("CacheFileIOManager::TruncateSeekSetEOFInternal() - failing because "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOFInternal() - failing because "
"cache size reached hard limit!"); } } while (0)
2865 "cache size reached hard limit!"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOFInternal() - failing because "
"cache size reached hard limit!"); } } while (0)
;
2866 return NS_ERROR_FILE_NO_DEVICE_SPACE;
2867 }
2868
2869 int64_t freeSpace;
2870 rv = mCacheDirectory->GetDiskSpaceAvailable(&freeSpace);
2871 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 2871)
) {
2872 freeSpace = -1;
2873 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, "CacheFileIOManager::TruncateSeekSetEOFInternal() - "
"GetDiskSpaceAvailable() failed! [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
2874 ("CacheFileIOManager::TruncateSeekSetEOFInternal() - "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOFInternal() - "
"GetDiskSpaceAvailable() failed! [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
2875 "GetDiskSpaceAvailable() failed! [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, "CacheFileIOManager::TruncateSeekSetEOFInternal() - "
"GetDiskSpaceAvailable() failed! [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
2876 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, "CacheFileIOManager::TruncateSeekSetEOFInternal() - "
"GetDiskSpaceAvailable() failed! [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
;
2877 } else {
2878 freeSpace >>= 10; // bytes to kilobytes
2879 uint32_t limit = CacheObserver::DiskFreeSpaceHardLimit();
2880 // Convert to KiB for comparison
2881 if (freeSpace - ((aEOFPos - aHandle->mFileSize) >> 10) < limit) {
2882 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, "CacheFileIOManager::TruncateSeekSetEOFInternal() - Low free space"
", refusing to write! [freeSpace=%" "l" "d" "kB, limit=%ukB]"
, freeSpace, limit); } } while (0)
2883 ("CacheFileIOManager::TruncateSeekSetEOFInternal() - Low free space"do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOFInternal() - Low free space"
", refusing to write! [freeSpace=%" "l" "d" "kB, limit=%ukB]"
, freeSpace, limit); } } while (0)
2884 ", refusing to write! [freeSpace=%" PRId64 "kB, limit=%ukB]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOFInternal() - Low free space"
", refusing to write! [freeSpace=%" "l" "d" "kB, limit=%ukB]"
, freeSpace, limit); } } while (0)
2885 freeSpace, limit))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TruncateSeekSetEOFInternal() - Low free space"
", refusing to write! [freeSpace=%" "l" "d" "kB, limit=%ukB]"
, freeSpace, limit); } } while (0)
;
2886 return NS_ERROR_FILE_NO_DEVICE_SPACE;
2887 }
2888 }
2889 }
2890
2891 // This operation always invalidates the entry
2892 aHandle->mInvalid = true;
2893
2894 rv = TruncFile(aHandle->mFD, aTruncatePos);
2895 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/CacheFileIOManager.cpp"
, 2895); return rv; } } while (false)
;
2896
2897 if (aTruncatePos != aEOFPos) {
2898 rv = TruncFile(aHandle->mFD, aEOFPos);
2899 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/CacheFileIOManager.cpp"
, 2899); return rv; } } while (false)
;
2900 }
2901
2902 uint32_t oldSizeInK = aHandle->FileSizeInK();
2903 aHandle->mFileSize = aEOFPos;
2904 uint32_t newSizeInK = aHandle->FileSizeInK();
2905
2906 if (oldSizeInK != newSizeInK && !aHandle->IsDoomed() &&
2907 !aHandle->IsSpecialFile()) {
2908 CacheIndex::UpdateEntry(aHandle->Hash(), nullptr, nullptr, nullptr, nullptr,
2909 nullptr, &newSizeInK);
2910
2911 if (oldSizeInK < newSizeInK) {
2912 EvictIfOverLimitInternal();
2913 }
2914 }
2915
2916 return NS_OK;
2917}
2918
2919// static
2920nsresult CacheFileIOManager::RenameFile(CacheFileHandle* aHandle,
2921 const nsACString& aNewName,
2922 CacheFileIOListener* aCallback) {
2923 LOG(("CacheFileIOManager::RenameFile() [handle=%p, newName=%s, listener=%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, "CacheFileIOManager::RenameFile() [handle=%p, newName=%s, listener=%p]"
, aHandle, TPromiseFlatString<char>(aNewName).get(), aCallback
); } } while (0)
2924 aHandle, PromiseFlatCString(aNewName).get(), aCallback))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RenameFile() [handle=%p, newName=%s, listener=%p]"
, aHandle, TPromiseFlatString<char>(aNewName).get(), aCallback
); } } while (0)
;
2925
2926 nsresult rv;
2927 RefPtr<CacheFileIOManager> ioMan = gInstance;
2928
2929 if (aHandle->IsClosed() || !ioMan) {
2930 return NS_ERROR_NOT_INITIALIZED;
2931 }
2932
2933 if (!aHandle->IsSpecialFile()) {
2934 return NS_ERROR_UNEXPECTED;
2935 }
2936
2937 RefPtr<RenameFileEvent> ev =
2938 new RenameFileEvent(aHandle, aNewName, aCallback);
2939 rv = ioMan->mIOThread->Dispatch(ev, aHandle->mPriority
2940 ? CacheIOThread::WRITE_PRIORITY
2941 : CacheIOThread::WRITE);
2942 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/CacheFileIOManager.cpp"
, 2942); return rv; } } while (false)
;
2943
2944 return NS_OK;
2945}
2946
2947nsresult CacheFileIOManager::RenameFileInternal(CacheFileHandle* aHandle,
2948 const nsACString& aNewName) {
2949 LOG(("CacheFileIOManager::RenameFileInternal() [handle=%p, newName=%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, "CacheFileIOManager::RenameFileInternal() [handle=%p, newName=%s]"
, aHandle, TPromiseFlatString<char>(aNewName).get()); }
} while (0)
2950 aHandle, PromiseFlatCString(aNewName).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, "CacheFileIOManager::RenameFileInternal() [handle=%p, newName=%s]"
, aHandle, TPromiseFlatString<char>(aNewName).get()); }
} while (0)
;
2951
2952 nsresult rv;
2953
2954 MOZ_ASSERT(aHandle->IsSpecialFile())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aHandle->IsSpecialFile())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aHandle->IsSpecialFile())
)), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aHandle->IsSpecialFile()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 2954); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "aHandle->IsSpecialFile()" ")"); do { MOZ_CrashSequence
(__null, 2954); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2955
2956 if (aHandle->IsDoomed()) {
2957 return NS_ERROR_NOT_AVAILABLE;
2958 }
2959
2960 // Doom old handle if it exists and is not doomed
2961 for (uint32_t i = 0; i < mSpecialHandles.Length(); i++) {
2962 if (!mSpecialHandles[i]->IsDoomed() &&
2963 mSpecialHandles[i]->Key() == aNewName) {
2964 MOZ_ASSERT(aHandle != mSpecialHandles[i])do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aHandle != mSpecialHandles[i])>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aHandle != mSpecialHandles[i
]))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("aHandle != mSpecialHandles[i]", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 2964); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aHandle != mSpecialHandles[i]"
")"); do { MOZ_CrashSequence(__null, 2964); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2965 rv = DoomFileInternal(mSpecialHandles[i]);
2966 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/CacheFileIOManager.cpp"
, 2966); return rv; } } while (false)
;
2967 break;
2968 }
2969 }
2970
2971 nsCOMPtr<nsIFile> file;
2972 rv = GetSpecialFile(aNewName, getter_AddRefs(file));
2973 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/CacheFileIOManager.cpp"
, 2973); return rv; } } while (false)
;
2974
2975 bool exists;
2976 rv = file->Exists(&exists);
2977 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/CacheFileIOManager.cpp"
, 2977); return rv; } } while (false)
;
2978
2979 if (exists) {
2980 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, "CacheFileIOManager::RenameFileInternal() - Removing old file from "
"disk"); } } while (0)
2981 ("CacheFileIOManager::RenameFileInternal() - Removing old file from "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RenameFileInternal() - Removing old file from "
"disk"); } } while (0)
2982 "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, "CacheFileIOManager::RenameFileInternal() - Removing old file from "
"disk"); } } while (0)
;
2983 rv = file->Remove(false);
2984 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
2985 NS_WARNING("Cannot remove file from the disk")NS_DebugBreak(NS_DEBUG_WARNING, "Cannot remove file from the disk"
, nullptr, "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 2985)
;
2986 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, "CacheFileIOManager::RenameFileInternal() - Removing old file failed"
". [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } }
while (0)
2987 ("CacheFileIOManager::RenameFileInternal() - Removing old file 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, "CacheFileIOManager::RenameFileInternal() - Removing old file failed"
". [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } }
while (0)
2988 ". [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, "CacheFileIOManager::RenameFileInternal() - Removing old file failed"
". [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } }
while (0)
2989 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, "CacheFileIOManager::RenameFileInternal() - Removing old file failed"
". [rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } }
while (0)
;
2990 }
2991 }
2992
2993 if (!aHandle->FileExists()) {
2994 aHandle->mKey = aNewName;
2995 return NS_OK;
2996 }
2997
2998 rv = MaybeReleaseNSPRHandleInternal(aHandle, true);
2999 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/CacheFileIOManager.cpp"
, 2999); return rv; } } while (false)
;
3000
3001 rv = aHandle->mFile->MoveToNative(nullptr, aNewName);
3002 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/CacheFileIOManager.cpp"
, 3002); return rv; } } while (false)
;
3003
3004 aHandle->mKey = aNewName;
3005 return NS_OK;
3006}
3007
3008// static
3009nsresult CacheFileIOManager::EvictIfOverLimit() {
3010 LOG(("CacheFileIOManager::EvictIfOverLimit()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimit()"
); } } while (0)
;
3011
3012 nsresult rv;
3013 RefPtr<CacheFileIOManager> ioMan = gInstance;
3014
3015 if (!ioMan) {
3016 return NS_ERROR_NOT_INITIALIZED;
3017 }
3018
3019 nsCOMPtr<nsIRunnable> ev;
3020 ev = NewRunnableMethod("net::CacheFileIOManager::EvictIfOverLimitInternal",
3021 ioMan, &CacheFileIOManager::EvictIfOverLimitInternal);
3022
3023 rv = ioMan->mIOThread->Dispatch(ev, CacheIOThread::EVICT);
3024 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/CacheFileIOManager.cpp"
, 3024); return rv; } } while (false)
;
3025
3026 return NS_OK;
3027}
3028
3029nsresult CacheFileIOManager::EvictIfOverLimitInternal() {
3030 LOG(("CacheFileIOManager::EvictIfOverLimitInternal()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal()"
); } } while (0)
;
3031
3032 nsresult rv;
3033
3034 MOZ_ASSERT(mIOThread->IsCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIOThread->IsCurrentThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mIOThread->IsCurrentThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mIOThread->IsCurrentThread()", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3034); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { MOZ_CrashSequence(__null, 3034); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3035
3036 if (mShuttingDown) {
3037 return NS_ERROR_NOT_INITIALIZED;
3038 }
3039
3040 if (mOverLimitEvicting) {
3041 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, "CacheFileIOManager::EvictIfOverLimitInternal() - Eviction already "
"running."); } } while (0)
3042 ("CacheFileIOManager::EvictIfOverLimitInternal() - Eviction already "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - Eviction already "
"running."); } } while (0)
3043 "running."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - Eviction already "
"running."); } } while (0)
;
3044 return NS_OK;
3045 }
3046
3047 CacheIOThread::Cancelable cancelable(true);
3048
3049 int64_t freeSpace;
3050 rv = mCacheDirectory->GetDiskSpaceAvailable(&freeSpace);
3051 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3051)
) {
3052 freeSpace = -1;
3053
3054 // Do not change smart size.
3055 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, "CacheFileIOManager::EvictIfOverLimitInternal() - "
"GetDiskSpaceAvailable() failed! [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
3056 ("CacheFileIOManager::EvictIfOverLimitInternal() - "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - "
"GetDiskSpaceAvailable() failed! [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
3057 "GetDiskSpaceAvailable() failed! [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, "CacheFileIOManager::EvictIfOverLimitInternal() - "
"GetDiskSpaceAvailable() failed! [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
3058 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, "CacheFileIOManager::EvictIfOverLimitInternal() - "
"GetDiskSpaceAvailable() failed! [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
;
3059 } else {
3060 freeSpace >>= 10; // bytes to kilobytes
3061 UpdateSmartCacheSize(freeSpace);
3062 }
3063
3064 uint32_t cacheUsage;
3065 rv = CacheIndex::GetCacheSize(&cacheUsage);
3066 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/CacheFileIOManager.cpp"
, 3066); return rv; } } while (false)
;
3067
3068 uint32_t cacheLimit = CacheObserver::DiskCacheCapacity();
3069 uint32_t freeSpaceLimit = CacheObserver::DiskFreeSpaceSoftLimit();
3070
3071 if (cacheUsage <= cacheLimit &&
3072 (freeSpace == -1 || freeSpace >= freeSpaceLimit)) {
3073 LOG(do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - Cache size and free "
"space in limits. [cacheSize=%ukB, cacheSizeLimit=%ukB, " "freeSpace=%"
"l" "d" "kB, freeSpaceLimit=%ukB]", cacheUsage, cacheLimit, freeSpace
, freeSpaceLimit); } } while (0)
3074 ("CacheFileIOManager::EvictIfOverLimitInternal() - Cache size and free "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - Cache size and free "
"space in limits. [cacheSize=%ukB, cacheSizeLimit=%ukB, " "freeSpace=%"
"l" "d" "kB, freeSpaceLimit=%ukB]", cacheUsage, cacheLimit, freeSpace
, freeSpaceLimit); } } while (0)
3075 "space in limits. [cacheSize=%ukB, cacheSizeLimit=%ukB, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - Cache size and free "
"space in limits. [cacheSize=%ukB, cacheSizeLimit=%ukB, " "freeSpace=%"
"l" "d" "kB, freeSpaceLimit=%ukB]", cacheUsage, cacheLimit, freeSpace
, freeSpaceLimit); } } while (0)
3076 "freeSpace=%" PRId64 "kB, freeSpaceLimit=%ukB]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - Cache size and free "
"space in limits. [cacheSize=%ukB, cacheSizeLimit=%ukB, " "freeSpace=%"
"l" "d" "kB, freeSpaceLimit=%ukB]", cacheUsage, cacheLimit, freeSpace
, freeSpaceLimit); } } while (0)
3077 cacheUsage, cacheLimit, freeSpace, freeSpaceLimit))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - Cache size and free "
"space in limits. [cacheSize=%ukB, cacheSizeLimit=%ukB, " "freeSpace=%"
"l" "d" "kB, freeSpaceLimit=%ukB]", cacheUsage, cacheLimit, freeSpace
, freeSpaceLimit); } } while (0)
;
3078 return NS_OK;
3079 }
3080
3081 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, "CacheFileIOManager::EvictIfOverLimitInternal() - Cache size exceeded "
"limit. Starting overlimit eviction. [cacheSize=%ukB, limit=%ukB]"
, cacheUsage, cacheLimit); } } while (0)
3082 ("CacheFileIOManager::EvictIfOverLimitInternal() - Cache size exceeded "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - Cache size exceeded "
"limit. Starting overlimit eviction. [cacheSize=%ukB, limit=%ukB]"
, cacheUsage, cacheLimit); } } while (0)
3083 "limit. Starting overlimit eviction. [cacheSize=%ukB, limit=%ukB]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - Cache size exceeded "
"limit. Starting overlimit eviction. [cacheSize=%ukB, limit=%ukB]"
, cacheUsage, cacheLimit); } } while (0)
3084 cacheUsage, cacheLimit))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - Cache size exceeded "
"limit. Starting overlimit eviction. [cacheSize=%ukB, limit=%ukB]"
, cacheUsage, cacheLimit); } } while (0)
;
3085
3086 nsCOMPtr<nsIRunnable> ev;
3087 ev = NewRunnableMethod("net::CacheFileIOManager::OverLimitEvictionInternal",
3088 this, &CacheFileIOManager::OverLimitEvictionInternal);
3089
3090 rv = mIOThread->Dispatch(ev, CacheIOThread::EVICT);
3091 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/CacheFileIOManager.cpp"
, 3091); return rv; } } while (false)
;
3092
3093 mOverLimitEvicting = true;
3094 return NS_OK;
3095}
3096
3097nsresult CacheFileIOManager::OverLimitEvictionInternal() {
3098 LOG(("CacheFileIOManager::OverLimitEvictionInternal()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal()"
); } } while (0)
;
3099
3100 nsresult rv;
3101
3102 MOZ_ASSERT(mIOThread->IsCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIOThread->IsCurrentThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mIOThread->IsCurrentThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mIOThread->IsCurrentThread()", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3102); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { MOZ_CrashSequence(__null, 3102); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3103
3104 // mOverLimitEvicting is accessed only on IO thread, so we can set it to false
3105 // here and set it to true again once we dispatch another event that will
3106 // continue with the eviction. The reason why we do so is that we can fail
3107 // early anywhere in this method and the variable will contain a correct
3108 // value. Otherwise we would need to set it to false on every failing place.
3109 mOverLimitEvicting = false;
3110
3111 if (mShuttingDown) {
3112 return NS_ERROR_NOT_INITIALIZED;
3113 }
3114
3115 auto frecencySnapshot = CacheIndex::GetSortedSnapshotForEviction();
3116 while (true) {
3117 int64_t freeSpace;
3118 rv = mCacheDirectory->GetDiskSpaceAvailable(&freeSpace);
3119 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3119)
) {
3120 freeSpace = -1;
3121
3122 // Do not change smart size.
3123 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, "CacheFileIOManager::EvictIfOverLimitInternal() - "
"GetDiskSpaceAvailable() failed! [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
3124 ("CacheFileIOManager::EvictIfOverLimitInternal() - "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictIfOverLimitInternal() - "
"GetDiskSpaceAvailable() failed! [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
3125 "GetDiskSpaceAvailable() failed! [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, "CacheFileIOManager::EvictIfOverLimitInternal() - "
"GetDiskSpaceAvailable() failed! [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
3126 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, "CacheFileIOManager::EvictIfOverLimitInternal() - "
"GetDiskSpaceAvailable() failed! [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
;
3127 } else {
3128 freeSpace >>= 10; // bytes to kilobytes
3129 UpdateSmartCacheSize(freeSpace);
3130 }
3131
3132 uint32_t cacheUsage;
3133 rv = CacheIndex::GetCacheSize(&cacheUsage);
3134 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/CacheFileIOManager.cpp"
, 3134); return rv; } } while (false)
;
3135
3136 uint32_t cacheLimit = CacheObserver::DiskCacheCapacity();
3137 uint32_t freeSpaceLimit = CacheObserver::DiskFreeSpaceSoftLimit();
3138
3139 if (cacheUsage > cacheLimit) {
3140 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, "CacheFileIOManager::OverLimitEvictionInternal() - Cache size over "
"limit. [cacheSize=%ukB, limit=%ukB]", cacheUsage, cacheLimit
); } } while (0)
3141 ("CacheFileIOManager::OverLimitEvictionInternal() - Cache size over "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Cache size over "
"limit. [cacheSize=%ukB, limit=%ukB]", cacheUsage, cacheLimit
); } } while (0)
3142 "limit. [cacheSize=%ukB, limit=%ukB]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Cache size over "
"limit. [cacheSize=%ukB, limit=%ukB]", cacheUsage, cacheLimit
); } } while (0)
3143 cacheUsage, cacheLimit))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Cache size over "
"limit. [cacheSize=%ukB, limit=%ukB]", cacheUsage, cacheLimit
); } } while (0)
;
3144
3145 // We allow cache size to go over the specified limit. Eviction should
3146 // keep the size within the limit in a long run, but in case the eviction
3147 // is too slow, the cache could go way over the limit. To prevent this we
3148 // set flag mCacheSizeOnHardLimit when the size reaches 105% of the limit
3149 // and WriteInternal() and TruncateSeekSetEOFInternal() fail to cache
3150 // additional data.
3151 if ((cacheUsage - cacheLimit) > (cacheLimit / 20)) {
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, "CacheFileIOManager::OverLimitEvictionInternal() - Cache size "
"reached hard limit."); } } while (0)
3153 ("CacheFileIOManager::OverLimitEvictionInternal() - Cache size "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Cache size "
"reached hard limit."); } } while (0)
3154 "reached hard limit."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Cache size "
"reached hard limit."); } } while (0)
;
3155 mCacheSizeOnHardLimit = true;
3156 } else {
3157 mCacheSizeOnHardLimit = false;
3158 }
3159 } else if (freeSpace != -1 && freeSpace < freeSpaceLimit) {
3160 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, "CacheFileIOManager::OverLimitEvictionInternal() - Free space under "
"limit. [freeSpace=%" "l" "d" "kB, freeSpaceLimit=%ukB]", freeSpace
, freeSpaceLimit); } } while (0)
3161 ("CacheFileIOManager::OverLimitEvictionInternal() - Free space under "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Free space under "
"limit. [freeSpace=%" "l" "d" "kB, freeSpaceLimit=%ukB]", freeSpace
, freeSpaceLimit); } } while (0)
3162 "limit. [freeSpace=%" PRId64 "kB, freeSpaceLimit=%ukB]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Free space under "
"limit. [freeSpace=%" "l" "d" "kB, freeSpaceLimit=%ukB]", freeSpace
, freeSpaceLimit); } } while (0)
3163 freeSpace, freeSpaceLimit))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Free space under "
"limit. [freeSpace=%" "l" "d" "kB, freeSpaceLimit=%ukB]", freeSpace
, freeSpaceLimit); } } while (0)
;
3164 } else {
3165 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, "CacheFileIOManager::OverLimitEvictionInternal() - Cache size and "
"free space in limits. [cacheSize=%ukB, cacheSizeLimit=%ukB, "
"freeSpace=%" "l" "d" "kB, freeSpaceLimit=%ukB]", cacheUsage
, cacheLimit, freeSpace, freeSpaceLimit); } } while (0)
3166 ("CacheFileIOManager::OverLimitEvictionInternal() - Cache size and "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Cache size and "
"free space in limits. [cacheSize=%ukB, cacheSizeLimit=%ukB, "
"freeSpace=%" "l" "d" "kB, freeSpaceLimit=%ukB]", cacheUsage
, cacheLimit, freeSpace, freeSpaceLimit); } } while (0)
3167 "free space in limits. [cacheSize=%ukB, cacheSizeLimit=%ukB, "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Cache size and "
"free space in limits. [cacheSize=%ukB, cacheSizeLimit=%ukB, "
"freeSpace=%" "l" "d" "kB, freeSpaceLimit=%ukB]", cacheUsage
, cacheLimit, freeSpace, freeSpaceLimit); } } while (0)
3168 "freeSpace=%" PRId64 "kB, freeSpaceLimit=%ukB]",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Cache size and "
"free space in limits. [cacheSize=%ukB, cacheSizeLimit=%ukB, "
"freeSpace=%" "l" "d" "kB, freeSpaceLimit=%ukB]", cacheUsage
, cacheLimit, freeSpace, freeSpaceLimit); } } while (0)
3169 cacheUsage, cacheLimit, freeSpace, freeSpaceLimit))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Cache size and "
"free space in limits. [cacheSize=%ukB, cacheSizeLimit=%ukB, "
"freeSpace=%" "l" "d" "kB, freeSpaceLimit=%ukB]", cacheUsage
, cacheLimit, freeSpace, freeSpaceLimit); } } while (0)
;
3170
3171 mCacheSizeOnHardLimit = false;
3172 return NS_OK;
3173 }
3174
3175 if (CacheIOThread::YieldAndRerun()) {
3176 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, "CacheFileIOManager::OverLimitEvictionInternal() - Breaking loop "
"for higher level events."); } } while (0)
3177 ("CacheFileIOManager::OverLimitEvictionInternal() - Breaking loop "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - Breaking loop "
"for higher level events."); } } while (0)
3178 "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, "CacheFileIOManager::OverLimitEvictionInternal() - Breaking loop "
"for higher level events."); } } while (0)
;
3179 mOverLimitEvicting = true;
3180 return NS_OK;
3181 }
3182
3183 SHA1Sum::Hash hash;
3184 uint32_t cnt = 0;
3185 static uint32_t consecutiveFailures = 0;
3186 rv = CacheIndex::GetEntryForEviction(frecencySnapshot, false, &hash, &cnt);
3187 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/CacheFileIOManager.cpp"
, 3187); return rv; } } while (false)
;
3188
3189 rv = DoomFileByKeyInternal(&hash);
3190 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
3191 consecutiveFailures = 0;
3192 } else if (rv == NS_ERROR_NOT_AVAILABLE) {
3193 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, "CacheFileIOManager::OverLimitEvictionInternal() - "
"DoomFileByKeyInternal() failed. [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
3194 ("CacheFileIOManager::OverLimitEvictionInternal() - "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - "
"DoomFileByKeyInternal() failed. [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
3195 "DoomFileByKeyInternal() failed. [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, "CacheFileIOManager::OverLimitEvictionInternal() - "
"DoomFileByKeyInternal() failed. [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
3196 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, "CacheFileIOManager::OverLimitEvictionInternal() - "
"DoomFileByKeyInternal() failed. [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
;
3197 // TODO index is outdated, start update
3198
3199 // Make sure index won't return the same entry again
3200 // XXX find the key for the hash
3201 CacheIndex::RemoveEntry(&hash, ""_ns);
3202 consecutiveFailures = 0;
3203 } else {
3204 // This shouldn't normally happen, but the eviction must not fail
3205 // completely if we ever encounter this problem.
3206 NS_WARNING(NS_DebugBreak(NS_DEBUG_WARNING, "CacheFileIOManager::OverLimitEvictionInternal() - Unexpected "
"failure of DoomFileByKeyInternal()", nullptr, "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3208)
3207 "CacheFileIOManager::OverLimitEvictionInternal() - Unexpected "NS_DebugBreak(NS_DEBUG_WARNING, "CacheFileIOManager::OverLimitEvictionInternal() - Unexpected "
"failure of DoomFileByKeyInternal()", nullptr, "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3208)
3208 "failure of DoomFileByKeyInternal()")NS_DebugBreak(NS_DEBUG_WARNING, "CacheFileIOManager::OverLimitEvictionInternal() - Unexpected "
"failure of DoomFileByKeyInternal()", nullptr, "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3208)
;
3209
3210 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, "CacheFileIOManager::OverLimitEvictionInternal() - "
"DoomFileByKeyInternal() failed. [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
3211 ("CacheFileIOManager::OverLimitEvictionInternal() - "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OverLimitEvictionInternal() - "
"DoomFileByKeyInternal() failed. [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
3212 "DoomFileByKeyInternal() failed. [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, "CacheFileIOManager::OverLimitEvictionInternal() - "
"DoomFileByKeyInternal() failed. [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
3213 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, "CacheFileIOManager::OverLimitEvictionInternal() - "
"DoomFileByKeyInternal() failed. [rv=0x%08" "x" "]", static_cast
<uint32_t>(rv)); } } while (0)
;
3214
3215 if (++consecutiveFailures >= cnt) {
3216 // This doesn't necessarily mean that we've tried to doom every entry
3217 // but we've reached a sane number of tries. It is likely that another
3218 // eviction will start soon. And as said earlier, this normally doesn't
3219 // happen at all.
3220 return NS_OK;
3221 }
3222 }
3223 }
3224
3225 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/CacheFileIOManager.cpp"
, 3225); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "We should never get here" ")"); do
{ MOZ_CrashSequence(__null, 3225); __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
3226 return NS_OK;
3227}
3228
3229// static
3230nsresult CacheFileIOManager::EvictAll() {
3231 LOG(("CacheFileIOManager::EvictAll()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictAll()"
); } } while (0)
;
3232
3233 nsresult rv;
3234 RefPtr<CacheFileIOManager> ioMan = gInstance;
3235
3236 if (!ioMan) {
3237 return NS_ERROR_NOT_INITIALIZED;
3238 }
3239
3240 nsCOMPtr<nsIRunnable> ev;
3241 ev = NewRunnableMethod("net::CacheFileIOManager::EvictAllInternal", ioMan,
3242 &CacheFileIOManager::EvictAllInternal);
3243
3244 rv = ioMan->mIOThread->DispatchAfterPendingOpens(ev);
3245 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3245)
) {
3246 return rv;
3247 }
3248
3249 return NS_OK;
3250}
3251
3252namespace {
3253
3254class EvictionNotifierRunnable : public Runnable {
3255 public:
3256 EvictionNotifierRunnable() : Runnable("EvictionNotifierRunnable") {}
3257 NS_DECL_NSIRUNNABLEvirtual nsresult Run(void) override;
3258};
3259
3260NS_IMETHODIMPnsresult
3261EvictionNotifierRunnable::Run() {
3262 nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService();
3263 if (obsSvc) {
3264 obsSvc->NotifyObservers(nullptr, "cacheservice:empty-cache", nullptr);
3265 }
3266 return NS_OK;
3267}
3268
3269} // namespace
3270
3271nsresult CacheFileIOManager::EvictAllInternal() {
3272 LOG(("CacheFileIOManager::EvictAllInternal()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictAllInternal()"
); } } while (0)
;
3273
3274 nsresult rv;
3275
3276 MOZ_ASSERT(mIOThread->IsCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIOThread->IsCurrentThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mIOThread->IsCurrentThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mIOThread->IsCurrentThread()", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3276); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { MOZ_CrashSequence(__null, 3276); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3277
3278 RefPtr<EvictionNotifierRunnable> r = new EvictionNotifierRunnable();
3279
3280 if (!mCacheDirectory) {
3281 // This is a kind of hack. Somebody called EvictAll() without a profile.
3282 // This happens in xpcshell tests that use cache without profile. We need
3283 // to notify observers in this case since the tests are waiting for it.
3284 NS_DispatchToMainThread(r);
3285 return NS_ERROR_FILE_INVALID_PATH;
3286 }
3287
3288 if (mShuttingDown) {
3289 return NS_ERROR_NOT_INITIALIZED;
3290 }
3291
3292 if (!mTreeCreated) {
3293 rv = CreateCacheTree();
3294 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3295 return rv;
3296 }
3297 }
3298
3299 // Doom all active handles
3300 nsTArray<RefPtr<CacheFileHandle>> handles;
3301 mHandles.GetActiveHandles(&handles);
3302
3303 for (uint32_t i = 0; i < handles.Length(); ++i) {
3304 rv = DoomFileInternal(handles[i]);
3305 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3305)
) {
3306 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, "CacheFileIOManager::EvictAllInternal() - Cannot doom handle "
"[handle=%p]", handles[i].get()); } } while (0)
3307 ("CacheFileIOManager::EvictAllInternal() - Cannot doom handle "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictAllInternal() - Cannot doom handle "
"[handle=%p]", handles[i].get()); } } while (0)
3308 "[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, "CacheFileIOManager::EvictAllInternal() - Cannot doom handle "
"[handle=%p]", handles[i].get()); } } while (0)
3309 handles[i].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, "CacheFileIOManager::EvictAllInternal() - Cannot doom handle "
"[handle=%p]", handles[i].get()); } } while (0)
;
3310 }
3311 }
3312
3313 nsCOMPtr<nsIFile> file;
3314 rv = mCacheDirectory->Clone(getter_AddRefs(file));
3315 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3315)
) {
3316 return rv;
3317 }
3318
3319 rv = file->AppendNative(nsLiteralCString(ENTRIES_DIR"entries"));
3320 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3320)
) {
3321 return rv;
3322 }
3323
3324 // Trash current entries directory
3325 rv = TrashDirectory(file);
3326 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3326)
) {
3327 return rv;
3328 }
3329
3330 // Files are now inaccessible in entries directory, notify observers.
3331 NS_DispatchToMainThread(r);
3332
3333 // Create a new empty entries directory
3334 rv = CheckAndCreateDir(mCacheDirectory, ENTRIES_DIR"entries", false);
3335 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3335)
) {
3336 return rv;
3337 }
3338
3339 CacheIndex::RemoveAll();
3340
3341 return NS_OK;
3342}
3343
3344// static
3345nsresult CacheFileIOManager::EvictByContext(
3346 nsILoadContextInfo* aLoadContextInfo, bool aPinned,
3347 const nsAString& aOrigin, const nsAString& aBaseDomain) {
3348 LOG(("CacheFileIOManager::EvictByContext() [loadContextInfo=%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, "CacheFileIOManager::EvictByContext() [loadContextInfo=%p]"
, aLoadContextInfo); } } while (0)
3349 aLoadContextInfo))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictByContext() [loadContextInfo=%p]"
, aLoadContextInfo); } } while (0)
;
3350
3351 // XXX evict dictionary data from memory cache
3352 nsresult rv;
3353 RefPtr<CacheFileIOManager> ioMan = gInstance;
3354
3355 if (!ioMan) {
3356 return NS_ERROR_NOT_INITIALIZED;
3357 }
3358
3359 nsCOMPtr<nsIRunnable> ev;
3360 ev =
3361 NewRunnableMethod<nsCOMPtr<nsILoadContextInfo>, bool, nsString, nsString>(
3362 "net::CacheFileIOManager::EvictByContextInternal", ioMan,
3363 &CacheFileIOManager::EvictByContextInternal, aLoadContextInfo,
3364 aPinned, aOrigin, aBaseDomain);
3365
3366 rv = ioMan->mIOThread->DispatchAfterPendingOpens(ev);
3367 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3367)
) {
3368 return rv;
3369 }
3370 // Clear the entries from the Index immediately, to comply with
3371 // https://www.w3.org/TR/clear-site-data/#fetch-integration
3372 // aBaseDomain isn't needed for Clear-Site-Data, but is for
3373 // ClearBaseDomain. This can also make CacheStorageService::Clear() and
3374 // ClearBaseDomain() be synchronous.
3375 // Note that we will effectively hide the entries until the actual evict
3376 // happens.
3377 CacheIndex::EvictByContext(aOrigin, aBaseDomain);
3378
3379 return NS_OK;
3380}
3381
3382nsresult CacheFileIOManager::EvictByContextInternal(
3383 nsILoadContextInfo* aLoadContextInfo, bool aPinned,
3384 const nsAString& aOrigin, const nsAString& aBaseDomain) {
3385 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, "CacheFileIOManager::EvictByContextInternal() [loadContextInfo=%p, "
"pinned=%d]", aLoadContextInfo, aPinned); } } while (0)
3386 ("CacheFileIOManager::EvictByContextInternal() [loadContextInfo=%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, "CacheFileIOManager::EvictByContextInternal() [loadContextInfo=%p, "
"pinned=%d]", aLoadContextInfo, aPinned); } } while (0)
3387 "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, "CacheFileIOManager::EvictByContextInternal() [loadContextInfo=%p, "
"pinned=%d]", aLoadContextInfo, aPinned); } } while (0)
3388 aLoadContextInfo, 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, "CacheFileIOManager::EvictByContextInternal() [loadContextInfo=%p, "
"pinned=%d]", aLoadContextInfo, aPinned); } } while (0)
;
3389
3390 nsresult rv;
3391
3392 if (aLoadContextInfo) {
3393 nsAutoCString suffix;
3394 aLoadContextInfo->OriginAttributesPtr()->CreateSuffix(suffix);
3395 LOG((" anonymous=%u, suffix=%s]", aLoadContextInfo->IsAnonymous(),do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " anonymous=%u, suffix=%s]"
, aLoadContextInfo->IsAnonymous(), suffix.get()); } } while
(0)
3396 suffix.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, " anonymous=%u, suffix=%s]"
, aLoadContextInfo->IsAnonymous(), suffix.get()); } } while
(0)
;
3397
3398 MOZ_ASSERT(mIOThread->IsCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIOThread->IsCurrentThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mIOThread->IsCurrentThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mIOThread->IsCurrentThread()", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3398); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { MOZ_CrashSequence(__null, 3398); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3399
3400 MOZ_ASSERT(!aLoadContextInfo->IsPrivate())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!aLoadContextInfo->IsPrivate())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!aLoadContextInfo->IsPrivate
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("!aLoadContextInfo->IsPrivate()", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3400); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aLoadContextInfo->IsPrivate()"
")"); do { MOZ_CrashSequence(__null, 3400); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3401 if (aLoadContextInfo->IsPrivate()) {
3402 return NS_ERROR_INVALID_ARG;
3403 }
3404 }
3405
3406 if (!mCacheDirectory) {
3407 // This is a kind of hack. Somebody called EvictAll() without a profile.
3408 // This happens in xpcshell tests that use cache without profile. We need
3409 // to notify observers in this case since the tests are waiting for it.
3410 // Also notify for aPinned == true, those are interested as well.
3411
3412 // XXX This doesn't actually clear anything in this case (is there anything
3413 // to clear?)
3414 if (!aLoadContextInfo) {
3415 RefPtr<EvictionNotifierRunnable> r = new EvictionNotifierRunnable();
3416 NS_DispatchToMainThread(r);
3417 }
3418 return NS_ERROR_FILE_INVALID_PATH;
3419 }
3420
3421 if (mShuttingDown) {
3422 return NS_ERROR_NOT_INITIALIZED;
3423 }
3424
3425 if (!mTreeCreated) {
3426 rv = CreateCacheTree();
3427 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3428 return rv;
3429 }
3430 }
3431
3432 NS_ConvertUTF16toUTF8 origin(aOrigin);
3433 NS_ConvertUTF16toUTF8 baseDomain(aBaseDomain);
3434
3435 // Doom all active handles that matches the load context
3436 // NOTE: Dictionaries have already been cleared synchronously,
3437 // so there's no need to re-clear them (which might cause
3438 // problems if they were re-created in to interim).
3439 nsTArray<RefPtr<CacheFileHandle>> handles;
3440 mHandles.GetActiveHandles(&handles);
3441
3442 for (uint32_t i = 0; i < handles.Length(); ++i) {
3443 CacheFileHandle* handle = handles[i];
3444
3445 const bool shouldRemove = [&] {
3446 nsAutoCString uriSpec;
3447 RefPtr<nsILoadContextInfo> info =
3448 CacheFileUtils::ParseKey(handle->Key(), nullptr, &uriSpec);
3449 if (!info) {
3450 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, "CacheFileIOManager::EvictByContextInternal() - Cannot parse key "
"in " "handle! [handle=%p, key=%s]", handle, handle->Key(
).get()); } } while (0)
3451 ("CacheFileIOManager::EvictByContextInternal() - Cannot parse key "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictByContextInternal() - Cannot parse key "
"in " "handle! [handle=%p, key=%s]", handle, handle->Key(
).get()); } } while (0)
3452 "in "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictByContextInternal() - Cannot parse key "
"in " "handle! [handle=%p, key=%s]", handle, handle->Key(
).get()); } } while (0)
3453 "handle! [handle=%p, 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, "CacheFileIOManager::EvictByContextInternal() - Cannot parse key "
"in " "handle! [handle=%p, key=%s]", handle, handle->Key(
).get()); } } while (0)
3454 handle, handle->Key().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, "CacheFileIOManager::EvictByContextInternal() - Cannot parse key "
"in " "handle! [handle=%p, key=%s]", handle, handle->Key(
).get()); } } while (0)
;
3455 MOZ_CRASH("Unexpected error!")do { do { } while (false); MOZ_ReportCrash("" "Unexpected error!"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 3455); AnnotateMozCrashReason
("MOZ_CRASH(" "Unexpected error!" ")"); do { MOZ_CrashSequence
(__null, 3455); __attribute__((nomerge)) ::abort(); } while (
false); } while (false)
;
3456 }
3457
3458 // Filter by base domain.
3459 if (!aBaseDomain.IsEmpty()) {
3460 if (StoragePrincipalHelper::PartitionKeyHasBaseDomain(
3461 info->OriginAttributesPtr()->mPartitionKey, aBaseDomain)) {
3462 return true;
3463 }
3464
3465 // If the partitionKey does not match, check the entry URI next.
3466
3467 // Get host portion of uriSpec.
3468 nsCOMPtr<nsIURI> uri;
3469 rv = NS_NewURI(getter_AddRefs(uri), uriSpec);
3470 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3470)
) {
3471 return false;
3472 }
3473 nsAutoCString host;
3474 rv = uri->GetHost(host);
3475 // Some entries may not have valid hosts. We can skip them.
3476 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0))) || host.IsEmpty()) {
3477 return false;
3478 }
3479
3480 // Clear entry if the host belongs to the given base domain.
3481 bool hasRootDomain = false;
3482 rv = HasRootDomain(host, baseDomain, &hasRootDomain);
3483 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3483)
) {
3484 return false;
3485 }
3486
3487 return hasRootDomain;
3488 }
3489
3490 // Filter by LoadContextInfo.
3491 if (aLoadContextInfo && !info->Equals(aLoadContextInfo)) {
3492 return false;
3493 }
3494
3495 // Filter by origin.
3496 if (!origin.IsEmpty()) { // XXX also look for dict:<origin>, or let that
3497 // be handled by Doom? Probably Doom
3498 RefPtr<MozURL> url;
3499 rv = MozURL::Init(getter_AddRefs(url), uriSpec);
3500 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3501 return false;
3502 }
3503
3504 nsAutoCString urlOrigin;
3505 url->Origin(urlOrigin);
3506
3507 if (!urlOrigin.Equals(origin)) {
3508 return false;
3509 }
3510 }
3511 return true;
3512 }();
3513
3514 if (!shouldRemove) {
3515 continue;
3516 }
3517
3518 // handle will be doomed only when pinning status is known and equal or
3519 // doom decision will be deferred until pinning status is determined.
3520 rv = DoomFileInternal(handle,
3521 aPinned ? CacheFileIOManager::DOOM_WHEN_PINNED
3522 : CacheFileIOManager::DOOM_WHEN_NON_PINNED,
3523 false);
3524 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3524)
) {
3525 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, "CacheFileIOManager::EvictByContextInternal() - Cannot doom handle"
" [handle=%p]", handle); } } while (0)
3526 ("CacheFileIOManager::EvictByContextInternal() - Cannot doom handle"do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictByContextInternal() - Cannot doom handle"
" [handle=%p]", handle); } } while (0)
3527 " [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, "CacheFileIOManager::EvictByContextInternal() - Cannot doom handle"
" [handle=%p]", handle); } } while (0)
3528 handle))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::EvictByContextInternal() - Cannot doom handle"
" [handle=%p]", handle); } } while (0)
;
3529 }
3530 }
3531
3532 if (!aLoadContextInfo) {
3533 RefPtr<EvictionNotifierRunnable> r = new EvictionNotifierRunnable();
3534 NS_DispatchToMainThread(r);
3535 }
3536
3537 if (!mContextEvictor) {
3538 mContextEvictor = new CacheFileContextEvictor();
3539 mContextEvictor->Init(mCacheDirectory);
3540 }
3541
3542 mContextEvictor->AddContext(aLoadContextInfo, aPinned, aOrigin, aBaseDomain);
3543
3544 return NS_OK;
3545}
3546
3547// static
3548nsresult CacheFileIOManager::CacheIndexStateChanged() {
3549 LOG(("CacheFileIOManager::CacheIndexStateChanged()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::CacheIndexStateChanged()"
); } } while (0)
;
3550
3551 nsresult rv;
3552
3553 // CacheFileIOManager lives longer than CacheIndex so gInstance must be
3554 // non-null here.
3555 MOZ_ASSERT(gInstance)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(gInstance)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(gInstance))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("gInstance", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3555); AnnotateMozCrashReason("MOZ_ASSERT" "(" "gInstance" ")"
); do { MOZ_CrashSequence(__null, 3555); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3556
3557 // We have to re-dispatch even if we are on IO thread to prevent reentering
3558 // the lock in CacheIndex
3559 nsCOMPtr<nsIRunnable> ev = NewRunnableMethod(
3560 "net::CacheFileIOManager::CacheIndexStateChangedInternal",
3561 gInstance.get(), &CacheFileIOManager::CacheIndexStateChangedInternal);
3562
3563 nsCOMPtr<nsIEventTarget> ioTarget = IOTarget();
3564 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/CacheFileIOManager.cpp"
, 3564); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ioTarget" ")"
); do { MOZ_CrashSequence(__null, 3564); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3565
3566 rv = ioTarget->Dispatch(ev, nsIEventTarget::DISPATCH_NORMAL);
3567 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3567)
) {
3568 return rv;
3569 }
3570
3571 return NS_OK;
3572}
3573
3574void CacheFileIOManager::CacheIndexStateChangedInternal() {
3575 if (mShuttingDown) {
3576 // ignore notification during shutdown
3577 return;
3578 }
3579
3580 if (!mContextEvictor) {
3581 return;
3582 }
3583
3584 mContextEvictor->CacheIndexStateChanged();
3585}
3586
3587nsresult CacheFileIOManager::TrashDirectory(nsIFile* aFile) {
3588 LOG(("CacheFileIOManager::TrashDirectory() [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, "CacheFileIOManager::TrashDirectory() [file=%s]"
, aFile->HumanReadablePath().get()); } } while (0)
3589 aFile->HumanReadablePath().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, "CacheFileIOManager::TrashDirectory() [file=%s]"
, aFile->HumanReadablePath().get()); } } while (0)
;
3590
3591 nsresult rv;
3592
3593 MOZ_ASSERT(mIOThread->IsCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIOThread->IsCurrentThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mIOThread->IsCurrentThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mIOThread->IsCurrentThread()", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3593); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { MOZ_CrashSequence(__null, 3593); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3594 MOZ_ASSERT(mCacheDirectory)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mCacheDirectory)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mCacheDirectory))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("mCacheDirectory"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 3594); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mCacheDirectory" ")"); do { MOZ_CrashSequence
(__null, 3594); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
3595
3596 // When the directory is empty, it is cheaper to remove it directly instead of
3597 // using the trash mechanism.
3598 bool isEmpty;
3599 rv = IsEmptyDirectory(aFile, &isEmpty);
3600 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/CacheFileIOManager.cpp"
, 3600); return rv; } } while (false)
;
3601
3602 if (isEmpty) {
3603 rv = aFile->Remove(false);
3604 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, "CacheFileIOManager::TrashDirectory() - Directory removed "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
3605 ("CacheFileIOManager::TrashDirectory() - Directory removed "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TrashDirectory() - Directory removed "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
3606 "[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, "CacheFileIOManager::TrashDirectory() - Directory removed "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
3607 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, "CacheFileIOManager::TrashDirectory() - Directory removed "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
;
3608 return rv;
3609 }
3610
3611#ifdef DEBUG1
3612 nsCOMPtr<nsIFile> dirCheck;
3613 rv = aFile->GetParent(getter_AddRefs(dirCheck));
3614 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/CacheFileIOManager.cpp"
, 3614); return rv; } } while (false)
;
3615
3616 bool equals = false;
3617 rv = dirCheck->Equals(mCacheDirectory, &equals);
3618 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/CacheFileIOManager.cpp"
, 3618); return rv; } } while (false)
;
3619
3620 MOZ_ASSERT(equals)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(equals)>::isValid, "invalid assertion condition")
; if ((__builtin_expect(!!(!(!!(equals))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("equals", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3620); AnnotateMozCrashReason("MOZ_ASSERT" "(" "equals" ")"
); do { MOZ_CrashSequence(__null, 3620); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3621#endif
3622
3623 nsCOMPtr<nsIFile> dir, trash;
3624 nsAutoCString leaf;
3625
3626 rv = aFile->Clone(getter_AddRefs(dir));
3627 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/CacheFileIOManager.cpp"
, 3627); return rv; } } while (false)
;
3628
3629 rv = aFile->Clone(getter_AddRefs(trash));
3630 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/CacheFileIOManager.cpp"
, 3630); return rv; } } while (false)
;
3631
3632 const int32_t kMaxTries = 16;
3633 srand(static_cast<unsigned>(PR_Now()));
3634 for (int32_t triesCount = 0;; ++triesCount) {
3635 leaf = TRASH_DIR"trash";
3636 leaf.AppendInt(rand());
3637 rv = trash->SetNativeLeafName(leaf);
3638 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/CacheFileIOManager.cpp"
, 3638); return rv; } } while (false)
;
3639
3640 bool exists;
3641 if (NS_SUCCEEDED(trash->Exists(&exists))((bool)(__builtin_expect(!!(!NS_FAILED_impl(trash->Exists(
&exists))), 1)))
&& !exists) {
3642 break;
3643 }
3644
3645 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, "CacheFileIOManager::TrashDirectory() - Trash directory already "
"exists [leaf=%s]", leaf.get()); } } while (0)
3646 ("CacheFileIOManager::TrashDirectory() - Trash directory already "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TrashDirectory() - Trash directory already "
"exists [leaf=%s]", leaf.get()); } } while (0)
3647 "exists [leaf=%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, "CacheFileIOManager::TrashDirectory() - Trash directory already "
"exists [leaf=%s]", leaf.get()); } } while (0)
3648 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, "CacheFileIOManager::TrashDirectory() - Trash directory already "
"exists [leaf=%s]", leaf.get()); } } while (0)
;
3649
3650 if (triesCount == kMaxTries) {
3651 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, "CacheFileIOManager::TrashDirectory() - Could not find unused trash "
"directory in %d tries.", kMaxTries); } } while (0)
3652 ("CacheFileIOManager::TrashDirectory() - Could not find unused trash "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TrashDirectory() - Could not find unused trash "
"directory in %d tries.", kMaxTries); } } while (0)
3653 "directory in %d tries.",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TrashDirectory() - Could not find unused trash "
"directory in %d tries.", kMaxTries); } } while (0)
3654 kMaxTries))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::TrashDirectory() - Could not find unused trash "
"directory in %d tries.", kMaxTries); } } while (0)
;
3655 return NS_ERROR_FAILURE;
3656 }
3657 }
3658
3659 LOG(("CacheFileIOManager::TrashDirectory() - Renaming directory [leaf=%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, "CacheFileIOManager::TrashDirectory() - Renaming directory [leaf=%s]"
, leaf.get()); } } while (0)
3660 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, "CacheFileIOManager::TrashDirectory() - Renaming directory [leaf=%s]"
, leaf.get()); } } while (0)
;
3661
3662 rv = dir->MoveToNative(nullptr, leaf);
3663 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/CacheFileIOManager.cpp"
, 3663); return rv; } } while (false)
;
3664
3665 StartRemovingTrash();
3666 return NS_OK;
3667}
3668
3669// static
3670void CacheFileIOManager::OnTrashTimer(nsITimer* aTimer, void* aClosure) {
3671 LOG(("CacheFileIOManager::OnTrashTimer() [timer=%p, closure=%p]", aTimer,do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OnTrashTimer() [timer=%p, closure=%p]"
, aTimer, aClosure); } } while (0)
3672 aClosure))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OnTrashTimer() [timer=%p, closure=%p]"
, aTimer, aClosure); } } while (0)
;
3673
3674 RefPtr<CacheFileIOManager> ioMan = gInstance;
3675
3676 if (!ioMan) {
3677 return;
3678 }
3679
3680 ioMan->mTrashTimer = nullptr;
3681 ioMan->StartRemovingTrash();
3682}
3683
3684nsresult CacheFileIOManager::StartRemovingTrash() {
3685 LOG(("CacheFileIOManager::StartRemovingTrash()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::StartRemovingTrash()"
); } } while (0)
;
3686
3687 nsresult rv;
3688
3689 MOZ_ASSERT(mIOThread->IsCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIOThread->IsCurrentThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mIOThread->IsCurrentThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mIOThread->IsCurrentThread()", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3689); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { MOZ_CrashSequence(__null, 3689); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3690
3691 if (mShuttingDown) {
3692 return NS_ERROR_NOT_INITIALIZED;
3693 }
3694
3695 if (!mCacheDirectory) {
3696 return NS_ERROR_FILE_INVALID_PATH;
3697 }
3698
3699 if (mTrashTimer) {
3700 LOG(("CacheFileIOManager::StartRemovingTrash() - Trash timer exists."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::StartRemovingTrash() - Trash timer exists."
); } } while (0)
;
3701 return NS_OK;
3702 }
3703
3704 if (mRemovingTrashDirs) {
3705 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, "CacheFileIOManager::StartRemovingTrash() - Trash removing in "
"progress."); } } while (0)
3706 ("CacheFileIOManager::StartRemovingTrash() - Trash removing in "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::StartRemovingTrash() - Trash removing in "
"progress."); } } while (0)
3707 "progress."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::StartRemovingTrash() - Trash removing in "
"progress."); } } while (0)
;
3708 return NS_OK;
3709 }
3710
3711 uint32_t elapsed = (TimeStamp::NowLoRes() - mStartTime).ToMilliseconds();
3712 if (elapsed < kRemoveTrashStartDelay60000) {
3713 nsCOMPtr<nsIEventTarget> ioTarget = IOTarget();
3714 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/CacheFileIOManager.cpp"
, 3714); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ioTarget" ")"
); do { MOZ_CrashSequence(__null, 3714); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3715
3716 return NS_NewTimerWithFuncCallback(
3717 getter_AddRefs(mTrashTimer), CacheFileIOManager::OnTrashTimer, nullptr,
3718 kRemoveTrashStartDelay60000 - elapsed, nsITimer::TYPE_ONE_SHOT,
3719 "net::CacheFileIOManager::StartRemovingTrash"_ns, ioTarget);
3720 }
3721
3722 nsCOMPtr<nsIRunnable> ev;
3723 ev = NewRunnableMethod("net::CacheFileIOManager::RemoveTrashInternal", this,
3724 &CacheFileIOManager::RemoveTrashInternal);
3725
3726 rv = mIOThread->Dispatch(ev, CacheIOThread::EVICT);
3727 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/CacheFileIOManager.cpp"
, 3727); return rv; } } while (false)
;
3728
3729 mRemovingTrashDirs = true;
3730 return NS_OK;
3731}
3732
3733nsresult CacheFileIOManager::RemoveTrashInternal() {
3734 LOG(("CacheFileIOManager::RemoveTrashInternal()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RemoveTrashInternal()"
); } } while (0)
;
3735
3736 nsresult rv;
3737
3738 MOZ_ASSERT(mIOThread->IsCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIOThread->IsCurrentThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mIOThread->IsCurrentThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mIOThread->IsCurrentThread()", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3738); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { MOZ_CrashSequence(__null, 3738); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3739
3740 if (mShuttingDown) {
3741 return NS_ERROR_NOT_INITIALIZED;
3742 }
3743
3744 CacheIOThread::Cancelable cancelable(true);
3745
3746 MOZ_ASSERT(!mTrashTimer)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mTrashTimer)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!mTrashTimer))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("!mTrashTimer", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3746); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mTrashTimer"
")"); do { MOZ_CrashSequence(__null, 3746); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3747 MOZ_ASSERT(mRemovingTrashDirs)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mRemovingTrashDirs)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mRemovingTrashDirs))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("mRemovingTrashDirs"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 3747); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mRemovingTrashDirs" ")"); do { MOZ_CrashSequence
(__null, 3747); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
3748
3749 if (!mTreeCreated) {
3750 rv = CreateCacheTree();
3751 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3752 return rv;
3753 }
3754 }
3755
3756 // mRemovingTrashDirs is accessed only on IO thread, so we can drop the flag
3757 // here and set it again once we dispatch a continuation event. By doing so,
3758 // we don't have to drop the flag on any possible early return.
3759 mRemovingTrashDirs = false;
3760
3761 while (true) {
3762 if (CacheIOThread::YieldAndRerun()) {
3763 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, "CacheFileIOManager::RemoveTrashInternal() - Breaking loop for "
"higher level events."); } } while (0)
3764 ("CacheFileIOManager::RemoveTrashInternal() - Breaking loop 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, "CacheFileIOManager::RemoveTrashInternal() - Breaking loop for "
"higher level events."); } } while (0)
3765 "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, "CacheFileIOManager::RemoveTrashInternal() - Breaking loop for "
"higher level events."); } } while (0)
;
3766 mRemovingTrashDirs = true;
3767 return NS_OK;
3768 }
3769
3770 // Find some trash directory
3771 if (!mTrashDir) {
3772 MOZ_ASSERT(!mTrashDirEnumerator)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mTrashDirEnumerator)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!mTrashDirEnumerator))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("!mTrashDirEnumerator"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 3772); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!mTrashDirEnumerator" ")"); do { MOZ_CrashSequence
(__null, 3772); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
3773
3774 rv = FindTrashDirToRemove();
3775 if (rv == NS_ERROR_NOT_AVAILABLE) {
3776 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, "CacheFileIOManager::RemoveTrashInternal() - No trash directory "
"found."); } } while (0)
3777 ("CacheFileIOManager::RemoveTrashInternal() - No trash directory "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RemoveTrashInternal() - No trash directory "
"found."); } } while (0)
3778 "found."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RemoveTrashInternal() - No trash directory "
"found."); } } while (0)
;
3779 return NS_OK;
3780 }
3781 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/CacheFileIOManager.cpp"
, 3781); return rv; } } while (false)
;
3782
3783 rv = mTrashDir->GetDirectoryEntries(getter_AddRefs(mTrashDirEnumerator));
3784 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/CacheFileIOManager.cpp"
, 3784); return rv; } } while (false)
;
3785
3786 continue; // check elapsed time
3787 }
3788
3789 // We null out mTrashDirEnumerator once we remove all files in the
3790 // directory, so remove the trash directory if we don't have enumerator.
3791 if (!mTrashDirEnumerator) {
3792 rv = mTrashDir->Remove(false);
3793 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3794 // There is no reason why removing an empty directory should fail, but
3795 // if it does, we should continue and try to remove all other trash
3796 // directories.
3797 nsAutoCString leafName;
3798 mTrashDir->GetNativeLeafName(leafName);
3799 mFailedTrashDirs.AppendElement(leafName);
3800 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, "CacheFileIOManager::RemoveTrashInternal() - Cannot remove "
"trashdir. [name=%s]", leafName.get()); } } while (0)
3801 ("CacheFileIOManager::RemoveTrashInternal() - Cannot remove "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RemoveTrashInternal() - Cannot remove "
"trashdir. [name=%s]", leafName.get()); } } while (0)
3802 "trashdir. [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, "CacheFileIOManager::RemoveTrashInternal() - Cannot remove "
"trashdir. [name=%s]", leafName.get()); } } while (0)
3803 leafName.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, "CacheFileIOManager::RemoveTrashInternal() - Cannot remove "
"trashdir. [name=%s]", leafName.get()); } } while (0)
;
3804 }
3805
3806 mTrashDir = nullptr;
3807 continue; // check elapsed time
3808 }
3809
3810 nsCOMPtr<nsIFile> file;
3811 rv = mTrashDirEnumerator->GetNextFile(getter_AddRefs(file));
Value stored to 'rv' is never read
3812 if (!file) {
3813 mTrashDirEnumerator->Close();
3814 mTrashDirEnumerator = nullptr;
3815 continue; // check elapsed time
3816 }
3817 bool isDir = false;
3818 file->IsDirectory(&isDir);
3819 if (isDir) {
3820 NS_WARNING(NS_DebugBreak(NS_DEBUG_WARNING, "Found a directory in a trash directory! It will be removed "
"recursively, but this can block IO thread for a while!", nullptr
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 3822)
3821 "Found a directory in a trash directory! It will be removed "NS_DebugBreak(NS_DEBUG_WARNING, "Found a directory in a trash directory! It will be removed "
"recursively, but this can block IO thread for a while!", nullptr
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 3822)
3822 "recursively, but this can block IO thread for a while!")NS_DebugBreak(NS_DEBUG_WARNING, "Found a directory in a trash directory! It will be removed "
"recursively, but this can block IO thread for a while!", nullptr
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 3822)
;
3823 if (LOG_ENABLED()(__builtin_expect(!!(mozilla::detail::log_test(gCache2Log, mozilla
::LogLevel::Debug)), 0))
) {
3824 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, "CacheFileIOManager::RemoveTrashInternal() - Found a directory in "
"a trash " "directory! It will be removed recursively, but this can block IO "
"thread for a while! [file=%s]", file->HumanReadablePath(
).get()); } } while (0)
3825 ("CacheFileIOManager::RemoveTrashInternal() - Found a directory in "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RemoveTrashInternal() - Found a directory in "
"a trash " "directory! It will be removed recursively, but this can block IO "
"thread for a while! [file=%s]", file->HumanReadablePath(
).get()); } } while (0)
3826 "a trash "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RemoveTrashInternal() - Found a directory in "
"a trash " "directory! It will be removed recursively, but this can block IO "
"thread for a while! [file=%s]", file->HumanReadablePath(
).get()); } } while (0)
3827 "directory! It will be removed recursively, but this can block IO "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::RemoveTrashInternal() - Found a directory in "
"a trash " "directory! It will be removed recursively, but this can block IO "
"thread for a while! [file=%s]", file->HumanReadablePath(
).get()); } } while (0)
3828 "thread for a while! [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, "CacheFileIOManager::RemoveTrashInternal() - Found a directory in "
"a trash " "directory! It will be removed recursively, but this can block IO "
"thread for a while! [file=%s]", file->HumanReadablePath(
).get()); } } while (0)
3829 file->HumanReadablePath().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, "CacheFileIOManager::RemoveTrashInternal() - Found a directory in "
"a trash " "directory! It will be removed recursively, but this can block IO "
"thread for a while! [file=%s]", file->HumanReadablePath(
).get()); } } while (0)
;
3830 }
3831 }
3832 file->Remove(isDir);
3833 }
3834
3835 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/CacheFileIOManager.cpp"
, 3835); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "We should never get here" ")"); do
{ MOZ_CrashSequence(__null, 3835); __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
3836 return NS_OK;
3837}
3838
3839nsresult CacheFileIOManager::FindTrashDirToRemove() {
3840 LOG(("CacheFileIOManager::FindTrashDirToRemove()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::FindTrashDirToRemove()"
); } } while (0)
;
3841
3842 nsresult rv;
3843
3844 if (!mCacheDirectory) {
3845 return NS_ERROR_UNEXPECTED;
3846 }
3847
3848 // We call this method on the main thread during shutdown when user wants to
3849 // remove all cache files.
3850 MOZ_ASSERT(mIOThread->IsCurrentThread() || mShuttingDown)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIOThread->IsCurrentThread() || mShuttingDown)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(mIOThread->IsCurrentThread() || mShuttingDown))),
0))) { do { } while (false); MOZ_ReportAssertionFailure("mIOThread->IsCurrentThread() || mShuttingDown"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 3850); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread() || mShuttingDown"
")"); do { MOZ_CrashSequence(__null, 3850); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3851
3852 nsCOMPtr<nsIDirectoryEnumerator> iter;
3853 rv = mCacheDirectory->GetDirectoryEntries(getter_AddRefs(iter));
3854 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/CacheFileIOManager.cpp"
, 3854); return rv; } } while (false)
;
3855
3856 nsCOMPtr<nsIFile> file;
3857 while (NS_SUCCEEDED(iter->GetNextFile(getter_AddRefs(file)))((bool)(__builtin_expect(!!(!NS_FAILED_impl(iter->GetNextFile
(getter_AddRefs(file)))), 1)))
&& file) {
3858 bool isDir = false;
3859 file->IsDirectory(&isDir);
3860 if (!isDir) {
3861 continue;
3862 }
3863
3864 nsAutoCString leafName;
3865 rv = file->GetNativeLeafName(leafName);
3866 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
3867 continue;
3868 }
3869
3870 if (leafName.Length() < strlen(TRASH_DIR"trash")) {
3871 continue;
3872 }
3873
3874 if (!StringBeginsWith(leafName, nsLiteralCString(TRASH_DIR"trash"))) {
3875 continue;
3876 }
3877
3878 if (mFailedTrashDirs.Contains(leafName)) {
3879 continue;
3880 }
3881
3882 LOG(("CacheFileIOManager::FindTrashDirToRemove() - Returning directory %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, "CacheFileIOManager::FindTrashDirToRemove() - Returning directory %s"
, leafName.get()); } } while (0)
3883 leafName.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, "CacheFileIOManager::FindTrashDirToRemove() - Returning directory %s"
, leafName.get()); } } while (0)
;
3884
3885 mTrashDir = std::move(file);
3886 return NS_OK;
3887 }
3888
3889 // When we're here we've tried to delete all trash directories. Clear
3890 // mFailedTrashDirs so we will try to delete them again when we start removing
3891 // trash directories next time.
3892 mFailedTrashDirs.Clear();
3893 return NS_ERROR_NOT_AVAILABLE;
3894}
3895
3896// static
3897nsresult CacheFileIOManager::InitIndexEntry(CacheFileHandle* aHandle,
3898 OriginAttrsHash aOriginAttrsHash,
3899 bool aAnonymous, bool aPinning) {
3900 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, "CacheFileIOManager::InitIndexEntry() [handle=%p, "
"originAttrsHash=%" "l" "x" ", " "anonymous=%d, pinning=%d]"
, aHandle, aOriginAttrsHash, aAnonymous, aPinning); } } while
(0)
3901 ("CacheFileIOManager::InitIndexEntry() [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, "CacheFileIOManager::InitIndexEntry() [handle=%p, "
"originAttrsHash=%" "l" "x" ", " "anonymous=%d, pinning=%d]"
, aHandle, aOriginAttrsHash, aAnonymous, aPinning); } } while
(0)
3902 "originAttrsHash=%" PRIx64 ", "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::InitIndexEntry() [handle=%p, "
"originAttrsHash=%" "l" "x" ", " "anonymous=%d, pinning=%d]"
, aHandle, aOriginAttrsHash, aAnonymous, aPinning); } } while
(0)
3903 "anonymous=%d, pinning=%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, "CacheFileIOManager::InitIndexEntry() [handle=%p, "
"originAttrsHash=%" "l" "x" ", " "anonymous=%d, pinning=%d]"
, aHandle, aOriginAttrsHash, aAnonymous, aPinning); } } while
(0)
3904 aHandle, aOriginAttrsHash, aAnonymous, aPinning))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::InitIndexEntry() [handle=%p, "
"originAttrsHash=%" "l" "x" ", " "anonymous=%d, pinning=%d]"
, aHandle, aOriginAttrsHash, aAnonymous, aPinning); } } while
(0)
;
3905
3906 nsresult rv;
3907 RefPtr<CacheFileIOManager> ioMan = gInstance;
3908
3909 if (aHandle->IsClosed() || !ioMan) {
3910 return NS_ERROR_NOT_INITIALIZED;
3911 }
3912
3913 if (aHandle->IsSpecialFile()) {
3914 return NS_ERROR_UNEXPECTED;
3915 }
3916
3917 RefPtr<InitIndexEntryEvent> ev =
3918 new InitIndexEntryEvent(aHandle, aOriginAttrsHash, aAnonymous, aPinning);
3919 rv = ioMan->mIOThread->Dispatch(ev, aHandle->mPriority
3920 ? CacheIOThread::WRITE_PRIORITY
3921 : CacheIOThread::WRITE);
3922 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/CacheFileIOManager.cpp"
, 3922); return rv; } } while (false)
;
3923
3924 return NS_OK;
3925}
3926
3927// static
3928nsresult CacheFileIOManager::UpdateIndexEntry(CacheFileHandle* aHandle,
3929 const uint32_t* aFrecency,
3930 const bool* aHasAltData,
3931 const uint32_t* aLastFetched,
3932 const uint32_t* aFetchCount,
3933 const uint8_t* aContentType) {
3934 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, "CacheFileIOManager::UpdateIndexEntry() [handle=%p, frecency=%s, "
"hasAltData=%s, lastFetched=%s, fetchCount=%s, contentType=%s]"
, aHandle, aFrecency ? nsPrintfCString("%u", *aFrecency).get(
) : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "",
aLastFetched ? nsPrintfCString("%u", *aLastFetched).get() : ""
, aFetchCount ? nsPrintfCString("%u", *aFetchCount).get() : ""
, aContentType ? nsPrintfCString("%u", *aContentType).get() :
""); } } while (0)
3935 ("CacheFileIOManager::UpdateIndexEntry() [handle=%p, frecency=%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, "CacheFileIOManager::UpdateIndexEntry() [handle=%p, frecency=%s, "
"hasAltData=%s, lastFetched=%s, fetchCount=%s, contentType=%s]"
, aHandle, aFrecency ? nsPrintfCString("%u", *aFrecency).get(
) : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "",
aLastFetched ? nsPrintfCString("%u", *aLastFetched).get() : ""
, aFetchCount ? nsPrintfCString("%u", *aFetchCount).get() : ""
, aContentType ? nsPrintfCString("%u", *aContentType).get() :
""); } } while (0)
3936 "hasAltData=%s, lastFetched=%s, fetchCount=%s, contentType=%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, "CacheFileIOManager::UpdateIndexEntry() [handle=%p, frecency=%s, "
"hasAltData=%s, lastFetched=%s, fetchCount=%s, contentType=%s]"
, aHandle, aFrecency ? nsPrintfCString("%u", *aFrecency).get(
) : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "",
aLastFetched ? nsPrintfCString("%u", *aLastFetched).get() : ""
, aFetchCount ? nsPrintfCString("%u", *aFetchCount).get() : ""
, aContentType ? nsPrintfCString("%u", *aContentType).get() :
""); } } while (0)
3937 aHandle, 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, "CacheFileIOManager::UpdateIndexEntry() [handle=%p, frecency=%s, "
"hasAltData=%s, lastFetched=%s, fetchCount=%s, contentType=%s]"
, aHandle, aFrecency ? nsPrintfCString("%u", *aFrecency).get(
) : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "",
aLastFetched ? nsPrintfCString("%u", *aLastFetched).get() : ""
, aFetchCount ? nsPrintfCString("%u", *aFetchCount).get() : ""
, aContentType ? nsPrintfCString("%u", *aContentType).get() :
""); } } while (0)
3938 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, "CacheFileIOManager::UpdateIndexEntry() [handle=%p, frecency=%s, "
"hasAltData=%s, lastFetched=%s, fetchCount=%s, contentType=%s]"
, aHandle, aFrecency ? nsPrintfCString("%u", *aFrecency).get(
) : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "",
aLastFetched ? nsPrintfCString("%u", *aLastFetched).get() : ""
, aFetchCount ? nsPrintfCString("%u", *aFetchCount).get() : ""
, aContentType ? nsPrintfCString("%u", *aContentType).get() :
""); } } while (0)
3939 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, "CacheFileIOManager::UpdateIndexEntry() [handle=%p, frecency=%s, "
"hasAltData=%s, lastFetched=%s, fetchCount=%s, contentType=%s]"
, aHandle, aFrecency ? nsPrintfCString("%u", *aFrecency).get(
) : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "",
aLastFetched ? nsPrintfCString("%u", *aLastFetched).get() : ""
, aFetchCount ? nsPrintfCString("%u", *aFetchCount).get() : ""
, aContentType ? nsPrintfCString("%u", *aContentType).get() :
""); } } while (0)
3940 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, "CacheFileIOManager::UpdateIndexEntry() [handle=%p, frecency=%s, "
"hasAltData=%s, lastFetched=%s, fetchCount=%s, contentType=%s]"
, aHandle, aFrecency ? nsPrintfCString("%u", *aFrecency).get(
) : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "",
aLastFetched ? nsPrintfCString("%u", *aLastFetched).get() : ""
, aFetchCount ? nsPrintfCString("%u", *aFetchCount).get() : ""
, aContentType ? nsPrintfCString("%u", *aContentType).get() :
""); } } while (0)
3941 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, "CacheFileIOManager::UpdateIndexEntry() [handle=%p, frecency=%s, "
"hasAltData=%s, lastFetched=%s, fetchCount=%s, contentType=%s]"
, aHandle, aFrecency ? nsPrintfCString("%u", *aFrecency).get(
) : "", aHasAltData ? (*aHasAltData ? "true" : "false") : "",
aLastFetched ? nsPrintfCString("%u", *aLastFetched).get() : ""
, aFetchCount ? nsPrintfCString("%u", *aFetchCount).get() : ""
, aContentType ? nsPrintfCString("%u", *aContentType).get() :
""); } } while (0)
;
3942
3943 nsresult rv;
3944 RefPtr<CacheFileIOManager> ioMan = gInstance;
3945
3946 if (aHandle->IsClosed() || !ioMan) {
3947 return NS_ERROR_NOT_INITIALIZED;
3948 }
3949
3950 if (aHandle->IsSpecialFile()) {
3951 return NS_ERROR_UNEXPECTED;
3952 }
3953
3954 RefPtr<UpdateIndexEntryEvent> ev = new UpdateIndexEntryEvent(
3955 aHandle, aFrecency, aHasAltData, aLastFetched, aFetchCount, aContentType);
3956 rv = ioMan->mIOThread->Dispatch(ev, aHandle->mPriority
3957 ? CacheIOThread::WRITE_PRIORITY
3958 : CacheIOThread::WRITE);
3959 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/CacheFileIOManager.cpp"
, 3959); return rv; } } while (false)
;
3960
3961 return NS_OK;
3962}
3963
3964nsresult CacheFileIOManager::CreateFile(CacheFileHandle* aHandle) {
3965 MOZ_ASSERT(!aHandle->mFD)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!aHandle->mFD)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!aHandle->mFD))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("!aHandle->mFD"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 3965); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!aHandle->mFD" ")"); do { MOZ_CrashSequence
(__null, 3965); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
3966 MOZ_ASSERT(aHandle->mFile)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aHandle->mFile)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aHandle->mFile))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("aHandle->mFile"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 3966); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "aHandle->mFile" ")"); do { MOZ_CrashSequence
(__null, 3966); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
3967
3968 nsresult rv;
3969
3970 if (aHandle->IsDoomed()) {
3971 nsCOMPtr<nsIFile> file;
3972
3973 rv = GetDoomedFile(getter_AddRefs(file));
3974 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/CacheFileIOManager.cpp"
, 3974); return rv; } } while (false)
;
3975
3976 aHandle->mFile.swap(file);
3977 } else {
3978 bool exists;
3979 if (NS_SUCCEEDED(aHandle->mFile->Exists(&exists))((bool)(__builtin_expect(!!(!NS_FAILED_impl(aHandle->mFile
->Exists(&exists))), 1)))
&& exists) {
3980 NS_WARNING("Found a file that should not exist!")NS_DebugBreak(NS_DEBUG_WARNING, "Found a file that should not exist!"
, nullptr, "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 3980)
;
3981 }
3982 }
3983
3984 rv = OpenNSPRHandle(aHandle, true);
3985 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/CacheFileIOManager.cpp"
, 3985); return rv; } } while (false)
;
3986
3987 aHandle->mFileSize = 0;
3988 return NS_OK;
3989}
3990
3991// static
3992void CacheFileIOManager::HashToStr(const SHA1Sum::Hash* aHash,
3993 nsACString& _retval) {
3994 _retval.Truncate();
3995 const char hexChars[] = {'0', '1', '2', '3', '4', '5', '6', '7',
3996 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
3997 for (uint32_t i = 0; i < sizeof(SHA1Sum::Hash); i++) {
3998 _retval.Append(hexChars[(*aHash)[i] >> 4]);
3999 _retval.Append(hexChars[(*aHash)[i] & 0xF]);
4000 }
4001}
4002
4003// static
4004nsresult CacheFileIOManager::StrToHash(const nsACString& aHash,
4005 SHA1Sum::Hash* _retval) {
4006 if (aHash.Length() != 2 * sizeof(SHA1Sum::Hash)) {
4007 return NS_ERROR_INVALID_ARG;
4008 }
4009
4010 for (uint32_t i = 0; i < aHash.Length(); i++) {
4011 uint8_t value;
4012
4013 if (aHash[i] >= '0' && aHash[i] <= '9') {
4014 value = aHash[i] - '0';
4015 } else if (aHash[i] >= 'A' && aHash[i] <= 'F') {
4016 value = aHash[i] - 'A' + 10;
4017 } else if (aHash[i] >= 'a' && aHash[i] <= 'f') {
4018 value = aHash[i] - 'a' + 10;
4019 } else {
4020 return NS_ERROR_INVALID_ARG;
4021 }
4022
4023 if (i % 2 == 0) {
4024 (reinterpret_cast<uint8_t*>(_retval))[i / 2] = value << 4;
4025 } else {
4026 (reinterpret_cast<uint8_t*>(_retval))[i / 2] += value;
4027 }
4028 }
4029
4030 return NS_OK;
4031}
4032
4033nsresult CacheFileIOManager::GetFile(const SHA1Sum::Hash* aHash,
4034 nsIFile** _retval) {
4035 nsresult rv;
4036 nsCOMPtr<nsIFile> file;
4037 rv = mCacheDirectory->Clone(getter_AddRefs(file));
4038 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/CacheFileIOManager.cpp"
, 4038); return rv; } } while (false)
;
4039
4040 rv = file->AppendNative(nsLiteralCString(ENTRIES_DIR"entries"));
4041 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/CacheFileIOManager.cpp"
, 4041); return rv; } } while (false)
;
4042
4043 nsAutoCString leafName;
4044 HashToStr(aHash, leafName);
4045
4046 rv = file->AppendNative(leafName);
4047 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/CacheFileIOManager.cpp"
, 4047); return rv; } } while (false)
;
4048
4049 file.swap(*_retval);
4050 return NS_OK;
4051}
4052
4053nsresult CacheFileIOManager::GetSpecialFile(const nsACString& aKey,
4054 nsIFile** _retval) {
4055 nsresult rv;
4056 nsCOMPtr<nsIFile> file;
4057 rv = mCacheDirectory->Clone(getter_AddRefs(file));
4058 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/CacheFileIOManager.cpp"
, 4058); return rv; } } while (false)
;
4059
4060 rv = file->AppendNative(aKey);
4061 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/CacheFileIOManager.cpp"
, 4061); return rv; } } while (false)
;
4062
4063 file.swap(*_retval);
4064 return NS_OK;
4065}
4066
4067nsresult CacheFileIOManager::GetDoomedFile(nsIFile** _retval) {
4068 nsresult rv;
4069 nsCOMPtr<nsIFile> file;
4070 rv = mCacheDirectory->Clone(getter_AddRefs(file));
4071 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/CacheFileIOManager.cpp"
, 4071); return rv; } } while (false)
;
4072
4073 rv = file->AppendNative(nsLiteralCString(DOOMED_DIR"doomed"));
4074 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/CacheFileIOManager.cpp"
, 4074); return rv; } } while (false)
;
4075
4076 rv = file->AppendNative("dummyleaf"_ns);
4077 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/CacheFileIOManager.cpp"
, 4077); return rv; } } while (false)
;
4078
4079 const int32_t kMaxTries = 64;
4080 srand(static_cast<unsigned>(PR_Now()));
4081 nsAutoCString leafName;
4082 for (int32_t triesCount = 0;; ++triesCount) {
4083 leafName.AppendInt(rand());
4084 rv = file->SetNativeLeafName(leafName);
4085 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/CacheFileIOManager.cpp"
, 4085); return rv; } } while (false)
;
4086
4087 bool exists;
4088 if (NS_SUCCEEDED(file->Exists(&exists))((bool)(__builtin_expect(!!(!NS_FAILED_impl(file->Exists(&
exists))), 1)))
&& !exists) {
4089 break;
4090 }
4091
4092 if (triesCount == kMaxTries) {
4093 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, "CacheFileIOManager::GetDoomedFile() - Could not find unused file "
"name in %d tries.", kMaxTries); } } while (0)
4094 ("CacheFileIOManager::GetDoomedFile() - Could not find unused 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, "CacheFileIOManager::GetDoomedFile() - Could not find unused file "
"name in %d tries.", kMaxTries); } } while (0)
4095 "name in %d tries.",do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::GetDoomedFile() - Could not find unused file "
"name in %d tries.", kMaxTries); } } while (0)
4096 kMaxTries))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::GetDoomedFile() - Could not find unused file "
"name in %d tries.", kMaxTries); } } while (0)
;
4097 return NS_ERROR_FAILURE;
4098 }
4099
4100 leafName.Truncate();
4101 }
4102
4103 file.swap(*_retval);
4104 return NS_OK;
4105}
4106
4107nsresult CacheFileIOManager::IsEmptyDirectory(nsIFile* aFile, bool* _retval) {
4108 MOZ_ASSERT(mIOThread->IsCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIOThread->IsCurrentThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mIOThread->IsCurrentThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mIOThread->IsCurrentThread()", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 4108); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { MOZ_CrashSequence(__null, 4108); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4109
4110 nsresult rv;
4111
4112 nsCOMPtr<nsIDirectoryEnumerator> enumerator;
4113 rv = aFile->GetDirectoryEntries(getter_AddRefs(enumerator));
4114 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/CacheFileIOManager.cpp"
, 4114); return rv; } } while (false)
;
4115
4116 bool hasMoreElements = false;
4117 rv = enumerator->HasMoreElements(&hasMoreElements);
4118 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/CacheFileIOManager.cpp"
, 4118); return rv; } } while (false)
;
4119
4120 *_retval = !hasMoreElements;
4121 return NS_OK;
4122}
4123
4124nsresult CacheFileIOManager::CheckAndCreateDir(nsIFile* aFile, const char* aDir,
4125 bool aEnsureEmptyDir) {
4126 nsresult rv;
4127
4128 nsCOMPtr<nsIFile> file;
4129 if (!aDir) {
4130 file = aFile;
4131 } else {
4132 nsAutoCString dir(aDir);
4133 rv = aFile->Clone(getter_AddRefs(file));
4134 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/CacheFileIOManager.cpp"
, 4134); return rv; } } while (false)
;
4135 rv = file->AppendNative(dir);
4136 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/CacheFileIOManager.cpp"
, 4136); return rv; } } while (false)
;
4137 }
4138
4139 bool exists = false;
4140 rv = file->Exists(&exists);
4141 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && exists) {
4142 bool isDirectory = false;
4143 rv = file->IsDirectory(&isDirectory);
4144 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0))) || !isDirectory) {
4145 // Try to remove the file
4146 rv = file->Remove(false);
4147 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
4148 exists = false;
4149 }
4150 }
4151 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/CacheFileIOManager.cpp"
, 4151); return rv; } } while (false)
;
4152 }
4153
4154 if (aEnsureEmptyDir && NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && exists) {
4155 bool isEmpty;
4156 rv = IsEmptyDirectory(file, &isEmpty);
4157 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/CacheFileIOManager.cpp"
, 4157); return rv; } } while (false)
;
4158
4159 if (!isEmpty) {
4160 // Don't check the result, if this fails, it's OK. We do this
4161 // only for the doomed directory that doesn't need to be deleted
4162 // for the cost of completely disabling the whole browser.
4163 TrashDirectory(file);
4164 }
4165 }
4166
4167 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && !exists) {
4168 rv = file->Create(nsIFile::DIRECTORY_TYPE, 0700);
4169 }
4170 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
4171 NS_WARNING("Cannot create directory")NS_DebugBreak(NS_DEBUG_WARNING, "Cannot create directory", nullptr
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 4171)
;
4172 return NS_ERROR_FAILURE;
4173 }
4174
4175 return NS_OK;
4176}
4177
4178nsresult CacheFileIOManager::CreateCacheTree() {
4179 MOZ_ASSERT(mIOThread->IsCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIOThread->IsCurrentThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mIOThread->IsCurrentThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mIOThread->IsCurrentThread()", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 4179); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { MOZ_CrashSequence(__null, 4179); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4180 MOZ_ASSERT(!mTreeCreated)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mTreeCreated)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!mTreeCreated))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("!mTreeCreated",
"./../../../netwerk/cache2/CacheFileIOManager.cpp", 4180); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!mTreeCreated" ")"); do { MOZ_CrashSequence
(__null, 4180); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
4181
4182 if (!mCacheDirectory || mTreeCreationFailed) {
4183 return NS_ERROR_FILE_INVALID_PATH;
4184 }
4185
4186 nsresult rv;
4187
4188 // Set the flag here and clear it again below when the tree is created
4189 // successfully.
4190 mTreeCreationFailed = true;
4191
4192 // ensure parent directory exists
4193 nsCOMPtr<nsIFile> parentDir;
4194 rv = mCacheDirectory->GetParent(getter_AddRefs(parentDir));
4195 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/CacheFileIOManager.cpp"
, 4195); return rv; } } while (false)
;
4196 rv = CheckAndCreateDir(parentDir, nullptr, false);
4197 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/CacheFileIOManager.cpp"
, 4197); return rv; } } while (false)
;
4198
4199 // ensure cache directory exists
4200 rv = CheckAndCreateDir(mCacheDirectory, nullptr, false);
4201 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/CacheFileIOManager.cpp"
, 4201); return rv; } } while (false)
;
4202
4203 // ensure entries directory exists
4204 rv = CheckAndCreateDir(mCacheDirectory, ENTRIES_DIR"entries", false);
4205 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/CacheFileIOManager.cpp"
, 4205); return rv; } } while (false)
;
4206
4207 // ensure doomed directory exists
4208 rv = CheckAndCreateDir(mCacheDirectory, DOOMED_DIR"doomed", true);
4209 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/CacheFileIOManager.cpp"
, 4209); return rv; } } while (false)
;
4210
4211 mTreeCreated = true;
4212 mTreeCreationFailed = false;
4213
4214 if (!mContextEvictor) {
4215 RefPtr<CacheFileContextEvictor> contextEvictor;
4216 contextEvictor = new CacheFileContextEvictor();
4217
4218 // Init() method will try to load unfinished contexts from the disk. Store
4219 // the evictor as a member only when there is some unfinished job.
4220 contextEvictor->Init(mCacheDirectory);
4221 if (contextEvictor->ContextsCount()) {
4222 contextEvictor.swap(mContextEvictor);
4223 }
4224 }
4225
4226 StartRemovingTrash();
4227
4228 return NS_OK;
4229}
4230
4231nsresult CacheFileIOManager::OpenNSPRHandle(CacheFileHandle* aHandle,
4232 bool aCreate) {
4233 LOG(("CacheFileIOManager::OpenNSPRHandle BEGIN, handle=%p", 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, "CacheFileIOManager::OpenNSPRHandle BEGIN, handle=%p"
, aHandle); } } while (0)
;
4234
4235 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 4235); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { MOZ_CrashSequence(__null, 4235); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4236 MOZ_ASSERT(!aHandle->mFD)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!aHandle->mFD)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!aHandle->mFD))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("!aHandle->mFD"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 4236); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!aHandle->mFD" ")"); do { MOZ_CrashSequence
(__null, 4236); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
4237 MOZ_ASSERT(mHandlesByLastUsed.IndexOf(aHandle) == mHandlesByLastUsed.NoIndex)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mHandlesByLastUsed.IndexOf(aHandle) == mHandlesByLastUsed
.NoIndex)>::isValid, "invalid assertion condition"); if ((
__builtin_expect(!!(!(!!(mHandlesByLastUsed.IndexOf(aHandle) ==
mHandlesByLastUsed.NoIndex))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mHandlesByLastUsed.IndexOf(aHandle) == mHandlesByLastUsed.NoIndex"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 4237); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mHandlesByLastUsed.IndexOf(aHandle) == mHandlesByLastUsed.NoIndex"
")"); do { MOZ_CrashSequence(__null, 4237); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4238 MOZ_ASSERT(mHandlesByLastUsed.Length() <= kOpenHandlesLimit)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mHandlesByLastUsed.Length() <= 128)>::isValid,
"invalid assertion condition"); if ((__builtin_expect(!!(!(!
!(mHandlesByLastUsed.Length() <= 128))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("mHandlesByLastUsed.Length() <= 128"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 4238); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "mHandlesByLastUsed.Length() <= 128" ")"
); do { MOZ_CrashSequence(__null, 4238); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4239 MOZ_ASSERT((aCreate && !aHandle->mFileExists) ||do { static_assert( mozilla::detail::AssertionConditionType<
decltype((aCreate && !aHandle->mFileExists) || (!aCreate
&& aHandle->mFileExists))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!((aCreate && !aHandle
->mFileExists) || (!aCreate && aHandle->mFileExists
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("(aCreate && !aHandle->mFileExists) || (!aCreate && aHandle->mFileExists)"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 4240); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "(aCreate && !aHandle->mFileExists) || (!aCreate && aHandle->mFileExists)"
")"); do { MOZ_CrashSequence(__null, 4240); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
4240 (!aCreate && aHandle->mFileExists))do { static_assert( mozilla::detail::AssertionConditionType<
decltype((aCreate && !aHandle->mFileExists) || (!aCreate
&& aHandle->mFileExists))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!((aCreate && !aHandle
->mFileExists) || (!aCreate && aHandle->mFileExists
)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("(aCreate && !aHandle->mFileExists) || (!aCreate && aHandle->mFileExists)"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 4240); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "(aCreate && !aHandle->mFileExists) || (!aCreate && aHandle->mFileExists)"
")"); do { MOZ_CrashSequence(__null, 4240); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4241
4242 nsresult rv;
4243
4244 if (mHandlesByLastUsed.Length() == kOpenHandlesLimit128) {
4245 // close handle that hasn't been used for the longest time
4246 rv = MaybeReleaseNSPRHandleInternal(mHandlesByLastUsed[0], true);
4247 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/CacheFileIOManager.cpp"
, 4247); return rv; } } while (false)
;
4248 }
4249
4250 if (aCreate) {
4251 rv = aHandle->mFile->OpenNSPRFileDesc(
4252 PR_RDWR0x04 | PR_CREATE_FILE0x08 | PR_TRUNCATE0x20, 0600, &aHandle->mFD);
4253 if (rv == NS_ERROR_FILE_ALREADY_EXISTS || // error from nsLocalFileWin
4254 rv == NS_ERROR_FILE_NO_DEVICE_SPACE) { // error from nsLocalFileUnix
4255 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, "CacheFileIOManager::OpenNSPRHandle() - Cannot create a new file, we"
" might reached a limit on FAT32. Will evict a single entry and try "
"again. [hash=%08x%08x%08x%08x%08x]", PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[0]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[4])); } } while (
0)
4256 ("CacheFileIOManager::OpenNSPRHandle() - Cannot create a new file, we"do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenNSPRHandle() - Cannot create a new file, we"
" might reached a limit on FAT32. Will evict a single entry and try "
"again. [hash=%08x%08x%08x%08x%08x]", PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[0]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[4])); } } while (
0)
4257 " might reached a limit on FAT32. Will evict a single entry and try "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenNSPRHandle() - Cannot create a new file, we"
" might reached a limit on FAT32. Will evict a single entry and try "
"again. [hash=%08x%08x%08x%08x%08x]", PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[0]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[4])); } } while (
0)
4258 "again. [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, "CacheFileIOManager::OpenNSPRHandle() - Cannot create a new file, we"
" might reached a limit on FAT32. Will evict a single entry and try "
"again. [hash=%08x%08x%08x%08x%08x]", PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[0]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[4])); } } while (
0)
4259 LOGSHA1(aHandle->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, "CacheFileIOManager::OpenNSPRHandle() - Cannot create a new file, we"
" might reached a limit on FAT32. Will evict a single entry and try "
"again. [hash=%08x%08x%08x%08x%08x]", PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[0]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[1]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[2]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[3]), PR_htonl((reinterpret_cast
<const uint32_t*>(aHandle->Hash()))[4])); } } while (
0)
;
4260
4261 SHA1Sum::Hash hash;
4262 uint32_t cnt;
4263 auto snapshot = CacheIndex::GetSortedSnapshotForEviction();
4264 rv = CacheIndex::GetEntryForEviction(snapshot, true, &hash, &cnt);
4265 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
4266 rv = DoomFileByKeyInternal(&hash);
4267 }
4268 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
4269 rv = aHandle->mFile->OpenNSPRFileDesc(
4270 PR_RDWR0x04 | PR_CREATE_FILE0x08 | PR_TRUNCATE0x20, 0600, &aHandle->mFD);
4271 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, "CacheFileIOManager::OpenNSPRHandle() - Successfully evicted entry"
" with hash %08x%08x%08x%08x%08x. %s to create the new file."
, 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]), ((bool)(__builtin_expect(!!(!NS_FAILED_impl
(rv)), 1))) ? "Succeeded" : "Failed"); } } while (0)
4272 ("CacheFileIOManager::OpenNSPRHandle() - Successfully evicted 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, "CacheFileIOManager::OpenNSPRHandle() - Successfully evicted entry"
" with hash %08x%08x%08x%08x%08x. %s to create the new file."
, 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]), ((bool)(__builtin_expect(!!(!NS_FAILED_impl
(rv)), 1))) ? "Succeeded" : "Failed"); } } while (0)
4273 " with hash %08x%08x%08x%08x%08x. %s to create the new 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, "CacheFileIOManager::OpenNSPRHandle() - Successfully evicted entry"
" with hash %08x%08x%08x%08x%08x. %s to create the new file."
, 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]), ((bool)(__builtin_expect(!!(!NS_FAILED_impl
(rv)), 1))) ? "Succeeded" : "Failed"); } } while (0)
4274 LOGSHA1(&hash), NS_SUCCEEDED(rv) ? "Succeeded" : "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, "CacheFileIOManager::OpenNSPRHandle() - Successfully evicted entry"
" with hash %08x%08x%08x%08x%08x. %s to create the new file."
, 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]), ((bool)(__builtin_expect(!!(!NS_FAILED_impl
(rv)), 1))) ? "Succeeded" : "Failed"); } } while (0)
;
4275 } else {
4276 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, "CacheFileIOManager::OpenNSPRHandle() - Couldn't evict an existing"
" entry."); } } while (0)
4277 ("CacheFileIOManager::OpenNSPRHandle() - Couldn't evict an existing"do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenNSPRHandle() - Couldn't evict an existing"
" entry."); } } while (0)
4278 " 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, "CacheFileIOManager::OpenNSPRHandle() - Couldn't evict an existing"
" entry."); } } while (0)
;
4279 rv = NS_ERROR_FILE_NO_DEVICE_SPACE;
4280 }
4281 }
4282 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
4283 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, "CacheFileIOManager::OpenNSPRHandle() Create failed with "
"0x%08" "x", static_cast<uint32_t>(rv)); } } while (0)
4284 ("CacheFileIOManager::OpenNSPRHandle() Create failed with "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::OpenNSPRHandle() Create failed with "
"0x%08" "x", static_cast<uint32_t>(rv)); } } while (0)
4285 "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, "CacheFileIOManager::OpenNSPRHandle() Create failed with "
"0x%08" "x", static_cast<uint32_t>(rv)); } } while (0)
4286 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, "CacheFileIOManager::OpenNSPRHandle() Create failed with "
"0x%08" "x", static_cast<uint32_t>(rv)); } } while (0)
;
4287 }
4288 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/CacheFileIOManager.cpp"
, 4288); return rv; } } while (false)
;
4289
4290 aHandle->mFileExists = true;
4291 } else {
4292 rv = aHandle->mFile->OpenNSPRFileDesc(PR_RDWR0x04, 0600, &aHandle->mFD);
4293 if (NS_ERROR_FILE_NOT_FOUND == rv) {
4294 LOG((" file doesn't exists"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, " file doesn't exists"
); } } while (0)
;
4295 aHandle->mFileExists = false;
4296 return DoomFileInternal(aHandle);
4297 }
4298 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
4299 LOG(("CacheFileIOManager::OpenNSPRHandle() Open failed with 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, "CacheFileIOManager::OpenNSPRHandle() Open failed with 0x%08"
"x", static_cast<uint32_t>(rv)); } } while (0)
4300 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, "CacheFileIOManager::OpenNSPRHandle() Open failed with 0x%08"
"x", static_cast<uint32_t>(rv)); } } while (0)
;
4301 }
4302 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/CacheFileIOManager.cpp"
, 4302); return rv; } } while (false)
;
4303 }
4304
4305 mHandlesByLastUsed.AppendElement(aHandle);
4306
4307 LOG(("CacheFileIOManager::OpenNSPRHandle END, handle=%p", 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, "CacheFileIOManager::OpenNSPRHandle END, handle=%p"
, aHandle); } } while (0)
;
4308
4309 return NS_OK;
4310}
4311
4312void CacheFileIOManager::NSPRHandleUsed(CacheFileHandle* aHandle) {
4313 MOZ_ASSERT(CacheFileIOManager::IsOnIOThreadOrCeased())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(CacheFileIOManager::IsOnIOThreadOrCeased())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(CacheFileIOManager::IsOnIOThreadOrCeased()))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("CacheFileIOManager::IsOnIOThreadOrCeased()"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 4313); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "CacheFileIOManager::IsOnIOThreadOrCeased()"
")"); do { MOZ_CrashSequence(__null, 4313); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4314 MOZ_ASSERT(aHandle->mFD)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aHandle->mFD)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aHandle->mFD))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("aHandle->mFD"
, "./../../../netwerk/cache2/CacheFileIOManager.cpp", 4314); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "aHandle->mFD" ")"); do { MOZ_CrashSequence
(__null, 4314); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
4315
4316 DebugOnly<bool> found{};
4317 found = mHandlesByLastUsed.RemoveElement(aHandle);
4318 MOZ_ASSERT(found)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(found)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(found))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("found", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 4318); AnnotateMozCrashReason("MOZ_ASSERT" "(" "found" ")")
; do { MOZ_CrashSequence(__null, 4318); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4319
4320 mHandlesByLastUsed.AppendElement(aHandle);
4321}
4322
4323nsresult CacheFileIOManager::SyncRemoveDir(nsIFile* aFile, const char* aDir) {
4324 nsresult rv;
4325 nsCOMPtr<nsIFile> file;
4326
4327 if (!aFile) {
4328 return NS_ERROR_INVALID_ARG;
4329 }
4330
4331 if (!aDir) {
4332 file = aFile;
4333 } else {
4334 rv = aFile->Clone(getter_AddRefs(file));
4335 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 4335)
) {
4336 return rv;
4337 }
4338
4339 rv = file->AppendNative(nsDependentCString(aDir));
4340 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 4340)
) {
4341 return rv;
4342 }
4343 }
4344
4345 if (LOG_ENABLED()(__builtin_expect(!!(mozilla::detail::log_test(gCache2Log, mozilla
::LogLevel::Debug)), 0))
) {
4346 LOG(("CacheFileIOManager::SyncRemoveDir() - Removing directory %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, "CacheFileIOManager::SyncRemoveDir() - Removing directory %s"
, file->HumanReadablePath().get()); } } while (0)
4347 file->HumanReadablePath().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, "CacheFileIOManager::SyncRemoveDir() - Removing directory %s"
, file->HumanReadablePath().get()); } } while (0)
;
4348 }
4349
4350 rv = file->Remove(true);
4351 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 4351)
) {
4352 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, "CacheFileIOManager::SyncRemoveDir() - Removing failed! "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
4353 ("CacheFileIOManager::SyncRemoveDir() - Removing 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, "CacheFileIOManager::SyncRemoveDir() - Removing failed! "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
4354 "[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, "CacheFileIOManager::SyncRemoveDir() - Removing failed! "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
4355 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, "CacheFileIOManager::SyncRemoveDir() - Removing failed! "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
;
4356 }
4357
4358 return rv;
4359}
4360
4361nsresult CacheFileIOManager::DispatchPurgeTask(
4362 const nsCString& aCacheDirName, const nsCString& aSecondsToWait,
4363 const nsCString& aPurgeExtension) {
4364#if !defined(MOZ_BACKGROUNDTASKS1)
4365 // If background tasks are disabled, then we should just bail out early.
4366 return NS_ERROR_NOT_IMPLEMENTED;
4367#else
4368 nsCOMPtr<nsIFile> cacheDir;
4369 nsresult rv = mCacheDirectory->Clone(getter_AddRefs(cacheDir));
4370 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/CacheFileIOManager.cpp"
, 4370); return rv; } } while (false)
;
4371
4372 nsCOMPtr<nsIFile> profileDir;
4373 rv = cacheDir->GetParent(getter_AddRefs(profileDir));
4374 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/CacheFileIOManager.cpp"
, 4374); return rv; } } while (false)
;
4375
4376 nsCOMPtr<nsIFile> lf;
4377 rv = XRE_GetBinaryPath(getter_AddRefs(lf));
4378 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/CacheFileIOManager.cpp"
, 4378); return rv; } } while (false)
;
4379
4380 nsAutoCString path;
4381# if !defined(XP_WIN)
4382 rv = profileDir->GetNativePath(path);
4383# else
4384 rv = profileDir->GetNativeTarget(path);
4385# endif
4386 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/CacheFileIOManager.cpp"
, 4386); return rv; } } while (false)
;
4387
4388 nsCOMPtr<nsIBackgroundTasksRunner> runner =
4389 do_GetService("@mozilla.org/backgroundtasksrunner;1");
4390
4391 return runner->RemoveDirectoryInDetachedProcess(
4392 path, aCacheDirName, aSecondsToWait, aPurgeExtension, "HttpCache"_ns);
4393#endif
4394}
4395
4396void CacheFileIOManager::SyncRemoveAllCacheFiles() {
4397 LOG(("CacheFileIOManager::SyncRemoveAllCacheFiles()"))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::SyncRemoveAllCacheFiles()"
); } } while (0)
;
4398 nsresult rv;
4399
4400 // If we are already running in a background task, we
4401 // don't want to spawn yet another one at shutdown.
4402 if (inBackgroundTask()) {
4403 return;
4404 }
4405
4406 if (StaticPrefs::network_cache_shutdown_purge_in_background_task()) {
4407 rv = [&]() -> nsresult {
4408 nsresult rv;
4409
4410 // If there is no cache directory, there's nothing to remove.
4411 if (!mCacheDirectory) {
4412 return NS_OK;
4413 }
4414
4415 nsAutoCString leafName;
4416 rv = mCacheDirectory->GetNativeLeafName(leafName);
4417 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/CacheFileIOManager.cpp"
, 4417); return rv; } } while (false)
;
4418
4419 leafName.Append('.');
4420
4421 PRExplodedTime now;
4422 PR_ExplodeTime(PR_Now(), PR_GMTParameters, &now);
4423 leafName.AppendPrintf("%04d-%02d-%02d-%02d-%02d-%02d", now.tm_year,
4424 now.tm_month + 1, now.tm_mday, now.tm_hour,
4425 now.tm_min, now.tm_sec);
4426 leafName.Append(kPurgeExtension);
4427
4428 nsAutoCString secondsToWait;
4429 secondsToWait.AppendInt(
4430 StaticPrefs::network_cache_shutdown_purge_folder_wait_seconds());
4431
4432 rv = DispatchPurgeTask(leafName, secondsToWait, kPurgeExtension);
4433 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/CacheFileIOManager.cpp"
, 4433); return rv; } } while (false)
;
4434
4435 rv = mCacheDirectory->RenameToNative(nullptr, leafName);
4436 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/CacheFileIOManager.cpp"
, 4436); return rv; } } while (false)
;
4437
4438 return NS_OK;
4439 }();
4440
4441 // Dispatching to the background task has succeeded. This is finished.
4442 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
4443 return;
4444 }
4445 }
4446
4447 SyncRemoveDir(mCacheDirectory, ENTRIES_DIR"entries");
4448 SyncRemoveDir(mCacheDirectory, DOOMED_DIR"doomed");
4449
4450 // Clear any intermediate state of trash dir enumeration.
4451 mFailedTrashDirs.Clear();
4452 mTrashDir = nullptr;
4453
4454 while (true) {
4455 // FindTrashDirToRemove() fills mTrashDir if there is any trash directory.
4456 rv = FindTrashDirToRemove();
4457 if (rv == NS_ERROR_NOT_AVAILABLE) {
4458 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, "CacheFileIOManager::SyncRemoveAllCacheFiles() - No trash directory "
"found."); } } while (0)
4459 ("CacheFileIOManager::SyncRemoveAllCacheFiles() - No trash directory "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::SyncRemoveAllCacheFiles() - No trash directory "
"found."); } } while (0)
4460 "found."))do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::SyncRemoveAllCacheFiles() - No trash directory "
"found."); } } while (0)
;
4461 break;
4462 }
4463 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 4463)
) {
4464 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, "CacheFileIOManager::SyncRemoveAllCacheFiles() - "
"FindTrashDirToRemove() returned an unexpected error. " "[rv=0x%08"
"x" "]", static_cast<uint32_t>(rv)); } } while (0)
4465 ("CacheFileIOManager::SyncRemoveAllCacheFiles() - "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::SyncRemoveAllCacheFiles() - "
"FindTrashDirToRemove() returned an unexpected error. " "[rv=0x%08"
"x" "]", static_cast<uint32_t>(rv)); } } while (0)
4466 "FindTrashDirToRemove() returned an unexpected error. "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::SyncRemoveAllCacheFiles() - "
"FindTrashDirToRemove() returned an unexpected error. " "[rv=0x%08"
"x" "]", static_cast<uint32_t>(rv)); } } while (0)
4467 "[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, "CacheFileIOManager::SyncRemoveAllCacheFiles() - "
"FindTrashDirToRemove() returned an unexpected error. " "[rv=0x%08"
"x" "]", static_cast<uint32_t>(rv)); } } while (0)
4468 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, "CacheFileIOManager::SyncRemoveAllCacheFiles() - "
"FindTrashDirToRemove() returned an unexpected error. " "[rv=0x%08"
"x" "]", static_cast<uint32_t>(rv)); } } while (0)
;
4469 break;
4470 }
4471
4472 rv = SyncRemoveDir(mTrashDir, nullptr);
4473 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
4474 nsAutoCString leafName;
4475 mTrashDir->GetNativeLeafName(leafName);
4476 mFailedTrashDirs.AppendElement(leafName);
4477 }
4478 }
4479}
4480
4481// Returns default ("smart") size (in KB) of cache, given available disk space
4482// (also in KB)
4483static uint32_t SmartCacheSize(const int64_t availKB) {
4484 uint32_t maxSize;
4485
4486 if (CacheObserver::ClearCacheOnShutdown()) {
4487 maxSize = kMaxClearOnShutdownCacheSizeKB;
4488 } else {
4489 maxSize = kMaxCacheSizeKB;
4490 }
4491
4492 if (availKB > 25 * 1024 * 1024) {
4493 return maxSize; // skip computing if we're over 25 GB
4494 }
4495
4496 // Grow/shrink in 10 MB units, deliberately, so that in the common case we
4497 // don't shrink cache and evict items every time we startup (it's important
4498 // that we don't slow down startup benchmarks).
4499 uint32_t sz10MBs = 0;
4500 uint32_t avail10MBs = availKB / (1024 * 10);
4501
4502 // 2.5% of space above 7GB
4503 if (avail10MBs > 700) {
4504 sz10MBs += static_cast<uint32_t>((avail10MBs - 700) * .025);
4505 avail10MBs = 700;
4506 }
4507 // 7.5% of space between 500 MB -> 7 GB
4508 if (avail10MBs > 50) {
4509 sz10MBs += static_cast<uint32_t>((avail10MBs - 50) * .075);
4510 avail10MBs = 50;
4511 }
4512
4513#ifdef ANDROID
4514 // On Android, smaller/older devices may have very little storage and
4515 // device owners may be sensitive to storage footprint: Use a smaller
4516 // percentage of available space and a smaller minimum.
4517
4518 // 16% of space up to 500 MB (10 MB min)
4519 sz10MBs += std::max<uint32_t>(1, static_cast<uint32_t>(avail10MBs * .16));
4520#else
4521 // 30% of space up to 500 MB (50 MB min)
4522 sz10MBs += std::max<uint32_t>(5, static_cast<uint32_t>(avail10MBs * .3));
4523#endif
4524
4525 return std::min<uint32_t>(maxSize, sz10MBs * 10 * 1024);
4526}
4527
4528nsresult CacheFileIOManager::UpdateSmartCacheSize(int64_t aFreeSpace) {
4529 MOZ_ASSERT(mIOThread->IsCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mIOThread->IsCurrentThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mIOThread->IsCurrentThread
()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure
("mIOThread->IsCurrentThread()", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 4529); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mIOThread->IsCurrentThread()"
")"); do { MOZ_CrashSequence(__null, 4529); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4530
4531 nsresult rv;
4532
4533 if (!CacheObserver::SmartCacheSizeEnabled()) {
4534 return NS_ERROR_NOT_AVAILABLE;
4535 }
4536
4537 // Wait at least kSmartSizeUpdateInterval before recomputing smart size.
4538 static const TimeDuration kUpdateLimit =
4539 TimeDuration::FromMilliseconds(kSmartSizeUpdateInterval60000);
4540 if (!mLastSmartSizeTime.IsNull() &&
4541 (TimeStamp::NowLoRes() - mLastSmartSizeTime) < kUpdateLimit) {
4542 return NS_OK;
4543 }
4544
4545 // Do not compute smart size when cache size is not reliable.
4546 bool isUpToDate = false;
4547 CacheIndex::IsUpToDate(&isUpToDate);
4548 if (!isUpToDate) {
4549 return NS_ERROR_NOT_AVAILABLE;
4550 }
4551
4552 uint32_t cacheUsage;
4553 rv = CacheIndex::GetCacheSize(&cacheUsage);
4554 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 4554)
) {
4555 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, "CacheFileIOManager::UpdateSmartCacheSize() - Cannot get cacheUsage! "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
4556 ("CacheFileIOManager::UpdateSmartCacheSize() - Cannot get cacheUsage! "do { const ::mozilla::LogModule* moz_real_module = gCache2Log
; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module
, mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print
(moz_real_module, mozilla::LogLevel::Debug, "CacheFileIOManager::UpdateSmartCacheSize() - Cannot get cacheUsage! "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
4557 "[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, "CacheFileIOManager::UpdateSmartCacheSize() - Cannot get cacheUsage! "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
4558 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, "CacheFileIOManager::UpdateSmartCacheSize() - Cannot get cacheUsage! "
"[rv=0x%08" "x" "]", static_cast<uint32_t>(rv)); } } while
(0)
;
4559 return rv;
4560 }
4561
4562 mLastSmartSizeTime = TimeStamp::NowLoRes();
4563
4564 uint32_t smartSize = SmartCacheSize(aFreeSpace + cacheUsage);
4565
4566 if (smartSize == CacheObserver::DiskCacheCapacity()) {
4567 // Smart size has not changed.
4568 return NS_OK;
4569 }
4570
4571 CacheObserver::SetSmartDiskCacheCapacity(smartSize);
4572
4573 return NS_OK;
4574}
4575
4576// Memory reporting
4577
4578namespace {
4579
4580// A helper class that dispatches and waits for an event that gets result of
4581// CacheFileIOManager->mHandles.SizeOfExcludingThis() on the I/O thread
4582// to safely get handles memory report.
4583// We must do this, since the handle list is only accessed and managed w/o
4584// locking on the I/O thread. That is by design.
4585class SizeOfHandlesRunnable : public Runnable {
4586 public:
4587 SizeOfHandlesRunnable(mozilla::MallocSizeOf mallocSizeOf,
4588 CacheFileHandles const& handles,
4589 nsTArray<CacheFileHandle*> const& specialHandles)
4590 : Runnable("net::SizeOfHandlesRunnable"),
4591 mMonitor("SizeOfHandlesRunnable.mMonitor"),
4592 mMonitorNotified(false),
4593 mMallocSizeOf(mallocSizeOf),
4594 mHandles(handles),
4595 mSpecialHandles(specialHandles),
4596 mSize(0) {}
4597
4598 size_t Get(CacheIOThread* thread) {
4599 nsCOMPtr<nsIEventTarget> target = thread->Target();
4600 if (!target) {
4601 NS_ERROR("If we have the I/O thread we also must have the I/O target")do { NS_DebugBreak(NS_DEBUG_ASSERTION, "If we have the I/O thread we also must have the I/O target"
, "Error", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 4601); MOZ_PretendNoReturn(); } while (0)
;
4602 return 0;
4603 }
4604
4605 mozilla::MonitorAutoLock mon(mMonitor);
4606 mMonitorNotified = false;
4607 nsresult rv = target->Dispatch(this, nsIEventTarget::DISPATCH_NORMAL);
4608 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
4609 NS_ERROR("Dispatch failed, cannot do memory report of CacheFileHandles")do { NS_DebugBreak(NS_DEBUG_ASSERTION, "Dispatch failed, cannot do memory report of CacheFileHandles"
, "Error", "./../../../netwerk/cache2/CacheFileIOManager.cpp"
, 4609); MOZ_PretendNoReturn(); } while (0)
;
4610 return 0;
4611 }
4612
4613 while (!mMonitorNotified) {
4614 mon.Wait();
4615 }
4616 return mSize;
4617 }
4618
4619 NS_IMETHODvirtual nsresult Run() override {
4620 mozilla::MonitorAutoLock mon(mMonitor);
4621 // Excluding this since the object itself is a member of CacheFileIOManager
4622 // reported in CacheFileIOManager::SizeOfIncludingThis as part of |this|.
4623 mSize = mHandles.SizeOfExcludingThis(mMallocSizeOf);
4624 for (uint32_t i = 0; i < mSpecialHandles.Length(); ++i) {
4625 mSize += mSpecialHandles[i]->SizeOfIncludingThis(mMallocSizeOf);
4626 }
4627
4628 mMonitorNotified = true;
4629 mon.Notify();
4630 return NS_OK;
4631 }
4632
4633 private:
4634 mozilla::Monitor mMonitor;
4635 bool mMonitorNotified;
4636 mozilla::MallocSizeOf mMallocSizeOf;
4637 CacheFileHandles const& mHandles;
4638 nsTArray<CacheFileHandle*> const& mSpecialHandles;
4639 size_t mSize;
4640};
4641
4642} // namespace
4643
4644size_t CacheFileIOManager::SizeOfExcludingThisInternal(
4645 mozilla::MallocSizeOf mallocSizeOf) const {
4646 size_t n = 0;
4647
4648 if (mIOThread) {
4649 n += mIOThread->SizeOfIncludingThis(mallocSizeOf);
4650
4651 // mHandles and mSpecialHandles must be accessed only on the I/O thread,
4652 // must sync dispatch.
4653 RefPtr<SizeOfHandlesRunnable> sizeOfHandlesRunnable =
4654 new SizeOfHandlesRunnable(mallocSizeOf, mHandles, mSpecialHandles);
4655 n += sizeOfHandlesRunnable->Get(mIOThread);
4656 }
4657
4658 // mHandlesByLastUsed just refers handles reported by mHandles.
4659
4660 // mCacheDirectory is an nsIFile which we don't have reporting for.
4661
4662 // mMetadataWritesTimer is an nsITimer which we don't have reporting for.
4663 // Note that it would need to be accessed on the I/O thread.
4664
4665 // mTrashTimer is an nsITimer which we don't have reporting for.
4666
4667 // mTrashDir is an nsIFile which we don't have reporting for.
4668
4669 for (uint32_t i = 0; i < mFailedTrashDirs.Length(); ++i) {
4670 n += mFailedTrashDirs[i].SizeOfExcludingThisIfUnshared(mallocSizeOf);
4671 }
4672
4673 return n;
4674}
4675
4676// static
4677size_t CacheFileIOManager::SizeOfExcludingThis(
4678 mozilla::MallocSizeOf mallocSizeOf) {
4679 if (!gInstance) return 0;
4680
4681 return gInstance->SizeOfExcludingThisInternal(mallocSizeOf);
4682}
4683
4684// static
4685size_t CacheFileIOManager::SizeOfIncludingThis(
4686 mozilla::MallocSizeOf mallocSizeOf) {
4687 return mallocSizeOf(gInstance) + SizeOfExcludingThis(mallocSizeOf);
4688}
4689
4690#if defined(MOZ_CACHE_ASYNC_IO1)
4691void CacheFileIOManager::DispatchPendingEvents() {
4692 auto pendingEvents = std::move(mPendingEvents);
4693 for (auto& event : pendingEvents) {
4694 mIOThread->Dispatch(event.first, event.second);
4695 }
4696}
4697#endif
4698
4699} // namespace mozilla::net