@@ -537,7 +537,6 @@ class ShutdownEvent : public Runnable {
537537 ShutdownEvent ()
538538 : mMonitor (" ShutdownEvent.mMonitor" )
539539 , mNotified (false )
540- , mPrepare (true )
541540 {
542541 MOZ_COUNT_CTOR (ShutdownEvent);
543542 }
@@ -551,21 +550,6 @@ class ShutdownEvent : public Runnable {
551550public:
552551 NS_IMETHOD Run ()
553552 {
554- if (mPrepare ) {
555- MOZ_ASSERT (CacheFileIOManager::gInstance ->mIOThread ->IsCurrentThread ());
556-
557- mPrepare = false ;
558-
559- // This event is first posted to the XPCOM level (executed ASAP) of the IO thread
560- // and sets the timestamp of the shutdown start. This will cause some operations
561- // to be bypassed when due (actually leak most of the open files).
562- CacheFileIOManager::gInstance ->mShutdownDemandedTime = TimeStamp::NowLoRes ();
563-
564- // Redispatch to the right level to proceed with shutdown.
565- CacheFileIOManager::gInstance ->mIOThread ->Dispatch (this , CacheIOThread::CLOSE);
566- return NS_OK;
567- }
568-
569553 MonitorAutoLock mon (mMonitor );
570554
571555 CacheFileIOManager::gInstance ->ShutdownInternal ();
@@ -581,10 +565,8 @@ class ShutdownEvent : public Runnable {
581565 MonitorAutoLock mon (mMonitor );
582566
583567 DebugOnly<nsresult> rv;
584- nsCOMPtr<nsIEventTarget> ioTarget =
585- CacheFileIOManager::gInstance ->mIOThread ->Target ();
586- MOZ_ASSERT (ioTarget);
587- rv = ioTarget->Dispatch (this , nsIEventTarget::DISPATCH_NORMAL);
568+ rv = CacheFileIOManager::gInstance ->mIOThread ->Dispatch (
569+ this , CacheIOThread::CLOSE);
588570 MOZ_ASSERT (NS_SUCCEEDED(rv));
589571 while (!mNotified ) {
590572 mon.Wait ();
@@ -594,7 +576,6 @@ class ShutdownEvent : public Runnable {
594576protected:
595577 mozilla::Monitor mMonitor ;
596578 bool mNotified ;
597- bool mPrepare ;
598579};
599580
600581class OpenFileEvent : public Runnable {
@@ -735,7 +716,7 @@ class WriteEvent : public Runnable {
735716 // We usually get here only after the internal shutdown
736717 // (i.e. mShuttingDown == true). Pretend write has succeeded
737718 // to avoid any past-shutdown file dooming.
738- rv = (CacheFileIOManager:: gInstance -> IsPastShutdownIOLag () ||
719+ rv = (CacheObserver:: IsPastShutdownIOLag () ||
739720 CacheFileIOManager::gInstance ->mShuttingDown )
740721 ? NS_OK
741722 : NS_ERROR_NOT_INITIALIZED;
@@ -1176,8 +1157,6 @@ CacheFileIOManager::Shutdown()
11761157 return NS_ERROR_NOT_INITIALIZED;
11771158 }
11781159
1179- gInstance ->mShutdownDemanded = true ;
1180-
11811160 Telemetry::AutoTimer<Telemetry::NETWORK_DISK_CACHE_SHUTDOWN_V2> shutdownTimer;
11821161
11831162 CacheIndex::PreShutdown ();
@@ -1274,26 +1253,6 @@ CacheFileIOManager::ShutdownInternal()
12741253 return NS_OK;
12751254}
12761255
1277- bool
1278- CacheFileIOManager::IsPastShutdownIOLag ()
1279- {
1280- #ifdef DEBUG
1281- return false ;
1282- #endif
1283-
1284- if (mShutdownDemandedTime .IsNull ()) {
1285- return false ;
1286- }
1287-
1288- TimeDuration const & preferredIOLag = CacheObserver::MaxShutdownIOLag ();
1289- if (preferredIOLag < TimeDuration (0 )) {
1290- return false ;
1291- }
1292-
1293- TimeDuration currentIOLag = TimeStamp::NowLoRes () - mShutdownDemandedTime ;
1294- return currentIOLag > preferredIOLag;
1295- }
1296-
12971256// static
12981257nsresult
12991258CacheFileIOManager::OnProfile ()
@@ -1979,7 +1938,7 @@ CacheFileIOManager::WriteInternal(CacheFileHandle *aHandle, int64_t aOffset,
19791938
19801939 nsresult rv;
19811940
1982- if (IsPastShutdownIOLag ()) {
1941+ if (CacheObserver:: IsPastShutdownIOLag ()) {
19831942 LOG ((" past the shutdown I/O lag, nothing written" ));
19841943 // Pretend the write has succeeded, otherwise upper layers will doom
19851944 // the file and we end up with I/O anyway.
@@ -2306,9 +2265,11 @@ CacheFileIOManager::ReleaseNSPRHandleInternal(CacheFileHandle *aHandle,
23062265 // Leak other handles when past the shutdown time maximum lag.
23072266 if (
23082267#ifndef DEBUG
2309- ((aHandle->mInvalid || aHandle->mIsDoomed ) && MOZ_UNLIKELY (mShutdownDemanded )) ||
2268+ ((aHandle->mInvalid || aHandle->mIsDoomed ) &&
2269+ MOZ_UNLIKELY (CacheObserver::ShuttingDown ())) ||
23102270#endif
2311- MOZ_UNLIKELY (!aIgnoreShutdownLag && IsPastShutdownIOLag ())) {
2271+ MOZ_UNLIKELY (!aIgnoreShutdownLag &&
2272+ CacheObserver::IsPastShutdownIOLag ())) {
23122273 // Pretend this file has been validated (the metadata has been written)
23132274 // to prevent removal I/O on this apparently used file. The entry will
23142275 // never be used, since it doesn't have correct metadata, thus we don't
0 commit comments