Bug Summary

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