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