mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
c271b42cf8
- Bug 1251253 - prevent null pointer dereference of |aContext| in CacheStorageService::DoomStorageEntries. r=mayhemer (35b449c612)
- Bug 1260498 - Make test_rel_preconnect work in e10s mode. r=mcmanus (e6823ce4c4)
- Bug 1016628 - Add prefetch abilities to the predictor. r=mayhemer (53ab180c97)
- Bug 1258482 - FileList should contain only Files, not Directories, r=smaug (ff78125454)
- Bug 1258694 - Implement Directory::GetFiles(), r=smaug (305784524e)
- Bug 1263992 - patch 1 - Remove DirectoryType enum, r=smaug (89e1a59041)
- Bug 1263992 - patch 2 - Support the creation of directories from FileSystemTasks, r=smaug (c569092cef)
- Bug 1243586 - Implement Upgrade-Insecure-Requests HTTP Request Header Field. r=rbarnes (4b8a84c656)
- Bug 1262572 - http 0.9 telemetry. r=hurley (6006881336)
- Bug 587177 - Update all comments before SetOriginalURI to reflect reality, r=mcmanus (b2fedb0728)
- Bug 1261632 - Assert that OnStopRequest is called only once. r=michal (c35b1922b9)
- Bug 1232422 - Convert 5 tests within netwerk/test to use AsyncOpen2 (r=mcmanus) (4af8d43814)
- Bug 831450 - No Range Requests against weak Etag r=mayhemer (9b4a159e1e)
- Bug 1214277 - Avoid bypassing opening a cache entry for possibly intercepted channels; r=mcmanus (c5b0de6990)
- partial apply Bug 1234369 - Convert 25 tests within netwerk/test to use AsyncOpen2 (1b81d5a303)
- Bug 299031 - heuristic cache rule for 410 should be longer r=mayhemer (848834fc31)
- Bug 1121447 - trust cache less for error codes r=mayhemer (0424fec819)
- Bug 1125916 - Check whether loadInfo and loadContext match. r=sicking, r=jduell (6740850922)
- Bug 1258778 - Purge the skia glyph cache when receiving a low memory notice. r=erahm (633c60b0c6)
- Bug 1125916 - Add SEC_FORCE_PRIVATE_BROWSING to LoadInfo. r=sicking, r=jduell (10b5a1cacb)
- Bug 1105556 - test fixes. r=sicking, ckerschb (845d0dbd65)
- Bug 1258481 - Use RegionBuilder for nsRegion IPC. r=jrmuizel (616c279297)
- Bug 1014691 - Fix an include-what-you-use error in TestCompositor.cpp. r=kats (2797f83f1d)
- Bug 1256408 - Add graphics microbenchmarking. r=mstange (49b11b051b)
- Bug 1258481 - Add a RegionBuilder for accumulating rects. r=jrmuizel (acd79192db)
- Track whether or not remote layers have acknowledged compositor changes. (bug 1256517 part 1, r=mattwoodrow) (e3cc77ed41)
- Move compositable field out of individual compositable ops. (bug 1256517 part 2, r=mattwoodrow) (1d4a063df3)
- Bug 1241058: Assure several operations properly operate on the current group target. r=jrmuizel (6119e2b4db)
- Bug 1247700: Avoid crash from invalid fonts. r=bas (c4c2799b94)
- Bug 1242421 - remove useless null check. r=roc@ocallahan.org (44faf6556d)
- Add instrumentation for when content processes fail to acquire D3D11 devices. (bug 1247539, r=milan) (bd9265d78e)
- Make access to gfxWindowsPlatform D3D11 devices thread-safe. (bug 1258174, r=bas) (032e74b163)
- Disable device access on textures created against stale layers. (bug 1256517 part 3, r=nical) (ffcebbdee6)
- Block compositable updates from stale layers. (bug 1256517 part 4, r=mattwoodrow,nical) (fc83339f2d)
- Fix build bustage for bug 1256517 r=broken tree (3952871373)
- Bug 1256678 - Replace DrawTargetCairo::FillGlyphs crashes with other crashes - r=bobowen (b7245ba436)
- Bug 1120485. Log CloseHandle error reason during MessageChannel shutdown failure. r=milan (2f81d9c2aa)
- Bug 1242448 - Ensure the tile pool does not hold textures during shutdown. r=edwin (d31c304258)
- Bug 1258851 - Propagate the isScrollbarContainer layer flag to the compositor. r=mattwoodrow (b9906d7557)
- Bug 1260391: Transfer |CompositableOperation| in |AsyncChildMessageData|, r=dvander (1def34c5f8)
- Bug 1252324 - add DrawTarget API for 3D transforms for use in layers. r=jrmuizel (bc80529422)
- Bug 1255342 - implement DrawTargetCairo::LockBits for Cairo Win32 surfaces. r=sotaro (6f5661691b)
- Bug 1263480 - Don't let cairo go into an error state when DrawSurface is called with an empty destination rectangle. r=lsalzman (4300940101)
- Bug 1251241 - return from DrawTargetCairo::FillGlyphs if |aFont| is ullptr. r=roc (bb92f95ccd)
- Bug 1255320 - Create DrawTarget with DIB as similar DrawTarget r=jrmuizel (03f1da030d)
- Bug 1215265 - Put shutting down gfx ipdl protocols for child processes behind a pref. r=sotaro (aa781b37f9)
- Bug 1262898: Keep the GeckoChildProcessHost alive for the lifetime of the CompositorBridge and ImageBridge parent actors. r=jimm r=nical (dcca3b54e1)
- Bug 1251619: Remove unused gfxPlatform::CreateDrawTargetForUpdateSurface r=mchang (b29565995e)
- Bug 1255973 - Remove redundant overrides from gfxPlatform subclasses. r=jfkthame (d45f8a6640)
- Bug 1259466. Rename layers.offmainthreadcomposition.enabled. r=milan We would rather people not use this pref. (f362da1bd3)
- Bug 881609: Call InitLayersAccelerationPrefs only once. r=nrc (faed10a0d4)
- Bug 1209780. Mark some DrawResult's as unused in layout/svg. r=seth (48192d6b34)
- Bug 1251115 - Fix incorrect rendering result while mask path is not resolvable; r=mstange (a52b478fdf)
- Bug 1228354 - Part1 - Support luminance mask mode. r=mstange r=bas (b03abbe8a6)
- Bug 1228354 - Part2. Add test case for mask-mode. r=heycam (6bea36a70c)
- Bug 1259802: Add type replacement annotations to simplify rust binding generation for nsStyleStruct.h, r=bholley (48c13e62f2)
- Bug 1261754 - Part 1: Improve static assertions for style struct bits. r=dholbert (2ce6d994a5)
- Bug 1261552 - Reimplement default placement-new for style structs. r=heycam (db9d7782e2)
- Bug 1261552 - Introduce StaticPresData and hoist some shared functionality into it. r=heycam (adf2e16b4d)
- Bug 1226627 - Truncate the result in ZoomText/UnZoomText rather than rounding it for better performance. r=roc (f1d1084ba1)
- Bug 1247777 - Part1: parse and compute -webkit-text-fill-color property. r=heycam (fc4161355c)
- Bug 1247777 - Part2: implement -webkit-text-fill-color rendering. r=jfkthame (0f30da9c5b)
- Bug 1247777 - Part3: reftests for -webkit-text-fill-color. r=jfkthame Add this test into web-platform-tests. (02e41db8cc)
- Bug 1043461 - Followup to ensure we still test custom property position when the UA style sheet doesn't have custom properties in it. r=dholbert (48df73d684)
- Bug 1247777 - Part4.1: replace windows-style line endings with unix-style line endings. r=bz (be8ba60960)
- Bug 1247777 - Part4.2: add compatible webkit prefixed properties in CSS properties ordering check test. r=bz (7b78825e14)
- Bug 1261552 - Introduce StyleStructContext, and make all style struct constructors take it. r=heycam (65b3966841)
- Bug 1258017 - Use an nsCOMPtr to hold onto the nsIStyleRule. r=dbaron (e88d7e368f)
- Bug 1258017 - Use a RefPtr to hold onto the parent style context. r=dbaron (6a7289ca43)
- Bug 1258017 - Redesign and simplify rule tree GC. r=dbaron (3bf60a9b04)
- Bug 1253149 - Remove the #ifdef __cplusplus bits from ServoBindings.h. r=SimonSapin (bf2b18a470)
- Bug 1251496 - Forward stylesheet management to RawServoStyleSet. r=heycam (0a3aa90b2d)
- Bug 1260310 - Generalize nsStyleContext to support resolving styles from either nsRuleNode or ServoComputedValues. r=heycam (82b6d5d008)
- Bug 1258017 - Cleanup fixes for trunk. r=me (674a65815a)
- Bug 1236400 part 1: Add internal enum values to represent "display: -webkit-box" & "display: -webkit-inline-box". r=mats (509c94da15)
- Bug 1236400 part 2: Extend NeedsAnonFlexOrGridItem() & related code to wrap all inline-level -webkit-box children in an anonymous flex item. r=mats (dc11b9b09f)
- Bug 1236400 part 3: If webkit prefix support is enabled, skip CSS Parser code that converts "display: -webkit-box" directly to "display: flex". r=mats (e09b459124)
- Bug 1236400 part 4: Add reftests to test how non-block-level content gets wrapped inside a -webkit-box. (no review) (46e4d8cb07)
- Bug 1261754 - Part 2: Make quotes computed values shareable between different structs. r=dholbert (a78e43b706)
- Bug 1261754 - Part 3: Move quotes from nsStyleQuotes to nsStyleList and delete nsStyleQuotes. r=dholbert (fdcd9aaa3f)
- Bug 1209273 - Part 1: Support for adjust-color CSS property. r=dbaron (818a7fe0ff)
- Bug 1209273 - Part 2: Force printing background if color-adjust: exact. r=dbaron (ffd52c0dbc)
- Bug 1030712 - Ruleview: Skip apply() after clicking suggestion. r=pbro (3c08d18d7c)
- Bug 1246677 - 6 - Get rid of 'content' in ruleview head.js; r=tromey (79e46d4a32)
- Bug 1247263 - Round 2 of fixing unhandled rejected promises in ruleview tests; r=tromey (d1be475238)
- Bug 1181837 - 8 - Include inspector's head.js in markup view to remove duplication; r=bgrins (96a51c4825)
- Bug 1242570 - Fix unhandled promise rejections in markupview tests; r=bgrins (fc4ce8731c)
- Bug 1252099 - Main eslint cleanup of markupview tests; r=zer0 (b56dc99c43)
- Bug 1252099 - Final eslint cleanups in devtools/client/inspector/markup/test; r=miker (8800b13bf1)
- Bug 916582 - skip autocomplete suggestions if style attribute already closed;r=tromey (ad0e5d2ab9)
- Bug 1168246 - part2: fix tests relying on CSS suggestions order;r=pbrosset (e6bd0e56fe)
- Bug 1209273 - Part 3: Make CSS autocompletion tests pass. r=gl (d4b66a37af)
- Bug 1261754 - Part 4: Move image-rendering from nsStyleSVG to nsStyleVisibility. r=dholbert (ee8372fb94)
- Bug 1261754 - Part 5: Move text-rendering from nsStyleSVG to nsStyleText. r=dholbert (c13a11313d)
- Bug 1261754 - Part 6: Move vertical-align from nsStyleTextReset to nsStyleDisplay. r=dholbert (d374b3700b)
- Bug 1261754 - Part 7: Move pointer-events from nsStyleVisibility to nsStyleUserInterface. r=dholbert (8693251243)
- Bug 1261754 - Part 8: Move box-shadow from nsStyleBorder to a new nsStyleEffects struct. r=dholbert (8263476827)
- Bug 1261754 - Part 9: Move clip from nsStyleDisplay to nsStyleEffects. r=dholbert (5418597309)
- Bug 1261754 - Part 10: Move mix-blend-mode from nsStyleDisplay to nsStyleEffects. r=dholbert (ebae613929)
- Bug 1261754 - Part 11: Move opacity from nsStyleDisplay to nsStyleEffects. r=dholbert (589292af44)
- Bug 1187851 patch 6 - Make dynamic changes to filter change fixed position containing block for descendants. r=roc (003a3aa6ce)
- Bug 1261754 - Part 12: Move filter from nsStyleSVGReset to nsStyleEffects. r=dholbert (78d87914f9)
- Bug 1259513: Make gfxContext constructor private, use a utility function that can return nullptr. r=bas,lsalzman (43df6e429f)
- Bug 1259785: Do a proper flush when taking a snapshot so our dependent targets and command lists get appropriately cleared. r=jrmuizel (9f7372cce1)
- Bug 1251431 - Part 1: Allow usage of an A8 source pattern to MaskSurface for D2D 1.1 Moz2D backend. r=jwatt (632eb6d2da)
- Bug 1251431 - Part 2: Do not apply the device transform when drawing to an already intermediate surface. r=jwatt (3a24f4a5c6)
- Bug 1251431 - GCC compilation fixup. (2356f0a58c)
- Bug 1238328: Purge stored command lists by calling EndDraw/BeginDraw on a regular basis when they're used. r=jrmuizel (33f47b281f)
- Bug 1246641: Also execute an occasional EndDraw for CommandLists used by non-operator OVER drawing. r=jrmuizel (b3e03ad111)
- Bug 1258168: Push ClearType compatible clipping layers when the last pushed layer was marked as opaque. r=jrmuizel (bd069ad7b6)
- Bug 1264736: Crash sooner if we can't get a valid command list, at least in nightly/aurora. r=bas (fb4bb56815)
- Bug 1255438 - create nsI{Mutable,}Array directly; r=keeler (1b802b23b7)
- Bug 1255438 - fix OS X warning bustage and reopen this CLOSED TREE; r=me (07a05910a6)
- bug 1197314: Remove PR_snprintf calls in security/manager/ssl/ r=keeler (f2271aad87)
- Bug 1258298 - Switch more Scoped.h templates in PSM to UniquePtr equivalents. r=keeler (2ee1a85d8e)
- Bug 1191414 - gather telemetry on usage of <keygen>. r=keeler,r=vladan (150bad38a1)
- Bug 1260644 - Use UniquePLArenaPool to manage PLArenaPools in PSM. r=keeler (9e8ad9c0d4)
- Bug 1247250 - Enable TLS 1.3 anti-downgrade on non-secure fallback. r=keeler (7a950b427a)
- Bug 1215796 - Remove the static fallback whitelist. r=keeler (fa55b5920b)
- bug 1254667 - change certificate verification SHA1 policy to "allow or locally-installed roots" r=jcj (5d0bb9e8b1)
- bug 1245280 - add policy mechanism to optionally enforce BRs for falling back to subject CN r=Cykesiopka,mgoodwin (ecd4f2180a)
- Bug 1254653 - Add telemetry to measure how often we encounter EV certificates r=keeler (9da287b490)
- Bug 1259909 - Obviate char PORT_Free() calls in PSM. r=keeler (b7ba2a47da)
- Bug 1252882 - Add a Content Signature Service r=keeler,r=franziskus,r=Cykesiopka (8b806022a0)
- Bug 1255784 - u2f tests should use SpecialPowers.pushPrefEnv, r=jjones (839a58476f)
- Bug 1244960 - Complete FIDO u2f NSSToken (Part 1). r=keeler, r=baku (3d64aa2b7c)
- Bug 1244960 - FIDO u2f NSSToken (Part 2): Use Attestation Certificates. r=keeler (aee3ffc830)
- Bug 1244960 - FIDO u2f NSSToken (Part 3): Review updates. r=keeler (b2f81c2b72)
- Bug 1244960 - FIDO u2f NSSToken (Part 4): Correct FacetID base algorithm. r=keeler (9e70506580)
- Bug 1244960 - FIDO u2f NSSToken (Part 5): Review updates. r=keeler (62a28f2502)
- Bug 1231643 - Part 1. Create skia-A8-surface for mask composition when backendtype of the source DrawTarget is CG; r=mstange (dd03d86f55)
- Bug 1244598 - Move resource files of w3c-css/masking into ./support subdir. r=dbaron (4c9e789191)
- Bug 1243675 - Part 1. Add mask-image property reftest. r=dbaron (18e5dfa90b)
- Bug 1243675 - Part 2. Add mask-clip property reftest. r=dbaron (ddf834d408)
- Bug 1243675 - Part 3. Add mask-position property reftest. r=dbaron (68cae7c7e6)
- Bug 1243675 - Part 4. Add mask-repeat property reftest. r=dbaron (0a3ed45377)
- Bug 1243675 - Part 5. Add mask-origin property reftest. r=dbaron (f5785145a7)
- Bug 1243675 - Part 6. Add mask-size property reftest. r=dbaron (1ab2040973)
- Bug 1231643 - Part 2. Enable mask-composite reftest; r=dbaron (8c3b863d97)
- Bug 1263622 - Fixed nsNSSComponent.cpp compilation on mingw. r=dkeeler,ted (0e651c0211)
- Bug 1266249 - Remove mHasCachedOutline. r=dbaron (c46459acf2)
- Bug 1235634 - Construct nsNSSShutdownList::singleton lazily on first use r=keeler (1b53753c2e)
- Bug 1262645 - Address misc issues with nsGetUserCertChoice(). r=keeler (ec675be29a)
- Bug 1238001 - Allow TLS info to be updated on renegotiation, r=keeler (a2ec0c8a07)
- Bug 1201437 - Add new WebProgress state flag for user-overridden cert. r=keeler (0b9edbc8d8)
- Bug 1201437 - Make cert override tests check for STATE_CERT_USER_OVERRIDDEN. r=keeler (5246515084)
- bug 1261936 - stop using the subject common name in certificate verification error messages r=Cykesiopka (982cf43a11)
- bug 1230234 - fix a leak in client auth certificate handling r=Cykesiopka (6e83f81218)
- Bug 1260643 - Convert most uses of ScopedCERTCertificate in PSM to UniqueCERTCertificate. r=keeler (806b895c41)
- Bug 1207137 - Set a security state flag when weak crypto override is needed. r=keeler Bug 1254306 - Do not check the fallback limit version for the RC4 fallback. r=keeler (8b5cb7101f)
- Bug 1253010 - part 3 - create all nsIDateTimeFormat instances directly; r=smontagu (c1aa5d1d62)
- Bug 1260310 - Create servo style contexts from ServoStyleSet. r=heycam (05f876eb13)
- Bug 759568 - Part 1. Parse background-clip:text; r=dholbert r=heycam (d013b8fd84)
- Bug 1251995 part 6 - Use struct to pass params for nsTextFrame::PainText* functions. r=jfkthame (3b9c163eab)
- Bug 759568 - Part 2. Render background-clip:text; r=jfkthame (e534e048bf)
- Bug 759568 - Part 4. mochitest for background-clip:text; r=heycom (3e548ebf99)
- Bug 759568 - Part 5. reftest for background-clip:text; r=dbaron (43d2915305)
- Bug 759568 - Part 6. Remove unused nsDisplayList::mVisibleRect; r=jfkthame (960a85de40)
- Bug 1264910 - Simplify pref callback register/unregister in nsLayoutUtils. r=dholbert (f50219f117)
- Bug 1097499 part 1 - Control support of 'text-combine-upright: digits' via a separate pref. r=heycam (37df36e815)
- Bug 1261062 - When constraining the displayport by the max texture size, maintain the relative distribution of the margins. r=dvander (9a9423bdf1)
- Bug 1246290 - Add a pref to allow disabling APZ on documents which have scroll-linked effects. r=botond (781b63c578)
- Bug 1263347 - When checking if displayport changes should schedule a paint, make sure to use the proper displayport. r=mstange (998f59843e)
- Bug 1097499 part 15 - Add reftests for text-combine-upright. r=jfkthame (843bea00bc)
- Bug 1097499 followup - Fix metadata of tests submitted to w3c. DONTBUILD (e671b5b38b)
- Bug 1097499 followup 2 - Fix metadata of tests submitted to w3c. DONTBUILD (abf0895450)
- Bug 1097499 part 2 - Add a macro to simplify usage of nsStyleContext::GetUniqueStyleData. r=heycam (10486f1f24)
- Bug 1097499 part 3 - Add a separate anonbox for text nodes. r=heycam (7dd4347215)
- Bug 1097499 part 4 - Adjust computed value of writing-mode on text frames when text-combine-upright is used. r=heycam (c193f14b27)
- Bug 1097499 part 5 - Layout text combine upright. r=jfkthame (c21422930b)
- Bug 1097499 part 6 - Inherit move direction from parent for horizontal-in-vertical text. r=jfkthame (cf436b8494)
- Bug 1097499 part 7 - Add reverse function of GetFullWidth. r=emk (32d02e7437)
- Bug 1097499 part 8 - Move CountGraphemeClusters to mozilla::unicode. r=emk (e2b8942e53)
- Bug 1156588 - Add crashtest. (237adb0604)
- Bug 1234622. Tweak how nsDocumentViewer::FindContainerView finds the parent presshell. r=bz (d1e76ae2e9)
- Bug 1245978 part 1: Make nsDocumentViewer::CreateStyleSet directly return the thing it creates. r=heycam (ede16260a4)
- Bug 1245978 part 2: Drop redundant 'virtual' keyword from NS_DECL_NSIDOCUMENTVIEWERPRINT macro (which already includes 'override' keyword). r=heycam (42b8962e4f)
- Bug 1183879 - Soften "non-subdocument frame" warning to also allow dummy nsFrames, which exist while subdocument is loading. r=dholbert (6ebcb53421)
- Bug 1259246. Move nsIPresShell::GetRealPrimaryFrameFor to nsLayoutUtils::GetRealPrimaryFrameFor. r=dholbert (d3efd2f03a)
- Bug 645647 part 1 - Don't let empty bullet frames block suppressing white-space in intrinsic size calculations. r=dholbert (2ce0a86bfb)
- Bug 645647 part 2 - Reftests. (496e491990)
- Bug 645647 part 3 - Remove unused trailingTextFrame member. r=dholbert (bd26ea25e6)
- Bug 645647 part 4 - Add an 'm' prefix to some members to follow our naming conventions. r=dholbert (fe3c5240c9)
- Bug 1097499 part 9 - Transform full-width characters to non-full-width correspondents for combined text. r=jfkthame (5b1eafe2a7)
- Bug 1097499 part 10 - Add fwid/hwid/twid/qwid font feature support to gfx. r=jfkthame (682698dd38)
- Bug 1097499 part 11 - Set width variant for text-combined frame. r=jfkthame (937f61e0e9)
- Bug 1097499 part 12 - Handle spacing sensibly for text-combine-upright. r=jfkthame (9ae1ab2941)
- Bug 1220438 - Correct baseline offset computation of text decoration for vertical-rl. r=jfkthame (10ad32d702)
- Bug 1258636 part 1 - Use structs to pass params for decoration-related functions in nsCSSRendering. r=jfkthame (deef7071f1)
- Bug 1258636 part 2 - Use struct to pass params for nsTextFrame::PaintDecorationLine. r=jfkthame (df5bde2547)
- Bug 1229743 part 1 - Simplify text decoration handling code with lambda function and range-based for loop. r=jfkthame (51cd3ea4ca)
- Bug 1229743 part 2 - Fix up decoration rect computation for vertical-rl and sideways-lr. r=jfkthame (0113279f53)
- Bug 1251995 part 7 - Use struct to pass params for nsTextFrame::Paint*Shadow functions. r=jfkthame (e81ba231aa)
- Bug 759568 - Part 3. Render text-selection beneath background image; r=jfkthame (e6757762ff)
- Bug 1097499 part 13 - Draw decoration line properly for text-combine-upright. r=jfkthame (8f4be7f987)
- Bug 1264120. Remove usage of nsAutoPtr from gfx/src. r=jfkthame (6831454d8c)
- Bug 1119619 - Allow font-selection to fall back to an alternative face within the same family if the first-found face was not Regular, to handle cases where some styled faces have a reduced character set. r=m_kato (d8851b2877)
- Bug 1243226 - relax the limit on fontconfig generics. r=heycam, a=me (05df737d0e)
- Bug 1245811 - part 1 (based on patch by Andrew Comminos) - Replace gfxPlatformFontList::FindFamily with FindAndAddFamilies to allow for the possibility of the implementation returning multiple font families (e.g. when fontconfig has 'prefer' aliases). r=karlt (2bef9fafb0)
- Bug 1245811 - part 2 (based on patch by Andrew Comminos) - Let gfxFcPlatformFontList return multiple families for a given name once fontconfig substitutions have been applied. r=karlt (1ffb425a0e)
- Bug 1265452 - Remove use of nsAutoPtr from gfx/thebes. r=jrmuizel (d02c913ad5)
- Bug 1265459 - Replace uses of nsAutoPtr<gfxTextRun> with UniquePtr, and let MakeTextRun and similar methods return a UniquePtr. r=jrmuizel (da32e376b7)
- Bug 1097499 part 14 - Draw emphasis marks properly for text-combine-upright. r=jfkthame (c9115615c6)
- Bug 1097499 part 16 - Enable text-combine-upright by default. r=jfkthame (b616987f95)
- Bug 1261699 - preserve user fontconfig autohint settings in Cairo glyph rendering options. r=jfkthame (3e46dff5ff)
- Bug 1216001 - Fix a typo that eliminated a possible paint optimization. r=xidorn (6a350cadb7)
- Bug 1261568 - part1: take -webkit-text-fill-color into consideration while (d49cf427ab)
- Bug 1261568 - part2.1: update manifest before adding test. r=jgraham Bug 1261568 - part2.2: add reftest. r=jfkthame (ef3c22cfb4)
2124 lines
60 KiB
C++
2124 lines
60 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "CacheLog.h"
|
|
#include "CacheStorageService.h"
|
|
#include "CacheFileIOManager.h"
|
|
#include "CacheObserver.h"
|
|
#include "CacheIndex.h"
|
|
#include "CacheIndexIterator.h"
|
|
#include "CacheStorage.h"
|
|
#include "AppCacheStorage.h"
|
|
#include "CacheEntry.h"
|
|
#include "CacheFileUtils.h"
|
|
|
|
#include "OldWrappers.h"
|
|
#include "nsCacheService.h"
|
|
#include "nsDeleteDir.h"
|
|
|
|
#include "nsICacheStorageVisitor.h"
|
|
#include "nsIObserverService.h"
|
|
#include "nsIFile.h"
|
|
#include "nsIURI.h"
|
|
#include "nsCOMPtr.h"
|
|
#include "nsAutoPtr.h"
|
|
#include "nsNetCID.h"
|
|
#include "nsNetUtil.h"
|
|
#include "nsServiceManagerUtils.h"
|
|
#include "nsWeakReference.h"
|
|
#include "mozilla/TimeStamp.h"
|
|
#include "mozilla/DebugOnly.h"
|
|
#include "mozilla/Services.h"
|
|
|
|
namespace mozilla {
|
|
namespace net {
|
|
|
|
namespace {
|
|
|
|
void AppendMemoryStorageID(nsAutoCString &key)
|
|
{
|
|
key.Append('/');
|
|
key.Append('M');
|
|
}
|
|
|
|
} // namespace
|
|
|
|
// Not defining as static or class member of CacheStorageService since
|
|
// it would otherwise need to include CacheEntry.h and that then would
|
|
// need to be exported to make nsNetModule.cpp compilable.
|
|
typedef nsClassHashtable<nsCStringHashKey, CacheEntryTable>
|
|
GlobalEntryTables;
|
|
|
|
/**
|
|
* Keeps tables of entries. There is one entries table for each distinct load
|
|
* context type. The distinction is based on following load context info states:
|
|
* <isPrivate|isAnon|appId|inIsolatedMozBrowser> which builds a mapping key.
|
|
*
|
|
* Thread-safe to access, protected by the service mutex.
|
|
*/
|
|
static GlobalEntryTables* sGlobalEntryTables;
|
|
|
|
CacheMemoryConsumer::CacheMemoryConsumer(uint32_t aFlags)
|
|
: mReportedMemoryConsumption(0)
|
|
, mFlags(aFlags)
|
|
{
|
|
}
|
|
|
|
void
|
|
CacheMemoryConsumer::DoMemoryReport(uint32_t aCurrentSize)
|
|
{
|
|
if (!(mFlags & DONT_REPORT) && CacheStorageService::Self()) {
|
|
CacheStorageService::Self()->OnMemoryConsumptionChange(this, aCurrentSize);
|
|
}
|
|
}
|
|
|
|
CacheStorageService::MemoryPool::MemoryPool(EType aType)
|
|
: mType(aType)
|
|
, mMemorySize(0)
|
|
{
|
|
}
|
|
|
|
CacheStorageService::MemoryPool::~MemoryPool()
|
|
{
|
|
if (mMemorySize != 0) {
|
|
NS_ERROR("Network cache reported memory consumption is not at 0, probably leaking?");
|
|
}
|
|
}
|
|
|
|
uint32_t
|
|
CacheStorageService::MemoryPool::Limit() const
|
|
{
|
|
switch (mType) {
|
|
case DISK:
|
|
return CacheObserver::MetadataMemoryLimit();
|
|
case MEMORY:
|
|
return CacheObserver::MemoryCacheCapacity();
|
|
}
|
|
|
|
MOZ_CRASH("Bad pool type");
|
|
return 0;
|
|
}
|
|
|
|
NS_IMPL_ISUPPORTS(CacheStorageService,
|
|
nsICacheStorageService,
|
|
nsIMemoryReporter,
|
|
nsITimerCallback,
|
|
nsICacheTesting)
|
|
|
|
CacheStorageService* CacheStorageService::sSelf = nullptr;
|
|
|
|
CacheStorageService::CacheStorageService()
|
|
: mLock("CacheStorageService.mLock")
|
|
, mForcedValidEntriesLock("CacheStorageService.mForcedValidEntriesLock")
|
|
, mShutdown(false)
|
|
, mDiskPool(MemoryPool::DISK)
|
|
, mMemoryPool(MemoryPool::MEMORY)
|
|
{
|
|
CacheFileIOManager::Init();
|
|
|
|
MOZ_ASSERT(!sSelf);
|
|
|
|
sSelf = this;
|
|
sGlobalEntryTables = new GlobalEntryTables();
|
|
|
|
RegisterStrongMemoryReporter(this);
|
|
}
|
|
|
|
CacheStorageService::~CacheStorageService()
|
|
{
|
|
LOG(("CacheStorageService::~CacheStorageService"));
|
|
sSelf = nullptr;
|
|
}
|
|
|
|
void CacheStorageService::Shutdown()
|
|
{
|
|
if (mShutdown)
|
|
return;
|
|
|
|
LOG(("CacheStorageService::Shutdown - start"));
|
|
|
|
mShutdown = true;
|
|
|
|
nsCOMPtr<nsIRunnable> event =
|
|
NS_NewRunnableMethod(this, &CacheStorageService::ShutdownBackground);
|
|
Dispatch(event);
|
|
|
|
mozilla::MutexAutoLock lock(mLock);
|
|
sGlobalEntryTables->Clear();
|
|
delete sGlobalEntryTables;
|
|
sGlobalEntryTables = nullptr;
|
|
|
|
LOG(("CacheStorageService::Shutdown - done"));
|
|
}
|
|
|
|
void CacheStorageService::ShutdownBackground()
|
|
{
|
|
MOZ_ASSERT(IsOnManagementThread());
|
|
|
|
// Cancel purge timer to avoid leaking.
|
|
if (mPurgeTimer) {
|
|
mPurgeTimer->Cancel();
|
|
}
|
|
|
|
Pool(false).mFrecencyArray.Clear();
|
|
Pool(false).mExpirationArray.Clear();
|
|
Pool(true).mFrecencyArray.Clear();
|
|
Pool(true).mExpirationArray.Clear();
|
|
}
|
|
|
|
// Internal management methods
|
|
|
|
namespace {
|
|
|
|
// WalkCacheRunnable
|
|
// Base class for particular storage entries visiting
|
|
class WalkCacheRunnable : public nsRunnable
|
|
, public CacheStorageService::EntryInfoCallback
|
|
{
|
|
protected:
|
|
WalkCacheRunnable(nsICacheStorageVisitor* aVisitor,
|
|
bool aVisitEntries)
|
|
: mService(CacheStorageService::Self())
|
|
, mCallback(aVisitor)
|
|
, mSize(0)
|
|
, mNotifyStorage(true)
|
|
, mVisitEntries(aVisitEntries)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
}
|
|
|
|
virtual ~WalkCacheRunnable()
|
|
{
|
|
if (mCallback) {
|
|
ProxyReleaseMainThread(mCallback);
|
|
}
|
|
}
|
|
|
|
RefPtr<CacheStorageService> mService;
|
|
nsCOMPtr<nsICacheStorageVisitor> mCallback;
|
|
|
|
uint64_t mSize;
|
|
|
|
bool mNotifyStorage : 1;
|
|
bool mVisitEntries : 1;
|
|
};
|
|
|
|
// WalkMemoryCacheRunnable
|
|
// Responsible to visit memory storage and walk
|
|
// all entries on it asynchronously.
|
|
class WalkMemoryCacheRunnable : public WalkCacheRunnable
|
|
{
|
|
public:
|
|
WalkMemoryCacheRunnable(nsILoadContextInfo *aLoadInfo,
|
|
bool aVisitEntries,
|
|
nsICacheStorageVisitor* aVisitor)
|
|
: WalkCacheRunnable(aVisitor, aVisitEntries)
|
|
{
|
|
CacheFileUtils::AppendKeyPrefix(aLoadInfo, mContextKey);
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
}
|
|
|
|
nsresult Walk()
|
|
{
|
|
return mService->Dispatch(this);
|
|
}
|
|
|
|
private:
|
|
NS_IMETHODIMP Run()
|
|
{
|
|
if (CacheStorageService::IsOnManagementThread()) {
|
|
LOG(("WalkMemoryCacheRunnable::Run - collecting [this=%p]", this));
|
|
// First, walk, count and grab all entries from the storage
|
|
|
|
mozilla::MutexAutoLock lock(CacheStorageService::Self()->Lock());
|
|
|
|
if (!CacheStorageService::IsRunning())
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
CacheEntryTable* entries;
|
|
if (sGlobalEntryTables->Get(mContextKey, &entries)) {
|
|
for (auto iter = entries->Iter(); !iter.Done(); iter.Next()) {
|
|
CacheEntry* entry = iter.UserData();
|
|
|
|
// Ignore disk entries
|
|
if (entry->IsUsingDisk()) {
|
|
continue;
|
|
}
|
|
|
|
mSize += entry->GetMetadataMemoryConsumption();
|
|
|
|
int64_t size;
|
|
if (NS_SUCCEEDED(entry->GetDataSize(&size))) {
|
|
mSize += size;
|
|
}
|
|
mEntryArray.AppendElement(entry);
|
|
}
|
|
}
|
|
|
|
// Next, we dispatch to the main thread
|
|
} else if (NS_IsMainThread()) {
|
|
LOG(("WalkMemoryCacheRunnable::Run - notifying [this=%p]", this));
|
|
|
|
if (mNotifyStorage) {
|
|
LOG((" storage"));
|
|
|
|
// Second, notify overall storage info
|
|
mCallback->OnCacheStorageInfo(mEntryArray.Length(), mSize,
|
|
CacheObserver::MemoryCacheCapacity(), nullptr);
|
|
if (!mVisitEntries)
|
|
return NS_OK; // done
|
|
|
|
mNotifyStorage = false;
|
|
|
|
} else {
|
|
LOG((" entry [left=%d]", mEntryArray.Length()));
|
|
|
|
// Third, notify each entry until depleted
|
|
if (!mEntryArray.Length()) {
|
|
mCallback->OnCacheEntryVisitCompleted();
|
|
return NS_OK; // done
|
|
}
|
|
|
|
// Grab the next entry
|
|
RefPtr<CacheEntry> entry = mEntryArray[0];
|
|
mEntryArray.RemoveElementAt(0);
|
|
|
|
// Invokes this->OnEntryInfo, that calls the callback with all
|
|
// information of the entry.
|
|
CacheStorageService::GetCacheEntryInfo(entry, this);
|
|
}
|
|
} else {
|
|
MOZ_CRASH("Bad thread");
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
NS_DispatchToMainThread(this);
|
|
return NS_OK;
|
|
}
|
|
|
|
virtual ~WalkMemoryCacheRunnable()
|
|
{
|
|
if (mCallback)
|
|
ProxyReleaseMainThread(mCallback);
|
|
}
|
|
|
|
virtual void OnEntryInfo(const nsACString & aURISpec, const nsACString & aIdEnhance,
|
|
int64_t aDataSize, int32_t aFetchCount,
|
|
uint32_t aLastModifiedTime, uint32_t aExpirationTime,
|
|
bool aPinned)
|
|
{
|
|
nsCOMPtr<nsIURI> uri;
|
|
nsresult rv = NS_NewURI(getter_AddRefs(uri), aURISpec);
|
|
if (NS_FAILED(rv))
|
|
return;
|
|
|
|
mCallback->OnCacheEntryInfo(uri, aIdEnhance, aDataSize, aFetchCount,
|
|
aLastModifiedTime, aExpirationTime, aPinned);
|
|
}
|
|
|
|
private:
|
|
nsCString mContextKey;
|
|
nsTArray<RefPtr<CacheEntry> > mEntryArray;
|
|
};
|
|
|
|
// WalkDiskCacheRunnable
|
|
// Using the cache index information to get the list of files per context.
|
|
class WalkDiskCacheRunnable : public WalkCacheRunnable
|
|
{
|
|
public:
|
|
WalkDiskCacheRunnable(nsILoadContextInfo *aLoadInfo,
|
|
bool aVisitEntries,
|
|
nsICacheStorageVisitor* aVisitor)
|
|
: WalkCacheRunnable(aVisitor, aVisitEntries)
|
|
, mLoadInfo(aLoadInfo)
|
|
, mPass(COLLECT_STATS)
|
|
{
|
|
}
|
|
|
|
nsresult Walk()
|
|
{
|
|
// TODO, bug 998693
|
|
// Initial index build should be forced here so that about:cache soon
|
|
// after startup gives some meaningfull results.
|
|
|
|
// Dispatch to the INDEX level in hope that very recent cache entries
|
|
// information gets to the index list before we grab the index iterator
|
|
// for the first time. This tries to avoid miss of entries that has
|
|
// been created right before the visit is required.
|
|
RefPtr<CacheIOThread> thread = CacheFileIOManager::IOThread();
|
|
NS_ENSURE_TRUE(thread, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
return thread->Dispatch(this, CacheIOThread::INDEX);
|
|
}
|
|
|
|
private:
|
|
// Invokes OnCacheEntryInfo callback for each single found entry.
|
|
// There is one instance of this class per one entry.
|
|
class OnCacheEntryInfoRunnable : public nsRunnable
|
|
{
|
|
public:
|
|
explicit OnCacheEntryInfoRunnable(WalkDiskCacheRunnable* aWalker)
|
|
: mWalker(aWalker)
|
|
{
|
|
}
|
|
|
|
NS_IMETHODIMP Run()
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
nsresult rv = NS_NewURI(getter_AddRefs(uri), mURISpec);
|
|
if (NS_FAILED(rv))
|
|
return NS_OK;
|
|
|
|
mWalker->mCallback->OnCacheEntryInfo(
|
|
uri, mIdEnhance, mDataSize, mFetchCount,
|
|
mLastModifiedTime, mExpirationTime, mPinned);
|
|
return NS_OK;
|
|
}
|
|
|
|
RefPtr<WalkDiskCacheRunnable> mWalker;
|
|
|
|
nsCString mURISpec;
|
|
nsCString mIdEnhance;
|
|
int64_t mDataSize;
|
|
int32_t mFetchCount;
|
|
uint32_t mLastModifiedTime;
|
|
uint32_t mExpirationTime;
|
|
bool mPinned;
|
|
};
|
|
|
|
NS_IMETHODIMP Run()
|
|
{
|
|
// The main loop
|
|
nsresult rv;
|
|
|
|
if (CacheStorageService::IsOnManagementThread()) {
|
|
switch (mPass) {
|
|
case COLLECT_STATS:
|
|
// Get quickly the cache stats.
|
|
uint32_t size;
|
|
rv = CacheIndex::GetCacheStats(mLoadInfo, &size, &mCount);
|
|
if (NS_FAILED(rv)) {
|
|
if (mVisitEntries) {
|
|
// both onStorageInfo and onCompleted are expected
|
|
NS_DispatchToMainThread(this);
|
|
}
|
|
return NS_DispatchToMainThread(this);
|
|
}
|
|
|
|
mSize = size << 10;
|
|
|
|
// Invoke onCacheStorageInfo with valid information.
|
|
NS_DispatchToMainThread(this);
|
|
|
|
if (!mVisitEntries) {
|
|
return NS_OK; // done
|
|
}
|
|
|
|
mPass = ITERATE_METADATA;
|
|
MOZ_FALLTHROUGH;
|
|
|
|
case ITERATE_METADATA:
|
|
// Now grab the context iterator.
|
|
if (!mIter) {
|
|
rv = CacheIndex::GetIterator(mLoadInfo, true, getter_AddRefs(mIter));
|
|
if (NS_FAILED(rv)) {
|
|
// Invoke onCacheEntryVisitCompleted now
|
|
return NS_DispatchToMainThread(this);
|
|
}
|
|
}
|
|
|
|
while (true) {
|
|
if (CacheIOThread::YieldAndRerun())
|
|
return NS_OK;
|
|
|
|
SHA1Sum::Hash hash;
|
|
rv = mIter->GetNextHash(&hash);
|
|
if (NS_FAILED(rv))
|
|
break; // done (or error?)
|
|
|
|
// This synchronously invokes onCacheEntryInfo on this class where we
|
|
// redispatch to the main thread for the consumer callback.
|
|
CacheFileIOManager::GetEntryInfo(&hash, this);
|
|
}
|
|
|
|
// Invoke onCacheEntryVisitCompleted on the main thread
|
|
NS_DispatchToMainThread(this);
|
|
}
|
|
} else if (NS_IsMainThread()) {
|
|
if (mNotifyStorage) {
|
|
nsCOMPtr<nsIFile> dir;
|
|
CacheFileIOManager::GetCacheDirectory(getter_AddRefs(dir));
|
|
mCallback->OnCacheStorageInfo(mCount, mSize, CacheObserver::DiskCacheCapacity(), dir);
|
|
mNotifyStorage = false;
|
|
} else {
|
|
mCallback->OnCacheEntryVisitCompleted();
|
|
}
|
|
} else {
|
|
MOZ_CRASH("Bad thread");
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
virtual void OnEntryInfo(const nsACString & aURISpec, const nsACString & aIdEnhance,
|
|
int64_t aDataSize, int32_t aFetchCount,
|
|
uint32_t aLastModifiedTime, uint32_t aExpirationTime,
|
|
bool aPinned)
|
|
{
|
|
// Called directly from CacheFileIOManager::GetEntryInfo.
|
|
|
|
// Invoke onCacheEntryInfo on the main thread for this entry.
|
|
RefPtr<OnCacheEntryInfoRunnable> info = new OnCacheEntryInfoRunnable(this);
|
|
info->mURISpec = aURISpec;
|
|
info->mIdEnhance = aIdEnhance;
|
|
info->mDataSize = aDataSize;
|
|
info->mFetchCount = aFetchCount;
|
|
info->mLastModifiedTime = aLastModifiedTime;
|
|
info->mExpirationTime = aExpirationTime;
|
|
info->mPinned = aPinned;
|
|
|
|
NS_DispatchToMainThread(info);
|
|
}
|
|
|
|
RefPtr<nsILoadContextInfo> mLoadInfo;
|
|
enum {
|
|
// First, we collect stats for the load context.
|
|
COLLECT_STATS,
|
|
|
|
// Second, if demanded, we iterate over the entries gethered
|
|
// from the iterator and call CacheFileIOManager::GetEntryInfo
|
|
// for each found entry.
|
|
ITERATE_METADATA,
|
|
} mPass;
|
|
|
|
RefPtr<CacheIndexIterator> mIter;
|
|
uint32_t mCount;
|
|
};
|
|
|
|
} // namespace
|
|
|
|
void CacheStorageService::DropPrivateBrowsingEntries()
|
|
{
|
|
mozilla::MutexAutoLock lock(mLock);
|
|
|
|
if (mShutdown)
|
|
return;
|
|
|
|
nsTArray<nsCString> keys;
|
|
for (auto iter = sGlobalEntryTables->Iter(); !iter.Done(); iter.Next()) {
|
|
const nsACString& key = iter.Key();
|
|
nsCOMPtr<nsILoadContextInfo> info = CacheFileUtils::ParseKey(key);
|
|
if (info && info->IsPrivate()) {
|
|
keys.AppendElement(key);
|
|
}
|
|
}
|
|
|
|
for (uint32_t i = 0; i < keys.Length(); ++i) {
|
|
DoomStorageEntries(keys[i], nullptr, true, false, nullptr);
|
|
}
|
|
}
|
|
|
|
namespace {
|
|
|
|
class CleaupCacheDirectoriesRunnable : public nsRunnable
|
|
{
|
|
public:
|
|
NS_DECL_NSIRUNNABLE
|
|
static bool Post(uint32_t aVersion, uint32_t aActive);
|
|
|
|
private:
|
|
CleaupCacheDirectoriesRunnable(uint32_t aVersion, uint32_t aActive)
|
|
: mVersion(aVersion), mActive(aActive)
|
|
{
|
|
nsCacheService::GetDiskCacheDirectory(getter_AddRefs(mCache1Dir));
|
|
CacheFileIOManager::GetCacheDirectory(getter_AddRefs(mCache2Dir));
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
CacheFileIOManager::GetProfilelessCacheDirectory(getter_AddRefs(mCache2Profileless));
|
|
#endif
|
|
}
|
|
|
|
virtual ~CleaupCacheDirectoriesRunnable() {}
|
|
uint32_t mVersion, mActive;
|
|
nsCOMPtr<nsIFile> mCache1Dir, mCache2Dir;
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
nsCOMPtr<nsIFile> mCache2Profileless;
|
|
#endif
|
|
};
|
|
|
|
// static
|
|
bool CleaupCacheDirectoriesRunnable::Post(uint32_t aVersion, uint32_t aActive)
|
|
{
|
|
// CleaupCacheDirectories is called regardless what cache version is set up to use.
|
|
// To obtain the cache1 directory we must unfortunatelly instantiate the old cache
|
|
// service despite it may not be used at all... This also initialize nsDeleteDir.
|
|
nsCOMPtr<nsICacheService> service = do_GetService(NS_CACHESERVICE_CONTRACTID);
|
|
if (!service)
|
|
return false;
|
|
|
|
nsCOMPtr<nsIEventTarget> thread;
|
|
service->GetCacheIOTarget(getter_AddRefs(thread));
|
|
if (!thread)
|
|
return false;
|
|
|
|
RefPtr<CleaupCacheDirectoriesRunnable> r =
|
|
new CleaupCacheDirectoriesRunnable(aVersion, aActive);
|
|
thread->Dispatch(r, NS_DISPATCH_NORMAL);
|
|
return true;
|
|
}
|
|
|
|
NS_IMETHODIMP CleaupCacheDirectoriesRunnable::Run()
|
|
{
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
if (mCache1Dir) {
|
|
nsDeleteDir::RemoveOldTrashes(mCache1Dir);
|
|
}
|
|
if (mCache2Dir) {
|
|
nsDeleteDir::RemoveOldTrashes(mCache2Dir);
|
|
}
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
if (mCache2Profileless) {
|
|
nsDeleteDir::RemoveOldTrashes(mCache2Profileless);
|
|
// Always delete the profileless cache on Android
|
|
nsDeleteDir::DeleteDir(mCache2Profileless, true, 30000);
|
|
}
|
|
#endif
|
|
|
|
// Delete the non-active version cache data right now
|
|
if (mVersion == mActive) {
|
|
return NS_OK;
|
|
}
|
|
|
|
switch (mVersion) {
|
|
case 0:
|
|
if (mCache1Dir) {
|
|
nsDeleteDir::DeleteDir(mCache1Dir, true, 30000);
|
|
}
|
|
break;
|
|
case 1:
|
|
if (mCache2Dir) {
|
|
nsDeleteDir::DeleteDir(mCache2Dir, true, 30000);
|
|
}
|
|
break;
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
// static
|
|
void CacheStorageService::CleaupCacheDirectories(uint32_t aVersion, uint32_t aActive)
|
|
{
|
|
// Make sure we schedule just once in case CleaupCacheDirectories gets called
|
|
// multiple times from some reason.
|
|
static bool runOnce = CleaupCacheDirectoriesRunnable::Post(aVersion, aActive);
|
|
if (!runOnce) {
|
|
NS_WARNING("Could not start cache trashes cleanup");
|
|
}
|
|
}
|
|
|
|
// Helper methods
|
|
|
|
// static
|
|
bool CacheStorageService::IsOnManagementThread()
|
|
{
|
|
RefPtr<CacheStorageService> service = Self();
|
|
if (!service)
|
|
return false;
|
|
|
|
nsCOMPtr<nsIEventTarget> target = service->Thread();
|
|
if (!target)
|
|
return false;
|
|
|
|
bool currentThread;
|
|
nsresult rv = target->IsOnCurrentThread(¤tThread);
|
|
return NS_SUCCEEDED(rv) && currentThread;
|
|
}
|
|
|
|
already_AddRefed<nsIEventTarget> CacheStorageService::Thread() const
|
|
{
|
|
return CacheFileIOManager::IOTarget();
|
|
}
|
|
|
|
nsresult CacheStorageService::Dispatch(nsIRunnable* aEvent)
|
|
{
|
|
RefPtr<CacheIOThread> cacheIOThread = CacheFileIOManager::IOThread();
|
|
if (!cacheIOThread)
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
return cacheIOThread->Dispatch(aEvent, CacheIOThread::MANAGEMENT);
|
|
}
|
|
|
|
// nsICacheStorageService
|
|
|
|
NS_IMETHODIMP CacheStorageService::MemoryCacheStorage(nsILoadContextInfo *aLoadContextInfo,
|
|
nsICacheStorage * *_retval)
|
|
{
|
|
NS_ENSURE_ARG(aLoadContextInfo);
|
|
NS_ENSURE_ARG(_retval);
|
|
|
|
nsCOMPtr<nsICacheStorage> storage;
|
|
if (CacheObserver::UseNewCache()) {
|
|
storage = new CacheStorage(aLoadContextInfo, false, false, false, false);
|
|
}
|
|
else {
|
|
storage = new _OldStorage(aLoadContextInfo, false, false, false, nullptr);
|
|
}
|
|
|
|
storage.forget(_retval);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP CacheStorageService::DiskCacheStorage(nsILoadContextInfo *aLoadContextInfo,
|
|
bool aLookupAppCache,
|
|
nsICacheStorage * *_retval)
|
|
{
|
|
NS_ENSURE_ARG(aLoadContextInfo);
|
|
NS_ENSURE_ARG(_retval);
|
|
|
|
// TODO save some heap granularity - cache commonly used storages.
|
|
|
|
// When disk cache is disabled, still provide a storage, but just keep stuff
|
|
// in memory.
|
|
bool useDisk = CacheObserver::UseDiskCache();
|
|
|
|
nsCOMPtr<nsICacheStorage> storage;
|
|
if (CacheObserver::UseNewCache()) {
|
|
storage = new CacheStorage(aLoadContextInfo, useDisk, aLookupAppCache, false /* size limit */, false /* don't pin */);
|
|
}
|
|
else {
|
|
storage = new _OldStorage(aLoadContextInfo, useDisk, aLookupAppCache, false, nullptr);
|
|
}
|
|
|
|
storage.forget(_retval);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP CacheStorageService::PinningCacheStorage(nsILoadContextInfo *aLoadContextInfo,
|
|
nsICacheStorage * *_retval)
|
|
{
|
|
NS_ENSURE_ARG(aLoadContextInfo);
|
|
NS_ENSURE_ARG(_retval);
|
|
|
|
if (!CacheObserver::UseNewCache()) {
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
}
|
|
|
|
// When disk cache is disabled don't pretend we cache.
|
|
if (!CacheObserver::UseDiskCache()) {
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
}
|
|
|
|
nsCOMPtr<nsICacheStorage> storage = new CacheStorage(
|
|
aLoadContextInfo, true /* use disk */, false /* no appcache */, true /* ignore size checks */, true /* pin */);
|
|
storage.forget(_retval);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP CacheStorageService::AppCacheStorage(nsILoadContextInfo *aLoadContextInfo,
|
|
nsIApplicationCache *aApplicationCache,
|
|
nsICacheStorage * *_retval)
|
|
{
|
|
NS_ENSURE_ARG(aLoadContextInfo);
|
|
NS_ENSURE_ARG(_retval);
|
|
|
|
nsCOMPtr<nsICacheStorage> storage;
|
|
if (CacheObserver::UseNewCache()) {
|
|
// Using classification since cl believes we want to instantiate this method
|
|
// having the same name as the desired class...
|
|
storage = new mozilla::net::AppCacheStorage(aLoadContextInfo, aApplicationCache);
|
|
}
|
|
else {
|
|
storage = new _OldStorage(aLoadContextInfo, true, false, true, aApplicationCache);
|
|
}
|
|
|
|
storage.forget(_retval);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP CacheStorageService::SynthesizedCacheStorage(nsILoadContextInfo *aLoadContextInfo,
|
|
nsICacheStorage * *_retval)
|
|
{
|
|
NS_ENSURE_ARG(aLoadContextInfo);
|
|
NS_ENSURE_ARG(_retval);
|
|
|
|
nsCOMPtr<nsICacheStorage> storage;
|
|
if (CacheObserver::UseNewCache()) {
|
|
storage = new CacheStorage(aLoadContextInfo, false, false, true /* skip size checks for synthesized cache */, false /* no pinning */);
|
|
}
|
|
else {
|
|
storage = new _OldStorage(aLoadContextInfo, false, false, false, nullptr);
|
|
}
|
|
|
|
storage.forget(_retval);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP CacheStorageService::Clear()
|
|
{
|
|
nsresult rv;
|
|
|
|
if (CacheObserver::UseNewCache()) {
|
|
// Tell the index to block notification to AsyncGetDiskConsumption.
|
|
// Will be allowed again from CacheFileContextEvictor::EvictEntries()
|
|
// when all the context have been removed from disk.
|
|
CacheIndex::OnAsyncEviction(true);
|
|
|
|
{
|
|
mozilla::MutexAutoLock lock(mLock);
|
|
|
|
{
|
|
mozilla::MutexAutoLock forcedValidEntriesLock(mForcedValidEntriesLock);
|
|
mForcedValidEntries.Clear();
|
|
}
|
|
|
|
NS_ENSURE_TRUE(!mShutdown, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
nsTArray<nsCString> keys;
|
|
for (auto iter = sGlobalEntryTables->Iter(); !iter.Done(); iter.Next()) {
|
|
keys.AppendElement(iter.Key());
|
|
}
|
|
|
|
for (uint32_t i = 0; i < keys.Length(); ++i) {
|
|
DoomStorageEntries(keys[i], nullptr, true, false, nullptr);
|
|
}
|
|
|
|
// Passing null as a load info means to evict all contexts.
|
|
// EvictByContext() respects the entry pinning. EvictAll() does not.
|
|
rv = CacheFileIOManager::EvictByContext(nullptr, false);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
}
|
|
} else {
|
|
nsCOMPtr<nsICacheService> serv =
|
|
do_GetService(NS_CACHESERVICE_CONTRACTID, &rv);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = serv->EvictEntries(nsICache::STORE_ANYWHERE);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP CacheStorageService::PurgeFromMemory(uint32_t aWhat)
|
|
{
|
|
uint32_t what;
|
|
|
|
switch (aWhat) {
|
|
case PURGE_DISK_DATA_ONLY:
|
|
what = CacheEntry::PURGE_DATA_ONLY_DISK_BACKED;
|
|
break;
|
|
|
|
case PURGE_DISK_ALL:
|
|
what = CacheEntry::PURGE_WHOLE_ONLY_DISK_BACKED;
|
|
break;
|
|
|
|
case PURGE_EVERYTHING:
|
|
what = CacheEntry::PURGE_WHOLE;
|
|
break;
|
|
|
|
default:
|
|
return NS_ERROR_INVALID_ARG;
|
|
}
|
|
|
|
nsCOMPtr<nsIRunnable> event =
|
|
new PurgeFromMemoryRunnable(this, what);
|
|
|
|
return Dispatch(event);
|
|
}
|
|
|
|
NS_IMETHODIMP CacheStorageService::PurgeFromMemoryRunnable::Run()
|
|
{
|
|
if (NS_IsMainThread()) {
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
mozilla::services::GetObserverService();
|
|
if (observerService) {
|
|
observerService->NotifyObservers(nullptr, "cacheservice:purge-memory-pools", nullptr);
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
if (mService) {
|
|
// TODO not all flags apply to both pools
|
|
mService->Pool(true).PurgeAll(mWhat);
|
|
mService->Pool(false).PurgeAll(mWhat);
|
|
mService = nullptr;
|
|
}
|
|
|
|
NS_DispatchToMainThread(this);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP CacheStorageService::AsyncGetDiskConsumption(
|
|
nsICacheStorageConsumptionObserver* aObserver)
|
|
{
|
|
NS_ENSURE_ARG(aObserver);
|
|
|
|
nsresult rv;
|
|
|
|
if (CacheObserver::UseNewCache()) {
|
|
rv = CacheIndex::AsyncGetDiskConsumption(aObserver);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
} else {
|
|
rv = _OldGetDiskConsumption::Get(aObserver);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP CacheStorageService::GetIoTarget(nsIEventTarget** aEventTarget)
|
|
{
|
|
NS_ENSURE_ARG(aEventTarget);
|
|
|
|
if (CacheObserver::UseNewCache()) {
|
|
nsCOMPtr<nsIEventTarget> ioTarget = CacheFileIOManager::IOTarget();
|
|
ioTarget.forget(aEventTarget);
|
|
}
|
|
else {
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsICacheService> serv =
|
|
do_GetService(NS_CACHESERVICE_CONTRACTID, &rv);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = serv->GetCacheIOTarget(aEventTarget);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
// Methods used by CacheEntry for management of in-memory structures.
|
|
|
|
namespace {
|
|
|
|
class FrecencyComparator
|
|
{
|
|
public:
|
|
bool Equals(CacheEntry* a, CacheEntry* b) const {
|
|
return a->GetFrecency() == b->GetFrecency();
|
|
}
|
|
bool LessThan(CacheEntry* a, CacheEntry* b) const {
|
|
return a->GetFrecency() < b->GetFrecency();
|
|
}
|
|
};
|
|
|
|
class ExpirationComparator
|
|
{
|
|
public:
|
|
bool Equals(CacheEntry* a, CacheEntry* b) const {
|
|
return a->GetExpirationTime() == b->GetExpirationTime();
|
|
}
|
|
bool LessThan(CacheEntry* a, CacheEntry* b) const {
|
|
return a->GetExpirationTime() < b->GetExpirationTime();
|
|
}
|
|
};
|
|
|
|
} // namespace
|
|
|
|
void
|
|
CacheStorageService::RegisterEntry(CacheEntry* aEntry)
|
|
{
|
|
MOZ_ASSERT(IsOnManagementThread());
|
|
|
|
if (mShutdown || !aEntry->CanRegister())
|
|
return;
|
|
|
|
LOG(("CacheStorageService::RegisterEntry [entry=%p]", aEntry));
|
|
|
|
MemoryPool& pool = Pool(aEntry->IsUsingDisk());
|
|
pool.mFrecencyArray.AppendElement(aEntry);
|
|
pool.mExpirationArray.AppendElement(aEntry);
|
|
|
|
aEntry->SetRegistered(true);
|
|
}
|
|
|
|
void
|
|
CacheStorageService::UnregisterEntry(CacheEntry* aEntry)
|
|
{
|
|
MOZ_ASSERT(IsOnManagementThread());
|
|
|
|
if (!aEntry->IsRegistered())
|
|
return;
|
|
|
|
LOG(("CacheStorageService::UnregisterEntry [entry=%p]", aEntry));
|
|
|
|
MemoryPool& pool = Pool(aEntry->IsUsingDisk());
|
|
mozilla::DebugOnly<bool> removedFrecency = pool.mFrecencyArray.RemoveElement(aEntry);
|
|
mozilla::DebugOnly<bool> removedExpiration = pool.mExpirationArray.RemoveElement(aEntry);
|
|
|
|
MOZ_ASSERT(mShutdown || (removedFrecency && removedExpiration));
|
|
|
|
// Note: aEntry->CanRegister() since now returns false
|
|
aEntry->SetRegistered(false);
|
|
}
|
|
|
|
static bool
|
|
AddExactEntry(CacheEntryTable* aEntries,
|
|
nsACString const& aKey,
|
|
CacheEntry* aEntry,
|
|
bool aOverwrite)
|
|
{
|
|
RefPtr<CacheEntry> existingEntry;
|
|
if (!aOverwrite && aEntries->Get(aKey, getter_AddRefs(existingEntry))) {
|
|
bool equals = existingEntry == aEntry;
|
|
LOG(("AddExactEntry [entry=%p equals=%d]", aEntry, equals));
|
|
return equals; // Already there...
|
|
}
|
|
|
|
LOG(("AddExactEntry [entry=%p put]", aEntry));
|
|
aEntries->Put(aKey, aEntry);
|
|
return true;
|
|
}
|
|
|
|
static bool
|
|
RemoveExactEntry(CacheEntryTable* aEntries,
|
|
nsACString const& aKey,
|
|
CacheEntry* aEntry,
|
|
bool aOverwrite)
|
|
{
|
|
RefPtr<CacheEntry> existingEntry;
|
|
if (!aEntries->Get(aKey, getter_AddRefs(existingEntry))) {
|
|
LOG(("RemoveExactEntry [entry=%p already gone]", aEntry));
|
|
return false; // Already removed...
|
|
}
|
|
|
|
if (!aOverwrite && existingEntry != aEntry) {
|
|
LOG(("RemoveExactEntry [entry=%p already replaced]", aEntry));
|
|
return false; // Already replaced...
|
|
}
|
|
|
|
LOG(("RemoveExactEntry [entry=%p removed]", aEntry));
|
|
aEntries->Remove(aKey);
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
CacheStorageService::RemoveEntry(CacheEntry* aEntry, bool aOnlyUnreferenced)
|
|
{
|
|
LOG(("CacheStorageService::RemoveEntry [entry=%p]", aEntry));
|
|
|
|
nsAutoCString entryKey;
|
|
nsresult rv = aEntry->HashingKey(entryKey);
|
|
if (NS_FAILED(rv)) {
|
|
NS_ERROR("aEntry->HashingKey() failed?");
|
|
return false;
|
|
}
|
|
|
|
mozilla::MutexAutoLock lock(mLock);
|
|
|
|
if (mShutdown) {
|
|
LOG((" after shutdown"));
|
|
return false;
|
|
}
|
|
|
|
if (aOnlyUnreferenced) {
|
|
if (aEntry->IsReferenced()) {
|
|
LOG((" still referenced, not removing"));
|
|
return false;
|
|
}
|
|
|
|
if (!aEntry->IsUsingDisk() && IsForcedValidEntry(aEntry->GetStorageID(), entryKey)) {
|
|
LOG((" forced valid, not removing"));
|
|
return false;
|
|
}
|
|
}
|
|
|
|
CacheEntryTable* entries;
|
|
if (sGlobalEntryTables->Get(aEntry->GetStorageID(), &entries))
|
|
RemoveExactEntry(entries, entryKey, aEntry, false /* don't overwrite */);
|
|
|
|
nsAutoCString memoryStorageID(aEntry->GetStorageID());
|
|
AppendMemoryStorageID(memoryStorageID);
|
|
|
|
if (sGlobalEntryTables->Get(memoryStorageID, &entries))
|
|
RemoveExactEntry(entries, entryKey, aEntry, false /* don't overwrite */);
|
|
|
|
return true;
|
|
}
|
|
|
|
void
|
|
CacheStorageService::RecordMemoryOnlyEntry(CacheEntry* aEntry,
|
|
bool aOnlyInMemory,
|
|
bool aOverwrite)
|
|
{
|
|
LOG(("CacheStorageService::RecordMemoryOnlyEntry [entry=%p, memory=%d, overwrite=%d]",
|
|
aEntry, aOnlyInMemory, aOverwrite));
|
|
// This method is responsible to put this entry to a special record hashtable
|
|
// that contains only entries that are stored in memory.
|
|
// Keep in mind that every entry, regardless of whether is in-memory-only or not
|
|
// is always recorded in the storage master hash table, the one identified by
|
|
// CacheEntry.StorageID().
|
|
|
|
mLock.AssertCurrentThreadOwns();
|
|
|
|
if (mShutdown) {
|
|
LOG((" after shutdown"));
|
|
return;
|
|
}
|
|
|
|
nsresult rv;
|
|
|
|
nsAutoCString entryKey;
|
|
rv = aEntry->HashingKey(entryKey);
|
|
if (NS_FAILED(rv)) {
|
|
NS_ERROR("aEntry->HashingKey() failed?");
|
|
return;
|
|
}
|
|
|
|
CacheEntryTable* entries = nullptr;
|
|
nsAutoCString memoryStorageID(aEntry->GetStorageID());
|
|
AppendMemoryStorageID(memoryStorageID);
|
|
|
|
if (!sGlobalEntryTables->Get(memoryStorageID, &entries)) {
|
|
if (!aOnlyInMemory) {
|
|
LOG((" not recorded as memory only"));
|
|
return;
|
|
}
|
|
|
|
entries = new CacheEntryTable(CacheEntryTable::MEMORY_ONLY);
|
|
sGlobalEntryTables->Put(memoryStorageID, entries);
|
|
LOG((" new memory-only storage table for %s", memoryStorageID.get()));
|
|
}
|
|
|
|
if (aOnlyInMemory) {
|
|
AddExactEntry(entries, entryKey, aEntry, aOverwrite);
|
|
}
|
|
else {
|
|
RemoveExactEntry(entries, entryKey, aEntry, aOverwrite);
|
|
}
|
|
}
|
|
|
|
// Checks if a cache entry is forced valid (will be loaded directly from cache
|
|
// without further validation) - see nsICacheEntry.idl for further details
|
|
bool CacheStorageService::IsForcedValidEntry(nsACString const &aContextKey,
|
|
nsACString const &aEntryKey)
|
|
{
|
|
return IsForcedValidEntry(aContextKey + aEntryKey);
|
|
}
|
|
|
|
bool CacheStorageService::IsForcedValidEntry(nsACString const &aContextEntryKey)
|
|
{
|
|
mozilla::MutexAutoLock lock(mForcedValidEntriesLock);
|
|
|
|
TimeStamp validUntil;
|
|
|
|
if (!mForcedValidEntries.Get(aContextEntryKey, &validUntil)) {
|
|
return false;
|
|
}
|
|
|
|
if (validUntil.IsNull()) {
|
|
return false;
|
|
}
|
|
|
|
// Entry timeout not reached yet
|
|
if (TimeStamp::NowLoRes() <= validUntil) {
|
|
return true;
|
|
}
|
|
|
|
// Entry timeout has been reached
|
|
mForcedValidEntries.Remove(aContextEntryKey);
|
|
return false;
|
|
}
|
|
|
|
// Allows a cache entry to be loaded directly from cache without further
|
|
// validation - see nsICacheEntry.idl for further details
|
|
void CacheStorageService::ForceEntryValidFor(nsACString const &aContextKey,
|
|
nsACString const &aEntryKey,
|
|
uint32_t aSecondsToTheFuture)
|
|
{
|
|
mozilla::MutexAutoLock lock(mForcedValidEntriesLock);
|
|
|
|
TimeStamp now = TimeStamp::NowLoRes();
|
|
ForcedValidEntriesPrune(now);
|
|
|
|
// This will be the timeout
|
|
TimeStamp validUntil = now + TimeDuration::FromSeconds(aSecondsToTheFuture);
|
|
|
|
mForcedValidEntries.Put(aContextKey + aEntryKey, validUntil);
|
|
}
|
|
|
|
void CacheStorageService::RemoveEntryForceValid(nsACString const &aContextKey,
|
|
nsACString const &aEntryKey)
|
|
{
|
|
mozilla::MutexAutoLock lock(mForcedValidEntriesLock);
|
|
|
|
LOG(("CacheStorageService::RemoveEntryForceValid context='%s' entryKey=%s",
|
|
aContextKey.BeginReading(), aEntryKey.BeginReading()));
|
|
mForcedValidEntries.Remove(aContextKey + aEntryKey);
|
|
}
|
|
|
|
// Cleans out the old entries in mForcedValidEntries
|
|
void CacheStorageService::ForcedValidEntriesPrune(TimeStamp &now)
|
|
{
|
|
static TimeDuration const oneMinute = TimeDuration::FromSeconds(60);
|
|
static TimeStamp dontPruneUntil = now + oneMinute;
|
|
if (now < dontPruneUntil)
|
|
return;
|
|
|
|
for (auto iter = mForcedValidEntries.Iter(); !iter.Done(); iter.Next()) {
|
|
if (iter.Data() < now) {
|
|
iter.Remove();
|
|
}
|
|
}
|
|
dontPruneUntil = now + oneMinute;
|
|
}
|
|
|
|
void
|
|
CacheStorageService::OnMemoryConsumptionChange(CacheMemoryConsumer* aConsumer,
|
|
uint32_t aCurrentMemoryConsumption)
|
|
{
|
|
LOG(("CacheStorageService::OnMemoryConsumptionChange [consumer=%p, size=%u]",
|
|
aConsumer, aCurrentMemoryConsumption));
|
|
|
|
uint32_t savedMemorySize = aConsumer->mReportedMemoryConsumption;
|
|
if (savedMemorySize == aCurrentMemoryConsumption)
|
|
return;
|
|
|
|
// Exchange saved size with current one.
|
|
aConsumer->mReportedMemoryConsumption = aCurrentMemoryConsumption;
|
|
|
|
bool usingDisk = !(aConsumer->mFlags & CacheMemoryConsumer::MEMORY_ONLY);
|
|
bool overLimit = Pool(usingDisk).OnMemoryConsumptionChange(
|
|
savedMemorySize, aCurrentMemoryConsumption);
|
|
|
|
if (!overLimit)
|
|
return;
|
|
|
|
// It's likely the timer has already been set when we get here,
|
|
// check outside the lock to save resources.
|
|
if (mPurgeTimer)
|
|
return;
|
|
|
|
// We don't know if this is called under the service lock or not,
|
|
// hence rather dispatch.
|
|
RefPtr<nsIEventTarget> cacheIOTarget = Thread();
|
|
if (!cacheIOTarget)
|
|
return;
|
|
|
|
// Dispatch as a priority task, we want to set the purge timer
|
|
// ASAP to prevent vain redispatch of this event.
|
|
nsCOMPtr<nsIRunnable> event =
|
|
NS_NewRunnableMethod(this, &CacheStorageService::SchedulePurgeOverMemoryLimit);
|
|
cacheIOTarget->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL);
|
|
}
|
|
|
|
bool
|
|
CacheStorageService::MemoryPool::OnMemoryConsumptionChange(uint32_t aSavedMemorySize,
|
|
uint32_t aCurrentMemoryConsumption)
|
|
{
|
|
mMemorySize -= aSavedMemorySize;
|
|
mMemorySize += aCurrentMemoryConsumption;
|
|
|
|
LOG((" mMemorySize=%u (+%u,-%u)", uint32_t(mMemorySize), aCurrentMemoryConsumption, aSavedMemorySize));
|
|
|
|
// Bypass purging when memory has not grew up significantly
|
|
if (aCurrentMemoryConsumption <= aSavedMemorySize)
|
|
return false;
|
|
|
|
return mMemorySize > Limit();
|
|
}
|
|
|
|
void
|
|
CacheStorageService::SchedulePurgeOverMemoryLimit()
|
|
{
|
|
mozilla::MutexAutoLock lock(mLock);
|
|
|
|
if (mPurgeTimer)
|
|
return;
|
|
|
|
mPurgeTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
|
|
if (mPurgeTimer)
|
|
mPurgeTimer->InitWithCallback(this, 1000, nsITimer::TYPE_ONE_SHOT);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
CacheStorageService::Notify(nsITimer* aTimer)
|
|
{
|
|
if (aTimer == mPurgeTimer) {
|
|
mPurgeTimer = nullptr;
|
|
|
|
nsCOMPtr<nsIRunnable> event =
|
|
NS_NewRunnableMethod(this, &CacheStorageService::PurgeOverMemoryLimit);
|
|
Dispatch(event);
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
CacheStorageService::PurgeOverMemoryLimit()
|
|
{
|
|
MOZ_ASSERT(IsOnManagementThread());
|
|
|
|
LOG(("CacheStorageService::PurgeOverMemoryLimit"));
|
|
|
|
static TimeDuration const kFourSeconds = TimeDuration::FromSeconds(4);
|
|
TimeStamp now = TimeStamp::NowLoRes();
|
|
|
|
if (!mLastPurgeTime.IsNull() && now - mLastPurgeTime < kFourSeconds) {
|
|
LOG((" bypassed, too soon"));
|
|
return;
|
|
}
|
|
|
|
mLastPurgeTime = now;
|
|
|
|
Pool(true).PurgeOverMemoryLimit();
|
|
Pool(false).PurgeOverMemoryLimit();
|
|
}
|
|
|
|
void
|
|
CacheStorageService::MemoryPool::PurgeOverMemoryLimit()
|
|
{
|
|
TimeStamp start(TimeStamp::Now());
|
|
|
|
uint32_t const memoryLimit = Limit();
|
|
if (mMemorySize > memoryLimit) {
|
|
LOG((" memory data consumption over the limit, abandon expired entries"));
|
|
PurgeExpired();
|
|
}
|
|
|
|
bool frecencyNeedsSort = true;
|
|
|
|
// No longer makes sense since:
|
|
// Memory entries are never purged partially, only as a whole when the memory
|
|
// cache limit is overreached.
|
|
// Disk entries throw the data away ASAP so that only metadata are kept.
|
|
// TODO when this concept of two separate pools is found working, the code should
|
|
// clean up.
|
|
#if 0
|
|
if (mMemorySize > memoryLimit) {
|
|
LOG((" memory data consumption over the limit, abandon disk backed data"));
|
|
PurgeByFrecency(frecencyNeedsSort, CacheEntry::PURGE_DATA_ONLY_DISK_BACKED);
|
|
}
|
|
|
|
if (mMemorySize > memoryLimit) {
|
|
LOG((" metadata consumtion over the limit, abandon disk backed entries"));
|
|
PurgeByFrecency(frecencyNeedsSort, CacheEntry::PURGE_WHOLE_ONLY_DISK_BACKED);
|
|
}
|
|
#endif
|
|
|
|
if (mMemorySize > memoryLimit) {
|
|
LOG((" memory data consumption over the limit, abandon any entry"));
|
|
PurgeByFrecency(frecencyNeedsSort, CacheEntry::PURGE_WHOLE);
|
|
}
|
|
|
|
LOG((" purging took %1.2fms", (TimeStamp::Now() - start).ToMilliseconds()));
|
|
}
|
|
|
|
void
|
|
CacheStorageService::MemoryPool::PurgeExpired()
|
|
{
|
|
MOZ_ASSERT(IsOnManagementThread());
|
|
|
|
mExpirationArray.Sort(ExpirationComparator());
|
|
uint32_t now = NowInSeconds();
|
|
|
|
uint32_t const memoryLimit = Limit();
|
|
|
|
for (uint32_t i = 0; mMemorySize > memoryLimit && i < mExpirationArray.Length();) {
|
|
if (CacheIOThread::YieldAndRerun())
|
|
return;
|
|
|
|
RefPtr<CacheEntry> entry = mExpirationArray[i];
|
|
|
|
uint32_t expirationTime = entry->GetExpirationTime();
|
|
if (expirationTime > 0 && expirationTime <= now &&
|
|
entry->Purge(CacheEntry::PURGE_WHOLE)) {
|
|
LOG((" purged expired, entry=%p, exptime=%u (now=%u)",
|
|
entry.get(), entry->GetExpirationTime(), now));
|
|
continue;
|
|
}
|
|
|
|
// not purged, move to the next one
|
|
++i;
|
|
}
|
|
}
|
|
|
|
void
|
|
CacheStorageService::MemoryPool::PurgeByFrecency(bool &aFrecencyNeedsSort, uint32_t aWhat)
|
|
{
|
|
MOZ_ASSERT(IsOnManagementThread());
|
|
|
|
if (aFrecencyNeedsSort) {
|
|
mFrecencyArray.Sort(FrecencyComparator());
|
|
aFrecencyNeedsSort = false;
|
|
}
|
|
|
|
uint32_t const memoryLimit = Limit();
|
|
|
|
for (uint32_t i = 0; mMemorySize > memoryLimit && i < mFrecencyArray.Length();) {
|
|
if (CacheIOThread::YieldAndRerun())
|
|
return;
|
|
|
|
RefPtr<CacheEntry> entry = mFrecencyArray[i];
|
|
|
|
if (entry->Purge(aWhat)) {
|
|
LOG((" abandoned (%d), entry=%p, frecency=%1.10f",
|
|
aWhat, entry.get(), entry->GetFrecency()));
|
|
continue;
|
|
}
|
|
|
|
// not purged, move to the next one
|
|
++i;
|
|
}
|
|
}
|
|
|
|
void
|
|
CacheStorageService::MemoryPool::PurgeAll(uint32_t aWhat)
|
|
{
|
|
LOG(("CacheStorageService::MemoryPool::PurgeAll aWhat=%d", aWhat));
|
|
MOZ_ASSERT(IsOnManagementThread());
|
|
|
|
for (uint32_t i = 0; i < mFrecencyArray.Length();) {
|
|
if (CacheIOThread::YieldAndRerun())
|
|
return;
|
|
|
|
RefPtr<CacheEntry> entry = mFrecencyArray[i];
|
|
|
|
if (entry->Purge(aWhat)) {
|
|
LOG((" abandoned entry=%p", entry.get()));
|
|
continue;
|
|
}
|
|
|
|
// not purged, move to the next one
|
|
++i;
|
|
}
|
|
}
|
|
|
|
// Methods exposed to and used by CacheStorage.
|
|
|
|
nsresult
|
|
CacheStorageService::AddStorageEntry(CacheStorage const* aStorage,
|
|
nsIURI* aURI,
|
|
const nsACString & aIdExtension,
|
|
bool aReplace,
|
|
CacheEntryHandle** aResult)
|
|
{
|
|
NS_ENSURE_FALSE(mShutdown, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
NS_ENSURE_ARG(aStorage);
|
|
|
|
nsAutoCString contextKey;
|
|
CacheFileUtils::AppendKeyPrefix(aStorage->LoadInfo(), contextKey);
|
|
|
|
return AddStorageEntry(contextKey, aURI, aIdExtension,
|
|
aStorage->WriteToDisk(),
|
|
aStorage->SkipSizeCheck(),
|
|
aStorage->Pinning(),
|
|
aReplace,
|
|
aResult);
|
|
}
|
|
|
|
nsresult
|
|
CacheStorageService::AddStorageEntry(nsCSubstring const& aContextKey,
|
|
nsIURI* aURI,
|
|
const nsACString & aIdExtension,
|
|
bool aWriteToDisk,
|
|
bool aSkipSizeCheck,
|
|
bool aPin,
|
|
bool aReplace,
|
|
CacheEntryHandle** aResult)
|
|
{
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
nsresult rv;
|
|
|
|
nsAutoCString entryKey;
|
|
rv = CacheEntry::HashingKey(EmptyCString(), aIdExtension, aURI, entryKey);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
LOG(("CacheStorageService::AddStorageEntry [entryKey=%s, contextKey=%s]",
|
|
entryKey.get(), aContextKey.BeginReading()));
|
|
|
|
RefPtr<CacheEntry> entry;
|
|
RefPtr<CacheEntryHandle> handle;
|
|
|
|
{
|
|
mozilla::MutexAutoLock lock(mLock);
|
|
|
|
NS_ENSURE_FALSE(mShutdown, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
// Ensure storage table
|
|
CacheEntryTable* entries;
|
|
if (!sGlobalEntryTables->Get(aContextKey, &entries)) {
|
|
entries = new CacheEntryTable(CacheEntryTable::ALL_ENTRIES);
|
|
sGlobalEntryTables->Put(aContextKey, entries);
|
|
LOG((" new storage entries table for context '%s'", aContextKey.BeginReading()));
|
|
}
|
|
|
|
bool entryExists = entries->Get(entryKey, getter_AddRefs(entry));
|
|
|
|
if (entryExists && !aReplace) {
|
|
// check whether we want to turn this entry to a memory-only.
|
|
if (MOZ_UNLIKELY(!aWriteToDisk) && MOZ_LIKELY(entry->IsUsingDisk())) {
|
|
LOG((" entry is persistent but we want mem-only, replacing it"));
|
|
aReplace = true;
|
|
}
|
|
}
|
|
|
|
// If truncate is demanded, delete and doom the current entry
|
|
if (entryExists && aReplace) {
|
|
entries->Remove(entryKey);
|
|
|
|
LOG((" dooming entry %p for %s because of OPEN_TRUNCATE", entry.get(), entryKey.get()));
|
|
// On purpose called under the lock to prevent races of doom and open on I/O thread
|
|
// No need to remove from both memory-only and all-entries tables. The new entry
|
|
// will overwrite the shadow entry in its ctor.
|
|
entry->DoomAlreadyRemoved();
|
|
|
|
entry = nullptr;
|
|
entryExists = false;
|
|
|
|
// Would only lead to deleting force-valid timestamp again. We don't need the
|
|
// replace information anymore after this point anyway.
|
|
aReplace = false;
|
|
}
|
|
|
|
// Ensure entry for the particular URL
|
|
if (!entryExists) {
|
|
// When replacing with a new entry, always remove the current force-valid timestamp,
|
|
// this is the only place to do it.
|
|
if (aReplace) {
|
|
RemoveEntryForceValid(aContextKey, entryKey);
|
|
}
|
|
|
|
// Entry is not in the hashtable or has just been truncated...
|
|
entry = new CacheEntry(aContextKey, aURI, aIdExtension, aWriteToDisk, aSkipSizeCheck, aPin);
|
|
entries->Put(entryKey, entry);
|
|
LOG((" new entry %p for %s", entry.get(), entryKey.get()));
|
|
}
|
|
|
|
if (entry) {
|
|
// Here, if this entry was not for a long time referenced by any consumer,
|
|
// gets again first 'handles count' reference.
|
|
handle = entry->NewHandle();
|
|
}
|
|
}
|
|
|
|
handle.forget(aResult);
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
CacheStorageService::CheckStorageEntry(CacheStorage const* aStorage,
|
|
nsIURI* aURI,
|
|
const nsACString & aIdExtension,
|
|
bool* aResult)
|
|
{
|
|
nsresult rv;
|
|
|
|
nsAutoCString contextKey;
|
|
CacheFileUtils::AppendKeyPrefix(aStorage->LoadInfo(), contextKey);
|
|
|
|
if (!aStorage->WriteToDisk()) {
|
|
AppendMemoryStorageID(contextKey);
|
|
}
|
|
|
|
if (LOG_ENABLED()) {
|
|
nsAutoCString uriSpec;
|
|
aURI->GetAsciiSpec(uriSpec);
|
|
LOG(("CacheStorageService::CheckStorageEntry [uri=%s, eid=%s, contextKey=%s]",
|
|
uriSpec.get(), aIdExtension.BeginReading(), contextKey.get()));
|
|
}
|
|
|
|
{
|
|
mozilla::MutexAutoLock lock(mLock);
|
|
|
|
NS_ENSURE_FALSE(mShutdown, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
nsAutoCString entryKey;
|
|
rv = CacheEntry::HashingKey(EmptyCString(), aIdExtension, aURI, entryKey);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
CacheEntryTable* entries;
|
|
if ((*aResult = sGlobalEntryTables->Get(contextKey, &entries)) &&
|
|
entries->GetWeak(entryKey, aResult)) {
|
|
LOG((" found in hash tables"));
|
|
return NS_OK;
|
|
}
|
|
}
|
|
|
|
if (!aStorage->WriteToDisk()) {
|
|
// Memory entry, nothing more to do.
|
|
LOG((" not found in hash tables"));
|
|
return NS_OK;
|
|
}
|
|
|
|
// Disk entry, not found in the hashtable, check the index.
|
|
nsAutoCString fileKey;
|
|
rv = CacheEntry::HashingKey(contextKey, aIdExtension, aURI, fileKey);
|
|
|
|
CacheIndex::EntryStatus status;
|
|
rv = CacheIndex::HasEntry(fileKey, &status);
|
|
if (NS_FAILED(rv) || status == CacheIndex::DO_NOT_KNOW) {
|
|
LOG((" index doesn't know, rv=0x%08x", rv));
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
}
|
|
|
|
*aResult = status == CacheIndex::EXISTS;
|
|
LOG((" %sfound in index", *aResult ? "" : "not "));
|
|
return NS_OK;
|
|
}
|
|
|
|
namespace {
|
|
|
|
class CacheEntryDoomByKeyCallback : public CacheFileIOListener
|
|
, public nsIRunnable
|
|
{
|
|
public:
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
explicit CacheEntryDoomByKeyCallback(nsICacheEntryDoomCallback* aCallback)
|
|
: mCallback(aCallback) { }
|
|
|
|
private:
|
|
virtual ~CacheEntryDoomByKeyCallback();
|
|
|
|
NS_IMETHOD OnFileOpened(CacheFileHandle *aHandle, nsresult aResult) override { return NS_OK; }
|
|
NS_IMETHOD OnDataWritten(CacheFileHandle *aHandle, const char *aBuf, nsresult aResult) override { return NS_OK; }
|
|
NS_IMETHOD OnDataRead(CacheFileHandle *aHandle, char *aBuf, nsresult aResult) override { return NS_OK; }
|
|
NS_IMETHOD OnFileDoomed(CacheFileHandle *aHandle, nsresult aResult) override;
|
|
NS_IMETHOD OnEOFSet(CacheFileHandle *aHandle, nsresult aResult) override { return NS_OK; }
|
|
NS_IMETHOD OnFileRenamed(CacheFileHandle *aHandle, nsresult aResult) override { return NS_OK; }
|
|
|
|
nsCOMPtr<nsICacheEntryDoomCallback> mCallback;
|
|
nsresult mResult;
|
|
};
|
|
|
|
CacheEntryDoomByKeyCallback::~CacheEntryDoomByKeyCallback()
|
|
{
|
|
if (mCallback)
|
|
ProxyReleaseMainThread(mCallback);
|
|
}
|
|
|
|
NS_IMETHODIMP CacheEntryDoomByKeyCallback::OnFileDoomed(CacheFileHandle *aHandle,
|
|
nsresult aResult)
|
|
{
|
|
if (!mCallback)
|
|
return NS_OK;
|
|
|
|
mResult = aResult;
|
|
if (NS_IsMainThread()) {
|
|
Run();
|
|
} else {
|
|
NS_DispatchToMainThread(this);
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP CacheEntryDoomByKeyCallback::Run()
|
|
{
|
|
mCallback->OnCacheEntryDoomed(mResult);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMPL_ISUPPORTS(CacheEntryDoomByKeyCallback, CacheFileIOListener, nsIRunnable);
|
|
|
|
} // namespace
|
|
|
|
nsresult
|
|
CacheStorageService::DoomStorageEntry(CacheStorage const* aStorage,
|
|
nsIURI *aURI,
|
|
const nsACString & aIdExtension,
|
|
nsICacheEntryDoomCallback* aCallback)
|
|
{
|
|
LOG(("CacheStorageService::DoomStorageEntry"));
|
|
|
|
NS_ENSURE_ARG(aStorage);
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
nsAutoCString contextKey;
|
|
CacheFileUtils::AppendKeyPrefix(aStorage->LoadInfo(), contextKey);
|
|
|
|
nsAutoCString entryKey;
|
|
nsresult rv = CacheEntry::HashingKey(EmptyCString(), aIdExtension, aURI, entryKey);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
RefPtr<CacheEntry> entry;
|
|
{
|
|
mozilla::MutexAutoLock lock(mLock);
|
|
|
|
NS_ENSURE_FALSE(mShutdown, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
CacheEntryTable* entries;
|
|
if (sGlobalEntryTables->Get(contextKey, &entries)) {
|
|
if (entries->Get(entryKey, getter_AddRefs(entry))) {
|
|
if (aStorage->WriteToDisk() || !entry->IsUsingDisk()) {
|
|
// When evicting from disk storage, purge
|
|
// When evicting from memory storage and the entry is memory-only, purge
|
|
LOG((" purging entry %p for %s [storage use disk=%d, entry use disk=%d]",
|
|
entry.get(), entryKey.get(), aStorage->WriteToDisk(), entry->IsUsingDisk()));
|
|
entries->Remove(entryKey);
|
|
}
|
|
else {
|
|
// Otherwise, leave it
|
|
LOG((" leaving entry %p for %s [storage use disk=%d, entry use disk=%d]",
|
|
entry.get(), entryKey.get(), aStorage->WriteToDisk(), entry->IsUsingDisk()));
|
|
entry = nullptr;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!entry) {
|
|
RemoveEntryForceValid(contextKey, entryKey);
|
|
}
|
|
}
|
|
|
|
if (entry) {
|
|
LOG((" dooming entry %p for %s", entry.get(), entryKey.get()));
|
|
return entry->AsyncDoom(aCallback);
|
|
}
|
|
|
|
LOG((" no entry loaded for %s", entryKey.get()));
|
|
|
|
if (aStorage->WriteToDisk()) {
|
|
nsAutoCString contextKey;
|
|
CacheFileUtils::AppendKeyPrefix(aStorage->LoadInfo(), contextKey);
|
|
|
|
rv = CacheEntry::HashingKey(contextKey, aIdExtension, aURI, entryKey);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
LOG((" dooming file only for %s", entryKey.get()));
|
|
|
|
RefPtr<CacheEntryDoomByKeyCallback> callback(
|
|
new CacheEntryDoomByKeyCallback(aCallback));
|
|
rv = CacheFileIOManager::DoomFileByKey(entryKey, callback);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
class Callback : public nsRunnable
|
|
{
|
|
public:
|
|
explicit Callback(nsICacheEntryDoomCallback* aCallback) : mCallback(aCallback) { }
|
|
NS_IMETHODIMP Run()
|
|
{
|
|
mCallback->OnCacheEntryDoomed(NS_ERROR_NOT_AVAILABLE);
|
|
return NS_OK;
|
|
}
|
|
nsCOMPtr<nsICacheEntryDoomCallback> mCallback;
|
|
};
|
|
|
|
if (aCallback) {
|
|
RefPtr<nsRunnable> callback = new Callback(aCallback);
|
|
return NS_DispatchToMainThread(callback);
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
CacheStorageService::DoomStorageEntries(CacheStorage const* aStorage,
|
|
nsICacheEntryDoomCallback* aCallback)
|
|
{
|
|
LOG(("CacheStorageService::DoomStorageEntries"));
|
|
|
|
NS_ENSURE_FALSE(mShutdown, NS_ERROR_NOT_INITIALIZED);
|
|
NS_ENSURE_ARG(aStorage);
|
|
|
|
nsAutoCString contextKey;
|
|
CacheFileUtils::AppendKeyPrefix(aStorage->LoadInfo(), contextKey);
|
|
|
|
mozilla::MutexAutoLock lock(mLock);
|
|
|
|
return DoomStorageEntries(contextKey, aStorage->LoadInfo(),
|
|
aStorage->WriteToDisk(), aStorage->Pinning(),
|
|
aCallback);
|
|
}
|
|
|
|
nsresult
|
|
CacheStorageService::DoomStorageEntries(nsCSubstring const& aContextKey,
|
|
nsILoadContextInfo* aContext,
|
|
bool aDiskStorage,
|
|
bool aPinned,
|
|
nsICacheEntryDoomCallback* aCallback)
|
|
{
|
|
LOG(("CacheStorageService::DoomStorageEntries [context=%s]", aContextKey.BeginReading()));
|
|
|
|
mLock.AssertCurrentThreadOwns();
|
|
|
|
NS_ENSURE_TRUE(!mShutdown, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
nsAutoCString memoryStorageID(aContextKey);
|
|
AppendMemoryStorageID(memoryStorageID);
|
|
|
|
if (aDiskStorage) {
|
|
LOG((" dooming disk+memory storage of %s", aContextKey.BeginReading()));
|
|
|
|
// Walk one by one and remove entries according their pin status
|
|
CacheEntryTable *diskEntries, *memoryEntries;
|
|
if (sGlobalEntryTables->Get(aContextKey, &diskEntries)) {
|
|
sGlobalEntryTables->Get(memoryStorageID, &memoryEntries);
|
|
|
|
for (auto iter = diskEntries->Iter(); !iter.Done(); iter.Next()) {
|
|
auto entry = iter.Data();
|
|
if (entry->DeferOrBypassRemovalOnPinStatus(aPinned)) {
|
|
continue;
|
|
}
|
|
|
|
if (memoryEntries) {
|
|
RemoveExactEntry(memoryEntries, iter.Key(), entry, false);
|
|
}
|
|
iter.Remove();
|
|
}
|
|
}
|
|
|
|
if (aContext && !aContext->IsPrivate()) {
|
|
LOG((" dooming disk entries"));
|
|
CacheFileIOManager::EvictByContext(aContext, aPinned);
|
|
}
|
|
} else {
|
|
LOG((" dooming memory-only storage of %s", aContextKey.BeginReading()));
|
|
|
|
// Remove the memory entries table from the global tables.
|
|
// Since we store memory entries also in the disk entries table
|
|
// we need to remove the memory entries from the disk table one
|
|
// by one manually.
|
|
nsAutoPtr<CacheEntryTable> memoryEntries;
|
|
sGlobalEntryTables->RemoveAndForget(memoryStorageID, memoryEntries);
|
|
|
|
CacheEntryTable* diskEntries;
|
|
if (memoryEntries && sGlobalEntryTables->Get(aContextKey, &diskEntries)) {
|
|
for (auto iter = memoryEntries->Iter(); !iter.Done(); iter.Next()) {
|
|
auto entry = iter.Data();
|
|
RemoveExactEntry(diskEntries, iter.Key(), entry, false);
|
|
}
|
|
}
|
|
}
|
|
|
|
{
|
|
mozilla::MutexAutoLock lock(mForcedValidEntriesLock);
|
|
|
|
if (aContext) {
|
|
for (auto iter = mForcedValidEntries.Iter(); !iter.Done(); iter.Next()) {
|
|
bool matches;
|
|
DebugOnly<nsresult> rv = CacheFileUtils::KeyMatchesLoadContextInfo(
|
|
iter.Key(), aContext, &matches);
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
if (matches) {
|
|
iter.Remove();
|
|
}
|
|
}
|
|
} else {
|
|
mForcedValidEntries.Clear();
|
|
}
|
|
}
|
|
|
|
// An artificial callback. This is a candidate for removal tho. In the new
|
|
// cache any 'doom' or 'evict' function ensures that the entry or entries
|
|
// being doomed is/are not accessible after the function returns. So there is
|
|
// probably no need for a callback - has no meaning. But for compatibility
|
|
// with the old cache that is still in the tree we keep the API similar to be
|
|
// able to make tests as well as other consumers work for now.
|
|
class Callback : public nsRunnable
|
|
{
|
|
public:
|
|
explicit Callback(nsICacheEntryDoomCallback* aCallback) : mCallback(aCallback) { }
|
|
NS_IMETHODIMP Run()
|
|
{
|
|
mCallback->OnCacheEntryDoomed(NS_OK);
|
|
return NS_OK;
|
|
}
|
|
nsCOMPtr<nsICacheEntryDoomCallback> mCallback;
|
|
};
|
|
|
|
if (aCallback) {
|
|
RefPtr<nsRunnable> callback = new Callback(aCallback);
|
|
return NS_DispatchToMainThread(callback);
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
CacheStorageService::WalkStorageEntries(CacheStorage const* aStorage,
|
|
bool aVisitEntries,
|
|
nsICacheStorageVisitor* aVisitor)
|
|
{
|
|
LOG(("CacheStorageService::WalkStorageEntries [cb=%p, visitentries=%d]", aVisitor, aVisitEntries));
|
|
NS_ENSURE_FALSE(mShutdown, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
NS_ENSURE_ARG(aStorage);
|
|
|
|
if (aStorage->WriteToDisk()) {
|
|
RefPtr<WalkDiskCacheRunnable> event =
|
|
new WalkDiskCacheRunnable(aStorage->LoadInfo(), aVisitEntries, aVisitor);
|
|
return event->Walk();
|
|
}
|
|
|
|
RefPtr<WalkMemoryCacheRunnable> event =
|
|
new WalkMemoryCacheRunnable(aStorage->LoadInfo(), aVisitEntries, aVisitor);
|
|
return event->Walk();
|
|
}
|
|
|
|
void
|
|
CacheStorageService::CacheFileDoomed(nsILoadContextInfo* aLoadContextInfo,
|
|
const nsACString & aIdExtension,
|
|
const nsACString & aURISpec)
|
|
{
|
|
nsAutoCString contextKey;
|
|
CacheFileUtils::AppendKeyPrefix(aLoadContextInfo, contextKey);
|
|
|
|
nsAutoCString entryKey;
|
|
CacheEntry::HashingKey(EmptyCString(), aIdExtension, aURISpec, entryKey);
|
|
|
|
mozilla::MutexAutoLock lock(mLock);
|
|
|
|
if (mShutdown) {
|
|
return;
|
|
}
|
|
|
|
CacheEntryTable* entries;
|
|
RefPtr<CacheEntry> entry;
|
|
|
|
if (sGlobalEntryTables->Get(contextKey, &entries) &&
|
|
entries->Get(entryKey, getter_AddRefs(entry))) {
|
|
if (entry->IsFileDoomed()) {
|
|
// Need to remove under the lock to avoid possible race leading
|
|
// to duplication of the entry per its key.
|
|
RemoveExactEntry(entries, entryKey, entry, false);
|
|
entry->DoomAlreadyRemoved();
|
|
}
|
|
|
|
// Entry found, but it's not the entry that has been found doomed
|
|
// by the lower eviction layer. Just leave everything unchanged.
|
|
return;
|
|
}
|
|
|
|
RemoveEntryForceValid(contextKey, entryKey);
|
|
}
|
|
|
|
bool
|
|
CacheStorageService::GetCacheEntryInfo(nsILoadContextInfo* aLoadContextInfo,
|
|
const nsACString & aIdExtension,
|
|
const nsACString & aURISpec,
|
|
EntryInfoCallback *aCallback)
|
|
{
|
|
nsAutoCString contextKey;
|
|
CacheFileUtils::AppendKeyPrefix(aLoadContextInfo, contextKey);
|
|
|
|
nsAutoCString entryKey;
|
|
CacheEntry::HashingKey(EmptyCString(), aIdExtension, aURISpec, entryKey);
|
|
|
|
RefPtr<CacheEntry> entry;
|
|
{
|
|
mozilla::MutexAutoLock lock(mLock);
|
|
|
|
if (mShutdown) {
|
|
return false;
|
|
}
|
|
|
|
CacheEntryTable* entries;
|
|
if (!sGlobalEntryTables->Get(contextKey, &entries)) {
|
|
return false;
|
|
}
|
|
|
|
if (!entries->Get(entryKey, getter_AddRefs(entry))) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
GetCacheEntryInfo(entry, aCallback);
|
|
return true;
|
|
}
|
|
|
|
// static
|
|
void
|
|
CacheStorageService::GetCacheEntryInfo(CacheEntry* aEntry,
|
|
EntryInfoCallback *aCallback)
|
|
{
|
|
nsIURI* uri = aEntry->GetURI();
|
|
nsAutoCString uriSpec;
|
|
if (uri) {
|
|
uri->GetAsciiSpec(uriSpec);
|
|
}
|
|
|
|
nsCString const enhanceId = aEntry->GetEnhanceID();
|
|
uint32_t dataSize;
|
|
if (NS_FAILED(aEntry->GetStorageDataSize(&dataSize))) {
|
|
dataSize = 0;
|
|
}
|
|
int32_t fetchCount;
|
|
if (NS_FAILED(aEntry->GetFetchCount(&fetchCount))) {
|
|
fetchCount = 0;
|
|
}
|
|
uint32_t lastModified;
|
|
if (NS_FAILED(aEntry->GetLastModified(&lastModified))) {
|
|
lastModified = 0;
|
|
}
|
|
uint32_t expirationTime;
|
|
if (NS_FAILED(aEntry->GetExpirationTime(&expirationTime))) {
|
|
expirationTime = 0;
|
|
}
|
|
|
|
aCallback->OnEntryInfo(uriSpec, enhanceId, dataSize,
|
|
fetchCount, lastModified, expirationTime,
|
|
aEntry->IsPinned());
|
|
}
|
|
|
|
// nsIMemoryReporter
|
|
|
|
size_t
|
|
CacheStorageService::SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const
|
|
{
|
|
CacheStorageService::Self()->Lock().AssertCurrentThreadOwns();
|
|
|
|
size_t n = 0;
|
|
// The elemets are referenced by sGlobalEntryTables and are reported from there
|
|
n += Pool(true).mFrecencyArray.ShallowSizeOfExcludingThis(mallocSizeOf);
|
|
n += Pool(true).mExpirationArray.ShallowSizeOfExcludingThis(mallocSizeOf);
|
|
n += Pool(false).mFrecencyArray.ShallowSizeOfExcludingThis(mallocSizeOf);
|
|
n += Pool(false).mExpirationArray.ShallowSizeOfExcludingThis(mallocSizeOf);
|
|
// Entries reported manually in CacheStorageService::CollectReports callback
|
|
if (sGlobalEntryTables) {
|
|
n += sGlobalEntryTables->ShallowSizeOfIncludingThis(mallocSizeOf);
|
|
}
|
|
|
|
return n;
|
|
}
|
|
|
|
size_t
|
|
CacheStorageService::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const
|
|
{
|
|
return mallocSizeOf(this) + SizeOfExcludingThis(mallocSizeOf);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
CacheStorageService::CollectReports(nsIMemoryReporterCallback* aHandleReport,
|
|
nsISupports* aData, bool aAnonymize)
|
|
{
|
|
nsresult rv;
|
|
|
|
rv = MOZ_COLLECT_REPORT(
|
|
"explicit/network/cache2/io", KIND_HEAP, UNITS_BYTES,
|
|
CacheFileIOManager::SizeOfIncludingThis(MallocSizeOf),
|
|
"Memory used by the cache IO manager.");
|
|
if (NS_WARN_IF(NS_FAILED(rv)))
|
|
return rv;
|
|
|
|
rv = MOZ_COLLECT_REPORT(
|
|
"explicit/network/cache2/index", KIND_HEAP, UNITS_BYTES,
|
|
CacheIndex::SizeOfIncludingThis(MallocSizeOf),
|
|
"Memory used by the cache index.");
|
|
if (NS_WARN_IF(NS_FAILED(rv)))
|
|
return rv;
|
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
// Report the service instance, this doesn't report entries, done lower
|
|
rv = MOZ_COLLECT_REPORT(
|
|
"explicit/network/cache2/service", KIND_HEAP, UNITS_BYTES,
|
|
SizeOfIncludingThis(MallocSizeOf),
|
|
"Memory used by the cache storage service.");
|
|
if (NS_WARN_IF(NS_FAILED(rv)))
|
|
return rv;
|
|
|
|
// Report all entries, each storage separately (by the context key)
|
|
//
|
|
// References are:
|
|
// sGlobalEntryTables to N CacheEntryTable
|
|
// CacheEntryTable to N CacheEntry
|
|
// CacheEntry to 1 CacheFile
|
|
// CacheFile to
|
|
// N CacheFileChunk (keeping the actual data)
|
|
// 1 CacheFileMetadata (keeping http headers etc.)
|
|
// 1 CacheFileOutputStream
|
|
// N CacheFileInputStream
|
|
if (sGlobalEntryTables) {
|
|
for (auto iter1 = sGlobalEntryTables->Iter(); !iter1.Done(); iter1.Next()) {
|
|
CacheStorageService::Self()->Lock().AssertCurrentThreadOwns();
|
|
|
|
CacheEntryTable* table = iter1.UserData();
|
|
|
|
size_t size = 0;
|
|
mozilla::MallocSizeOf mallocSizeOf = CacheStorageService::MallocSizeOf;
|
|
|
|
size += table->ShallowSizeOfIncludingThis(mallocSizeOf);
|
|
for (auto iter2 = table->Iter(); !iter2.Done(); iter2.Next()) {
|
|
size += iter2.Key().SizeOfExcludingThisIfUnshared(mallocSizeOf);
|
|
|
|
// Bypass memory-only entries, those will be reported when iterating the
|
|
// memory only table. Memory-only entries are stored in both ALL_ENTRIES
|
|
// and MEMORY_ONLY hashtables.
|
|
RefPtr<mozilla::net::CacheEntry> const& entry = iter2.Data();
|
|
if (table->Type() == CacheEntryTable::MEMORY_ONLY ||
|
|
entry->IsUsingDisk()) {
|
|
size += entry->SizeOfIncludingThis(mallocSizeOf);
|
|
}
|
|
}
|
|
|
|
// These key names are not privacy-sensitive.
|
|
aHandleReport->Callback(
|
|
EmptyCString(),
|
|
nsPrintfCString("explicit/network/cache2/%s-storage(%s)",
|
|
table->Type() == CacheEntryTable::MEMORY_ONLY ? "memory" : "disk",
|
|
iter1.Key().BeginReading()),
|
|
nsIMemoryReporter::KIND_HEAP,
|
|
nsIMemoryReporter::UNITS_BYTES,
|
|
size,
|
|
NS_LITERAL_CSTRING("Memory used by the cache storage."),
|
|
aData);
|
|
}
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
// nsICacheTesting
|
|
|
|
NS_IMETHODIMP
|
|
CacheStorageService::IOThreadSuspender::Run()
|
|
{
|
|
MonitorAutoLock mon(mMon);
|
|
mon.Wait();
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
CacheStorageService::IOThreadSuspender::Notify()
|
|
{
|
|
MonitorAutoLock mon(mMon);
|
|
mon.Notify();
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
CacheStorageService::SuspendCacheIOThread(uint32_t aLevel)
|
|
{
|
|
RefPtr<CacheIOThread> thread = CacheFileIOManager::IOThread();
|
|
if (!thread) {
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
}
|
|
|
|
MOZ_ASSERT(!mActiveIOSuspender);
|
|
mActiveIOSuspender = new IOThreadSuspender();
|
|
return thread->Dispatch(mActiveIOSuspender, aLevel);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
CacheStorageService::ResumeCacheIOThread()
|
|
{
|
|
MOZ_ASSERT(mActiveIOSuspender);
|
|
|
|
RefPtr<IOThreadSuspender> suspender;
|
|
suspender.swap(mActiveIOSuspender);
|
|
suspender->Notify();
|
|
return NS_OK;
|
|
}
|
|
|
|
} // namespace net
|
|
} // namespace mozilla
|